@@ -32,6 +32,8 @@ log_function_t default_logging_function = NULL;
32
32
#define DPS_REGISTER_CUSTOM_PAYLOAD_BEGIN " {\" modelId\" :\" "
33
33
#define DPS_REGISTER_CUSTOM_PAYLOAD_END " \" }"
34
34
35
+ #define NUMBER_OF_SECONDS_IN_A_MINUTE 60
36
+
35
37
#define EXIT_IF_TRUE (condition, retcode, message, ...) \
36
38
do \
37
39
{ \
@@ -45,8 +47,6 @@ log_function_t default_logging_function = NULL;
45
47
#define EXIT_IF_AZ_FAILED (azresult, retcode, message, ...) \
46
48
EXIT_IF_TRUE (az_result_failed(azresult), retcode, message, ##__VA_ARGS__ )
47
49
48
- #define NUMBER_OF_SECONDS_IN_A_MINUTE 60
49
-
50
50
/* --- Internal function prototypes --- */
51
51
static uint32_t get_current_unix_time ();
52
52
@@ -160,7 +160,7 @@ int azure_iot_stop(azure_iot_t* azure_iot)
160
160
{
161
161
if (azure_iot->mqtt_client_handle != NULL )
162
162
{
163
- if (azure_iot->config ->mqtt_client_interface .mqtt_client_deinit (& azure_iot->mqtt_client_handle ) != 0 )
163
+ if (azure_iot->config ->mqtt_client_interface .mqtt_client_deinit (azure_iot->mqtt_client_handle ) != 0 )
164
164
{
165
165
azure_iot->state = azure_iot_state_error;
166
166
LogError (" Failed deinitializing MQTT client." );
@@ -289,7 +289,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot)
289
289
azure_iot->state = azure_iot_state_subscribing_to_dps;
290
290
291
291
packet_id = azure_iot->config ->mqtt_client_interface .mqtt_client_subscribe (
292
- azure_iot->mqtt_client_handle ,
292
+ azure_iot->mqtt_client_handle ,
293
293
AZ_SPAN_FROM_STR (AZ_IOT_PROVISIONING_CLIENT_REGISTER_SUBSCRIBE_TOPIC),
294
294
mqtt_qos_at_most_once);
295
295
@@ -417,6 +417,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot)
417
417
case azure_iot_state_provisioned:
418
418
// Disconnect from Provisioning Service first.
419
419
if (azure_iot->config ->use_device_provisioning &&
420
+ azure_iot->mqtt_client_handle != NULL &&
420
421
azure_iot->config ->mqtt_client_interface .mqtt_client_deinit (azure_iot->mqtt_client_handle ) != 0 )
421
422
{
422
423
azure_iot->state = azure_iot_state_error;
@@ -470,7 +471,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot)
470
471
azure_iot->state = azure_iot_state_subscribing_to_pnp_props;
471
472
472
473
packet_id = azure_iot->config ->mqtt_client_interface .mqtt_client_subscribe (
473
- azure_iot->mqtt_client_handle ,
474
+ azure_iot->mqtt_client_handle ,
474
475
AZ_SPAN_FROM_STR (AZ_IOT_HUB_CLIENT_PROPERTIES_MESSAGE_SUBSCRIBE_TOPIC),
475
476
mqtt_qos_at_least_once);
476
477
@@ -510,16 +511,19 @@ void azure_iot_do_work(azure_iot_t* azure_iot)
510
511
{
511
512
azure_iot->state = azure_iot_state_error;
512
513
LogError (" Failed getting current time for checking SAS token expiration." );
514
+ return ;
513
515
}
514
516
else if ((azure_iot->sas_token_expiration_time - now) < SAS_TOKEN_REFRESH_THRESHOLD_IN_SECS)
515
517
{
516
518
azure_iot->state = azure_iot_state_refreshing_sas;
517
- if (azure_iot->config ->mqtt_client_interface .mqtt_client_deinit (& azure_iot->mqtt_client_handle ) != 0 )
519
+ if (azure_iot->config ->mqtt_client_interface .mqtt_client_deinit (azure_iot->mqtt_client_handle ) != 0 )
518
520
{
519
521
azure_iot->state = azure_iot_state_error;
520
522
LogError (" Failed de-initializing MQTT client." );
521
523
return ;
522
524
}
525
+
526
+ azure_iot->mqtt_client_handle = NULL ;
523
527
}
524
528
break ;
525
529
case azure_iot_state_refreshing_sas:
0 commit comments