eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
315 stars 178 forks source link

Missed DISCONNECT message on sleeping node #169

Closed LucDigi closed 4 years ago

LucDigi commented 4 years ago

I'm using the nRF52840 chip together with the nRF SDK 15.3 and a modified Thread MQTT-SN example, it all works fine for a while and sleep mode works without any problems. Until, I suspect, a DISCONNECT message from the gateway to the node gets lost and the node gets stuck waiting for its permission to sleep. I cannot really find in the MQTT-SN standard what should be done in such a case, any advise on a possible solution would be welcome :)

ty4tw commented 4 years ago

Hi LucDigi,

According to the specification, Upon receiving such a DISCONNECT message, a client should try to setup the connection again by sending a CONNECT message to the gateway or server.

image

LucDigi commented 4 years ago

Hi ty4tw,

Yes I understand that part of the protocol, my question is what is the proper procedure if the DISCONNECT message from the gateway to the node gets dropped/lost? As this seems to cause my nodes to hang after a few hours to days. So technically this isn't really a gateway issues, as the gateway can never know if the node received it or not.

Still my node will get stuck in a waiting state for the DISCONNECT message it never got. So if I now detect this scenario, I manually modify the MQTT-SN state from MQTTSN_CLIENT_WAITING_FOR_SLEEP to MQTTSN_CLIENT_AWAKE before sending a connect message, otherwise the MQTT-SN code provided in the nRF52 SDK will give an invalid state error when trying to send a connect message. It might thus be an issues related to who the MQTT-SN code in the nRF52 SDK handles this issues, but I don't know if this library is written by Nordic or if they also get it from another source.

ty4tw commented 4 years ago

This Issue is same as #171.