Skip to content

Commit 75af72b

Browse files
committed
Fix miniMQTT compatibility and native_networking examples
1 parent 9c5c57f commit 75af72b

15 files changed

+430
-22
lines changed

.gitignore

Lines changed: 193 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,200 @@
33
# SPDX-License-Identifier: Unlicense
44

55
*.mpy
6-
.idea
7-
__pycache__
86
_build
97
*.pyc
10-
.env
118
bundles
12-
*.DS_Store
13-
.eggs
14-
dist
15-
**/*.egg-info
16-
.vscode/settings.json
9+
10+
.vscode/*
11+
!.vscode/settings.json
12+
!.vscode/tasks.json
13+
!.vscode/launch.json
14+
!.vscode/extensions.json
15+
!.vscode/*.code-snippets
16+
17+
# Local History for Visual Studio Code
18+
.history/
19+
20+
# Built Visual Studio Code Extensions
21+
*.vsix
22+
23+
# Byte-compiled / optimized / DLL files
24+
__pycache__/
25+
*.py[cod]
26+
*$py.class
27+
28+
# C extensions
29+
*.so
30+
31+
# Distribution / packaging
32+
.Python
33+
build/
34+
develop-eggs/
35+
dist/
36+
downloads/
37+
eggs/
38+
.eggs/
39+
lib/
40+
lib64/
41+
parts/
42+
sdist/
43+
var/
44+
wheels/
45+
share/python-wheels/
46+
*.egg-info/
47+
.installed.cfg
48+
*.egg
49+
MANIFEST
50+
51+
# PyInstaller
52+
# Usually these files are written by a python script from a template
53+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
54+
*.manifest
55+
*.spec
56+
57+
# Installer logs
58+
pip-log.txt
59+
pip-delete-this-directory.txt
60+
61+
# Unit test / coverage reports
62+
htmlcov/
63+
.tox/
64+
.nox/
65+
.coverage
66+
.coverage.*
67+
.cache
68+
nosetests.xml
69+
coverage.xml
70+
*.cover
71+
*.py,cover
72+
.hypothesis/
73+
.pytest_cache/
74+
cover/
75+
76+
# Translations
77+
*.mo
78+
*.pot
79+
80+
# Django stuff:
81+
*.log
82+
local_settings.py
83+
db.sqlite3
84+
db.sqlite3-journal
85+
86+
# Flask stuff:
87+
instance/
88+
.webassets-cache
89+
90+
# Scrapy stuff:
91+
.scrapy
92+
93+
# Sphinx documentation
94+
docs/_build/
95+
96+
# PyBuilder
97+
.pybuilder/
98+
target/
99+
100+
# Jupyter Notebook
101+
.ipynb_checkpoints
102+
103+
# IPython
104+
profile_default/
105+
ipython_config.py
106+
107+
# pyenv
108+
# For a library or package, you might want to ignore these files since the code is
109+
# intended to run in multiple environments; otherwise, check them in:
110+
# .python-version
111+
112+
# pipenv
113+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
114+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
115+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
116+
# install all needed dependencies.
117+
#Pipfile.lock
118+
119+
# poetry
120+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
121+
# This is especially recommended for binary packages to ensure reproducibility, and is more
122+
# commonly ignored for libraries.
123+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
124+
#poetry.lock
125+
126+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
127+
__pypackages__/
128+
129+
# Celery stuff
130+
celerybeat-schedule
131+
celerybeat.pid
132+
133+
# SageMath parsed files
134+
*.sage.py
135+
136+
# Environments
137+
.env
17138
.venv
139+
env/
140+
venv/
141+
ENV/
142+
env.bak/
143+
venv.bak/
144+
145+
# Spyder project settings
146+
.spyderproject
147+
.spyproject
148+
149+
# Rope project settings
150+
.ropeproject
151+
152+
# mkdocs documentation
153+
/site
154+
155+
# mypy
156+
.mypy_cache/
157+
.dmypy.json
158+
dmypy.json
159+
160+
# Pyre type checker
161+
.pyre/
162+
163+
# pytype static type analyzer
164+
.pytype/
165+
166+
# Cython debug symbols
167+
cython_debug/
168+
169+
# PyCharm
170+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
171+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
172+
# and can be added to the global gitignore or merged into this file. For a more nuclear
173+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
174+
.idea/
175+
176+
# General
177+
.DS_Store
178+
.AppleDouble
179+
.LSOverride
180+
181+
# Icon must end with two \r
182+
Icon
183+
184+
185+
# Thumbnails
186+
._*
187+
188+
# Files that might appear in the root of a volume
189+
.DocumentRevisions-V100
190+
.fseventsd
191+
.Spotlight-V100
192+
.TemporaryItems
193+
.Trashes
194+
.VolumeIcon.icns
195+
.com.apple.timemachine.donotpresent
196+
197+
# Directories potentially created on remote AFP share
198+
.AppleDB
199+
.AppleDesktop
200+
Network Trash Folder
201+
Temporary Items
202+
.apdisk

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea
203203
204204
from adafruit_azureiot import IoTCentralDevice
205205
206-
device = IoTCentralDevice(wifi, secrets["id_scope"], secrets["device_id"], secrets["key"])
206+
device = IoTCentralDevice(wifi, secrets["id_scope"], secrets["device_id"], secrets["sas_key"])
207207
device.connect()
208208
209209
Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud.

adafruit_azureiot/device_registration.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
"""
1515

1616
import json
17+
import ssl
1718
import time
19+
1820
import adafruit_logging as logging
1921
from adafruit_logging import Logger
20-
import adafruit_minimqtt.adafruit_minimqtt as minimqtt
22+
import adafruit_minimqtt.adafruit_minimqtt as MQTT
23+
2124
from . import constants
2225
from .quote import quote
2326
from .keys import compute_derived_symmetric_key
@@ -177,16 +180,16 @@ def register_device(self, expiry: int) -> str:
177180
sig_encoded = quote(sig_no_encode, "~()*!.'")
178181
auth_string = f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={str(expiry)}&skn=registration"
179182

180-
minimqtt.set_socket(self._socket, self._iface)
183+
MQTT.set_socket(self._socket, self._iface)
181184

182-
self._mqtt = minimqtt.MQTT(
185+
self._mqtt = MQTT.MQTT(
183186
broker=constants.DPS_END_POINT,
184187
username=username,
185188
password=auth_string,
186189
port=8883,
187190
keep_alive=120,
188-
is_ssl=True,
189191
client_id=self._device_id,
192+
ssl_context=ssl.create_default_context(),
190193
)
191194

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

adafruit_azureiot/iot_mqtt.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414

1515
import gc
1616
import json
17+
import ssl
1718
import time
18-
import adafruit_minimqtt.adafruit_minimqtt as minimqtt
19+
20+
import adafruit_minimqtt.adafruit_minimqtt as MQTT
1921
import adafruit_logging as logging
22+
2023
from .iot_error import IoTError
2124
from .keys import compute_derived_symmetric_key
2225
from .quote import quote
@@ -108,7 +111,7 @@ def _gen_sas_token(self) -> str:
108111
return token
109112

110113
def _create_mqtt_client(self) -> None:
111-
minimqtt.set_socket(self._socket, self._iface)
114+
MQTT.set_socket(self._socket, self._iface)
112115

113116
self._logger.debug(
114117
str.replace(
@@ -118,14 +121,14 @@ def _create_mqtt_client(self) -> None:
118121
)
119122
)
120123

121-
self._mqtts = minimqtt.MQTT(
124+
self._mqtts = MQTT.MQTT(
122125
broker=self._hostname,
123126
username=self._username,
124127
password=self._passwd,
125128
port=8883,
126129
keep_alive=120,
127-
is_ssl=True,
128130
client_id=self._device_id,
131+
ssl_context=ssl.create_default_context(),
129132
)
130133

131134
self._mqtts.enable_logger(logging, self._logger.getEffectiveLevel())

examples/azureiot_central_commands.py renamed to examples/ esp32spi /azureiot_central_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
# Create an IoT Hub device client and connect
101101
device = IoTCentralDevice(
102-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"]
102+
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["sas_key"]
103103
)
104104

105105
# Subscribe to commands

examples/azureiot_central_notconnected.py renamed to examples/ esp32spi /azureiot_central_notconnected.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103

104104
# Create an IoT Hub device client and connect
105105
device = IoTCentralDevice(
106-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"]
106+
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["sas_key"]
107107
)
108108

109109
# don't connect

examples/azureiot_central_properties.py renamed to examples/ esp32spi /azureiot_central_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
# Create an IoT Hub device client and connect
9898
device = IoTCentralDevice(
99-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"]
99+
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["sas_key"]
100100
)
101101

102102
# Subscribe to property changes

examples/azureiot_central_simpletest.py renamed to examples/ esp32spi /azureiot_central_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
# Create an IoT Hub device client and connect
9999
device = IoTCentralDevice(
100-
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"]
100+
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["sas_key"]
101101
)
102102

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

examples/azureiot_secrets_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# key comes from either the Primary key or Secondary key
2828
"id_scope": "",
2929
"device_id": "",
30-
"key": "",
30+
"sas_key": "",
3131
# Azure IoT Hub settings - if you are connecting to Azure IoT Hub, fill in this value
3232
# To get this value, from the Azure Portal (https://aka.ms/AzurePortalHome), select your IoT Hub,
3333
# then select Explorers -> IoT devices, select your device, then copy the entire primary or secondary

0 commit comments

Comments
 (0)