Skip to content

Commit 0e3a968

Browse files
authored
Merge pull request #34 from Azure/ewertons/updateadusamplereadme
Add improvements to ADU sample readme documentation
2 parents 4215a2f + f3dca34 commit 0e3a968

File tree

1 file changed

+112
-76
lines changed

1 file changed

+112
-76
lines changed

examples/Azure_IoT_Adu_ESP32/readme.md

Lines changed: 112 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ products:
2323
- [Introduction](#introduction)
2424
- [What is Covered](#what-is-covered)
2525
- [Prerequisites](#prerequisites)
26-
- [Setup Instructions](#setup-instructions)
26+
- [Add Azure IoT Hub Device to an ADU Deployment Group](#add-azure-iot-hub-device-to-an-adu-deployment-group)
27+
- [Device Setup Instructions](#device-setup-instructions)
2728
- [New Image Instructions](#new-image-instructions)
2829
- [Generate the ADU Update Manifest](#generate-the-adu-update-manifest)
2930
- [Import the Update Manifest](#import-the-update-manifest)
30-
- [Tag Your Device](#tag-your-device)
31-
- [Upload Base Image Instructions](#upload-base-image-instructions)
3231
- [Deploy Update](#deploy-update)
32+
- [Monitor the Update Process](#monitor-the-update-process)
3333
- [Certificates - Important to know](#certificates---important-to-know)
3434
- [Additional Information](#additional-information)
3535
- [Troubleshooting](#troubleshooting)
@@ -63,7 +63,23 @@ _The following was run on Windows 11 and Ubuntu Desktop 20.04 environments, with
6363
- ESP32 boards are not natively supported by Arduino IDE, so you need to add them manually.
6464
- Follow the [instructions](https://github.com/espressif/arduino-esp32) in the official ESP32 repository.
6565

66-
## Setup Instructions
66+
67+
## Add Azure IoT Hub Device to an ADU Deployment Group
68+
69+
Add the `"ADUGroup"` tag to the device's top-level twin document. This is used to group devices together, and you may choose whichever tag you prefer (e.g., "embeddedSDK").
70+
71+
```json
72+
"tags": {
73+
"ADUGroup": "<your-tag-here>"
74+
},
75+
```
76+
77+
Viewing the device twin on the portal, the "tag" section should look similar to the following. Don't worry if you do or do not have a `"deviceUpdate"` section in the `"ADUGroup"` tag. ADU adds that as a default group.
78+
79+
![img](./docs/tagged-twin.png)
80+
81+
82+
## Device Setup Instructions
6783

6884
1. Run the Arduino IDE.
6985

@@ -91,75 +107,15 @@ _The following was run on Windows 11 and Ubuntu Desktop 20.04 environments, with
91107
- Add your cert PK to `IOT_CONFIG_DEVICE_CERT_PRIVATE_KEY`
92108
- If using **Symmetric Key**:
93109
- Add your device key to `IOT_CONFIG_DEVICE_KEY`
94-
- **IMPORTANT**: make sure to change the `ADU_DEVICE_VERSION` to version 1.1 so that we can build the new update image.
95-
96-
1. Select the appropriate partition scheme for your device. Go to `Tools` -> `Partition Scheme` -> `Minimal SPIFFS`.
97-
98-
## New Image Instructions
99-
100-
In order to update our device, we have to build the image which our device will update to. We will have to direct the Arduino IDE to specify an output directory so that we can easily find the binary. Open the `preferences.txt` (usually located at `C:\Users\<Your User Dir>\AppData\Local\Arduino15\`) and add `build.path=C:\Arduino-output` (or whichever directory you prefer).
101-
102-
Once you are done with the ADU sample, you may remove the added configuration to restore the build output to its original location.
103110

104111
1. Connect the ESP32 microcontroller to your USB port.
105112

106-
2. On the Arduino IDE, select the board and port.
113+
After connecting the device,
107114

108115
- Go to menu `Tools`, `Board` and select `ESP32`.
109116
- Go to menu `Tools`, `Port` and select the port to which the microcontroller is connected.
110117

111-
3. Click on "Verify" to build the update image. Make sure you changed the `ADU_DEVICE_VERSION` in your `iot_configs.h` file to `1.1`. You should now have a file called `Azure_IoT_Adu_ESP32.ino.bin` in your output directory. Copy that file to a new directory `C:\ADU-update`, and rename it `Azure_IoT_Adu_ESP32_1.1.bin`
112-
113-
### Generate the ADU Update Manifest
114-
115-
Navigate to the `C:\ADU-update` directory in a Powershell prompt.
116-
117-
Clone the ADU toolset.
118-
119-
```bash
120-
git clone https://github.com/Azure/iot-hub-device-update
121-
```
122-
123-
Generate the update manifest using **powershell**.
124-
125-
```powershell
126-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
127-
Import-Module .\iot-hub-device-update\tools\AduCmdlets\AduUpdate.psm1
128-
$updateId = New-AduUpdateId -Provider "ESPRESSIF" -Name "ESP32-Embedded" -Version 1.1
129-
$compat = New-AduUpdateCompatibility -Properties @{ deviceManufacturer = 'ESPRESSIF'; deviceModel = 'ESP32-Embedded' }
130-
$installStep = New-AduInstallationStep -Handler 'microsoft/swupdate:1'-HandlerProperties @{ installedCriteria = '1.1' } -Files C:\ADU-update\Azure_IoT_Adu_ESP32_1.1.bin
131-
$update = New-AduImportManifest -UpdateId $updateId -Compatibility $compat -InstallationSteps $installStep
132-
$update | Out-File "./$($updateId.provider).$($updateId.name).$($updateId.version).importmanifest.json" -Encoding utf8
133-
```
134-
135-
Verify you have the following files in your ADU-update directory:
136-
137-
- `Azure_IoT_Adu_ESP32_1.1.bin`
138-
- `ESPRESSIF.ESP32-Embedded.1.1.importmanifest.json`
139-
140-
### Import the Update Manifest
141-
142-
To import the update (`Azure_IoT_Adu_ESP32_1.1.bin`) and manifest (`ESPRESSIF.ESP32-Embedded.1.1.importmanifest.json`), follow the instructions at the link below:
143-
144-
- [Import Update and Manifest](https://docs.microsoft.com/azure/iot-hub-device-update/import-update)
145-
146-
### Tag Your Device
147-
148-
Add the `"ADUGroup"` tag to the device's top-level twin document. This is used to group devices together, and you may choose whichever tag you prefer (e.g., "embeddedSDK").
149-
150-
```json
151-
"tags": {
152-
"ADUGroup": "<your-tag-here>"
153-
},
154-
```
155-
156-
Viewing the device twin on the portal, the "tag" section should look similar to the following. Don't worry if you do or do not have a `"deviceUpdate"` section in the `"ADUGroup"` tag. ADU adds that as a default group.
157-
158-
![img](./docs/tagged-twin.png)
159-
160-
## Upload Base Image Instructions
161-
162-
Now revert the `ADU_DEVICE_VERSION` in your `iot_configs.h` file to `1.0` to create the base image.
118+
1. Select the appropriate partition scheme for your device. Go to `Tools` -> `Partition Scheme` -> `Minimal SPIFFS`.
163119

164120
1. Upload the sketch.
165121

@@ -222,30 +178,110 @@ Now revert the `ADU_DEVICE_VERSION` in your `iot_configs.h` file to `1.0` to cre
222178
</p>
223179
</details>
224180
225-
2. Monitor the MCU (microcontroller) locally via the Serial Port.
181+
1. Monitor the MCU (microcontroller) locally via the Serial Port.
226182
227183
- Go to menu `Tools`, `Serial Monitor`.
228184
229185
If you perform this step right away after uploading the sketch, the serial monitor will show an output similar to the following upon success:
230186
231187
```text
232-
Connecting to WIFI SSID buckaroo
233-
.......................WiFi connected, IP address:
234-
192.168.1.123
235-
Setting time using SNTP..............................done!
236-
Current time: Thu May 28 02:55:05 2020
237-
Client ID: mydeviceid
238-
Username: myiothub.azure-devices.net/mydeviceid/?api-version=2018-06-30&DeviceClientType=c%2F1.0.0
239-
SharedAccessSignature sr=myiothub.azure-devices.net%2Fdevices%2Fmydeviceid&sig=placeholder-password&se=1590620105
240-
MQTT connecting ... connected.
188+
1970/1/1 00:00:41 [INFO] WiFi connected, IP address: 192.168.1.123
189+
1970/1/1 00:00:41 [INFO] Setting time using SNTP
190+
....
191+
2022/11/2 20:56:20 [INFO] Time initialized!
192+
2022/11/2 20:56:20 [INFO] ------------------------------------------------------------------------------
193+
2022/11/2 20:56:20 [INFO] ADU SAMPLE
194+
2022/11/2 20:56:20 [INFO] Version: 1.0
195+
2022/11/2 20:56:20 [INFO] ------------------------------------------------------------------------------
196+
2022/11/2 20:56:20 [INFO] Client ID: mydeviceid
197+
2022/11/2 20:56:20 [INFO] Username: myiothub.azure-devices.net/mydeviceid/?api-version=2020-09-30&DeviceClientType=c%2f1.4.0-beta.1(ard;esp32)&model-id=dtmi%3Aazure%3Aiot%3AdeviceUpdateModel%3B1
198+
2022/11/2 20:202256/11/2: 20:56:2020 [INFO] [INFO] MQTT event MQTT_EVENT_BEFORE_CONNECT
199+
MQTT client started
200+
2022/11/2 20:56:20 [INFO] Requesting all device properties
201+
2022/11/2 20:56:20 [INFO] Client requesting device property document from service.
202+
2022/11/2 20:56:27 [INFO] MQTT event MQTT_EVENT_CONNECTED
241203
```
242204
205+
206+
## New Image Instructions
207+
208+
In order to update our device, we have to build the image which our device will update to. We will have to direct the Arduino IDE to specify an output directory so that we can easily find the binary. Open the `preferences.txt` (find its path going to menu `File`, `Preferences`) and add `build.path=C:\Arduino-output` (or whichever directory you prefer), then restart the Arduino IDE.
209+
210+
Once you are done with the ADU sample, you may remove the added configuration to restore the build output to its original location.
211+
212+
1. Update the image version in the sketch configuration
213+
214+
- In `iot_configs.h`, change the `ADU_DEVICE_VERSION` to version 1.1.
215+
216+
1. Click on "Verify" to build the update image.
217+
218+
Once the build is complete, you should then have a file called `Azure_IoT_Adu_ESP32.ino.bin` in your output directory. Copy that file to a new directory `C:\ADU-update`, and rename it `Azure_IoT_Adu_ESP32_1.1.bin`
219+
220+
### Generate the ADU Update Manifest
221+
222+
Navigate to the `C:\ADU-update` directory in a Powershell prompt.
223+
224+
Clone the ADU toolset.
225+
226+
```bash
227+
git clone https://github.com/Azure/iot-hub-device-update
228+
```
229+
230+
Generate the update manifest using **powershell**.
231+
232+
```powershell
233+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
234+
Import-Module .\iot-hub-device-update\tools\AduCmdlets\AduUpdate.psm1
235+
$updateId = New-AduUpdateId -Provider "ESPRESSIF" -Name "ESP32-Embedded" -Version 1.1
236+
$compat = New-AduUpdateCompatibility -Properties @{ deviceManufacturer = 'ESPRESSIF'; deviceModel = 'ESP32-Embedded' }
237+
$installStep = New-AduInstallationStep -Handler 'microsoft/swupdate:1'-HandlerProperties @{ installedCriteria = '1.1' } -Files C:\ADU-update\Azure_IoT_Adu_ESP32_1.1.bin
238+
$update = New-AduImportManifest -UpdateId $updateId -Compatibility $compat -InstallationSteps $installStep
239+
$update | Out-File "./$($updateId.provider).$($updateId.name).$($updateId.version).importmanifest.json" -Encoding utf8
240+
```
241+
242+
Verify you have the following files in your ADU-update directory:
243+
244+
- `Azure_IoT_Adu_ESP32_1.1.bin`
245+
- `ESPRESSIF.ESP32-Embedded.1.1.importmanifest.json`
246+
247+
### Import the Update Manifest
248+
249+
To import the update (`Azure_IoT_Adu_ESP32_1.1.bin`) and manifest (`ESPRESSIF.ESP32-Embedded.1.1.importmanifest.json`), follow the instructions at the link below:
250+
251+
- [Import Update and Manifest](https://docs.microsoft.com/azure/iot-hub-device-update/import-update)
252+
253+
243254
### Deploy Update
244255

245256
To deploy the update to your ESP32, follow the link below:
246257

247258
- [Deploy Update](https://docs.microsoft.com/azure/iot-hub-device-update/deploy-update)
248259

260+
### Monitor the Update Process
261+
262+
In Arduino IDE, go to menu `Tools`, `Serial Monitor`.
263+
264+
Once the update request is received by the device, a log similar to this should be displayed:
265+
266+
```text
267+
2022/11/3 05:25:32 [INFO] Client received a properties topic.
268+
2022/11/3 05:25:32 [INFO] Status: 200
269+
2022/11/3 05:25:32 [INFO] Message Type: Desired Properties
270+
2022/11/3 05:25:32 [INFO] Parsed Azure device update manifest.
271+
2022/11/3 05:25:32 [INFO] [JWS] Calculated manifest SHA matches parsed SHA
272+
2022/11/3 05:25:32 [INFO] Manifest authenticated successfully
273+
2022/11/3 05:25:32 [INFO] Sending manifest property accept
274+
...
275+
```
276+
277+
And once the update is complete (including the device automatic reboot), the new version should be printed:
278+
279+
```text
280+
2022/11/3 05:26:22 [INFO] ------------------------------------------------------------------------------
281+
2022/11/3 05:26:22 [INFO] ADU SAMPLE
282+
2022/11/3 05:26:22 [INFO] Version: 1.1
283+
2022/11/3 05:26:22 [INFO] ------------------------------------------------------------------------------
284+
```
249285

250286
## Certificates - Important to know
251287

0 commit comments

Comments
 (0)