Skip to content

Commit c648cc1

Browse files
committed
Did examples
1 parent 526356e commit c648cc1

21 files changed

+98
-61
lines changed

adafruit_azureiot/device_registration.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,21 @@ def register_device(self, expiry: int) -> str:
178178
:raises RuntimeError: if the internet connection is not responding or is unable to connect
179179
"""
180180

181-
username = (f"{self._id_scope}/registrations/{self._device_id}/api-version="
182-
f"{constants.DPS_API_VERSION}")
181+
username = (
182+
f"{self._id_scope}/registrations/{self._device_id}/api-version="
183+
f"{constants.DPS_API_VERSION}"
184+
)
183185

184186
# pylint: disable=C0103
185187
sr = self._id_scope + "%2Fregistrations%2F" + self._device_id
186188
sig_no_encode = compute_derived_symmetric_key(
187189
self._device_sas_key, sr + "\n" + str(expiry)
188190
)
189191
sig_encoded = quote(sig_no_encode, "~()*!.'")
190-
auth_string = (f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}"
191-
f"&skn=registration")
192+
auth_string = (
193+
f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}"
194+
f"&skn=registration"
195+
)
192196

193197
MQTT.set_socket(self._socket, self._iface)
194198

adafruit_azureiot/hmac.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,37 @@ def sha_init() -> dict:
6868
def ROR(x, y):
6969
return (((x & 0xFFFFFFFF) >> (y & 31)) | (x << (32 - (y & 31)))) & 0xFFFFFFFF
7070

71+
7172
def Ch(x, y, z):
72-
return (z ^ (x & (y ^ z)))
73+
return z ^ (x & (y ^ z))
74+
7375

7476
def Maj(x, y, z):
75-
return (((x | y) & z) | (x & y))
77+
return ((x | y) & z) | (x & y)
78+
7679

7780
def S(x, n):
7881
return ROR(x, n)
7982

83+
8084
def R(x, n):
8185
return (x & 0xFFFFFFFF) >> n
8286

87+
8388
def Sigma0(x):
84-
return (S(x, 2) ^ S(x, 13) ^ S(x, 22))
89+
return S(x, 2) ^ S(x, 13) ^ S(x, 22)
90+
8591

8692
def Sigma1(x):
87-
return (S(x, 6) ^ S(x, 11) ^ S(x, 25))
93+
return S(x, 6) ^ S(x, 11) ^ S(x, 25)
94+
8895

8996
def Gamma0(x):
90-
return (S(x, 7) ^ S(x, 18) ^ R(x, 3))
97+
return S(x, 7) ^ S(x, 18) ^ R(x, 3)
98+
9199

92100
def Gamma1(x):
93-
return (S(x, 17) ^ S(x, 19) ^ R(x, 10))
101+
return S(x, 17) ^ S(x, 19) ^ R(x, 10)
94102

95103

96104
def sha_transform(sha_info: dict) -> None:

adafruit_azureiot/iotcentral_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .iot_mqtt import IoTMQTT, IoTMQTTCallback, IoTResponse
2222

2323

24-
class IoTCentralDevice(IoTMQTTCallback):
24+
class IoTCentralDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes
2525
"""A device client for the Azure IoT Central service"""
2626

2727
def connection_status_change(self, connected: bool) -> None:

adafruit_azureiot/iothub_device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _validate_keys(connection_string_parts: Mapping) -> None:
6161
]
6262

6363

64-
class IoTHubDevice(IoTMQTTCallback):
64+
class IoTHubDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes
6565
"""A device client for the Azure IoT Hub service"""
6666

6767
def connection_status_change(self, connected: bool) -> None:
@@ -135,7 +135,7 @@ def device_twin_reported_updated(
135135
reported_property_name, reported_property_value, reported_version
136136
)
137137

138-
def __init__(
138+
def __init__( # pylint: disable=too-many-arguments
139139
self,
140140
socket,
141141
iface,

examples/azureiot_esp32spi/azureiot_central_commands.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@
7979
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
8080
# days, as well as free tiers of a load of services
8181
#
82-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
82+
# Create an Azure IoT Central app by following these instructions:
83+
# https://aka.ms/CreateIoTCentralApp
8384
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
8485
# telemetry and execute commands, and a form to set properties.
8586
#
86-
# Next create a device using the device template, and select Connect to get the device connection details.
87+
# Next create a device using the device template, and select Connect to get the device connection
88+
# details.
8789
# Add the connection details to your secrets.py file, using the following values:
8890
#
8991
# 'id_scope' - the devices ID scope
@@ -92,7 +94,7 @@
9294
#
9395
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9496
#
95-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
97+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9698
# * adafruit-circuitpython-minimqtt
9799
# * adafruit-circuitpython-requests
98100
# pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_central_notconnected.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@
7373
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7474
# days, as well as free tiers of a load of services
7575
#
76-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
76+
# Create an Azure IoT Central app by following these instructions:
77+
# https://aka.ms/CreateIoTCentralApp
7778
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
7879
# telemetry and execute commands, and a form to set properties.
7980
#
80-
# Next create a device using the device template, and select Connect to get the device connection details.
81+
# Next create a device using the device template, and select Connect to get the device connection
82+
# details.
8183
# Add the connection details to your secrets.py file, using the following values:
8284
#
8385
# 'id_scope' - the devices ID scope
@@ -86,7 +88,7 @@
8688
#
8789
# The adafruit-circuitpython-azureiot library depends on the following libraries:
8890
#
89-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
91+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9092
# * adafruit-circuitpython-minimqtt
9193
# * adafruit-circuitpython-requests
9294
# pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_central_properties.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@
8080
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
8181
# days, as well as free tiers of a load of services
8282
#
83-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
83+
# Create an Azure IoT Central app by following these instructions:
84+
# https://aka.ms/CreateIoTCentralApp
8485
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
8586
# telemetry and execute commands, and a form to set properties.
8687
#
87-
# Next create a device using the device template, and select Connect to get the device connection details.
88+
# Next create a device using the device template, and select Connect to get the device connection
89+
# details.
8890
# Add the connection details to your secrets.py file, using the following values:
8991
#
9092
# 'id_scope' - the devices ID scope
@@ -93,7 +95,7 @@
9395
#
9496
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9597
#
96-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
98+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9799
# * adafruit-circuitpython-minimqtt
98100
# * adafruit-circuitpython-requests
99101
from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_central_simpletest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@
8181
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
8282
# days, as well as free tiers of a load of services
8383
#
84-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
84+
# Create an Azure IoT Central app by following these instructions:
85+
# https://aka.ms/CreateIoTCentralApp
8586
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
8687
# telemetry and execute commands, and a form to set properties.
8788
#
88-
# Next create a device using the device template, and select Connect to get the device connection details.
89+
# Next create a device using the device template, and select Connect to get the device connection
90+
# details.
8991
# Add the connection details to your secrets.py file, using the following values:
9092
#
9193
# 'id_scope' - the devices ID scope
@@ -94,7 +96,7 @@
9496
#
9597
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9698
#
97-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
99+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
98100
# * adafruit-circuitpython-minimqtt
99101
# * adafruit-circuitpython-requests
100102
from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_hub_directmethods.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7777
# days, as well as free tiers of a load of services
7878
#
79-
# Create an Azure IoT Hub and an IoT device in the Azure portal here: https://aka.ms/AzurePortalHome.
79+
# Create an Azure IoT Hub and an IoT device in the Azure portal here:
80+
# https://aka.ms/AzurePortalHome.
8081
# Instructions to create an IoT Hub and device are here: https://aka.ms/CreateIoTHub
8182
#
8283
# The free tier of IoT Hub allows up to 8,000 messages a day, so try not to send messages too often
@@ -87,7 +88,7 @@
8788
#
8889
# The adafruit-circuitpython-azureiot library depends on the following libraries:
8990
#
90-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
91+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9192
# * adafruit-circuitpython-minimqtt
9293
# * adafruit-circuitpython-requests
9394
# pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_hub_messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7979
# days, as well as free tiers of a load of services
8080
#
81-
# Create an Azure IoT Hub and an IoT device in the Azure portal here: https://aka.ms/AzurePortalHome.
81+
# Create an Azure IoT Hub and an IoT device in the Azure portal here:
82+
# https://aka.ms/AzurePortalHome.
8283
# Instructions to create an IoT Hub and device are here: https://aka.ms/CreateIoTHub
8384
#
8485
# The free tier of IoT Hub allows up to 8,000 messages a day, so try not to send messages too often
@@ -89,7 +90,7 @@
8990
#
9091
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9192
#
92-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
93+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9394
# * adafruit-circuitpython-minimqtt
9495
# * adafruit-circuitpython-requests
9596
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_hub_simpletest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7979
# days, as well as free tiers of a load of services
8080
#
81-
# Create an Azure IoT Hub and an IoT device in the Azure portal here: https://aka.ms/AzurePortalHome.
81+
# Create an Azure IoT Hub and an IoT device in the Azure portal here:
82+
# https://aka.ms/AzurePortalHome.
8283
# Instructions to create an IoT Hub and device are here: https://aka.ms/CreateIoTHub
8384
#
8485
# The free tier of IoT Hub allows up to 8,000 messages a day, so try not to send messages too often
@@ -89,7 +90,7 @@
8990
#
9091
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9192
#
92-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
93+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9394
# * adafruit-circuitpython-minimqtt
9495
# * adafruit-circuitpython-requests
9596
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_hub_twin_operations.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7878
# days, as well as free tiers of a load of services
7979
#
80-
# Create an Azure IoT Hub and an IoT device in the Azure portal here: https://aka.ms/AzurePortalHome.
80+
# Create an Azure IoT Hub and an IoT device in the Azure portal here:
81+
# https://aka.ms/AzurePortalHome.
8182
# Instructions to create an IoT Hub and device are here: https://aka.ms/CreateIoTHub
8283
#
8384
# The free tier of IoT Hub allows up to 8,000 messages a day, so try not to send messages too often
@@ -91,7 +92,7 @@
9192
#
9293
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9394
#
94-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
95+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9596
# * adafruit-circuitpython-minimqtt
9697
# * adafruit-circuitpython-requests
9798
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position
@@ -132,8 +133,8 @@ def device_twin_desired_updated(
132133
try:
133134
if message_counter >= 60:
134135
# Send a reported property twin update every minute
135-
# You can see these in the portal by selecting the device in the IoT Hub blade, selecting
136-
# Device Twin then looking for the updates in the 'reported' section
136+
# You can see these in the portal by selecting the device in the IoT Hub blade,
137+
# selecting device Twin then looking for the updates in the 'reported' section
137138
patch = {"Temperature": random.randint(0, 50)}
138139
device.update_twin(patch)
139140
message_counter = 0

examples/azureiot_native_networking/azureiot_central_commands.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
4949
# days, as well as free tiers of a load of services
5050
#
51-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
51+
# Create an Azure IoT Central app by following these instructions:
52+
# https://aka.ms/CreateIoTCentralApp
5253
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
5354
# telemetry and execute commands, and a form to set properties.
5455
#
55-
# Next create a device using the device template, and select Connect to get the device connection details.
56+
# Next create a device using the device template, and select Connect to get the device connection
57+
# details.
5658
# Add the connection details to your secrets.py file, using the following values:
5759
#
5860
# 'id_scope' - the devices ID scope
@@ -61,7 +63,7 @@
6163
#
6264
# The adafruit-circuitpython-azureiot library depends on the following libraries:
6365
#
64-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
66+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
6567
# * adafruit-circuitpython-minimqtt
6668
# * adafruit-circuitpython-requests
6769

examples/azureiot_native_networking/azureiot_central_notconnected.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
5353
# days, as well as free tiers of a load of services
5454
#
55-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
55+
# Create an Azure IoT Central app by following these instructions:
56+
# https://aka.ms/CreateIoTCentralApp
5657
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
5758
# telemetry and execute commands, and a form to set properties.
5859
#
59-
# Next create a device using the device template, and select Connect to get the device connection details.
60+
# Next create a device using the device template, and select Connect to get the device connection
61+
# details.
6062
# Add the connection details to your secrets.py file, using the following values:
6163
#
6264
# 'id_scope' - the devices ID scope
@@ -65,7 +67,7 @@
6567
#
6668
# The adafruit-circuitpython-azureiot library depends on the following libraries:
6769
#
68-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
70+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
6971
# * adafruit-circuitpython-minimqtt
7072
# * adafruit-circuitpython-requests
7173

examples/azureiot_native_networking/azureiot_central_properties.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
4949
# days, as well as free tiers of a load of services
5050
#
51-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
51+
# Create an Azure IoT Central app by following these instructions:
52+
# https://aka.ms/CreateIoTCentralApp
5253
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
5354
# telemetry and execute commands, and a form to set properties.
5455
#
55-
# Next create a device using the device template, and select Connect to get the device connection details.
56+
# Next create a device using the device template, and select Connect to get the device connection
57+
# details.
5658
# Add the connection details to your secrets.py file, using the following values:
5759
#
5860
# 'id_scope' - the devices ID scope
@@ -61,7 +63,7 @@
6163
#
6264
# The adafruit-circuitpython-azureiot library depends on the following libraries:
6365
#
64-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
66+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
6567
# * adafruit-circuitpython-minimqtt
6668
# * adafruit-circuitpython-requests
6769

examples/azureiot_native_networking/azureiot_central_simpletest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@
4949
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
5050
# days, as well as free tiers of a load of services
5151
#
52-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
52+
# Create an Azure IoT Central app by following these instructions:
53+
# https://aka.ms/CreateIoTCentralApp
5354
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
5455
# telemetry and execute commands, and a form to set properties.
5556
#
56-
# Next create a device using the device template, and select Connect to get the device connection details.
57+
# Next create a device using the device template, and select Connect to get the device connection
58+
# details.
5759
# Add the connection details to your secrets.py file, using the following values:
5860
#
5961
# 'id_scope' - the devices ID scope
@@ -62,7 +64,7 @@
6264
#
6365
# The adafruit-circuitpython-azureiot library depends on the following libraries:
6466
#
65-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
67+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
6668
# * adafruit-circuitpython-minimqtt
6769
# * adafruit-circuitpython-requests
6870

0 commit comments

Comments
 (0)