You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Access to `Microsoft Azure IoT <https://azure.microsoft.com/en-us/overview/iot/>`_ from a CircuitPython device. This library can perform device
17
-
messaging services (cloud-to-device, device-to-cloud), device services, and job services.
16
+
A CircuitPython device library for `Microsoft Azure IoT Services <https://azure.microsoft.com/overview/iot/?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`_ from a CircuitPython device. This library only supports key-base authentication, it currently doesn't support X.509 certificates.
Please ensure all dependencies are available on the CircuitPython filesystem.
50
54
This is easily achieved by downloading
51
-
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
55
+
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_
56
+
and
57
+
`the CircuitPython community library and driver bundle <https://github.com/adafruit/CircuitPython_Community_Bundle>`_
52
58
53
59
Usage Example
54
60
=============
55
61
56
-
Create an instance of an Azure IoT Hub (you'll need your SAS Token).
62
+
This library supports both `Azure IoT Hub <https://azure.microsoft.com/services/iot-hub/?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`_ and `Azure IoT Central <https://azure.microsoft.com/services/iot-central/?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`__.
63
+
64
+
To create an Azure IoT Hub instance or an Azure IoT Central app, you will need an Azure subscription. If you don't have an Azure subscription, you can sign up for free:
65
+
66
+
- If you are a student 18 or over, head to `aka.ms/FreeStudentAzure <https://aka.ms/FreeStudentAzure>`_ and sign up, validating with your student email address. This will give you $100 of Azure credit and free tiers of a load of service, renewable each year you are a student. You will not need a credit card.
67
+
68
+
- If you are not a student, head to `aka.ms/FreeAz <https://aka.ms/FreeAz>`_ and sign up to get $200 of credit for 30 days, as well as free tiers of a load of services. You will need a credit card for validation only, your card will not be charged.
69
+
70
+
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 via the `Adafruit CircuitPython NTP <https://github.com/adafruit/Adafruit_CircuitPython_NTP>`_ library with the following code:
71
+
72
+
.. code-block:: python
73
+
74
+
ntp = NTP(esp)
75
+
76
+
# Wait for a valid time to be received
77
+
whilenot ntp.valid_time:
78
+
time.sleep(5)
79
+
ntp.set_time()
80
+
81
+
Azure IoT Hub
82
+
-------------
83
+
84
+
To interact with Azure IoT Hub, you will need to create a hub, and a register a device inside that hub. There is a free tier available, and this free tier allows up to 8,000 messages a day, so try not to send messages too often if you are using this tier.
85
+
86
+
- Open the `Azure Portal <https://aka.ms/AzurePortalHome>`_.
87
+
- Follow the instructions in `Microsoft Docs <https://aka.ms/CreateIoTHub>`_ to create an Azure IoT Hub and register a device.
88
+
- Copy the devices Primary or secondary connection string, and add this to your ``secrets.py`` file.
89
+
90
+
You can find the device connection string by selecting the IoT Hub in the `Azure Portal <https://aka.ms/AzurePortalHome>`_, *selecting Explorer -> IoT devices*, then selecting your device.
91
+
92
+
.. image:: iot-hub-device.png
93
+
:alt:Locating the device in the IoT hub blade
94
+
95
+
*Locating the device in the IoT hub blade*
96
+
97
+
Then copy either the primary or secondary connection string using the copy button next to the value.
To use Azure IoT Central, you will need to create an Azure IoT Central app, create a device template and register a device against the template.
175
+
176
+
- Head to `Azure IoT Central <https://apps.azureiotcentral.com/?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`__
177
+
- Follow the instructions in the `Microsoft Docs <https://docs.microsoft.com/azure/iot-central/core/quick-deploy-iot-central?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`__ to create an application. Every tier is free for up to 2 devices.
178
+
- Follow the instructions in the `Microsoft Docs <https://docs.microsoft.com/azure/iot-central/core/quick-create-simulated-device?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`__ to create a device template.
179
+
- Create a device based off the template, and select **Connect** to get the device connection details. Store the ID Scope, Device ID and either the Primary or secondary Key in your ``secrets.py`` file.
180
+
181
+
.. image:: iot-central-connect-button.png
182
+
:alt:The IoT Central connect button
183
+
184
+
*The connect button*
185
+
186
+
.. image:: iot-central-connect-dialog.png
187
+
:alt:The IoT Central connection details dialog
188
+
189
+
*The connection details dialog*
69
190
70
191
.. code-block:: python
71
192
72
-
hub_devices = my_hub.get_devices()
193
+
secrets = {
194
+
# WiFi settings
195
+
"ssid": "",
196
+
"password": "",
73
197
74
-
Get information about the current device on an Azure IoT Hub
198
+
# Azure IoT Central settings
199
+
"id_scope": "",
200
+
"device_id": "",
201
+
"key": ""
202
+
}
203
+
204
+
**Connect your device to your Azure IoT Central app**
If you want to learn more about setting up or using Azure IoT Services, check out the following resources:
260
+
261
+
- `Azure IoT documentation on Microsoft Docs <https://docs.microsoft.com/azure/iot-fundamentals/?WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`_
262
+
- `IoT learning paths and modules on Microsoft Learn <https://docs.microsoft.com/learn/browse/?term=iot&WT.mc_id=AdafruitCircuitPythonAzureIoT-github-jabenn>`_ - Free, online, self-guided hands on learning with Azure IoT services
0 commit comments