Skip to content

Commit 5421ff8

Browse files
authored
Merge pull request #63 from justmobilize/fix-ssl-and-set-socket
Fix SSL and set_socket
2 parents 99e3d34 + d36a351 commit 5421ff8

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ To create an Azure IoT Hub instance or an Azure IoT Central app, you will need a
7373
ESP32 AirLift Networking
7474
========================
7575

76+
*NOTE* currently the ESP32 AirLift is not supported due to the requirment of `ssl`, which is only on boards with native WiFi.
77+
7678
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:
7779

7880
.. code-block:: python

adafruit_azureiot/device_registration.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _connect_to_mqtt(self) -> None:
112112
" - device_registration :: connect :: created mqtt client. connecting.."
113113
)
114114
while not self._auth_response_received:
115-
self._mqtt.loop()
115+
self._mqtt.loop(2)
116116

117117
self._logger.info(
118118
" - device_registration :: connect :: on_connect must be fired. Connected ?"
@@ -139,7 +139,7 @@ def _start_registration(self) -> None:
139139
while self._operation_id is None and retry < 10:
140140
time.sleep(1)
141141
retry += 1
142-
self._mqtt.loop()
142+
self._mqtt.loop(2)
143143

144144
if self._operation_id is None:
145145
raise DeviceRegistrationError(
@@ -159,7 +159,7 @@ def _wait_for_operation(self) -> None:
159159
while self._hostname is None and retry < 10:
160160
time.sleep(1)
161161
retry += 1
162-
self._mqtt.loop()
162+
self._mqtt.loop(2)
163163

164164
if self._hostname is None:
165165
raise DeviceRegistrationError(
@@ -194,15 +194,15 @@ def register_device(self, expiry: int) -> str:
194194
"&skn=registration"
195195
)
196196

197-
MQTT.set_socket(self._socket, self._iface)
198-
199197
self._mqtt = MQTT.MQTT(
200198
broker=constants.DPS_END_POINT,
199+
port=8883,
201200
username=username,
202201
password=auth_string,
203-
port=8883,
204-
keep_alive=120,
205202
client_id=self._device_id,
203+
is_ssl=True,
204+
keep_alive=120,
205+
socket_pool=self._socket,
206206
ssl_context=ssl.create_default_context(),
207207
)
208208

adafruit_azureiot/iot_mqtt.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ def _gen_sas_token(self) -> str:
120120
)
121121

122122
def _create_mqtt_client(self) -> None:
123-
MQTT.set_socket(self._socket, self._iface)
124-
125123
log_text = (
126124
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = "
127125
+ f"{self._passwd}"
@@ -135,11 +133,13 @@ def _create_mqtt_client(self) -> None:
135133

136134
self._mqtts = MQTT.MQTT(
137135
broker=self._hostname,
136+
port=8883,
138137
username=self._username,
139138
password=self._passwd,
140-
port=8883,
141-
keep_alive=120,
142139
client_id=self._device_id,
140+
is_ssl=True,
141+
keep_alive=120,
142+
socket_pool=self._socket,
143143
ssl_context=ssl.create_default_context(),
144144
)
145145

@@ -457,7 +457,7 @@ def loop(self) -> None:
457457
if not self.is_connected():
458458
return
459459

460-
self._mqtts.loop()
460+
self._mqtts.loop(2)
461461
gc.collect()
462462

463463
def send_device_to_cloud_message(

0 commit comments

Comments
 (0)