This repo contains sample code for using Azure IoT Hub with Arduino boards.
This code is written using PlatformIO in Visual Studio Code. It targets an ESP32-Azure IoT Kit, an ESP32-based board with build in sensors and designed for Azure. You can use other boards, just update the platformio.ini file.
The sample demonstrates connecting to WiFi and setting the time, then connecting to IoT Hub and sending telemetry every few seconds. It will also respond to device twin updates and direct methods.
At the time of writing this, handling cloud to device messages is not supported as it appears to be broken in the core SDK.
At the time of writing, all the necessary Arduino libraries for Azure are not available from the Arduino library manager. Watch this issue to see when the last library is available and they can all be installed from the library manager.
This means that you need to install the libraries manually.
-
Ensure you have Python, Visual Studio Code and the PlatformIO VS Code extension installed
-
Clone the Azure Arduino IoT Pal GitHub repo
-
Open a terminal or command prompt and navigate to the
build_all
folder in that repo -
Run the following command to build the libraries:
python3 make_sdk.py -o build
-
This will compile the libraries and put them in the
build
folder -
Clone this repo
-
Copy the 5
AzureIoT*
folders from the newbuild
folder in the pal repo into thelib
folder in the clone of this repo -
Open this repo in VS Code, plug in an ESP32 board and upload the code using PlatformIO by launching the command palette and selecting PlatformIO: Upload. You may need to hold the boot button on your ESP32 device during the code upload to successfully copy the code over depending on your board.