This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MQTTSN Example: Client unable to reconnect to Broker after timeout


I am currently using mqttsn publisher exams with keep allive time of 30 seconds, so according to MQTT standard if period of inactivity will be 45 second and the client is unable to recieve ping response or broker doesn't recieve ping request from client in fixed time it will break the connection.

I would like to know how could I reconnect client to the broker once the broker timesout the client connection. Currently I am checking the state of client using isConnected api but it indeed take 3-4 minutes to restablish a connection. 

I would like to re-establish a connection as soon as the mqtt-sn client get's time out. I can't wait for 2-3 minutes to connect to broker. Also currently I have to wait for the next publish to check whether my client is connected to broker or not.

For Example: if I take a python MQTT client with keep alive time of 60 second and turn off and turn on the mosquito broker , the python client immediately connects within few seconds. I want some solution like that for mqtt-sn client. 

Please provide some tried and tested code or help for the same.  

  • Hi Brian

    Could you explain your setup, so that I can try to reproduce your problem?

    What hardware and which examples are you using?

    Sigurd Hellesvik

  • Hello Sigurd,

    In my setup I have a Sleepy End device running mqtt-sn sleepy publisher example. The mqtt-sn gateway setup on RPi is configured to send data on local mosquitto broker running on my PC. 

    1 : in mqttsn sleepy publisher example I am using app timer timeout to publish data at every 20 sec. I have currently kept mqtt-sn keep alive timeout to 60 seconds. 

    So currently what is happening is, I am checking wether my client is connected to broker or not by checking client state. If it's connected than only I am publishing data. So suppose I have just published data to local mosquitto broker, and if I restart mosquitto broker service it takes my mqtt-sn client around 2 minutes (1.5*keep alive time + client state update delay and connection establishing time etc) to publish next data. 

    if you take a normal python MQTT client connected to broker, if you restart the broker it will connect to broker instantly without much of delay. 

    So can you tell me is there any way I can connect to broker if timeout as soon as possible. 

    2:  Query regarding Poll period in Mqtt-sn sleepy publisher example

    Also I would like to know what's the use of polling period in mqtt-sn sleepy publisher example. From openthread docs it's state it basically is the time interval after which a client checks for data with its parent. But as mqtt-sn publisher is publishing, not receiving anything so what's the use of poll period in that example. Also the two function name wakeup and sleep is confusing as in wakeup we are just changing poll period. 

    So does  this mean  in mqttsn sleepy  publisher example if I want to make my device sleep for 1, minutes I can pass the 60,000 as polling period for that device. Is that the purpose of polling period in sleepy publisher example ? And if it brings the device in sleep state, than will app timer timeout after 20 second will wake sleep end device from sleep state ? 

    It will be helpful if you can elaborate the usage of polling period in mqttsn publisher example and how can I increase the time my sleep end device stay in sleep state. 

  • Hi Brian

    To test this I will have to set up a MQTT-SN router.
    I will return here with my results tomorrow.

    Sigurd Hellesvik

  • Hi Brian

    I will have to fix a bug with my install of the MQTT-SN router.

    I think I will be able to fix this at the start of next week. Sorry for this delay.

    Sigurd Hellesvik