Topic: PIC32 MQTT state machine lock-up

Hi,

We use wolfmqtt client on pic32 with TLSv1.2.
In some cases (usually related to internet connection problems) we see the following scenario:
The app state machine rolls into MqttClient_NetConnect():

int rc = MqttClient_NetConnect(&appData.myClient, (const char *)&appData.host,                sds_web_config.comm_setting.mqtt_port.Val, MQTT_DEFAULT_CMD_TIMEOUT_MS, SDS_TLS/*NULL*/, mqtt_sds_tls_cb/*NULL*/);

Since it fails to connect, timeout of 20 seconds sends the state machine to ERROR state:

        case APP_TCPIP_ERROR:
        {
            /*no matter what the issue is, free the tcp/mqtt resources and re-connect
              this will include cases of: cable removal, router disconnects, poor internet connection*/
            

            rc= MqttClient_NetDisconnect(&appData.myClient);

            if (rc== MQTT_CODE_SUCCESS)
            {
                
                   //start all over again including dhcp
                   appData.state = APP_TCPIP_WAIT_INIT; 


                   /* Free resources */
                    if (appData.myClient.tx_buf) WOLFMQTT_FREE(appData.myClient.tx_buf);
                    if (appData.myClient.rx_buf) WOLFMQTT_FREE(appData.myClient.rx_buf);
                    
                    /* Cleanup network */
                    MqttClientNet_DeInit(&appData.myNet); 
              
            }
            
        }
        break;

and goes back to MqttClient_NetConnect() state.

Then after about 20 loops, the MqttClient_NetConnect() function returns NetConnect: Rc=-1, SoErr=111

And from that poin on the MqttClient_NetConnect() function never recovers - therefore when internet connection comes back, state machine gets locked-up in a non-connect state.

In order to bring the mqtt connection back again, we power the board off and then on again

Do you know how can we make the state-machine recover from this lock-up?

Regards,

Gil

Share

Re: PIC32 MQTT state machine lock-up

Hello Gil,

Thank you for contacting wolfSSL Support. Is your application based on the wolfMQTT example from Microchip? Have you reviewed the latest version from the Harmony 3 Content Manager?

It looks like there were a number of changes to address initialization (and uninit) using the "Net_Glue" component.

Without having seen the whole execution loop, I can't say for sure. In the snippet you provided I don't see in where the state is being reset.

Thanks,
Eric @ wolfSSL Support

EDIT: I see the state reset, now. But without seeing the rest of the application loop I don't know if it is being reinitialized.