Skip to content

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

Open
@BlitzCityDIY

Description

@BlitzCityDIY

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions