Search code examples
azure-iot-sdk

iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection. mqtt_client timed out waiting for CONNACK


OS:Linux SDK Version : 2018-12-13 Description of the issue:

iothub_ll_telemetry_sample.c when i placed 60000 in the function ThreadAPI_Sleep(60000) works well but Tried with 120000 facing the timeout error.

cd ~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_ll_telemetry_sample $ ./iothub_ll_telemetry_sample

Console log of the issue:

Creating IoTHub Device handle Sending message 1 to IoTHub Sending message 2 to IoTHub Error: Time:Fri Dec 21 11:12:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Sending message 3 to IoTHub Sending message 4 to IoTHub Error: Time:Fri Dec 21 11:16:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Sending message 5 to IoTHub Error: Time:Fri Dec 21 11:18:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Error: Time:Fri Dec 21 11:20:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Error: Time:Fri Dec 21 11:22:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Error: Time:Fri Dec 21 11:24:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK Error: Time:Fri Dec 21 11:26:19 2018 File:/home/test/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2229 mqtt_client timed out waiting for CONNACK

Note: In previous version you said it's resolved but here it's not working form me. Please Explain me where is the problem.


Solution

  • The "LL" version of SDK functions are single threaded. When modify the code to sleep for two minutes the SDK is unable to service the socket and hence does not receive the CONNACK packet in time. The function call that services the socket is IoTHubDeviceClient_LL_DoWork. This function should be called at a bare minimum every 100 ms and preferably more quickly than that. If you only want to send a message every two minutes the onus is upon you to keep track of the time and send your message every time it has been two minutes since your last message. You cannot simply put the thread to sleep for two minutes.