This document describes how to connect the AVR-IoT WA or WG Development Board (featuring an 8-bit ATmega4808 AVR MCU, ATECC608A secure element, and ATWINC1510 Wi-Fi network controller module) to Azure IoT Hub. The AVR-IoT WA/WG Development Board will be provisioned for use with Azure IoT services using self-signed X.509 certificate-based authentication.
-
If you don't already have one, create a free Azure account.
-
Sign into the Azure Portal.
-
Follow the steps in the section titled "Create an IoT Hub" to use the Azure CLI to create your own resource group and IoT Hub within the resource group.
-
Clone this repository using Git Command Line or GitHub Desktop. Alternatively, you can download the ZIP file of this repository and extract the ZIP file directly onto your PC's hard drive.
-
Connect the AVR-IoT development board to the PC using a standard micro-USB cable. Generate and provision the required X.509 certificates by opening a Command Prompt or PowerShell window. Navigate to the location of the IoT Provisioning Tool which was previously downloaded (e.g. \iotprovision-bin-2.10.7.12.134\windows64). Execute the following command line:
.\iotprovision-bin.exe -c azure
NOTE: Ignore the error messages at the end regarding 'demo-azure'
-
The IoT Provisioning Tool should have created a hidden folder named
.microchip_iot
located in the user's "home" directory (e.g. C:\Users\username). Configure your O.S. to show hidden files & folders, and then confirm that the Root CA, Signer CA, and device certificates were generated in this hidden folder. The device certificate wiil be located in a sub-folder corresponding to the kit's USB serial number (e.g. ATML3203071800001079). -
Create copies of the 3 certificates (root-ca.crt, signer-ca.crt, device.crt) and rename them using the *.pem extension (root-ca.pem, signer-ca.pem, device.pem).
-
In the kit's USB serial number sub-folder, open the
azure-device-id.txt
file and note the device ID that is used for the Common Name field in the device certificate (e.g. sn0123460B75A64D68FE). Save this device ID information for use in a future step as this string will be used to identify your device's connection to the IoT Hub. -
Launch the Microchip Studio IDE. A picture of the AVR-IoT development board should appear in its own dedicated window within the IDE - showing that Microchip Studio has successfully connected to the AVR-IoT development board. Do not proceed until the connection to the board has been verified with the appearance of this pop-up window.
-
Modify the credentials of your wireless network, IoT Hub, and device in the provided example demo project.
- Open the
avr.iot-azure-demo.atsln
project located in theAVR-IoT_Azure_Demo\firmware
folder. - In the Solution Explorer window, expand the "cloud" sub-folder and double-click on
cloud.h
. - Modify the SSID and network password (PSK) for your wireless Access Point.
- Modify the
COMMON_NAME
with your device ID string which was discovered in a previous step. - Go to the Azure Portal and click on your IoT Hub name.
- Copy the name shown in the IoT Hub's
Hostname
field by clicking on the icon to the right of the string. - Modify (by pasting from the clipboard) the
HOST_ENDPOINT
definition with the value copied from theHostname
field. - Review and confirm that the 4 required settings were updated correctly for your scenario, and that every value is enclosed in double quotes. The following snippet is an example of one possible scenario:
- Open the
-
Rebuild and program the solution onto the AVR-IoT development board.
-
Go back into your Azure Portal account and click on your IoT Hub. Using the left-hand navigation pane, click on
Devices
and then+ Add Device
-
Enter/paste your Device ID and select
X.509 CA Signed
forAuthentication type
, then hit theSave
button. -
Confirm that your new device has been successfully registered with your IoT Hub.
-
Using the left-hand navigation pane, click on
Certificates
underSecurity settings
, then click on the+ Add
icon. -
Type in any arbitrary Certificate name (e.g. your initials), upload the
signer-ca.pem
file that was generated in a previous step, check the box for "Set certificate status to verified on upload", then click onSave
. The uploaded signer CA certificate can now be used by your IoT Hub to authenticate devices which have a leaf certificate derived from the signer CA certificate. -
Power cycle the AVR-IoT development board by unplugging and then plugging the micro-USB cable back into the board's USB connector. After a few moments, the Blue (WIFI) and Green (CONN) LEDs should turn constantly ON while the Yellow (DATA) LED blinks - signifying that the board has connected to the IoT Hub and is periodically sending data to the Cloud.
-
In your Azure Portal account, using the left-hand navigation pane, click on
Devices
underDevice management
, then click on your device name. -
Click on the
Device Twin
icon, then confirm that"connectionState"
= "Connected". -
Monitor the telemetry events being sent from the device to your IoT Hub. Open a Command Prompt or PowerShell window and execute the following command line:
az iot hub monitor-events --hub-name {MyIoTHubName} --device-id {MyDeviceID}
Note: replace {MyIoTHubName} and {MyDeviceID} with their actual names
-
Each telemetry event has a payload field containing a value ("L") corresponding to the on-board light sensor (lumens) and a second value ("T") corresponding to the on-board temperature sensor (deg C). Increase the ambient light source shining directly on top of the board and observe that the "L" value increases substantially compared to before the additional light source was applied. Similarly, if you are able to change the ambient temperature of the board easily, you can also see the "T" value change accordingly. When finished, hit [CTRL-Z] to exit the monitoring process.