nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to check the nRF is connected with MQTT broker or not?

Hi,
I am facing an issue, I am developing nRF9160 based Product, get sensor data  from peripherals and publish to AWS cloud.my firmware is based on AWS IoT sample. I observed that some time devices get disconnected from AWS.I missed the sensor data during that period.
1.Now I want to save data into SD card  during  that disconnected period.? So I need find Exact point in my application which shows that it is disconnected so I log data into SD card.
2.Once if I done it successfully, log the data then I want to send this file to AWS over MQTT when it again connected?

if I place check on shadow_update ( .So for test purpose I remove the antenna from Device while application is running .its Still updating the Shadow(although message not reached on AWS ).how to kill this issue?

static void shadow_update_work_fn(struct k_work *work)
{
int err;

err = shadow_update(false);
if (err) {
printk("shadow_update, error: %d\n", err);
}

printk("Next data publication in %d seconds\n", publication_interval_seconds);

k_delayed_work_submit(&shadow_update_work, K_SECONDS( publication_interval_seconds));
}




Thanks 

Parents
  • Hi,

    In some cases, it might not be possible to detect that the connection with the server has been broken until you try to send something (either keepalive messages or data).

    A good place to start is in AWS IoT event handler. If you get a AWS_IOT_EVT_DISCONNECTED event, you are no longer connected.

    In addition to the AWS IoT events, you can also keep track of the LTE link. Both +CEREG notifications, but also +CGEV notifications.

    Best regards,

    Didrik

  • Hi Thank you for you response.
    they continuously updating at some point device get reboot.
    I am publishing message every 5 min.
    yes, I am using PSM.
    I am still monitoring the device but I am not getting any notification. I enable notification from this command

    AT+CGEREP=1
     not getting these notification 

    +CGEV: NW DETACH

    Mobile Equipment (ME) detach:

    +CGEV: ME DETACH



    Thanks
     

  • When you are in PSM, it makes sense that you don't get any notifications that you are disconnected, at least until you try to send something.

    Could you take a modem trace, so I can see what the modem does?

  • Hi Didrik,
    thanks for reply, now I add the CGEV notification in my application and look for CEREG status before publishing the message.
    so after calling update function, I am sending CEREG command.so then from that response I can check network status.


    now I am getting  in 2nd Part of query.

    I successfully retrieve  data from SD card. the that is about 6KB.i had split this data to about 512 chunks.
    Now I want to send these chunks in shadow update function, by using  err += json_add_str(reported_obj,"SD_DATA",sd_data1);
    sd_data1 contain the chunk.

    but it will give me error in this function

    message = cJSON_Print(root_obj);
    if (message == NULL) {
    printk("cJSON_Print, error: returned NULL\n");
    err = -ENOMEM;
    goto cleanup;
    }





  • Hi,

    I see you have created a new ticket for this question. The discussion will be continued there.

    Best regards,

    Didrik

  • I created a new ticker for 2nd part. but  I am still stuck at first part not reliable solution still Ihad found?

Reply Children
Related