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 MQTT client failed with MQP alloc failed with msg type 0x1

Other Parts Discussed in Thread: CC3200, CC3100, CC3200SDK

Hi,

   While using the cc3200 sdk 1.1.0 mqtt library, I come into a problem while testing error handling. The scenario can be easily reproduced by

1. Using mqtt client and set the keepalive value to zero

2. Turn off the MQTT server

3. A timer is used to ask the MQTT client to periodically connect to to the unexisted MQTT server

4. After a few try, a MQP alloc failed error with msg type 0x1 is reported.

5. At the stage, when the MQTT server is up, we are not able to connect to the server any more. We have tried to re-create the MQTT context, by the alloc error still reported. Please let me know how we can release those memory. 

The following is the log file and the code we have.

Thanks,

Regards,

Michael

Version: Client LIB 1.0.3, Common LIB 1.1.1.
[MQTTClientTask]MQTT Client lib initialization success
[MQTTClientTask] Create MQTT Context
[StaleCounter]increment counter 1
Recieve event for MQTTQueue 81
[MQTTClient] result = FFFFFFFF

[MQTTClient] Broker connect fail for conn
[MQTTClient] Client disconnect
[StaleCounter]set to STale Counter
Recieve event for MQTTQueue 81
[MQTTClient] result = FFFFFFFF

[MQTTClient] Broker connect fail for conn
[MQTTClient] Client disconnect
[TimerGPIOTASK] Receive GPIO INT
[Motion Counter]set to Motion Counter
[TimerGPIOTASK] Receive GPIO INT
[TimerGPIOTASK] Receive GPIO INT
[StaleCounter]increment counter 0
Recieve event for MQTTQueue 81
MQP alloc failed - msg type 0x01
[MQTTClient] result = FFFFFFFF

[MQTTClient] Broker connect fail for conn

[MQTTClient] Client disconnect
[MQTTClient] delete context  <<<<
[StaleCounter]increment counter 1
Recieve event for MQTTQueue 81
[MQTTClientTask] Create MQTT Context <<<<<
[StaleCounter]set to STale Counter
Recieve event for MQTTQueue 81
MQP alloc failed - msg type 0x01  <<<<<
[MQTTClient] result = FFFFFFFF

 

if(!local_con_conf[0].is_initial){
lRetVal = sl_ExtLib_MqttClientInit(&Mqtt_Client);
if(lRetVal != 0)
{
// lib initialization failed
Report("[MQTTClientTask] MQTT Client lib initialization failed\n\r");
break;

}

else {
local_con_conf[0].is_initial = true;
UART_PRINT("[MQTTClientTask]MQTT Client lib initialization success\n\r");
}
}

if(local_con_conf[0].clt_ctx == NULL) {
UART_PRINT("[MQTTClientTask] Create MQTT Context\n\r");
local_con_conf[0].clt_ctx= sl_ExtLib_MqttClientCtxCreate(&local_con_conf[0].broker_config,
&local_con_conf[0].CallBAcks,
&(local_con_conf[0]));

//
// Set Client ID
//

sl_ExtLib_MqttClientSet((void*)local_con_conf[0].clt_ctx,
SL_MQTT_PARAM_CLIENT_ID,
local_con_conf[0].client_id,
strlen((char*)(local_con_conf[0].client_id)));
}

