This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

Hello,

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.  

Parents
  • Hi

    I have asked the developers for how to automatically detect if the MQTT broker disconnects, and will return to you with an answer on this by Tuesday.

    In the meantime, you could try to manually disconnect and connect the client when you get a timeout event.
    This should make the client able to reconnect after a single timeout interval rather than multiple.

    Regards,
    Sigurd Hellesvik

Reply
  • Hi

    I have asked the developers for how to automatically detect if the MQTT broker disconnects, and will return to you with an answer on this by Tuesday.

    In the meantime, you could try to manually disconnect and connect the client when you get a timeout event.
    This should make the client able to reconnect after a single timeout interval rather than multiple.

    Regards,
    Sigurd Hellesvik

Children
  • Hello Sigurd,

    I will wait for your response. 

    Can you tell me how can I implement your suggestion. If a event timeout occur it's reason could be anything I guess. And  also for a client to get timedout, it will wait for 1.5 times the keep alive time before disconnecting if no ping response is received. 

  • Hi

    Sigurd Hellesvik said:
    In the meantime, you could try to manually disconnect and connect the client when you get a timeout event.

    Yea, this will be inefficient. So lets try to find a way to find if there is another way first.

    First:

    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. 

    You test a MQTT client versus a MQTT-SN client. Could you try to find a python MQTT-SN server to test with?
    This is to test if the issue is with the MQTT-SN protocol.

    Secondly:

    Do you receive a disconnect callback in the code at the nRF client when you disconnect the broker?

    Third:

    A sniffer log would be useful. Could you set up the nRF Sniffer for 802.15.4, and sniff to see if a disconnect event is sent when you disconnect the broker?

    Regards,
    Sigurd Hellesvik

  • Secondly:

    Do you receive a disconnect callback in the code at the nRF client when you disconnect the broker?

    Third:

    Hello, i have tried debugging using Segger Studio with both mqttsn publisher/sleepy publisher example and adding a break point at below mqttsn_event handler case.Program never stops here at the below code, so the following event never get generated.

       

        case MQTTSN_EVENT_DISCONNECT_PERMIT:
                NRF_LOG_INFO("MQTT-SN event: Client disconnected.\r\n");
                disconnected_callback();
                device_connection_status = DEVICE_DISCONNECTED;
                break;
    



    the disconnect_callback function never gets called. So second answer is NO.

    Third:

    A sniffer log would be useful. Could you set up the nRF Sniffer for 802.15.4, and sniff to see if a disconnect event is sent when you disconnect the broker?

    Third:
    A sniffer log would be useful. Could you set up the nRF Sniffer for 802.15.4, and >sniff to see if a disconnect event is sent when you disconnect the broker?


    I don't see any disconnect packet sent, you can also verify the sniffed packets. I have attached two sniffer package: 1) After Broker has been shutdown 2) Full Communication

    afterbrokerdisconnected.pcapng

    FullPacketCapture.pcapng


    Regarding first i would try to find out by R&D.

    You test a MQTT client versus a MQTT-SN client. Could you try to find a python MQTT-SN server to test with?
    This is to test if the issue is with the MQTT-SN protocol.
Related