This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3235SF: Mqtt reconection after wifi connection lost

Part Number: CC3235SF

Hi, I am using the mqtt example, and I am interested in stability against wifi connection problems.

This is the situation: I start the example, send some messages and then switch off the wifi router. After that the device hangs an no longer responds to button press. But it is able to reconnect to the router after I switch it on.

Here is the output of the console.

[09:34:32:802] ␍[GEN::INFO] recived a message 0␊

[09:34:41:186] ␍[GEN::INFO] APP_MQTT_PUBLISH␍␊

turn off the router

[09:34:41:186]

[09:34:41:186] ␍Device disconnected from the AP on an ERROR..!! ␊

[09:34:45:996] ␍[GEN::TRACE] MQTT CLIENT CB: DISCONNECT␍␊

[09:34:51:515]

[09:34:51:515] ␍[GEN::TRACE] CONTEXT THREAD: MQTTClient_run RETURN␍␊

[09:34:51:522]

[09:34:51:522] ␍[GEN::TRACE] CONTEXT THREAD: MQTT CLIENT DELETED␊

[09:34:51:529] ␍[GEN::TRACE] CONTEXT THREAD EXIT␍␊

[09:34:51:529]

[09:34:51:529] ␍[GEN::TRACE] MQTT APP THREAD: DISCONNECT␍␊

[09:34:51:538]

[09:34:51:538] ␍[GEN::INFO] MQTT_EVENT_SERVER_DISCONNECT␍␊

[09:34:51:538]

turn on the router

[09:34:51:538] ␍[WLAN EVENT] STA Connected to the AP: Miljor2 , BSSID: a4:52:6f:0:da:f2␊

[09:35:16:642] ␍[NETAPP EVENT] IP acquired by the device␊

[09:35:16:642] ␍Device disconnected from the AP on an ERROR..!! ␊

[09:35:20:649] ␍[WLAN EVENT] STA Connected to the AP: Miljor2 , BSSID: a4:52:6f:0:da:f2␊

[09:35:29:048] ␍[NETAPP EVENT] IP acquired by the device␊

[09:35:29:058] ␍[network]SL_WLAN_EVENT_STA_ADDED ␊

[10:22:52:777] ␍␍When device is in AP mode and any client connects to it..␍␊

[10:22:52:777] ␍[NETAPP EVENT] IP Leased to Client: IP=192.168.44.100 , ␍␊

[10:22:52:777]

  • Hi Javier,

    Does the button start working again after the device reconnects?

    Best regards,

    Sarah

  • No, the device does not respond to any button pess nor any external mqtt message.

  • Hi Javier,

    In this demo, when the button handlers are called (pushButtonPublishHandler and pushButtonConnectionHandler), they disable the interrupt and wait for the MQTT_EventCallback to re-enable the interrupt on a connection or client disconnect event. You can decide to handle these interrupts on a server disconnect as well.

    Additionally, when the server disconnects, the demo only tries to reconnect once. If the connection to the AP is still down, this reconnect will fail. In your demo, you can try additional reconnections to the MQTT server triggered by a successful connection to the AP.

    Best regards,

    Sarah

  • the demo only tries to reconnect once

    Thanks for the fast reply ! everything is much clear.

    Can you please point out witch lines of code handle the one try reconnection?

    How can y subscribe to the event triggered by a successful connection to the AP?

  • Hi Javier,

    The MQTT_EVENT_SERVER_DISCONNECT case in MQTT_EventCallback sends one APP_MQTT_CON_TOGGLE event to the appQueue (handled around line 692).

    The connection event for the AP is the SL_WLAN_EVENT_CONNECT event in the SimpleLinkWlanEventHandler in network_if.c. You can add a message queue or some other semaphore to this event handler.

    Best regards,

    Sarah