Skip to content

CPython sockets compatibility #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
askpatrickw opened this issue Jan 21, 2021 · 8 comments · Fixed by #31
Closed

CPython sockets compatibility #24

askpatrickw opened this issue Jan 21, 2021 · 8 comments · Fixed by #31
Assignees
Labels
enhancement New feature or request

Comments

@askpatrickw
Copy link
Contributor

A typical setup requires an esp object which is related to the ESP32 wifi add-on boards.

device = IoTCentralDevice(socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"])

With the ESP32-s2 and its native wifi support, there is now a CPython-like socketpool.
IoTCentralDevice needs to be udpated to support both methods similarly if not the same way Requests does and MiniMQTT is going to be.

@brentru brentru added the bug Something isn't working label Jan 21, 2021
@brentru brentru added enhancement New feature or request and removed bug Something isn't working labels Feb 3, 2021
@brentru
Copy link
Member

brentru commented Feb 3, 2021

@askpatrickw CPython sockets now work in v5.0.0 of MiniMQTT. Do you want to tackle this issue?

@askpatrickw
Copy link
Contributor Author

@brentru woot!!

I may not get to it this week, but 100% Yes I will give it a go!

@brentru
Copy link
Member

brentru commented Feb 4, 2021

Thanks!

@askpatrickw
Copy link
Contributor Author

I finally have time to look at this. I'll commit to my fork and ping back if I get stuck.

@askpatrickw
Copy link
Contributor Author

Gotta take a break... but I'm moving along getting it working first just with native wifi, then I was thinking I'd figure out how to add the esp32spi support back.

Currently hitting the same error as this, not sure its the same problem yet. My current revisions are in my fork.
adafruit/Adafruit_CircuitPython_MiniMQTT#73

Traceback (most recent call last):
  File "code.py", line 88, in <module>
  File "/lib/adafruit_azureiot/iotcentral_device.py", line 162, in connect
  File "/lib/adafruit_azureiot/iot_mqtt.py", line 397, in connect
  File "/lib/adafruit_azureiot/iot_mqtt.py", line 142, in _create_mqtt_client
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 437, in connect
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 271, in _get_connect_socket
RuntimeError: Repeated socket failures

@askpatrickw
Copy link
Contributor Author

askpatrickw commented Mar 22, 2021

Quick update from me... I've not given up on this.

I wanted to be able to side-by-side test\verify with the SPI implementation. I only have ESP32S2 boards, so I ordered some hardware from Adafruit back on 5 March and it looks like its finally going to be delivered today 21 March. (Yay USPS!) so over the next week I'll look at this again.

@brentru
Copy link
Member

brentru commented Mar 24, 2021

@askpatrickw I also have hardware handy if you'd like me to test a PR.

@askpatrickw
Copy link
Contributor Author

I'm not finding great docs (which is weird for Msft) on the API version changes, but I do see this library was coded against the following version (constants.py)

# The version of the IoT Central MQTT API this code is built against
IOTC_API_VERSION = "2016-11-14"

# The version of the Azure Device Provisioning Service this code is built against
DPS_API_VERSION = "2018-11-01"

I changed these to IOTC_API_VERSION = "2018-06-30" and DPS_API_VERSION = "2019-03-31"

This is what IOT_MQTT looks like at _create_mqtt_client

{
    "_passwd": "SharedAccessSignature sig=snip1NN9%2B7y%2F8wZZftBtl8s%3D&se=1616847681&sr=iotc-snip-03dd-4ad0-be4a-snip.azure-devices.net%2Fdevices%snip",
    "_device_id": "snip",
    "_token_expires": 21600,
    "_logger": <Logger object at 200034b0>,
    "_auth_response_received": False,
    "_socket": <module "adafruit_esp32spi.adafruit_esp32spi_socket" from "/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy">,
    "_hostname": "iotc-snip-03dd-4ad0-be4a-snip.azure-devices.net",
    "_mqtts": None,
    "_username": "iotc-snip-03dd-4ad0-be4a-snip.azure-devices.net/snip/api-version=2018-06-30",
    "_key": "snip",
    "_mqtt_connected": False,
    "_iface": <ESP_SPIcontrol object at 200035e0>,
    "_callback": <IoTCentralDevice object at 20003460>,
    "_is_subscribed_to_twins": False
}

username, passwd, and hostname and device_id all look good to me and look like the IoT Hub MQTT docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants