MQTT Keepalive

We're developing an nRF9160 based piece of hardware that will use Asset Tracker 2 and nRF Cloud.

We're trying to understand what the "reported' "connection" status means in the Device Shadow.

I assume this refers to the status of the connection between the device and nRF Cloud.

However, I also notice that when this is reported as "status" : "disconnected", that the nRF Cloud is also reporting that the device no longer has an LTE connection.

This is confusing.  Does loss of connection betweent the Device and Cloud and mean loss of connection  to the LTE Network?

I assume that if there is a loss of connection to the LTE Network, then that would also cause a loss of connection to the nRF Cloud.

But the reason for the loss of connection to the cloud is reported as "MQTT_KEEP_ALIVE_TIMEOUT", and the "keepalive" timer is set to 1200.  So does that mean the if there is no MQTT activity for 1200 seconds that the cloud connection automatically shuts down?

Sorry, but I'm very confused by all this.  Can someone please help me understand how this all works.

Thanks,

JackNote to DevZone about MQTT timeout.pdf

Parents
  • Hi,

     

    There are several services in-between the client and the server in this case, and it highly depends on what the NAT timeout in your network is:

     RE: nrf9160 mqtt keep alive longer than 30 minutes not working 

     

    It is quite common that networks can have several minutes before a TCP connection is terminated (via. either firewall/NAT etc in the network chain). I would recommend that you try to reduce the KEEP_ALIVE and see what is working for your specific network. Alternative is to contact your tele-network provider and ask what the NAT timeout is, but it is generally easier to reduce the KEEPALIVE to a lower value until it starts keeping the connection successfully between each "ping".

    But the reason for the loss of connection to the cloud is reported as "MQTT_KEEP_ALIVE_TIMEOUT", and the "keepalive" timer is set to 1200.  So does that mean the if there is no MQTT activity for 1200 seconds that the cloud connection automatically shuts down?

    No, it means that it will contact the server each configured KEEP_ALIVE_TIMEOUT (in seconds). If nothing happens in 1200 seconds, it will to a ping to the server to maintain the connection.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    There are several services in-between the client and the server in this case, and it highly depends on what the NAT timeout in your network is:

     RE: nrf9160 mqtt keep alive longer than 30 minutes not working 

     

    It is quite common that networks can have several minutes before a TCP connection is terminated (via. either firewall/NAT etc in the network chain). I would recommend that you try to reduce the KEEP_ALIVE and see what is working for your specific network. Alternative is to contact your tele-network provider and ask what the NAT timeout is, but it is generally easier to reduce the KEEPALIVE to a lower value until it starts keeping the connection successfully between each "ping".

    But the reason for the loss of connection to the cloud is reported as "MQTT_KEEP_ALIVE_TIMEOUT", and the "keepalive" timer is set to 1200.  So does that mean the if there is no MQTT activity for 1200 seconds that the cloud connection automatically shuts down?

    No, it means that it will contact the server each configured KEEP_ALIVE_TIMEOUT (in seconds). If nothing happens in 1200 seconds, it will to a ping to the server to maintain the connection.

     

    Kind regards,

    Håkon

Children
No Data
Related