else if(!local_con_conf[0].is_connected){
signed long result = sl_ExtLib_MqttClientConnect((void*)local_con_conf[0].clt_ctx,
local_con_conf[0].is_clean,
local_con_conf[0].keep_alive_time);
UART_PRINT("[MQTTClient] result = %2X\n\r", result);
if((result & 0xFF) != 0)
{
CLR_STATUS_BIT(g_ulmqttStatus, STATUS_BIT_MQTT_SEND);
UART_PRINT("\n\r[MQTTClient] Broker connect fail for conn \n\r");
sl_ExtLib_MqttClientDisconnect((void*)local_con_conf[0].clt_ctx);
UART_PRINT("[MQTTClient] Client disconnect\n\r");
if(local_con_conf[0].counter < MQTT_MAX_COUNTER)
local_con_conf[0].counter++;

else {
UART_PRINT("[MQTTClient] delete context\n\r");
sl_ExtLib_MqttClientCtxDelete(local_con_conf[0].clt_ctx);
local_con_conf[0].counter = 0;
local_con_conf[0].clt_ctx = NULL;

}
}
else {
local_con_conf[0].is_connected = TRUE;
local_con_conf[0].counter = 0;
}
}

  • Hi,

    We will check and get back to you on this.

    Regards.
    Gigi Joseph.
  • Hi Michael,

    We have identified couple of issues in the MQTT library and added the fix for them at the wiki.
    processors.wiki.ti.com/.../CC32xx_Summary_of_Known_Issues

    Please let us know if your issue is resolved with these changes.

    Regards,
    Ankur
  • Hi Michael,

    I am closing this thread, if you have follow up queries please open a new thread and a link to this one for reference.

    Regards,
    Ankur
  • Hi Ankur,

    I get the same error even after implementing the fixes suggested above. I have tried this bit of code:

    <code>
    retry: osi_Sleep(2000);
    if((local_con_conf[iCount].is_connected == false) )
    {
    if(sl_ExtLib_MqttClientConnect((void*)local_con_conf[iCount].clt_ctx,true,0) < 0)
    {
    UART_PRINT("\n\rBroker connect fail for conn no. %d \n\r",iCount+1);
    UART_PRINT("\n\riCount = %d\n\r",iCount);
    goto retry;
    }
    </code>

    I get this on the UART:
    MQP alloc failed - msg type 0x01
    Broker connect fail for conn no. 1

    While I am trying to connect to the MQTT server I have manually switched off the internet access as the MQTT server is on the cloud. I was expecting a broker connect fail error but I don't get as to why the MQP error occurs, even after the using the said fixes.

    Any help regarding this would be appreciated.

  • Hi,

    I encountered the same issue in CC3100, SDK v 1.0.0.10.
    is the same solution apply to CC3100 ?
    I didn't see any fixes in: "CC31xx_Summary_of_Known_Issues#SDK_1.0.0_Known_issues"

    BR,
    Guy Roby,
    Embedded engineer,
    Sensibo
  • I had did same changes as described in wiki but same problem mqp alloc failed.

    Basically I am doing continuous ping to server for checking internet connection.But after 15 min I got internet connection and i got this error.

    MQP alloc failed : msg type 0x08

  • I applied all the fixes noted in the known issues FAQ for SDK 1.1 and linked them into my MQTT client project and still have errors on reconnects. Is there a fix for this or an explanation of the problem?

    I made some changes to the MQTT example project so it closely matches my requirements;

    1. It uses SSL to connect to the broker (I used the script found here to generate me a certificate: https://gist.github.com/toolness/3073310)

    2. I changed the logic so the example can attempt a reconnect once it detects a MQTT failure.

    And the error I get from the serial port:

    Version: Client LIB 1.0.3, Common LIB 1.1.1.

    C: FH-B1 0x10 to net 80, Sent (46 Bytes) [@ 1816]

    C: Rcvd msg Fix-Hdr (Byte1) 0x20 from net 80 [@ 1816]

    Success: conn to Broker no. 1

     MQP alloc failed - msg type 0x08

     Subscription Error for conn no. 1

    MQP alloc failed - msg type 0x0a

    Disconnecting from the broker

     Restarting the Application

    Here is a diff of the main.c for the mqtt client example that allows me to show the reconnection failures. 

    *** /Desktop/for_ti.c Sun Oct 30 22:20:10 2016

    --- C:/ti/CC3200SDK_1.1.0/cc3200-sdk/example/mqtt_client/main.c Mon Feb 09 17:14:17 2015

    ***************

    *** 80,88 ****

      #define WILL_RETAIN             false

      

      /*Defining Broker IP address and port Number*/

    ! #define SERVER_ADDRESS          "m10.cloudmqtt.com" //"messagesight.demos.ibm.com"

    ! #define PORT_NUMBER             24342

      

      #define MAX_BROKER_CONN         1

      

    --- 80,87 ----

      #define WILL_RETAIN             false

      

      /*Defining Broker IP address and port Number*/

    ! #define SERVER_ADDRESS          "messagesight.demos.ibm.com"

    ! #define PORT_NUMBER             1883

      

      #define MAX_BROKER_CONN         1

      

    ***************

    *** 97,103 ****

      #define KEEP_ALIVE_TIMER        25

      

      /*Clean session flag*/

    ! #define CLEAN_SESSION           false

      

      /*Retain Flag. Used in publish message. */

      #define RETAIN                  1

    --- 96,102 ----

      #define KEEP_ALIVE_TIMER        25

      

      /*Clean session flag*/

    ! #define CLEAN_SESSION           true

      

      /*Retain Flag. Used in publish message. */

      #define RETAIN                  1

    ***************

    *** 182,189 ****

      

      /*Message Queue*/

      OsiMsgQ_t g_PBQueue;

    - char *security_file_list1[] = {"/cert/ca.crt"};

      

      /* connection configuration */

      connect_config usr_connect_config[] =

    --- 181,186 ----

    ***************

    *** 191,225 ****

          {

              {

                  {

    ! (SL_MQTT_NETCONN_URL | SL_MQTT_NETCONN_SEC) ,

    ! "xxxxxxxx.amazonaws.com", 

    !                 8884,

    ! SL_SO_SEC_METHOD_TLSV1_2, // Mosquitto defaults to TLSV1_2 normally

    ! SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256, // Cipher selection

    !                 1, // Only one file needed, the certificate

    ! security_file_list1  // Points to name of the file in CC3200 NV memory

                  },

                  SERVER_MODE,

    !             true, // Blocking calls?

              },

    !         NULL, // CTX, do not set

    ! "CC3200", // CLIENT ID

    ! NULL, // USERNAME (Mosquitto login)

    ! NULL, // PASSWORD (Mosquitto login)

    !         true, // Clean session?

              KEEP_ALIVE_TIMER,

    !         {Mqtt_Recv, sl_MqttEvt, sl_MqttDisconnect}, // CALLBACKS

    !         TOPIC_COUNT, // Number of topics to subscribe to

    !         {TOPIC1, TOPIC2, TOPIC3}, // Topics to subscribe to

    !         {QOS2, QOS2, QOS2}, // Topic QOS levels

    !         {WILL_TOPIC,WILL_MSG,WILL_QOS,WILL_RETAIN}, // Messages for our wills

              false

          }

      };

      

      /* library configuration */

      SlMqttClientLibCfg_t Mqtt_Client={

    !     0,

          TASK_PRIORITY,

          30,

          true,

    --- 188,222 ----

          {

              {

                  {

    !                 SL_MQTT_NETCONN_URL,

    !                 SERVER_ADDRESS,

    !                 PORT_NUMBER,

    !                 0,

    !                 0,

    !                 0,

    !                 NULL

                  },

                  SERVER_MODE,

    !             true,

              },

    !         NULL,

    !         "user1",

    !         NULL,

    !         NULL,

    !         true,

              KEEP_ALIVE_TIMER,

    !         {Mqtt_Recv, sl_MqttEvt, sl_MqttDisconnect},

    !         TOPIC_COUNT,

    !         {TOPIC1, TOPIC2, TOPIC3},

    !         {QOS2, QOS2, QOS2},

    !         {WILL_TOPIC,WILL_MSG,WILL_QOS,WILL_RETAIN},

              false

          }

      };

      

      /* library configuration */

      SlMqttClientLibCfg_t Mqtt_Client={

    !     1882,

          TASK_PRIORITY,

          30,

          true,

    ***************

    *** 367,373 ****

          UART_PRINT("disconnect from broker %s\r\n",

                 (local_con_conf->broker_config).server_info.server_addr);

          local_con_conf->is_connected = false;

    !     //sl_ExtLib_MqttClientCtxDelete(local_con_conf->clt_ctx);

      

          //

          // write message indicating publish message

    --- 364,370 ----

          UART_PRINT("disconnect from broker %s\r\n",

                 (local_con_conf->broker_config).server_info.server_addr);

          local_con_conf->is_connected = false;

    !     sl_ExtLib_MqttClientCtxDelete(local_con_conf->clt_ctx);

      

          //

          // write message indicating publish message

    ***************

    *** 620,633 ****

      void MqttClient(void *pvParameters)

      {

      

    -     osi_messages MSG_BROKER_DISC = BROKER_DISCONNECTION;

          long lRetVal = -1;

          int iCount = 0;

          int iNumBroker = 0;

          int iConnBroker = 0;

          osi_messages RecvQue;

      

    -     while (1){

          connect_config *local_con_conf = (connect_config *)app_hndl;

      

          //

    --- 617,628 ----

    ***************

    *** 650,657 ****

          if(lRetVal < 0)

          {

             UART_PRINT("Failed to start SimpleLink Device\n\r",lRetVal);

    ! //       LOOP_FOREVER();

    !        goto end;

          }

      

          // switch on Green LED to indicate Simplelink is properly up

    --- 645,651 ----

          if(lRetVal < 0)

          {

             UART_PRINT("Failed to start SimpleLink Device\n\r",lRetVal);

    !        LOOP_FOREVER();

          }

      

          // switch on Green LED to indicate Simplelink is properly up

    ***************

    *** 672,679 ****

          if(lRetVal < 0)

          {

             UART_PRINT("Connection to an AP failed\n\r");

    ! //       LOOP_FOREVER();

    !        goto end;

          }

      

          //

    --- 666,672 ----

          if(lRetVal < 0)

          {

             UART_PRINT("Connection to an AP failed\n\r");

    !        LOOP_FOREVER();

          }

      

          //

    ***************

    *** 692,743 ****

          GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);

          GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);

      

    -     /**

    -      * SET THE SYSTEM TIME TO NEAR TODAY

    -      *

    -      */

    - #define SL_SSL_CA_CERT_FILE_NAME        "/cert/ca.crt"

    - #define DATE                16    /* Current Date */

    - #define MONTH               10     /* Month 1-12 */

    - #define YEAR                2016  /* Current year */

    - #define HOUR                12    /* Time - hours */

    - #define MINUTE              50    /* Time - minutes */

    - #define SECOND              35     /* Time - seconds */

    -     typedef struct

    -     {

    -        /* time */

    -        unsigned long tm_sec;

    -        unsigned long tm_min;

    -        unsigned long tm_hour;

    -        /* date */

    -        unsigned long tm_day;

    -        unsigned long tm_mon;

    -        unsigned long tm_year;

    -        unsigned long tm_week_day; //not required

    -        unsigned long tm_year_day; //not required

    -        unsigned long reserved[3];

    -     }SlDateTime;

    -     SlDateTime g_time;

    -     int retVal;

    -     g_time.tm_day = DATE;

    -     g_time.tm_mon = MONTH;

    -     g_time.tm_year = YEAR;

    -     g_time.tm_sec = HOUR;

    -     g_time.tm_hour = MINUTE;

    -     g_time.tm_min = SECOND;

    -     retVal = sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION,

    -                           SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,

    -                           sizeof(SlDateTime),(unsigned char *)(&g_time));

    -     ASSERT_ON_ERROR(retVal);

          //

          // Register Push Button Handlers

          //

    --- 685,690 ----

    ***************

    *** 751,758 ****

          {

              // lib initialization failed

              UART_PRINT("MQTT Client lib initialization failed\n\r");

    ! //        LOOP_FOREVER();

    !         goto end;

          }

      

          /******************* connection to the broker ***************************/

    --- 698,704 ----

          {

              // lib initialization failed

              UART_PRINT("MQTT Client lib initialization failed\n\r");

    !         LOOP_FOREVER();

          }

          

          /******************* connection to the broker ***************************/

    ***************

    *** 760,767 ****

          if(iNumBroker > MAX_BROKER_CONN)

          {

              UART_PRINT("Num of brokers are more then max num of brokers\n\r");

    ! //        LOOP_FOREVER();

    !         goto end;

          }

      

          while(iCount < iNumBroker)

    --- 706,712 ----

          if(iNumBroker > MAX_BROKER_CONN)

          {

              UART_PRINT("Num of brokers are more then max num of brokers\n\r");

    !         LOOP_FOREVER();

          }

      

          while(iCount < iNumBroker)

    ***************

    *** 820,828 ****

                  UART_PRINT("\n\rBroker connect fail for conn no. %d \n\r",iCount+1);

      

                  //delete the context for this connection

    !             //sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);

    !             osi_MsgQWrite(&g_PBQueue,&MSG_BROKER_DISC,OSI_NO_WAIT);

      

                  break;

              }

    --- 765,771 ----

                  UART_PRINT("\n\rBroker connect fail for conn no. %d \n\r",iCount+1);

                  

                  //delete the context for this connection

    !             sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);

                  

                  break;

              }

    ***************

    *** 842,859 ****

                                         local_con_conf[iCount].qos, TOPIC_COUNT) < 0)

              {

                  UART_PRINT("\n\r Subscription Error for conn no. %d\n\r", iCount+1);

    -             sl_ExtLib_MqttClientUnsub(local_con_conf->clt_ctx, local_con_conf->topic,

    -                                           TOPIC_COUNT);

                  UART_PRINT("Disconnecting from the broker\r\n");

    !             //sl_ExtLib_MqttClientDisconnect(local_con_conf[iCount].clt_ctx);

                  local_con_conf[iCount].is_connected = false;

      

                  //delete the context for this connection

    !             //sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);

                  iConnBroker--;

    -             osi_MsgQWrite(&g_PBQueue,&MSG_BROKER_DISC,OSI_NO_WAIT);

                  break;

              }

              else

    --- 785,797 ----

                                         local_con_conf[iCount].qos, TOPIC_COUNT) < 0)

              {

                  UART_PRINT("\n\r Subscription Error for conn no. %d\n\r", iCount+1);

                  UART_PRINT("Disconnecting from the broker\r\n");

    !             sl_ExtLib_MqttClientDisconnect(local_con_conf[iCount].clt_ctx);

                  local_con_conf[iCount].is_connected = false;

                  

                  //delete the context for this connection

    !             sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);

                  iConnBroker--;

                  break;

              }

              else

    ***************

    *** 919,936 ****

              }

          }

      end:

    - UART_PRINT("\n\r Restarting the Application\n\r");

    -     osi_Sleep(30000);

          //

          // Deinitializating the client library

    !     sl_ExtLib_MqttClientDisconnect(local_con_conf[0].clt_ctx);

    ! sl_ExtLib_MqttClientCtxDelete(local_con_conf[0].clt_ctx);

          sl_ExtLib_MqttClientExit();

    !     osi_Sleep(1000);

    ! //    LOOP_FOREVER();

    !     }

      }

      

      //*****************************************************************************

    --- 857,869 ----

              }

          }

      end:

          //

          // Deinitializating the client library

    !     //

          sl_ExtLib_MqttClientExit();

    !     UART_PRINT("\n\r Exiting the Application\n\r");

    !     

    !     LOOP_FOREVER();

      }

      

      //*****************************************************************************