Azure IoT central device cannot connect to MQTT after several days of working

Casey Park 40 Reputation points
2023-04-04T02:30:59.6566667+00:00

I was testing 1 IoT central devices over the weekend, from 3/31 19:00 KST, and another for more than 10 days, but I found that they are both disconnected since 4/1 05:34AM KST and 4/1 05:05AM KST. One of them shows error as follows. 2023/4/4 11:13:47 [ERROR] MQTT client in ERROR state. 2023/4/4 11:13:47 [ERROR] esp_tls_stack_err=0; esp_tls_cert_verify_flags=0;esp_transport_sock_errno=119;error_type=2;connect_return_code=5 2023/4/4 11:13:47 [ERROR] connect_return_code=MQTT_CONNECTION_REFUSE_NOT_AUTHORIZED E (319287887) MQTT_CLIENT: MQTT connect failed 2023/4/4 11:13:47 [INFO] MQTT client disconnected. If the problem persists from the beginning of the test, I would consider this might be an issue of provision or authentication, but this is happening while device is connected to IoT central. I'm using Aure SDK for C 1.1.3, Arduino 2.0.4 and ESP32 with ethernet. Key refresh timer is 60 min so devices are connecting and disconnecting in every hour, but disconnection was happened out of regenerating passkey generation sequence.

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
365 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,217 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
224 questions
0 comments No comments
{count} votes

Accepted answer
  1. AshokPeddakotla-MSFT 35,096 Reputation points
    2023-04-04T06:39:47.6866667+00:00

    @Casey Park Welcome to Microsoft Q&A forum!

    I was testing 1 IoT central devices over the weekend, from 3/31 19:00 KST, and another for more than 10 days, but I found that they are both disconnected since 4/1 05:34AM KST and 4/1 05:05AM KST.

    You have mentioned, you were you able connect the devices earlier successfully without any issues. What changes you have made to the device connectivity?

    [ERROR] connect_return_code=MQTT_CONNECTION_REFUSE_NOT_AUTHORIZED E (319287887) MQTT_CLIENT: MQTT connect failed 2023/4/4 11:13:47 [INFO] MQTT client disconnected.

    Based on the error message you provided, it seems that the MQTT client is failing to connect to Azure IoT Central due to authorization issues. This could be caused by incorrect credentials or permissions. Please double-check your credentials and make sure that the client has the necessary permissions to connect. You can also try to regenerate the device credentials and update them in the device code to see if that resolves the issue. When a device first tries to connect to your IoT Central application, it starts the process by connecting to the Device Provisioning Service (DPS). DPS checks the device's credentials and, if they're valid, provisions the device with the connection string for one of IoT Central's internal IoT hubs. Since you mentioned that the devices are connecting and disconnecting every hour, it's possible that the issue is related to the key refresh timer. You may want to check if the key refresh timer is properly configured and if it's causing the devices to disconnect unexpectedly. I would also suggest you to use the re-try mechanism in your code. To learn more about device error codes, see Troubleshooting device connections and Handle connection failures To learn more about implementing automatic reconnections, see Manage device reconnections to create resilient applications. If you need further help in this matter, please comment in the below section and we are happy to discuss!

    If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.