adafruit / adafruit/Adafruit_CircuitPython_AzureIoT

Consistent `MMQTTException: Connection Refused - Unauthorized` after 2-2.5 hours uptime

Open
#53 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
19
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Hello,

Recently I've noticed an issue where after approximately 2-2.5 hours of uptime, a KeepAlive period elapses and the code can't get a PINGRESP from the server and errors out:

7566.375: DEBUG - KeepAlive period elapsed - requesting a PINGRESP from the server...
7566.377: DEBUG - Sending PINGREQConnection error, reconnecting
PINGRESP not returned from broker.
7690.494: INFO - - iot_mqtt :: reconnect ::
7690.496: DEBUG - Attempting to reconnect with MQTT broker
7690.498: DEBUG - Attempting to establish MQTT connection...
7690.502: INFO - Establishing a SECURE SSL connection to iotc-********-****-****-****-************.azure-devices.net:8883
7691.429: DEBUG - Sending CONNECT to broker...
7691.434: DEBUG - Fixed Header: bytearray(b'\x10\xa7\x02\x00') Variable Header: bytearray(b'\x04MQTT\x04\xc2\x00x')
7691.445: DEBUG - Receiving CONNACK packet from broker
Traceback (most recent call last):
File "code.py", line 232, in
File "adafruit_azureiot/iotcentral_device.py", line 193, in reconnect
File "adafruit_azureiot/iot_mqtt.py", line 439, in reconnect
File "adafruit_minimqtt/adafruit_minimqtt.py", line 770, in reconnect
File "adafruit_minimqtt/adafruit_minimqtt.py", line 523, in connect
MMQTTException: Connection Refused - Unauthorized

There is a `try` and `except` in the loop:

```
except (ValueError, RuntimeError) as e:
print("Connection error, reconnecting\n", str(e))
wifi.radio.enabled = False
wifi.radio.enabled = True
wifi.radio.connect(secrets["ssid"], secrets["password"])
device.reconnect()
continue
```
But it doesn't seem to trigger a reconnection. Have tried with CP 7.3 and CP 8 on an ESP32-S2 Feather TFT and a QT Py ESP32-S2 both with my own project code and the example library code for IoT Central.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reconnect path shown in adafruit_azureiot/iot_central_device.py, adafruit_azureiot/iot_mqtt.py, and adafruit_minimqtt/adafruit_minimqtt.py, then inspect the keepalive and CONNACK handling around the reported traceback. Reproduce the failure after the keepalive timeout and determine what needs to change so reconnection does not end with Connection Refused - Unauthorized.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, python
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.