ESP32 library to access Azure IoT Services, using the Azure IoT Middleware for FreeRTOS interface, in an easier and cleaner way.
Just clone, configure using menuconfig and connect!
- ESP-IDF: v5.1
- Written in C using:
- APIs:
- All functions from Azure IoT Middleware for FreeRTOS
- Custom extensions
- Features supported (IoT Hub/IoT Central):
- Transport:
- Socket: esp_tls with built-in connection retries and updated Azure certificates.
- HTTP: FreeRTOS coreHTTP
- MQTT: FreeRTOS coreMQTT
- Cryptography: mbedtls
- Configurable: using menuconfig
- Everything is at the docs folder.
- Examples:
- Azure IoT Hub: examples/iot_hub
- Azure Device Provisioning Service: examples/provisioning
- Azure Device Update: examples/adu
Build options:
- Compile optimized for size (
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
). - Error logging (
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
). - Azure Cloud RSA certificate: (
CONFIG_ESP32_IOT_AZURE_HUB_CERT_USE_AZURE_RSA=y
)
This chart already includes the Azure IoT certificate and Device Update root key sizes.
DRAM (bss,data) | Flash (code,rodata) | |
---|---|---|
IoT Hub + PnP + DPS + ADU + ADU workflow | 874 B | 97.41 KB |
IoT Hub + PnP + DPS | 12 B | 54.73 KB |
IoT Hub + PnP | 12 B | 44.37 KB |
#include "esp32_iot_azure/azure_iot_sdk.h"
#include "esp32_iot_azure/azure_iot_provisioning.h"
#include "esp32_iot_azure/extension/azure_iot_provisioning_extension.h"
void app_main(void)
{
// 1. Configure this library via menuconfig.
// 2. Connect to WiFi.
// 3. Set up SNTP.
buffer_t symmetric_key = BUFFER_FROM_LITERAL("you_device_enrollment_symmetric_key");
buffer_t registration_id = BUFFER_FROM_LITERAL("your_device_registration_id");
buffer_t registration_payload = BUFFER_FOR_DPS_PNP_REGISTRATION_PAYLOAD();
buffer_t hostname = BUFFER_WITH_FIXED_LENGTH(AZURE_CONST_HOSTNAME_MAX_LENGTH);
buffer_t device_id = BUFFER_WITH_FIXED_LENGTH(AZURE_CONST_DEVICE_ID_MAX_LENGTH);
azure_iot_sdk_init();
AzureIoTProvisioningClientOptions_t *dps_client_options = NULL;
buffer_t buffer = {
.length = 2048,
.buffer = (uint8_t *)malloc(2048)};
azure_dps_context_t *dps = azure_dps_create(&buffer);
azure_dps_options_init(dps, &dps_client_options);
azure_dps_init_default(dps, registration_id->buffer, registration_id->length);
azure_dps_auth_set_symmetric_key(dps, symmetric_key->buffer, symmetric_key->length);
azure_dps_create_pnp_registration_payload(registration_payload.buffer, ®istration_payload.length);
azure_dps_set_registration_payload(dps, registration_payload.buffer, registration_payload.length);
azure_dps_register(dps);
azure_dps_get_device_and_hub(dps,
hostname->buffer,
&hostname->length,
device_id->buffer,
&device_id->length);
azure_dps_deinit(dps);
azure_dps_free(dps);
free(buffer.buffer);
azure_iot_sdk_deinit();
ESP_LOGI(TAG, "hostname: %.*s", (int)hostname.length, (char *)hostname.buffer);
ESP_LOGI(TAG, "device_id: %.*s", (int)device_id.length, (char *)device_id.buffer);
}