nrf cloud mqtt fota

Hi!

I am trying to subscribe to nrf cloud with topic "prod/<TEAM_ID>/<DEVICE_ID>/jobs/rcv". After that I get Disconnect event in the MQTT handler.

Topic "prod/<TEAM_ID>/m/#" works perfectly, no disconnections.

Device shadow is updated as:

FOTA V2
APP
What I missed?
Thank you
  • Hello, 

    I will need more information on what is going on. What version of the nRF Connect SDK are you working on? What application are you running on you board?


    Please note that our team wiil be out of office on Friday, Sept 2nd and an answer will be provided Monday 5th. 

    Kind regards,
    Øyvind

  • Hi Øyvind,

     

    I use nrf connect 1.9.1.

    It is my custom application on the custom board. Here is some code from it:

    #define CONFIG_MQTT_FOTA_JOB_RCV "prod/813d19e6-4222-4eeb-9d38-c0aa2c710f43/account-813d19e6-4222-4eeb-9d38-c0aa2c710f43/jobs/rcv"

    int subscribe(void)
    {
    struct mqtt_topic subscribe_topic = {
    .topic = {
    .utf8 = (uint8_t *)CONFIG_MQTT_FOTA_JOB_RCV,
    .size = strlen(CONFIG_MQTT_FOTA_JOB_RCV)
    },
    .qos = MQTT_QOS_1_AT_LEAST_ONCE
    };
    
    const struct mqtt_subscription_list subscription_list = {
    .list = &subscribe_topic,
    .list_count = 1,
    .message_id = 103
    };
    
    LOG_INF("Subscribing to: %s len %u", CONFIG_MQTT_SUB_TOPIC,
    (unsigned int)strlen(CONFIG_MQTT_SUB_TOPIC));
    
    return mqtt_subscribe(&client, &subscription_list);
    }

    void mqtt_evt_handler(struct mqtt_client *const c,
    const struct mqtt_evt *evt)
    {
    int err;
    
    err = nrf_cloud_fota_mqtt_evt_handler(evt);
    if (err == 0) {
    /* Event handled by FOTA library so we can skip it */
    return;
    } else if (err < 0) {
    printk("nrf_cloud_fota_mqtt_evt_handler: Failed! %d\n", err);
    }
    
    switch (evt->type) {
    case MQTT_EVT_CONNACK:
    if (evt->result != 0) {
    LOG_ERR("MQTT connect failed: %d", evt->result);
    break;
    }
    
    LOG_INF("MQTT client connected");
    err = subscribe();
    //err = nrf_cloud_fota_subscribe(); // <---- The bug is here
    if(err) LOG_INF("FOTA subscribe errorr: %d", err);
    break;
    
    case MQTT_EVT_DISCONNECT:
    LOG_INF("MQTT client disconnected: %d", evt->result);
    break;
    
    case MQTT_EVT_PUBLISH: {
    const struct mqtt_publish_param *p = &evt->param.publish;
    
    LOG_INF("MQTT PUBLISH result=%d len=%d",
    evt->result, p->message.payload.len);
    err = publish_get_payload(c, p->message.payload.len);
    
    if (p->message.topic.qos == MQTT_QOS_1_AT_LEAST_ONCE) {
    const struct mqtt_puback_param ack = {
    .message_id = p->message_id
    };
    
    /* Send acknowledgment. */
    mqtt_publish_qos1_ack(&client, &ack);
    }
    
    if (err >= 0) {
    data_print("Received: ", payload_buf,
    p->message.payload.len);
    /* Echo back received data */
    //data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE,
    // payload_buf, p->message.payload.len);
    } else if (err == -EMSGSIZE) {
    LOG_ERR("Received payload (%d bytes) is larger than the payload buffer "
    "size (%d bytes).",
    p->message.payload.len, sizeof(payload_buf));
    } else {
    LOG_ERR("publish_get_payload failed: %d", err);
    LOG_INF("Disconnecting MQTT client...");
    
    err = mqtt_disconnect(c);
    if (err) {
    LOG_ERR("Could not disconnect: %d", err);
    }
    }
    } break;
    
    case MQTT_EVT_PUBACK:
    if (evt->result != 0) {
    LOG_ERR("MQTT PUBACK error: %d", evt->result);
    break;
    }
    
    LOG_INF("PUBACK packet id: %u", evt->param.puback.message_id);
    break;
    
    case MQTT_EVT_SUBACK:
    if (evt->result != 0) {
    LOG_ERR("MQTT SUBACK error: %d", evt->result);
    break;
    }
    
    LOG_INF("SUBACK packet id: %u", evt->param.suback.message_id);
    //readyForFota = true;
    break;
    
    case MQTT_EVT_PINGRESP:
    if (evt->result != 0) {
    LOG_ERR("MQTT PINGRESP error: %d", evt->result);
    }
    break;
    
    default:
    LOG_INF("Unhandled MQTT event type: %d", evt->type);
    break;
    }
    }

    I also tried to use nrf_cloud_fota_subscribe() function, but it worked the same.

    Topic "prod/813d19e6-4222-4eeb-9d38-c0aa2c710f43/m/#" works good with the same code

  • Hi Øyvind,

    Here how it looks in Debug Terminal:

    [00:00:09.301,513] <inf> Waterguard: Setup Complete
    [00:00:16.713,684] <inf> mqtt_simple: MQTT client connected
    [00:00:16.715,332] <inf> mqtt_simple: Publishing: {"state":{"reported":{"device":{"serviceInfo":{"fota_v2":["APP"],"ui":null}}}}}
    [00:00:16.715,362] <inf> mqtt_simple: to topic: $aws/things/account-813d19e6-4222-4eeb-9d38-c0aa2c710f43/shadow/update len: 70
    [00:00:16.722,991] <inf> mqtt_simple: Subscribing to: prod/813d19e6-4222-4eeb-9d38-c0aa2c710f43/m/# len 45
    [00:01:22.145,843] <inf> nrf_cloud_fota: Topic: prod/813d19e6-4222-4eeb-9d38-c0aa2c710f43/account-813d19e6-4222-4eeb-9d38-c0aa2c710f43/jobs/req
    [00:01:22.145,904] <inf> nrf_cloud_fota: Payload (4 bytes): [""]
    [00:01:31.967,163] <inf> mqtt_simple: MQTT client disconnected: -128
    [00:01:31.967,224] <err> mqtt_simple: mqtt_input: -128
    [00:01:31.967,224] <inf> mqtt_simple: Disconnecting MQTT client...
    [00:01:31.967,285] <err> mqtt_simple: Could not disconnect MQTT client: -128

  • Hello, 

    My apologies for the late reply. 

    Have you read the nRF Cloud documentation "Getting started with FOTA"? As described in the nRF Cloud library in SDK documentation, the nRF Cloud implementation supports TLS secured MQTT as the communication protocol with more information provided under Firmware over-the-air (FOTA) updates.

    In nRF Connect SDK v2.0.x we have added the nRF9160: nRF Cloud MQTT multi-service sample

    Kind regards,
    Øyvind

  • Thank you for the information. Yes I read all this articles during project. I use TLS, CA crtificate, client certificate and private key. MQTT client can't connect to the broker without them.

    My MQTT client connects successfully to the NRF cloud broker. Also it successfully subscribes to all messages topic(prod/<TEAM_ID>/m/#). But when I try to subscribe to fota notifications(prod/<TEAM_ID>/<DEVICE_ID>/jobs/rcv) or publish request for fota jobs(prod/<TEAM_ID>/<DEVICE_ID>/jobs/req) MQTT client got MQTT_EVT_DISCONNECT event.

    Can you test these topics on your side with nRF Connect 1.9.1 SDK(We are not able to migrate our project every time when new version of SDK appears)?

    Thank you for your assistance.

Related