Since this library has been published, Microsoft has created newer versions of the Azure SDK for usage with the Espressif ESP32. This new library is better suited for microcontrollers, great for composition with your own network stack and officially supported by Microsoft.
The first one, Azure IoT middleware for FreeRTOS, is based on ESP-IDF and FreeRTOS and it has samples for IoT Hub and IoT Central using the device provisioning service (DPS).
The second one is based on Azure IoT for C library for Arduino and also has samples for IoT Hub.
If you can, avoid using this library for any new projects.
The ESP Azure IoT SDK is based on Azure IoT C SDK and enables users to connect their ESP32 based devices to the Azure IoT hub. It provides some examples which can help understand most common use cases.
You will basically just need a development host and an ESP32 development board to get started.
This project is to be used with Espressif's IoT Development Framework, ESP IDF. Follow these steps to get started:
$ git clone --recursive https://github.com/espressif/esp-azure.git
Note that if you ever change the branch or the git head of either esp-idf or esp-azure, ensure that all the submodules of the git repo are in sync by executing
git submodule update --init --recursive
Note: When selecting the "Pricing and scale tier", there is also an option to select , F1: Free tier, which should be sufficient for basic evaluation.
Connection string - primary key
from the Azure IoT Hub. This will be required later. The screenshot below will help you locate it.HostName=<azure-iot-hub-name>.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=<base64-encoded-access-key>
az
command to verify that the installation was successful. Output will be like this:$ az
Welcome to Azure CLI!
---------------------
Use `az -h` to see available commands or go to https://aka.ms/cli.
...
$ az extension add --name azure-cli-iot-ext
After that, you should be able to use azure CLI to manage your iot-device. A list of useful Azure CLIs can be found here
$ az login
$ az iot hub device-identity create -n [IoTHub Name] -d [Device ID]
$ az iot hub device-identity show-connection-string -n [IoTHub Name] -d [Device ID]
HostName=<azure-iot-hub-name>.azure-devices.net;DeviceId=<azure-iot-device-id>;SharedAccessKey=<base64-encoded-shared-access-key>
To see various events and the data being exchanged between the device and IoT hub from your command line, run the following command:
$ az iot hub monitor-events -n [IoTHub Name] --login '[Connection string - primary key]'
Note the single quotes for the connection string. Without them, the command wont work as desired.
To monitor activity on your ESP device, run:
$ make monitor
Some common problems can be fixed by disabling the firewall.
You can try with the followings, if your build fails:
$ git submodule update --init --recursive
make clean
and if required, using rm -rf build sdkconfig sdkconfig.old
Ensure that the device connection string received from Azure IoT Hub are correct.