From 10bb5307e030e18edf723bfda20e9addaf9e5c2c Mon Sep 17 00:00:00 2001 From: Justin Myers <justmobilize@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:13:18 -0800 Subject: [PATCH 1/2] Fix SSL and set_socket --- adafruit_azureiot/device_registration.py | 14 +++++++------- adafruit_azureiot/iot_mqtt.py | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/adafruit_azureiot/device_registration.py b/adafruit_azureiot/device_registration.py index 92fd80c..b616d3c 100644 --- a/adafruit_azureiot/device_registration.py +++ b/adafruit_azureiot/device_registration.py @@ -112,7 +112,7 @@ def _connect_to_mqtt(self) -> None: " - device_registration :: connect :: created mqtt client. connecting.." ) while not self._auth_response_received: - self._mqtt.loop() + self._mqtt.loop(2) self._logger.info( " - device_registration :: connect :: on_connect must be fired. Connected ?" @@ -139,7 +139,7 @@ def _start_registration(self) -> None: while self._operation_id is None and retry < 10: time.sleep(1) retry += 1 - self._mqtt.loop() + self._mqtt.loop(2) if self._operation_id is None: raise DeviceRegistrationError( @@ -159,7 +159,7 @@ def _wait_for_operation(self) -> None: while self._hostname is None and retry < 10: time.sleep(1) retry += 1 - self._mqtt.loop() + self._mqtt.loop(2) if self._hostname is None: raise DeviceRegistrationError( @@ -194,15 +194,15 @@ def register_device(self, expiry: int) -> str: "&skn=registration" ) - MQTT.set_socket(self._socket, self._iface) - self._mqtt = MQTT.MQTT( broker=constants.DPS_END_POINT, + port=8883, username=username, password=auth_string, - port=8883, - keep_alive=120, client_id=self._device_id, + is_ssl=True, + keep_alive=120, + socket_pool=self._socket, ssl_context=ssl.create_default_context(), ) diff --git a/adafruit_azureiot/iot_mqtt.py b/adafruit_azureiot/iot_mqtt.py index c55fbc2..0d13800 100644 --- a/adafruit_azureiot/iot_mqtt.py +++ b/adafruit_azureiot/iot_mqtt.py @@ -120,8 +120,6 @@ def _gen_sas_token(self) -> str: ) def _create_mqtt_client(self) -> None: - MQTT.set_socket(self._socket, self._iface) - log_text = ( f"- iot_mqtt :: _on_connect :: username = {self._username}, password = " + f"{self._passwd}" @@ -135,11 +133,13 @@ def _create_mqtt_client(self) -> None: self._mqtts = MQTT.MQTT( broker=self._hostname, + port=8883, username=self._username, password=self._passwd, - port=8883, - keep_alive=120, client_id=self._device_id, + is_ssl=True, + keep_alive=120, + socket_pool=self._socket, ssl_context=ssl.create_default_context(), ) @@ -457,7 +457,7 @@ def loop(self) -> None: if not self.is_connected(): return - self._mqtts.loop() + self._mqtts.loop(2) gc.collect() def send_device_to_cloud_message( From d36a351f822e2401867deb53da53278e6e652ff9 Mon Sep 17 00:00:00 2001 From: Justin Myers <justmobilize@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:18:57 -0800 Subject: [PATCH 2/2] Add ESP32SPI note --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 06d7fed..f79e725 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,8 @@ 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