problem is the module starts a watch by itself, so your setInterval starts a watch every 2s, which might lead to the memory problem
but you can create a custom module locally (put it into modules folder and call it myDCF77 or something)
and use it this way
setInterval(function(){
var watchId;
var result = require('myDCF77').connect(B1, function(err, date, info) {
if (err) {
console.log("Invalid time received: " + err);
}
else {
console.log('Date from DCF77 ' + date.toString());
if(watchId) {
clearWatch(watchId);
watchId = undefined;
}
}
});
watchId = result.watchId;
}, 1200000);
... the above needs a change inside the module as
exports.connect = function(dataPin, callback) {
var dcf = {
last : getTime(),
bits : '',
watchId: undefined
};
dcf.watchId = setWatch(function (e) {
// Work out what bit we got
var d = e.time-e.lastTime;
var bit = (d<0.15)?0:1;
// if we had a 2 sec gap then it's the beginning of a minute
if (e.time - dcf.last > 1.5) {
decode(dcf.bits, callback);
dcf.bits = "";
}
dcf.last = e.time;
// now add this bit of data
dcf.bits += bit;
if (dcf.bits.length>59)
dcf.bits = dcf.bits.substr(-59);
}, dataPin, { edge:"falling", repeat:true, debounce:75 });
return dcf;
};
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
problem is the module starts a watch by itself, so your setInterval starts a watch every 2s, which might lead to the memory problem
but you can create a custom module locally (put it into modules folder and call it myDCF77 or something)
and use it this way
... the above needs a change inside the module as
keep all other functions as is