diff --git a/README.rst b/README.rst index 0bed32c..1052c4d 100644 --- a/README.rst +++ b/README.rst @@ -49,16 +49,14 @@ This driver depends on: * `Adafruit CircuitPython `_ * `Adafruit CircuitPython BinASCII `_ -* `Adafruit CircuitPython ConnectionManager `_ * `Adafruit CircuitPython Logging `_ * `Adafruit CircuitPython MiniMQTT `_ -* `Adafruit CircuitPython Requests `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. -**Board Compatibility:** The following built-in modules must be available: gc, json, ssl, time +**Board Compatibility:** The following built-in modules must be available: gc, json, time Usage Example ============= @@ -74,8 +72,6 @@ To create an Azure IoT Hub instance or an Azure IoT Central app, you will need a ESP32 AirLift Networking ======================== -*NOTE* currently the ESP32 AirLift is not supported due to the requirment of `ssl`, which is only on boards with native WiFi. - 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: .. code-block:: python @@ -96,7 +92,7 @@ To use this library, with boards that have native networking support, you need t .. code-block:: python - pool = socketpool.SocketPool(wifi.radio) + pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time diff --git a/adafruit_azureiot/__init__.py b/adafruit_azureiot/__init__.py index 43d901d..efff896 100644 --- a/adafruit_azureiot/__init__.py +++ b/adafruit_azureiot/__init__.py @@ -21,15 +21,12 @@ **With ESP32 Airlift Networking** -* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice * Adafruit's ESP32SPI library: https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI -* Adafruit's NTP library: https://github.com/adafruit/Adafruit_CircuitPython_NTP **With Native Networking** * CircuitPython's Wifi Module: https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html -* Adafruit's Requests Library: https://github.com/adafruit/Adafruit_CircuitPython_Requests/ """ from .iot_error import IoTError diff --git a/adafruit_azureiot/device_registration.py b/adafruit_azureiot/device_registration.py index b616d3c..b4532a1 100644 --- a/adafruit_azureiot/device_registration.py +++ b/adafruit_azureiot/device_registration.py @@ -14,7 +14,6 @@ """ import json -import ssl import time import adafruit_logging as logging @@ -45,8 +44,8 @@ class DeviceRegistration: # pylint: disable=R0913 def __init__( self, - socket, - iface, + socket_pool, + ssl_context, id_scope: str, device_id: str, device_sas_key: str, @@ -74,8 +73,8 @@ def __init__( self._operation_id = None self._hostname = None - self._socket = socket - self._iface = iface + self._socket_pool = socket_pool + self._ssl_context = ssl_context # pylint: disable=W0613 # pylint: disable=C0103 @@ -202,8 +201,8 @@ def register_device(self, expiry: int) -> str: client_id=self._device_id, is_ssl=True, keep_alive=120, - socket_pool=self._socket, - ssl_context=ssl.create_default_context(), + socket_pool=self._socket_pool, + ssl_context=self._ssl_context, ) self._mqtt.enable_logger(logging, self._logger.getEffectiveLevel()) diff --git a/adafruit_azureiot/iot_mqtt.py b/adafruit_azureiot/iot_mqtt.py index 0d13800..c47f785 100644 --- a/adafruit_azureiot/iot_mqtt.py +++ b/adafruit_azureiot/iot_mqtt.py @@ -14,7 +14,6 @@ import gc import json -import ssl import time import adafruit_minimqtt.adafruit_minimqtt as MQTT @@ -139,8 +138,8 @@ def _create_mqtt_client(self) -> None: client_id=self._device_id, is_ssl=True, keep_alive=120, - socket_pool=self._socket, - ssl_context=ssl.create_default_context(), + socket_pool=self._socket_pool, + ssl_context=self._ssl_context, ) self._mqtts.enable_logger(logging, self._logger.getEffectiveLevel()) @@ -326,8 +325,8 @@ def _get_device_settings(self) -> None: def __init__( self, callback: IoTMQTTCallback, - socket, - iface, + socket_pool, + ssl_context, hostname: str, device_id: str, device_sas_key: str, @@ -347,8 +346,8 @@ def __init__( :param Logger logger: The logger """ self._callback = callback - self._socket = socket - self._iface = iface + self._socket_pool = socket_pool + self._ssl_context = ssl_context self._auth_response_received = False self._mqtts = None self._device_id = device_id diff --git a/examples/azureiot_esp32spi/azureiot_central_commands.py b/examples/azureiot_esp32spi/azureiot_central_commands.py index c829a32..d11cc1f 100644 --- a/examples/azureiot_esp32spi/azureiot_central_commands.py +++ b/examples/azureiot_esp32spi/azureiot_central_commands.py @@ -8,7 +8,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -96,16 +96,21 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # pylint: disable=wrong-import-position from adafruit_azureiot import IoTCentralDevice from adafruit_azureiot.iot_mqtt import IoTResponse # pylint: enable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect device = IoTCentralDevice( - socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) diff --git a/examples/azureiot_esp32spi/azureiot_central_notconnected.py b/examples/azureiot_esp32spi/azureiot_central_notconnected.py index f78afd1..8cb7863 100644 --- a/examples/azureiot_esp32spi/azureiot_central_notconnected.py +++ b/examples/azureiot_esp32spi/azureiot_central_notconnected.py @@ -10,7 +10,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -90,7 +90,6 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # pylint: disable=wrong-import-position from adafruit_azureiot import ( IoTCentralDevice, @@ -99,9 +98,15 @@ # pylint: enable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect device = IoTCentralDevice( - socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) # don't connect diff --git a/examples/azureiot_esp32spi/azureiot_central_properties.py b/examples/azureiot_esp32spi/azureiot_central_properties.py index 826cdf2..43d131b 100644 --- a/examples/azureiot_esp32spi/azureiot_central_properties.py +++ b/examples/azureiot_esp32spi/azureiot_central_properties.py @@ -9,7 +9,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -97,12 +97,17 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect device = IoTCentralDevice( - socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) diff --git a/examples/azureiot_esp32spi/azureiot_central_simpletest.py b/examples/azureiot_esp32spi/azureiot_central_simpletest.py index 546b5d0..ad66d2c 100644 --- a/examples/azureiot_esp32spi/azureiot_central_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_central_simpletest.py @@ -10,7 +10,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -98,12 +98,17 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect device = IoTCentralDevice( - socket, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) print("Connecting to Azure IoT Central...") diff --git a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py index 1a9e079..b329c0e 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py +++ b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py @@ -8,7 +8,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -90,15 +90,16 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # pylint: disable=wrong-import-position from adafruit_azureiot import IoTHubDevice from adafruit_azureiot.iot_mqtt import IoTResponse # pylint: enable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(socket, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to direct method calls diff --git a/examples/azureiot_esp32spi/azureiot_hub_messages.py b/examples/azureiot_esp32spi/azureiot_hub_messages.py index 999de2e..956a3a8 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_messages.py +++ b/examples/azureiot_esp32spi/azureiot_hub_messages.py @@ -10,7 +10,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -92,11 +92,12 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(socket, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to cloud to device messages diff --git a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py index 2e16a57..20d7136 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py @@ -10,7 +10,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -92,11 +92,12 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(socket, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) print("Connecting to Azure IoT Hub...") diff --git a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py index 41944b8..3ed7842 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py +++ b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py @@ -9,7 +9,7 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager # Get wifi details and more from a secrets.py file try: @@ -94,11 +94,12 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(socket, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to device twin desired property updates diff --git a/examples/azureiot_native_networking/azureiot_central_commands.py b/examples/azureiot_native_networking/azureiot_central_commands.py index 07e151e..85b0476 100644 --- a/examples/azureiot_native_networking/azureiot_central_commands.py +++ b/examples/azureiot_native_networking/azureiot_central_commands.py @@ -4,9 +4,9 @@ import time import rtc -import socketpool import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTCentralDevice from adafruit_azureiot.iot_mqtt import IoTResponse @@ -21,11 +21,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -65,14 +67,15 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # Create an IoT Hub device client and connect -esp = None -pool = socketpool.SocketPool(wifi.radio) device = IoTCentralDevice( - pool, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) diff --git a/examples/azureiot_native_networking/azureiot_central_notconnected.py b/examples/azureiot_native_networking/azureiot_central_notconnected.py index 5ad0f47..b695dae 100644 --- a/examples/azureiot_native_networking/azureiot_central_notconnected.py +++ b/examples/azureiot_native_networking/azureiot_central_notconnected.py @@ -6,9 +6,9 @@ import time import rtc -import socketpool import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import ( IoTCentralDevice, @@ -25,11 +25,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -69,14 +71,15 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # Create an IoT Hub device client and connect -esp = None -pool = socketpool.SocketPool(wifi.radio) device = IoTCentralDevice( - pool, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) # don't connect diff --git a/examples/azureiot_native_networking/azureiot_central_properties.py b/examples/azureiot_native_networking/azureiot_central_properties.py index 91a0a33..7cbd9c0 100644 --- a/examples/azureiot_native_networking/azureiot_central_properties.py +++ b/examples/azureiot_native_networking/azureiot_central_properties.py @@ -5,9 +5,9 @@ import time import rtc -import socketpool import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTCentralDevice @@ -21,11 +21,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -65,14 +67,15 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # Create an IoT Hub device client and connect -esp = None -pool = socketpool.SocketPool(wifi.radio) device = IoTCentralDevice( - pool, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) diff --git a/examples/azureiot_native_networking/azureiot_central_simpletest.py b/examples/azureiot_native_networking/azureiot_central_simpletest.py index 0595783..8ce022d 100644 --- a/examples/azureiot_native_networking/azureiot_central_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_central_simpletest.py @@ -6,9 +6,9 @@ import time import rtc -import socketpool import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTCentralDevice @@ -22,11 +22,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -66,14 +68,15 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests # Create an IoT Hub device client and connect -esp = None -pool = socketpool.SocketPool(wifi.radio) device = IoTCentralDevice( - pool, esp, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"] + pool, + ssl_context, + secrets["id_scope"], + secrets["device_id"], + secrets["device_sas_key"], ) print("Connecting to Azure IoT Central...") diff --git a/examples/azureiot_native_networking/azureiot_hub_directmethods.py b/examples/azureiot_native_networking/azureiot_hub_directmethods.py index 9589cf9..c0857f0 100644 --- a/examples/azureiot_native_networking/azureiot_hub_directmethods.py +++ b/examples/azureiot_native_networking/azureiot_hub_directmethods.py @@ -3,10 +3,10 @@ import time -import socketpool import rtc import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTHubDevice from adafruit_azureiot.iot_mqtt import IoTResponse @@ -21,11 +21,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -59,13 +61,10 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests -esp = None -pool = socketpool.SocketPool(wifi.radio) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to direct method calls diff --git a/examples/azureiot_native_networking/azureiot_hub_messages.py b/examples/azureiot_native_networking/azureiot_hub_messages.py index 1baea14..cc9a57e 100644 --- a/examples/azureiot_native_networking/azureiot_hub_messages.py +++ b/examples/azureiot_native_networking/azureiot_hub_messages.py @@ -5,10 +5,10 @@ import random import time -import socketpool import rtc import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTHubDevice @@ -22,11 +22,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -60,13 +62,10 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests -esp = None -pool = socketpool.SocketPool(wifi.radio) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to cloud to device messages diff --git a/examples/azureiot_native_networking/azureiot_hub_simpletest.py b/examples/azureiot_native_networking/azureiot_hub_simpletest.py index acc7a94..8da982d 100644 --- a/examples/azureiot_native_networking/azureiot_hub_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_hub_simpletest.py @@ -5,10 +5,10 @@ import random import time -import socketpool import rtc import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTHubDevice @@ -22,11 +22,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -60,13 +62,10 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests -esp = None -pool = socketpool.SocketPool(wifi.radio) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) print("Connecting to Azure IoT Hub...") diff --git a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py index 3984527..90b3303 100644 --- a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py +++ b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py @@ -4,10 +4,10 @@ import random import time -import socketpool import rtc import wifi +import adafruit_connection_manager import adafruit_ntp from adafruit_azureiot import IoTHubDevice @@ -21,11 +21,13 @@ print("Connecting to WiFi...") wifi.radio.connect(secrets["ssid"], secrets["password"]) +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) + print("Connected to WiFi!") if time.localtime().tm_year < 2022: print("Setting System Time in UTC") - pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) # NOTE: This changes the system time so make sure you aren't assuming that time @@ -59,13 +61,10 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# * adafruit-circuitpython-requests -esp = None -pool = socketpool.SocketPool(wifi.radio) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, esp, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) # Subscribe to device twin desired property updates diff --git a/requirements.txt b/requirements.txt index 228aa2a..abf61e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,4 @@ Adafruit-Blinka adafruit-circuitpython-logging>=4.0.1 adafruit-circuitpython-minimqtt -adafruit-circuitpython-requests adafruit-circuitpython-binascii