|
Azure SDK for Embedded C
|
This is the main page for the Azure SDK for Embedded C official IoT client libraries.
Here you will find everything you need to get devices connected to Azure.
The Azure IoT Client library is created to facilitate connectivity to Azure IoT services alongside an MQTT and TLS stack of the user's choice. This means that this SDK is NOT a platform but instead is a true SDK library.

From a functional perspective, this means that the user's application code (not the SDK) calls directly to the MQTT stack of their choice. The SDK provides utilities (functions, default values, etc.) that help make the connection and feature set easier to use. Some examples of those utilities include:
To better understand the responsibilities of the user application code and the Embedded C SDK, please take a look at the State Machine diagram, which explains the high-level architecture, SDK components, and a clear view of SDK x Application responsibilities.
For more details about the Azure IoT Hub, see the following Azure IoT Hub documentation. For more details about the Azure IoT Device Provisioning Service (DPS), see the Azure IOT DPS documentation.
NOTE: This Embedded C SDK requires a different programming model as compared to the earlier version of the C SDK.
Please view the API documentation here. After following that link, you can find the IoT specific documentation by navigating to the IoT section on the left of your screen, pick a version of the SDK, click on Files -> File List, then choose any of the header files prefixed with az_iot_.
The Azure IoT library is compiled following the same steps listed on the root Azure SDK for Embedded C README documentation, under "Getting Started Using the SDK".
The library targets made available via CMake are the following:
az::iot::hub - For Azure IoT Hub features (API documentation found by following the above link and selecting azure_iot_hub_client.h).az::iot::provisioning - For Azure IoT Provisioning features (API documentation found by following the above link and selecting azure_iot_provisioning_client.h).View the Azure Embedded C SDK IoT Samples README to learn how to run samples for the Azure Embedded C SDK IoT Hub Client and the Provisioning Clients. The README will provide general prerequisites, environment setup instructions, sample descriptions, as well as directions on how to build and run all the samples on either a Linux or Windows environment.
For more detailed, step-by-step guides to setup and run the IoT Hub certificate samples from scratch, refer to these documents:
Important Note on Linux and Windows Samples: While Windows and Linux devices are not likely to be considered constrained, these samples enable developers to test the Azure SDK for Embedded C libraries, debug, and step through the code, even without a real device. We understand not everyone will have a real device to test and that sometimes these devices won't have debugging capabilities.
For extra guidance, please feel free to watch our Deep Dive Video below which goes over building the SDK, running the samples, and the architecture of the samples.
Beyond the samples above, created, maintained and supported by Microsoft, there are additional samples created and maintained by the community:
If you have any issues with the community samples please let the owner know.
If you wish to see the link to your sample published here, please refer to the Contributing session in this page.
√ feature available √* feature partially available (see Description for details) × feature planned but not supported
| Feature | Azure SDK for Embedded C | Description |
|---|---|---|
| Send device-to-cloud message | √ | Send device-to-cloud messages to IoT Hub with the option to add custom message properties. |
| Receive cloud-to-device messages | √ | Receive cloud-to-device messages and associated properties from IoT Hub. |
| Device Twins | √ | IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin document, subscribe to desired property updates. |
| Direct Methods | √ | IoT Hub gives you the ability to invoke direct methods on devices from the cloud. |
| DPS - Device Provisioning Service | √ | This SDK supports connecting your device to the Device Provisioning Service via, for example, individual enrollment using an X.509 leaf certificate. |
| Protocol | MQTT | The Azure SDK for Embedded C supports only MQTT. |
| Retry Policies | √* | The Azure SDK for Embedded C provides guidelines for retries, but actual retries should be handled by the application. |
| IoT Plug and Play | √ | IoT Plug and Play enables solution builders to integrate smart devices with their solutions without any manual configuration. |
The following chart shows the RAM and ROM usage for the PIC24-IOT dev kit from Microchip found in https://github.com/Azure-Samples/Microchip-PIC-IoT-Wx compiled using Microchip’s XC16 version 1.60 compiler with the following compilation, preprocessor options: AZ_NO_LOGGING and AZ_NO_PRECONDITION_CHECKING.
The PIC24-IOT kit has two microcontrollers (MCUs):
The Pic24 sample includes both Hub and DPS services. The table below shows RAM/ROM sizes considering:
| Embedded C SDK size | Total Size | |||
|---|---|---|---|---|
| Sample | Program/ROM | Data/RAM | Program/ROM | Data/RAM |
| PIC24 (Hub + DPS + IoT Plug and Play) | 26.15KB | 0 | 103.61KB | 10.57KB |
| PIC24 Telemetry only | 2.58KB | 0 | 74.16KB | 8.26KB |
This table will be expanded as new hardware samples become available.
These examples are scenario-focused and introduce you to the API calls for a few key features of the Embedded C SDK.
General coding patterns that are MQTT stack agnostic are also available to view. These patterns can give you an overview of the API calls and structure needed to use the Azure IoT Embedded C SDK features.
For a more extensive demonstration of the API, please view and run the sample code, which uses Paho MQTT.
To use IoT Hub connectivity, the first action by a developer should be to initialize the client with the az_iot_hub_client_init() API. Once that is initialized, you may use the az_iot_hub_client_get_user_name() and az_iot_hub_client_get_client_id() to get the user name and client id to establish a connection with IoT Hub.
An example use case is below.
Included in the Azure SDK for Embedded C are helper functions to form and manage message properties for Azure IoT Hub services. Implementation starts by using the az_iot_message_properties_init() API. The user is free to initialize using an empty, but appropriately sized, span to later append properties or an already populated span containing a properly formatted property buffer. "Properly formatted" properties follow the form {key}={value}&{key}={value}.
Below is an example use case of appending properties.
Below is an example use case of initializing with an already populated property span.
Telemetry functionality can be achieved by sending a user payload to a specific topic. In order to get the appropriate topic to which to send, use the az_iot_hub_client_telemetry_get_publish_topic() API. An example use case is below.
azure and c tags.This project welcomes contributions and suggestions. Find more contributing details here.
If you wish to contribute with a sample please read the guideline below:
If you agree with the guidelines, please fork this repo, create your sample and open a PR with your sample so we can review it (as per #7 above, we won't take the PR but rather add a link to your repo with the sample).
Azure SDK for Embedded C is licensed under the MIT license.
1.8.20