Microsoft Azure IoTHub client MQTT transport
Dependents: STM32F746_iothub_client_sample_mqtt FXOS8700CQ_To_Azure_IoT f767zi_mqtt FXOS8700CQ_To_Azure_IoT ... more
Diff: iothubtransport_mqtt_common.c
- Revision:
- 32:103a46ed8822
- Parent:
- 31:d6198e67d1eb
- Child:
- 33:b7dfb208ef0a
--- a/iothubtransport_mqtt_common.c Fri Nov 03 13:17:53 2017 -0700 +++ b/iothubtransport_mqtt_common.c Fri Dec 15 14:08:57 2017 -0800 @@ -39,6 +39,7 @@ #define SAS_REFRESH_MULTIPLIER .8 #define EPOCH_TIME_T_VALUE 0 #define DEFAULT_MQTT_KEEPALIVE 4*60 // 4 min +#define DEFAULT_CONNACK_TIMEOUT 30 // 30 seconds #define BUILD_CONFIG_USERNAME 24 #define SAS_TOKEN_DEFAULT_LEN 10 #define RESEND_TIMEOUT_VALUE_MIN 1*60 @@ -176,6 +177,7 @@ bool device_twin_get_sent; bool isRecoverableError; uint16_t keepAliveValue; + uint16_t connect_timeout_in_sec; tickcounter_ms_t mqtt_connect_time; size_t connectFailCount; tickcounter_ms_t connectTick; @@ -1840,7 +1842,7 @@ LogError("failed verifying MQTT_CLIENT_STATUS_CONNECTING timeout"); result = __FAILURE__; } - else if ((current_time - transport_data->mqtt_connect_time) / 1000 > transport_data->keepAliveValue) + else if ((current_time - transport_data->mqtt_connect_time) / 1000 > transport_data->connect_timeout_in_sec) { LogError("mqtt_client timed out waiting for CONNACK"); DisconnectFromClient(transport_data); @@ -1991,6 +1993,7 @@ state->waitingToSend = waitingToSend; state->currPacketState = CONNECT_TYPE; state->keepAliveValue = DEFAULT_MQTT_KEEPALIVE; + state->connect_timeout_in_sec = DEFAULT_CONNACK_TIMEOUT; state->connectFailCount = 0; state->connectTick = 0; state->topic_MqttMessage = NULL; @@ -2665,6 +2668,15 @@ transport_data->option_sas_token_lifetime_secs = *sas_lifetime; result = IOTHUB_CLIENT_OK; } + else if (strcmp(OPTION_CONNECTION_TIMEOUT, option) == 0) + { + int* connection_time = (int*)value; + if (*connection_time != transport_data->connect_timeout_in_sec) + { + transport_data->connect_timeout_in_sec = (uint16_t)(*connection_time); + } + result = IOTHUB_CLIENT_OK; + } else if (strcmp(OPTION_KEEP_ALIVE, option) == 0) { /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_036: [If the option parameter is set to "keepalive" then the value shall be a int_ptr and the value will determine the mqtt keepalive time that is set for pings.] */