adafruit / Adafruit_CircuitPython_AzureIoT

Access to Microsoft Azure IoT device, messaging, and job services from CircuitPython!
MIT License
19 stars 15 forks source link

IOT Hub requires TLS #60

Closed geudrik closed 4 months ago

geudrik commented 1 year ago

IOT Hub requires TLS for MQTT connections now. Changing the port to 443 and adding is_ssl=True on the MQTT client init in iot_mqtt.py doesn't work though. After that change, I get the following

498.412: INFO - Establishing a SECURE SSL connection to hubname.azure-devices.net:443
499.814: DEBUG - Sending CONNECT to broker...
499.816: DEBUG - Fixed Header: bytearray(b'\x10\xfe\x01\x00')
499.818: DEBUG - Variable Header: bytearray(b'\x04MQTT\x04\xc2\x00x')
499.826: DEBUG - Receiving CONNACK packet from broker
499.850: DEBUG - Got message type: 0x48
499.853: DEBUG - Got message type: 0x54
499.855: DEBUG - Got message type: 0x54
499.857: DEBUG - Got message type: 0x50
499.860: DEBUG - Got message type: 0x2f
499.863: INFO - MMQT error: Topic length 12576 in PUBLISH packet exceeds remaining length 46 - 2

I'm not familiar enough with MQTT to understand what this is actually telling me. But ultimately, this library doesn't currently work because of the TLS requirement and it's not supported (at all) without making code changes in the lib.

The code I'm using for testing is the default example code in this repo (example code), with the added addition of an adafruit_logger() instance to the IOTHubDevice init

geudrik commented 1 year ago

Oh, and I was using a QtPy-S3 as my test device.

benbarnett02 commented 11 months ago

@geudrik - Did you find an alternative?

geudrik commented 11 months ago

I did not. I haven't had much time lately to keep messing around either :/

migster commented 11 months ago

Sharing this in case it's helpful. It seems related since IoT Central leverages IoT Hub. Last weekend I was trying to build an example that uses IoT Central and the device would not register. I was able to get the debug going and noticed it's not using SSL by default. I was able to get that turned up and get the device to register. I did it by changing the default in the adafruit_minimqtt. This thread has all of the details and debugs: https://forums.adafruit.com/viewtopic.php?p=980013#p980013

If can help get this fixed in anyway so the examples provided on the website work please or in testing fixes I'd be happy to do that. In the meantime I'll be tinkering with sensors and dashboards now that I have it reporting to up to Azure.

benbarnett02 commented 11 months ago

I switched to micropython and used the Microsoft version, which unfortunately uses upip (deprecated and doesn’t work on new micropython releases) to download its dependencies. I swapped this to mip (new package manager) and it worked. (alternatively just manually install it’s dependencies or use a micropython version that supports upip).

Will post the code when I get home in a few days, but my Pico W has been reporting happily to azure for at least 24 hours!

garretjacobson commented 11 months ago

I too ran into issues with connectivity following the tutorials and the provided examples in the readme and simple test . Similar to the blog post shared above, ensuring is_ssl is true when interfacing with MQTT results in the device connecting. Using Pico W with adafruit-circuitpython-raspberry_pi_pico_w-en_US-8.2.1 and adafruit-circuitpython-azureiot-py-2.5.15