Skip to content

Commit 077d539

Browse files
authored
Merge pull request #65 from justmobilize/fix-esp32spi
Fix ESP32SPI
2 parents 397db15 + 922b05c commit 077d539

21 files changed

+118
-96
lines changed

README.rst

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ This driver depends on:
4949

5050
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
5151
* `Adafruit CircuitPython BinASCII <https://github.com/adafruit/Adafruit_CircuitPython_Binascii>`_
52-
* `Adafruit CircuitPython ConnectionManager <https://github.com/adafruit/Adafruit_CircuitPython_ConnectionManager/>`_
5352
* `Adafruit CircuitPython Logging <https://github.com/adafruit/Adafruit_CircuitPython_Logging>`_
5453
* `Adafruit CircuitPython MiniMQTT <https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT>`_
55-
* `Adafruit CircuitPython Requests <https://github.com/adafruit/Adafruit_CircuitPython_Requests>`_
5654

5755
Please ensure all dependencies are available on the CircuitPython filesystem.
5856
This is easily achieved by downloading
5957
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
6058

61-
**Board Compatibility:** The following built-in modules must be available: gc, json, ssl, time
59+
**Board Compatibility:** The following built-in modules must be available: gc, json, time
6260

6361
Usage Example
6462
=============
@@ -74,8 +72,6 @@ To create an Azure IoT Hub instance or an Azure IoT Central app, you will need a
7472
ESP32 AirLift Networking
7573
========================
7674

77-
*NOTE* currently the ESP32 AirLift is not supported due to the requirment of `ssl`, which is only on boards with native WiFi.
78-
7975
To use this library, you will need to create an ESP32_SPI WifiManager, connected to WiFi. You will also need to set the current time, as this is used to generate time-based authentication keys. One way to do this is with the following code:
8076

8177
.. code-block:: python
@@ -96,7 +92,7 @@ To use this library, with boards that have native networking support, you need t
9692

9793
.. code-block:: python
9894
99-
pool = socketpool.SocketPool(wifi.radio)
95+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
10096
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
10197
10298
# NOTE: This changes the system time so make sure you aren't assuming that time

adafruit_azureiot/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121
2222
**With ESP32 Airlift Networking**
2323
24-
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2524
* Adafruit's ESP32SPI library: https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI
26-
* Adafruit's NTP library: https://github.com/adafruit/Adafruit_CircuitPython_NTP
2725
2826
**With Native Networking**
2927
3028
* CircuitPython's Wifi Module:
3129
https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html
32-
* Adafruit's Requests Library: https://github.com/adafruit/Adafruit_CircuitPython_Requests/
3330
"""
3431

3532
from .iot_error import IoTError

adafruit_azureiot/device_registration.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515

1616
import json
17-
import ssl
1817
import time
1918

2019
import adafruit_logging as logging
@@ -45,8 +44,8 @@ class DeviceRegistration:
4544
# pylint: disable=R0913
4645
def __init__(
4746
self,
48-
socket,
49-
iface,
47+
socket_pool,
48+
ssl_context,
5049
id_scope: str,
5150
device_id: str,
5251
device_sas_key: str,
@@ -74,8 +73,8 @@ def __init__(
7473
self._operation_id = None
7574
self._hostname = None
7675

77-
self._socket = socket
78-
self._iface = iface
76+
self._socket_pool = socket_pool
77+
self._ssl_context = ssl_context
7978

8079
# pylint: disable=W0613
8180
# pylint: disable=C0103
@@ -202,8 +201,8 @@ def register_device(self, expiry: int) -> str:
202201
client_id=self._device_id,
203202
is_ssl=True,
204203
keep_alive=120,
205-
socket_pool=self._socket,
206-
ssl_context=ssl.create_default_context(),
204+
socket_pool=self._socket_pool,
205+
ssl_context=self._ssl_context,
207206
)
208207

209208
self._mqtt.enable_logger(logging, self._logger.getEffectiveLevel())

adafruit_azureiot/iot_mqtt.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import gc
1616
import json
17-
import ssl
1817
import time
1918

2019
import adafruit_minimqtt.adafruit_minimqtt as MQTT
@@ -139,8 +138,8 @@ def _create_mqtt_client(self) -> None:
139138
client_id=self._device_id,
140139
is_ssl=True,
141140
keep_alive=120,
142-
socket_pool=self._socket,
143-
ssl_context=ssl.create_default_context(),
141+
socket_pool=self._socket_pool,
142+
ssl_context=self._ssl_context,
144143
)
145144

146145
self._mqtts.enable_logger(logging, self._logger.getEffectiveLevel())
@@ -326,8 +325,8 @@ def _get_device_settings(self) -> None:
326325
def __init__(
327326
self,
328327
callback: IoTMQTTCallback,
329-
socket,
330-
iface,
328+
socket_pool,
329+
ssl_context,
331330
hostname: str,
332331
device_id: str,
333332
device_sas_key: str,
@@ -347,8 +346,8 @@ def __init__(
347346
:param Logger logger: The logger
348347
"""
349348
self._callback = callback
350-
self._socket = socket
351-
self._iface = iface
349+
self._socket_pool = socket_pool
350+
self._ssl_context = ssl_context
352351
self._auth_response_received = False
353352
self._mqtts = None
354353
self._device_id = device_id

