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 Didrik,
    i am still looking for solution ,not getting the network registration status.
    I am sending CEREG? command after every 5 min

  • I am unable to get modem trace.

    device is not creating the modem trace.

    problem is that.
    let suppose that  I am looking for the network status(by sending command AT+CEREG?) before every publication.

    now I moved the place where no network connectivity available. if they device is placed at the that location for few hour.
    1.if a continuously look for the network status before the shadow update after 1 hour or 2 the device will reboot watch dog reset the device.

    2.if I let suppose moved the device to no network area after connectivity and not send the (CEREG?) command at every publication interval. Still device lock up somewhere and the watch dog reset it.


    3.if I move the device to no coverage area after connected with network ,and put check don't call shadow_ update function until the you get network (by modem it self show connected) then the device is not locking up.but when i moved the device again to coverage area ,device is not going to connect again with network even I placed it here for hours.

    my question is that after how much device itself look for network search? i am using PSM mode
    how can I change modem notification time?

    please 





  • Do you at least have some logs from the device showing what is happening?

    Why are you not able to get modem traces?

    Have you set CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=y? Do you send the AT%XMODEMTRACE=1,2 command or are you susing the lte_lc library?

    Do you get +CGEV notifications?

  • yes,
    when I am trying to add CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=y this give me some at build time  zephyr/include/generated/devicetree_unfixed.h:3321:38: error: 'DT_N_S_soc_S_peripheral_40000000_S_uart_9000_P_tx_pin' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_uart_8000_P_tx_pin'?

    +CGEV not getting Because I am using PSM.
    please found below the attached log

    8233.2022-02-08T15_09_43.710Z-log.txt

Reply Children
  • Waqar Ahmed said:
    let suppose that  I am looking for the network status(by sending command AT+CEREG?) before every publication.

    That would not really be a good way to check if you have a connection. Whn in PSM, the radio is turned off, which means that you have no way of knowing what the current signalling conditions are. Your log shows that your transmit interval is much shorter than the PSM period. This means that you will not be able to base your decision on whether to send or not on recent data.

    When in PSM, you cannot really know if you still are connected to the network or not, unless you try to send something. However, in mfw 1.3.0 and newer, you can use the %CONEVAL command to get an overview of the current conditions without having to send anything.

  • Hi Didrik,

    Thank you for  reply.
    1.Is mfw 1.3.0 or later is compatible with nrfConnect sdk 1.5.0?

    2.if I send this AT+CEREG? is it power consuming command? What is your opinion

  • Waqar Ahmed said:
    1.Is mfw 1.3.0 or later is compatible with nrfConnect sdk 1.5.0?

    MFW 1.3.0 was tested with NCS 1.6.0. However, the interface between the application core and the modem core has generally been quite stable, so even if the NCS and mfw combination hasn't been tested, I don't expect there to be any issues.

    Waqar Ahmed said:
    2.if I send this AT+CEREG? is it power consuming command? What is your opinion

    AT+CEREG? only returns information already stored in the modem, so it should not use much power (i.e. no radio activity, just the CPU time needed to respond). However, this also means that the information might be outdated or not very useful (e.g. you entered PSM while in a connection, then move out of coverage. Because the modem hasn't used the radio, it will still believe it is connected with the network).

Related