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
Parents
  • 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

Reply
  • 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

Children
No Data
Related