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.

CC3200: CC3200 MQTT Client disconnect procedure

Part Number: CC3200

Hi,

I'm working with SDK 1.2.0 and CCS version 6.1.3.00033

I've a  problem with sl_ExtLib_MqttClientDisconnect function.  It looks that it never returns.

I've made a slight modification to mqtt_client application to be able to initiate disconnect on SW3 button press.

 else if(PUSH_BUTTON_SW3_PRESSED == RecvQue.event)
        {
            Button_IF_EnableInterrupt(SW3);
            
            if(iConnBroker>=1)
           	{
  
            	UART_PRINT("Before disconnect: \n\r");
            	sl_ExtLib_MqttClientDisconnect((void*)local_con_conf[iCount].clt_ctx);
                UART_PRINT("After Disconnect Ok: \n\r");

           	}

And this is terminal output

Before disconnect:
C: FH-B1 0xe0 to net 17, Sent (2 Bytes) [@ 12]
C: TX closing Net 17 [DISCONN]
C: RX closing Net 17 [-7]
C: Cleaning session for net 17
C: Net 17 now closed
disconnect from broker  xxx.xxx.xxx.xxx  --> printed from sl_MqttDisconnect

After this there no more activity in MqttClient task.  It seem to be waiting forever and nothing happens

This problem was mentioned also  at https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/t/553736

  • Hi Menashe,

    Can you check if you are seeing any return messages on that function? Does it stay in sl_ExtLib_MqttClientDisconnect? If you pause the debugger in CCS, it will show you in the Debug window what function you are in and its call hierarchy.

    Also, is there a reason you have a (void*) before the clt_ctx? That type should already be void *clt_ctx in the connect_config struct.

    Best regards,
    Sarah
  • Hi Sarah,

    It never returns from sl_ExtLib_MqttClientDisconnect. I'm using SDK example based on FreeRTOS so pausing in debugger is not so helpful as I can only see the stack of the paused task and it always IDLE task.

    I've stepped into sl_ExtLib_MqttClientDisconnect and found that it hangs  inside  macro  MT_GIVE_ACK_WAIT_MT_TAKE_RC(client_ctx, retval);  

    Most likely it waits forever  for  ACK_RX_SIGNAL_WAIT(&(client_ctx->ack_sync_obj)) 

    The only  reason for (void *) is copy-paste . I don't know why but this is the way it is used all over the sample code.

  • Hi Menashe,

    It looks like it is waiting on a response from the server, as that macro is also used in other MQTT functions. What server are you using? Are you disconnecting and reconnecting or only disconnecting once?

    Best regards,
    Sarah
  • Hi Sarah,

    Is it expected to wait for response  forever? May be there is some timeout that must be configured?
    I'm testing it with mosquito server.
    Disconnect  and reconnect supposed to be a normal procedure for our use case.
    As  temporary  workaround I'm resetting the whole module but this results in unpleasant user expirience

  • Hi Menashe,

    Apologies, I meant a response from the network processor. I was able to replicate your issue and am still trying to debug.

    Best regards,
    Sarah
  • Hi Menashe,

    It looks like there may be a bug in the current implementation of sl_ExtLib_MqttClientDisconnect. We've created a work-around for now, but to be clear, it has not been extensively tested.

    In lines 244-249 of netapps/mqtt/sl/sl_mqtt_client.c, replace:

    		if(MQTT_DISCONNECT == client_ctx->awaited_ack) {
    				;   /* App is already aware - so do nothing */
    		} else if(client_ctx->awaited_ack != 0) {
    				client_ctx->awaited_ack = MQTT_DISCONNECT;
    				ACK_RX_SIGNAL_POST(&client_ctx->ack_sync_obj);
    		}

    with the code:

    		if(client_ctx->awaited_ack != 0) {
    			client_ctx->awaited_ack = MQTT_DISCONNECT;
    			ACK_RX_SIGNAL_POST(&client_ctx->ack_sync_obj);
    		}

    Please let me know if that resolves your issue.

    Best regards,

    Sarah

  • Hi Sarah,

    Thank you for a workaround.

    The main problem has been solved  and  sl_ExtLib_MqttClientDisconnect function now works but the return code of this function is incorrect.

    It successfuly sends a disconnect request and receives MQTT_DISCONNECT ACK  but returns -1.

    It seems that the pronlem is inside MT_GIVE_ACK_WAIT_MT_TAKE_RC  macro.