adafruit / Adafruit_CircuitPython_AzureIoT

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

Updating to latest requests and miniMQTT #31

Closed jimbobbennett closed 3 years ago

jimbobbennett commented 3 years ago

Fixes #24 and works for IoT Hub. Everything is still broken for IoT Central, but I'm investigating internally what it might be.

This sets up the requests correctly, and uses the new logging API changes for the miniMQTT class. It also adds more debug logging.

brentru commented 3 years ago

@askpatrickw Reviewing over this PR, it does not look like it'll work with SSL and native sockets (ESP32-S2). Are you planning to add that as part of https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT/issues/21?

brentru commented 3 years ago

@jimbobbennett You may want to comment on the readme that IoT Central functionality is not working at this time to avoid support issues.

askpatrickw commented 3 years ago

@askpatrickw Reviewing over this PR, it does not look like it'll work with SSL and native sockets (ESP32-S2). Are you planning to add that as part of https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT/issues/21?

Not until we figure out IoT Central

jimbobbennett commented 3 years ago

I don't thing the IoT Central issue is a change on our side. I've rolled back to last years code and it connects fine (CP 5.3, libraries from the June 11th 2020 release, latest code from this repo before this PR), so it implies it's a change in either CircuitPython or one of the MQTT libraries that is causing the issue.

I'm going to try a few more versions out to see if I can find where things broke.

jimbobbennett commented 3 years ago

Update - using the latest CircuitPython 6.2.0 and libraries from August, it works - so it's a library issue, not a CP issue. I'm still trying to find out which version introduces the break, but it's hard as I get random errors with different versions of the library bundle. Some will give OSError: 23, others an invalid broker error.

jimbobbennett commented 3 years ago

Right - got somewhere.

It seems the issue is using requests to call the DPS to get the hostname for the underlying IoT Hub used by IoT Central, then using MQTT to connect. There was a change in the ESP32SPI libs to only allow one socket connection at a time, and I think this might be the problem:

https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/releases/tag/3.5.3

If I comment out the call to the DPS and set the hostname manually, everything works.

@tannewt, @brentru - any ideas what is the correct thing to do here? Is there a way to disconnect the socket used by requests so that the code can use MQTT?

jimbobbennett commented 3 years ago

Another option is to connect to the DPS over MQTT - https://docs.microsoft.com/en-us/azure/iot-dps/iot-dps-mqtt-support

jimbobbennett commented 3 years ago

Option 2 done - the device registration now uses MQTT instead of HTTPS and this now works.

@brentru - can you review now please!

askpatrickw commented 3 years ago

Thank you @jimbobbennett ! I also opened an issue in EPS32SPI about the single TLS connection.

tannewt commented 3 years ago

@tannewt, @brentru - any ideas what is the correct thing to do here? Is there a way to disconnect the socket used by requests so that the code can use MQTT?

Sorry, no suggestions from me. I've context switched that info out of my brain.