Skip to content

Commit b1a8dd9

Browse files
authored
add connection timeouts for dps and hub (#261)
1 parent 0dd8907 commit b1a8dd9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/src/azure_iot_nx/azure_iot_nx_client.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#define MAX_EXPONENTIAL_BACKOFF_IN_SEC (10 * 60)
3232
#define INITIAL_EXPONENTIAL_BACKOFF_IN_SEC 3
3333

34+
// Connection timeouts in seconds
35+
#define HUB_CONNECT_TIMEOUT 10
36+
#define DPS_REGISTER_TIMEOUT 20
37+
3438
static UINT exponential_backoff_with_jitter(UINT* exponential_retry_count)
3539
{
3640
float jitter_percent = (MAX_EXPONENTIAL_BACKOFF_JITTER_PERCENT / 100.0f) * (rand() / ((float)RAND_MAX));
@@ -66,7 +70,7 @@ static VOID connection_status_callback(NX_AZURE_IOT_HUB_CLIENT* hub_client_ptr,
6670
{
6771
printf("Reconnecting to IoT Hub ...\r\n");
6872

69-
if ((connect_status = nx_azure_iot_hub_client_connect(hub_client_ptr, NX_TRUE, NX_WAIT_FOREVER)))
73+
if ((connect_status = nx_azure_iot_hub_client_connect(hub_client_ptr, NX_TRUE, HUB_CONNECT_TIMEOUT * TX_TIMER_TICKS_PER_SECOND)))
7074
{
7175
printf("Failed reconnect on nx_azure_iot_hub_client_connect (0x%08x)\r\n", connect_status);
7276
tx_thread_sleep(exponential_backoff_with_jitter(&retry_count));
@@ -626,7 +630,7 @@ UINT azure_iot_nx_client_dps_create(AZURE_IOT_NX_CONTEXT* context, CHAR* dps_id_
626630
}
627631

628632
// Register device
629-
else if ((status = nx_azure_iot_provisioning_client_register(&context->dps_client, NX_WAIT_FOREVER)))
633+
else if ((status = nx_azure_iot_provisioning_client_register(&context->dps_client, DPS_REGISTER_TIMEOUT * TX_TIMER_TICKS_PER_SECOND)))
630634
{
631635
printf("ERROR: nx_azure_iot_provisioning_client_register (0x%08x)\r\n", status);
632636
}

0 commit comments

Comments
 (0)