3 Replies Latest reply on Oct 2, 2017 2:56 AM by grsm

    MQTT Open Connection and Subscribe Issue

    grsm

      I have just received the Nebula board and are trying to create a project that connects to AWS MQTT, publishes and subscribes to topics, and displays any received messages out over UART.

       

      I have the project working on the 43907AEVAL1F board, and also on the BCM4343W kit (from Avnet).

      However when i try to run this on the Nebula board it fails on the connect to publisher and connect to subscribe section, returning a value of 4 which is decoded as ERROR (not particularly helpful but at least we know there is an issue).

       

      This is the Open function

       

       

      void MQTT_Open_Function(void)

      {

          WPRINT_APP_INFO(("[MQTT] Opening connection publish ..."));

          do

          {

              ret = mqtt_conn_open( mqtt_object_publish, &broker_address, WICED_STA_INTERFACE, mqtt_connection_event_cb, &security );

              connection_retries++ ;

          } while ( ( ret != WICED_SUCCESS ) && ( connection_retries < WICED_MQTT_CONNECTION_NUMBER_OF_RETRIES ) );

          if ( ret != WICED_SUCCESS )

          {

              WPRINT_APP_INFO(("Failed %d\n", ret));

          }

          WPRINT_APP_INFO(("Success publish connection\n"));

      }

       

      and this is the subscribe function

      void mqtt_subscribe_function(void) //function to subscribe to a mqtt topic

      {

          WPRINT_APP_INFO(("[MQTT] Subscribing..."));

          do

          {

              ret = mqtt_app_subscribe( mqtt_object_publish, WICED_TOPIC_SUBSCRIBE, WICED_MQTT_QOS_DELIVER_AT_MOST_ONCE );//subscribe to the defined topic

              retries++ ;

          } while ( ( ret != WICED_SUCCESS ) && ( retries < MQTT_SUBSCRIBE_RETRY_COUNT ) );

          if ( ret != WICED_SUCCESS )

          {

              WPRINT_APP_INFO((" Failed to subscribe %d\n",ret));

              mqtt_conn_close( mqtt_object_publish );

              MQTT_Open_Function();

              return;

          }

          WPRINT_APP_INFO(("Success subscribed to topic... %s\n", WICED_TOPIC_SUBSCRIBE));

      }

       

      This project is pretty stable and has been running in various forms for a couple of months. My suspicion is that i'm missing an include in the mk file or there is something wrong in the platform files.

      i am running standard wiced 5.2.0.22, and have tried on both windows and mac osX to rule out any hardware issues my side.

      Could someone advise/review the attached project to let me know what is wrong? I'm hoping to run this at the Egham FAE session on Wednesday this week

       

      the make file i've been using is  future.01_aws_demo-BCM943907AEVAL1F_WW101-ThreadX-NetX_Duo download run and have also tried download download_apps run as well

        • 1. Re: MQTT Open Connection and Subscribe Issue
          mifo

          Adding user_341228818 ,lazina.rahman_1486086 and user_424868667 from the Future technical team.

          • 2. Re: MQTT Open Connection and Subscribe Issue
            user_341228818

            Hi Graham!

             

            Initially, I wasn't able to get this to run on the Nebula board or the BCM94343WWCD1. I believe the issue is that you are trying to give your "MQTTPublishThread" too large of a stack with the following line:

             

            wiced_rtos_create_thread(&MQTTPublishHandle, 10, "MQTTPublishhread", &MQTTPublishThread, 40048, NULL);

             

            I'm guessing that you accidentally added an extra zero in there. After I removed the extra zero and used a stack size of 4048, it ran fine on both boards. It likely fails when using such a large stack size because it is running out of memory for the TLS security, connection, etc.

             

            Another thing that I'd recommend changing is not making your "ret" variable global especially since it is used in separate threads. It should be a local variable for each function that it is used in to check the result of function calls, otherwise it could cause you some headaches later.

             

            Kyle

            1 of 1 people found this helpful
            • 3. Re: MQTT Open Connection and Subscribe Issue
              grsm

              Just wanted to say thank you for helping to fix this issue.

              changing the stack size fixed all the bugs, and i modified the use of the global variable to make everything local as suggested.

               

              The demo worked fine (apart from some driver issues), all down to your quick response.

              Thanks again

              Graham