examples/azureiot_esp32spi/azureiot_central_commands.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import neopixel
99
import rtc
1010
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
11-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
11+
import adafruit_connection_manager
1212

1313
# Get wifi details and more from a secrets.py file
1414
try:
@@ -96,16 +96,21 @@
9696
#
9797
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9898
# * adafruit-circuitpython-minimqtt
99-
# * adafruit-circuitpython-requests
10099
# pylint: disable=wrong-import-position
101100
from adafruit_azureiot import IoTCentralDevice
102101
from adafruit_azureiot.iot_mqtt import IoTResponse
103102

104103
# pylint: enable=wrong-import-position
105104

105+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
106+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
106107
# Create an IoT Hub device client and connect
107108
device = IoTCentralDevice(
108-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"]
109+
pool,
110+
ssl_context,
111+
secrets["id_scope"],
112+
secrets["device_id"],
113+
secrets["device_sas_key"],
109114
)
110115

111116

examples/azureiot_esp32spi/azureiot_central_notconnected.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import neopixel
1111
import rtc
1212
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
13-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
13+
import adafruit_connection_manager
1414

1515
# Get wifi details and more from a secrets.py file
1616
try:
@@ -90,7 +90,6 @@
9090
#
9191
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9292
# * adafruit-circuitpython-minimqtt
93-
# * adafruit-circuitpython-requests
9493
# pylint: disable=wrong-import-position
9594
from adafruit_azureiot import (
9695
IoTCentralDevice,
@@ -99,9 +98,15 @@
9998

10099
# pylint: enable=wrong-import-position
101100

101+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
102+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
102103
# Create an IoT Hub device client and connect
103104
device = IoTCentralDevice(
104-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"]
105+
pool,
106+
ssl_context,
107+
secrets["id_scope"],
108+
secrets["device_id"],
109+
secrets["device_sas_key"],
105110
)
106111

107112
# don't connect

examples/azureiot_esp32spi/azureiot_central_properties.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import neopixel
1010
import rtc
1111
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
12-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
12+
import adafruit_connection_manager
1313

1414
# Get wifi details and more from a secrets.py file
1515
try:
@@ -97,12 +97,17 @@
9797
#
9898
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9999
# * adafruit-circuitpython-minimqtt
100-
# * adafruit-circuitpython-requests
101100
from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position
102101

102+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
103+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
103104
# Create an IoT Hub device client and connect
104105
device = IoTCentralDevice(
105-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"]
106+
pool,
107+
ssl_context,
108+
secrets["id_scope"],
109+
secrets["device_id"],
110+
secrets["device_sas_key"],
106111
)
107112

108113

examples/azureiot_esp32spi/azureiot_central_simpletest.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import neopixel
1111
import rtc
1212
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
13-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
13+
import adafruit_connection_manager
1414

1515
# Get wifi details and more from a secrets.py file
1616
try:
@@ -98,12 +98,17 @@
9898
#
9999
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
100100
# * adafruit-circuitpython-minimqtt
101-
# * adafruit-circuitpython-requests
102101
from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position
103102

103+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
104+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
104105
# Create an IoT Hub device client and connect
105106
device = IoTCentralDevice(
106-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"]
107+
pool,
108+
ssl_context,
109+
secrets["id_scope"],
110+
secrets["device_id"],
111+
secrets["device_sas_key"],
107112
)
108113

109114
print("Connecting to Azure IoT Central...")

examples/azureiot_esp32spi/azureiot_hub_directmethods.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import neopixel
99
import rtc
1010
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
11-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
11+
import adafruit_connection_manager
1212

1313
# Get wifi details and more from a secrets.py file
1414
try:
@@ -90,15 +90,16 @@
9090
#
9191
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9292
# * adafruit-circuitpython-minimqtt
93-
# * adafruit-circuitpython-requests
9493
# pylint: disable=wrong-import-position
9594
from adafruit_azureiot import IoTHubDevice
9695
from adafruit_azureiot.iot_mqtt import IoTResponse
9796

9897
# pylint: enable=wrong-import-position
9998

99+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
100+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
100101
# Create an IoT Hub device client and connect
101-
device = IoTHubDevice(socket, esp, secrets["device_connection_string"])
102+
device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"])
102103

103104

104105
# Subscribe to direct method calls

examples/azureiot_esp32spi/azureiot_hub_messages.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import neopixel
1111
import rtc
1212
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
13-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
13+
import adafruit_connection_manager
1414

1515
# Get wifi details and more from a secrets.py file
1616
try:
@@ -92,11 +92,12 @@
9292
#
9393
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9494
# * adafruit-circuitpython-minimqtt
95-
# * adafruit-circuitpython-requests
9695
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position
9796

97+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
98+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
9899
# Create an IoT Hub device client and connect
99-
device = IoTHubDevice(socket, esp, secrets["device_connection_string"])
100+
device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"])
100101

101102

102103
# Subscribe to cloud to device messages

examples/azureiot_esp32spi/azureiot_hub_simpletest.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import neopixel
1111
import rtc
1212
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
13-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
13+
import adafruit_connection_manager
1414

1515
# Get wifi details and more from a secrets.py file
1616
try:
@@ -92,11 +92,12 @@
9292
#
9393
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9494
# * adafruit-circuitpython-minimqtt
95-
# * adafruit-circuitpython-requests
9695
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position
9796

97+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
98+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
9899
# Create an IoT Hub device client and connect
99-
device = IoTHubDevice(socket, esp, secrets["device_connection_string"])
100+
device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"])
100101

101102
print("Connecting to Azure IoT Hub...")
102103

examples/azureiot_esp32spi/azureiot_hub_twin_operations.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import neopixel
1010
import rtc
1111
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
12-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
12+
import adafruit_connection_manager
1313

1414
# Get wifi details and more from a secrets.py file
1515
try:
@@ -94,11 +94,12 @@
9494
#
9595
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9696
# * adafruit-circuitpython-minimqtt
97-
# * adafruit-circuitpython-requests
9897
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position
9998

99+
pool = adafruit_connection_manager.get_radio_socketpool(esp)
100+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
100101
# Create an IoT Hub device client and connect
101-
device = IoTHubDevice(socket, esp, secrets["device_connection_string"])
102+
device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"])
102103

103104

104105
# Subscribe to device twin desired property updates

0 commit comments

Comments
 (0)