SDK version 1.7.1
I am working on a project involving a nRF9160 and the sample application nrf/samples/nrf9160/azire_iot_hub and working on reliability issues with disconnections and reconnections with Azure.
I have slightly modified the sample application to suit the project needs but the basic functionality remains the same.
When Azure is connected I receive an event AZURE_IOT_HUB_EVT_CONNECTED then AZURE_IOT_HUB_EVT_READY when it is ready to relay data.
When Azure is disconnected I also receive the event AZURE_IOT_HUB_EVT_DISCONNECTED in which case the application attempts to reconnect.
However, when the reconnect fails I receive no notification that the connection has failed to connect.
If I open up the source code located at nrf/subsys/net/lib/azure_iot_hub/src/azure_iot_hub.c I find on the following lines at about 1237...
int azure_iot_hub_connect(void)
{
int err;
if (connection_state_verify(STATE_CONNECTING)) {
LOG_WRN("Azure IoT Hub connection establishment in progress");
return -EINPROGRESS;
} else if (!connection_state_verify(STATE_INIT)) {
LOG_WRN("Azure IoT Hub is not in the initialized state");
return -ENOENT;
}
connection_state_set(STATE_CONNECTING);
err = connect_client(&conn_config);
if (err) {
LOG_ERR("Failed to connect MQTT client, error: %d", err);
connection_state_set(STATE_INIT);
return err;
}
k_sem_give(&connection_poll_sem);
return 0;
}
Internal connection state is set to connection_state_set(STATE_INIT); however, there is no notification to the application layer using azure_iot_hub_notify_event() to notify the application layer of the connect failure, it seems, can this be verified?
Also, is there a recommended solution besides modification of the library? I am considering adding the appropriate azure_iot_hub_notify_event() when connection fails.
Initially I was under the assumption that once a connection was established to the Azure service, it would retain that connection, even through reconnection if the connection was lost, but now it appears that a disconnection needs to be handled with the application layer.
With this, can I also verify the reconnection ability of the LTE connection? If the LTE connection is interrupted will it automatically reconnect and perform a DHCP request? If not, will this need the be handled with the application layer as well?
Sincerely,
Allan