Sensor node never reconnects after MQTT gateway reset

  • I have built an MQTT client gateway and a humidity node, both of them working properly in normal circumstances.

    Mysensors library: 2.0.0 (downloaded via the Arduino IDE library manager)

    When I power down the ethernet gateway for a couple of minutes and switch it back on, the gateway itself starts up properly but the humidity node will not be able to send messages to it.

    The serial output of the humidity node looks like this:

    Humidity: 60.20
    Humidity: 60.30
    Humidity: 60.20
    Temperature: 27.30
    Humidity: 60.20

    I have waited ~10minutes but no reconnect. The node currently measures / send every 2 seconds.

    The humidity node properly reconnects after a manual reset and after that the newly sent values show up in OpenHAB as well.

    What do I have to do to make the nodes automatically reconnect in a case like this? Since I plan a large number of nodes and some of my nodes will be placed at problematic locations, it is imperative that auto-reconnect happens properly.

    Any help is appreciated.

  • With a little digging I have found an other forum topic dealing with the same problem:

    I have experimented with the suggestion found there and - in my case - the 1000ms was still not enough for a full reconnect before the node goes to sleep, so I made it 3000ms. This seems to allow a reconnect all the time (at least in my environment).

    I placed the following transport testing/healing code right before the node goes to sleep:

      // @TODO remove after testing gateway outage
      if (!isTransportOK()) {
        #ifdef MY_DEBUG
        Serial.print("Transport ERROR. Waiting for a proper transport reconnect");

    I am unsure why MySensors doesn't have this self-healing element built-in. Maybe it is only a bug, maybe it has some deeper reason.

  • Mod

    @Andras-Soltesz it was something that wasn't considered in the library, so sketch developers need to handle it manually (as you do). In the next version of MySensors sketch developers will not need to handle it manually, thanks to great work by @tekka

    See for details.

    tekka007 created this issue in mysensors/MySensors

    closed Redesign sleep() functions #558

  • Great. I added a comment to the GitHub issue to signify its importance.