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.

CC3220SF-LAUNCHXL: CC3220

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

Hello Everyone,

                    I am trying to implement OTA in CC3220SF module. I am able to fetch the file from the server and upgrade OTA, But after file download is done my MQTT disconnects. I even tried to reconnect to Mqtt by doing mqtt_init and mqtt_start but nothing works and the MCU goes in a  hanged state. The log file of OTA upgrade is attached. I get the following error after doing sl_stop. 

00:04:07 INFO ../app/mqtt_client_cbs.c:180: Mqtt client disconnected!!
00:04:07 DEBUG ../app/event_queue.c:95: Emitted into APP Event Queue, Event = 6
00:04:07 DEBUG ../app/event_queue.c:146: Emitted into Mqtt Event Queue, Event = 12
00:04:07 ERROR ../app/mqtt_client_task.c:634: Could not PUSH to /topic/device/version/progress - Error: -7

please check the attached log for more information.

CC3220SF-OTA.txt

My function for "ota_test_and_reset_handler" is as follows:-

int32_t ota_test_and_reset_handler()
{
int32_t retVal;

log_info("OtaImageTestingAndReset: download done");
/* char *payload = (char *)malloc(512);

sprintf(payload, "{\"deviceId\": \"%16s\","
"\"state\": \"upgraded\", \"progress\": 100}",
aquaiConfig.deviceId);
// Push payload to mqtt queue
MqttEventPayload_t mqttEvt;
mqttEvt.event = PUBLISH_OTA_PROGRESS;
mqttEvt.msgPtr = payload;
mqttEvt.msgLen = strlen(payload);
event_queue_emit_mqtt(&mqttEvt);*/
mqtt_send(PUBLISH_OTA_PROGRESS, 128,
"{\"deviceId\": \"%16s\","
"\"state\": \"upgraded\", \"progress\": 100}",
gAppConfig.deviceId);

/* Sleep to ensure MQTT pushed data */
sleep(1);

log_info(
"OtaImageTestingAndReset: call sl_Stop to move the bundle to"
"testing state");
sl_Stop(SL_STOP_TIMEOUT);
log_info(
"OtaImageTestingAndReset: reset the platform to test the new"
"image...");
Platform_Reset();

/* if we reach here, the platform does not support self reset */
/* reset the NWP in order to test the new image */
log_info(
"OtaImageTestingAndReset: platform does not support self reset");
log_info(
"OtaImageTestingAndReset: reset the NWP to test the new image");

retVal = Network_IF_InitDriver(ROLE_STA);
//Mqtt_init();
//Mqtt_start();

/* The sl_Stop/Start will produce event APP_EVENT_STARTED */
return(retVal);
}

Can anyone help me resolve this issue?

  • I'm not sure what exactly you are doing when the download is completed, but this is probably the source of the problem. 

    Are you using the httpclient to download the content? if so, then the completion should not impact the mqtt. Only the operations that you do later (such as sl_Stop) would.

    Try to close the mqtt connection before calling sl_Stop (and then reset the platform).

  • Hi Thanks for your reply. I did one thing I manually added mqtt connect again from where I get the message of MQTT disconnect.It happens in the case MQTTClient_DISCONNECT_CB_EVENT: inside the MqttClientCallback() function. 

    case MQTTClient_DISCONNECT_CB_EVENT:
    {
    AppContext_t *const pCtx = &gAppCtx;

    log_info("Mqtt client disconnected!!");

    event_queue_emit_app(APP_EVENT_MQTT_DISCONNECTED);
    /* MQTT Init */
    Mqtt_init();

    /* Create the queue */
    int32_t ret = event_queue_create_app();

    if (ret < 0) {
    log_error("Unable to create the App Event Queue");
    }

    pCtx->currentState = APP_STATE_STARTING;
    pCtx->pendingEvents = 0;

    /*Start the driver */
    int retc = Network_IF_InitDriver(ROLE_STA);
    if (retc < 0) {
    log_error("Failed to start SimpleLink Device", retc);
    event_queue_emit_app(APP_EVENT_ERROR);
    }

    break;
    }

    Is this the right way to reconnect? I tried reconnecting from other functions but it doesnt work. This is temporary workaround but can you suggest me a better way?

  • I think you are doing too much in this context (the MQtt_init(), Network_IF_InitDriver( ) are not needed).

    Please refer to the latest MQTT example (in SDK.530 or SDK6.10) which has a simpler MQTT interface.

    I still don't understand the reason for the disconnection (is it always following the OTA download completion?).

  • Yes it always disconnects after OTA completes. Once OTA is completed it goes for sl_stop and immediately after that MQTT disconnects. I am using sdk5.20 in my code. wont be able to update the code as it is being developed by someone else in version 5.20.

  • sl_Stop (powering off the NWP) is not part of the OTA download. You should call it only when you decide to do the MCU reset (i.e. to enable the new version) and by that time the MQTT connection should be closed anyway. In the example the MCU reset happens as soon as the download is completed but if you are in the middle of other activity  (such as MQTT publishing) - you can delay it.

    Once you call sl_Stop all the networking activity will get disconnected.

  • BTW. you must call sl_Stop before doing the MCU reset (the sl_Stop will put the device in "test" mode which will be identified after the reset - so it will be "pending-commit") and once you call sl_Stop you shouldn't call sl_Start before the MCU reset.