If you have ever struggled to fit your application into a constrained IoT device, we have great news for you! We released the new Embedded C SDK, built to support microcontrollers, optimized for memory usage with no dynamic memory allocation, fully embracing MQTT and providing access to a number of Azure Services.
Why do we need an Embedded C SDK?
As the IoT industry evolves, companies and developers are identifying many more opportunities to create amazing solutions for real world problems.
When we look at the devices that are enabling these digital transformation scenarios, we can find all sorts of devices going from pretty powerful hardware running full OS (Windows / Linux), like the Raspberry PI, all the way down to single core MCU (microcontrollers) – constrained devices like the ESP8266.
While you can easily fit any of the Azure SDKs into more powerful devices, doing the same with a constrained device has previously required an optimized version of the C SDK, along with specific compiling requirements to reduce its footprint for the limited resources available.
Additionally, scenarios with constrained devices installed in remote locations, bring additional challenges. These devices may require limited power sources like solar power and battery-operation. Also, the lack of Wi-Fi will require network alternatives like cellular, mesh networks, or LoRa.
Overall, we recognized all of these challenges and the corresponding gaps in what our existing C SDK could provide, so we completely redesigned a new and improved embedded C SDK. We're happy to present it as the newest addition to the Azure SDK family: the public preview of the “Azure SDK for Embedded C”.
Embedded C SDK explained
At its core, the embedded C SDK is a set of libraries that will help you take advantage of Azure IoT capabilities. It provides helper functions so your application can connect to Azure IoT Hub, send telemetry messages (device to cloud), receive cloud to device messages, direct device methods, and device twin metadata. It can also be provisioned using the device provisioning services.
IoT developers will now have the flexibility to bring any MQTT client, TLS and socket layer they prefer to their application, allowing for extreme optimization by leveraging libraries that are optimized for the target device.
Embedded C SDK
The MQTT layer requires a MQTT client like Eclipse Paho, Mosquitto or any MQTT library that works on your device. The MQTT connection can also be used over Web Sockets.
There is no dynamic memory allocation in the Embedded C SDK. For constrained devices scenarios, you are in control of how much memory will be consumed by allocating the memory in the application and passing in the buffers with the SDK calls.
The following code snippet shows how the Embedded C SDK initialize the client to allow IoT Hub connectivity.
//Get the default IoT Hub options
az_iot_hub_client_options options = az_iot_hub_client_options_default();
//Initialize the client with hostname, device id, and options
az_iot_hub_client_init(&my_client, my_iothub_hostname, my_device_id, &options);
//Get the MQTT user name to connect
//Get the MQTT client id to connect
//At this point you are free to use my_mqtt_client_id and my_mqtt_user_name to connect using your MQTT client.
How to get started?
The best way to get started with the Embedded C SDK is to see it in action! Feel free to try any of the samples available:
- IoT Hub Telemetry: Send 5 telemetry messages using the IoT Hub Client.
- IoT Hub Twin: Use twin features such as updating reported properties, receiving the twin document, and receiving desired properties using the IoT Hub Client.
- IoT Hub Methods: Invoke device methods from the cloud. The sample supports a method named "ping" which, if successful, will return a “pong” response.
- IoT Hub C2D: Receive and view incoming cloud to device (C2D) messages using the IoT Hub Client.
- Device Provisioning Services: Register a device using the IoT Provisioning client
For a high-level understanding of the architecture and components of the Embedded C SDK, take a look at the state machine diagram which explains the SDK components, and a clear view of the separation of responsibilities between your application and the Embedded C SDK.
Let us know what you think!
As we continue to work on improving the experience for IoT developers, we encourage you to provide feedback through our open source GitHub repository and stay tuned on Azure Updates for any new IoT SDK announcements.