adafruit / Adafruit_CircuitPython_AzureIoT

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

Can't use this module on PyPortal or Metro M4 Airlift Lite due to no SSL module #55

Closed MathCatsAnd closed 6 months ago

MathCatsAnd commented 1 year ago

Disclosure: I'm completely new to adafruit and doing my very first project.

I am unable to use the adafruit_azureiot module on my PyPortal or my Metro M4 Airlift Lite. Both of these boards use adafruit_esp32spi and have no wifi or ssl module in their CircuitPython installations. There was an update to this adafruit_azureiot module which added an import of ssl in the iot_mqtt.py file.

https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT/commit/75af72b6b80388f2365c736039deb8507b11451d

As such, without building a custom CircuitPython installer for these boards, I am unable to use adafruit_azureiot since just importing a function will will trigger ModuleNotFoundError when iot_mqtt.py tries to import ssl.

tekktrik commented 1 year ago

I'm not entirely familiar with this library, but you should be able to overcome the wifi module by using adafruit_esp32spi and modifying the code accordingly. The ssl issue however doesn't have a similar fix.

Let me see if I'm missing something.

MathCatsAnd commented 1 year ago

Yes, indeed, I am using the adafruit_esp32spi module to connect to wifi, no problems there. I just mentioned it since I usually see the two modules together (either a board has wifi and ssl or it has neither). The boards describe having "onboard TLS/SSL."

Espressif ESP32 Wi-Fi coprocessor with TLS/SSL support built-in

So my naive understanding is that esp32spi should in some way replace the pair of wifi and ssl, though it is only the ssl part causing a problem for me here. (I naively created an empty ssl.py file to get past the import, but sadly there is a call to it when trying to register a device.)

tekktrik commented 1 year ago

So as it is right now, that board just isn't compatible with this library. Hopefully the adafruit_esp32spi library can be updated in a way to provide compatibility, and then (if necessary) update this module. There is at least one way to accomplish this without changing the library, but might require it, so it makes sense to leave the issue here.

MathCatsAnd commented 1 year ago

Would it make sense to add to the documentation on this (or did I just not see it)? I know the library documentation says that CircuitPython (implicitly in its entirety) is a requirement which technically covers it. However, for me as a newbie, it was a learning experience to find out all these boards "with CircuitPython" often only have a subset of it.

So does it make sense to clarify the builtins needed within the documentation to assist in figuring out board compatibility? I had purchased a PyPortal since it appeared compatible based on a tutorial. However, the tutorial was written before the mentioned commit. I tried rolling back the library to before the commit, but instead encountered a socket error. I will try to keeping rolling things back to see if I can reach a compatible version. (Meanwhile, I ordered a different board and left feedback on the aforementioned tutorial.) Thanks!

tekktrik commented 1 year ago

Submitted feedback to the Learn Guide about this so it can be addressed. I do think adding information about compatibility would be helpful as well, if you're up for submitting a PR, let me know - otherwise I can submit one.

MathCatsAnd commented 1 year ago

Very happy to make an attempt! I will try to do that now.

MathCatsAnd commented 1 year ago

Done. I will make an attempt to understand how this works and see if I can edit the library, but as I am so new to board-level work I have no idea how long that would take me...in case anyone sees this and wants to work on the issue.

tekktrik commented 1 year ago

I'll take a look at the not shortly, but in the meantime, if you do want to do this tutorial, you could try to use the firmware and the libraries from around May 26, 202 if you haven't already tried, at least while this is still an issue.

Grudon commented 1 year ago

I had the same issue as @MathCatsAnd described. I tried rolling back to CircuitPython for PyPortal 5.2.0 (April 2020) and installed the Library Bundle for 5.X. The code started running. I disabled the azure_gfx_helper due to errors and downgraded the adafruit_requests.py to the version in the Library Bundle 4.X due to errors.

I managed to get the project running and communicating with IoT Central this way. It's a workaround until the issue is getting fixed. I added feedback to their tutorial and also found a forum post talking about it from 2022. Let's hope it gets resolved soon.

Edit: CircuitPython Version 6.3.0 together with the Library Bundle 6.x are also working, even with azure_gfx_helper enabled.