Home/Support/Support Forum/Why Azure IoT Hub MQTT Returning Exception 5 after serval hours?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Why Azure IoT Hub MQTT Returning Exception 5 after serval hours?

0 votes
Hello,

Using:
XBC LTE-M/NB-IoT Global
FW: 11417

I am using the example code under https://github.com/digidotcom/xbee-micropython/tree/master/samples/cellular/azure to connect to MQTT.

Upon booting:
1. Verify that the cell is connected.
2. Verify the proper time using utime.localtime(utime.time()) .
3. Create the connection to Azure IoT Hub using a sas token that expires in 30 years as a test.
4. Send an MQTT message

Then every 15 minutes, a MQTT message is sent. This works great for about 8 to 24 hours but then receive MQTTException 5.

ISSUE:
The device receive MQTTException 5 that the device is not authorized. Once the device receive this message, the device is rebooted and everything works. My assumption is that it recreates the sas token and now everything works again.

Instead of rebooting the device, I don't understand why I am receiving Unauthorized exception since the sas token expires in 30 years. Maybe there is a time difference that occurs over time between the cell module time and Azure or something more simple?

Any help will be greatly appreciated.

Thank you.
asked Aug 20 in Digi Connect Cellular by flashgordonmjg New to the Community (1 point)

Please log in or register to answer this question.

3 Answers

0 votes
Check to make sure you are not timing out with Azure. Instead of rebooting, try simply re-establishing the socket.
answered Aug 20 by mvut Veteran of the Digi Community (14,777 points)
0 votes
yes you can through I am using the example code under https://github.com/digidotcom/xbee-micropython/tree/master/samples/cellular/azure to connect to MQTT.

Upon booting:
1. Verify that the cell is connected.
2. Verify the proper time using utime.localtime(utime.time()) .
3. Create the connection to Azure IoT Hub using a sas token that expires in 30 years as a test.
4. Send an MQTT message

to click here to know more about the installation process
already installed azure for client site
Then every 15 minutes, a MQTT message is sent. This works great for about 8 to 24 hours but then receive MQTTException 5.
answered Aug 23 by albaik New to the Community (1 point)
0 votes
I have tried to reset with no success. I have to restart the box.

An interesting note is that I tried to change the ttl to 10 hours, 24 hours, 1, 2 15 yers on the SAS token and I always get Unauthorized. In Azure logging, the device does connect and I see where Azure IoT Hub returns a 401 even though i created a SAS token in the future.

When i use ttl = time() + expiry + 946684800 as in the example code, the device connects and stays up for several hours sending data. Then, after several hours as noted, Azure IoT Hub will return UnAuthorized.

I can also add time to ttl = time() + expiry + 946684800. such as ttl = time() + expiry + 946684800 + 3153600 with no issues on startup. If i have any time less than ttl = time() + expiry + 946684800, then i immediately get UnAuthorized
answered Aug 23 by flashgordonmjg New to the Community (1 point)
...