That's interesting - what happens if you switch back to the original MQTT?
Are you still doing the thing where you save when there's an active connection? It could be that the connection that was active when you saved tries to ping, and can't because it finds out it is closed. It'll then clean up and emit the disconnected event, so that it tries to reconnect.
However in the mean time you already created a second MQTT connection in onInit.
var thisMQTT = mqtt;
mqtt.on('disconnected', function() {
if (mqtt!=thisMQTT) {
console.log("MQTT disconnected - but we already have a new MQTT");
return;
}
console.log("MQTT disconnected... reconnecting.");
setTimeout(function() {
mqtt.connect();
}, 1000);
});
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.
That's interesting - what happens if you switch back to the original MQTT?
Are you still doing the thing where you save when there's an active connection? It could be that the connection that was active when you saved tries to ping, and can't because it finds out it is closed. It'll then clean up and emit the
disconnected
event, so that it tries to reconnect.However in the mean time you already created a second MQTT connection in
onInit
.You could try replacing:
with
and see if that helps?