• 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:

      mqtt.on('disconnected', function() {
        console.log("MQTT disconnected... reconnecting.");
        setTimeout(function() {
          mqtt.connect();
        }, 1000);
      });
    

    with

      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);
      });
    

    and see if that helps?

About

Avatar for Gordon @Gordon started