Blog Post

Internet of Things Blog
3 MIN READ

Arduino library for Azure IoT

wduraes's avatar
wduraes
Icon for Microsoft rankMicrosoft
Dec 14, 2021

We are committed to meet you, IoT developers, where you are, and a significant number of you happen to use the Arduino IDE. We're making the experience better than ever by releasing a first-class integration of Azure IoT C libraries into the Arduino IDE and tool chain.

When we redesigned the Azure IoT SDK or C library for the Arduino IDE we focused on principles like simplicity and memory footprint with a bare metal approach. It is possible for you to install the library, add Azure credentials and get your IoT devices connected in less than 5 minutes! And this whether you are an experienced Embedded Developer, a student or a maker getting your first device connected to a professional cloud platform like Azure IoT.

 

The Azure IoT SDK for C library

 

When you add this library to your Arduino IDE, you’re getting a fully tested set of APIs, documentation, and sample implementations on popular embedded platforms. Features provided by the library include establishing a secure MQTT connection to Azure IoT services, help to create and refresh security tokens, sending telemetry messages and receiving commands. You get the benefits of open source – available on GitHub under the MIT license – and the official support of Microsoft.

Some of the hardware platforms with out-of-the-box support include Espressif ESP32, ESP8266 and the Realtek Ameba D.

 

How to get started?

 

The library has already been published and you can find it from within the Arduino IDE: Sketch --> Include Library --> Manage Libraries. Search for Azure, select the Azure SDK for C library by Microsoft and click install.

 

 

This library comes with samples for the Espressif ESP8266, ESP32 and the Realtek Ameba D. In all cases the sample structure is the same: look for the iot_config.h tab, and update the Wi-Fi credentials, and you Azure IoT Hub information.

That’s all you need to do! After loading the sketch to your device you’ll see simulated telemetry data flowing to your IoT Hub.

You’ll find more details about running the samples in our official repo: https://aka.ms/arduino

 

 

Baremetal or RTOS?

 

This library was created on top of the Azure IoT SDK for C which provides the core APIs to get your device connected. You’ll see in our samples it uses a bare metal approach with a super loop to get the device working.

If you’re looking for support to create more complex solutions and you need to manage multiple threads, use semaphores, mutexes, queues and have a deterministic response time, you’re likely to need a real time operating system (RTOS).

Microsoft also offers two alternatives for device builders like yourself:

  1. Azure RTOS - https://github.com/azure-rtos
  2. Azure IoT middleware for FreeRTOS - https://github.com/Azure/azure-iot-middleware-freertos

Regardless of whether you use the Arduino Library for Azure IoT or from one of the options above, you’ll be using an officially supported Microsoft solution for connecting your IoT devices.

 

Let us know what you think

 

As we continue to work on improving the experience for IoT developers, provide your feedback, file issues, contribute with your own pull requests and stay tuned here on the IoT blog and on Azure Updates for any new Azure IoT SDK announcements.

Updated Dec 13, 2021
Version 1.0
  • Hi woter , let me try and help answer your questions and for the sake of future readers new to Arduino and/or Azure RTOS, I want to use this opportunity to clarify some things.

     

    In short:

     

    To find boards that support Azure RTOS, check out our partners here.

    You can run Azure RTOS on some Arduino boards as solution-squad points out in their response.

    For the application you are trying to build, I don't think you get much from Azure RTOS and I believe you can use an Arduino board + the library discussed in this post (assuming your Arduino board has network + TLS capabilities) to connect it to Azure IoT and implement the rest in the Cloud. You will find a list of the Arduino Compatible boards this library has been tested with in the library repo at https://aka.ms/arduino

     

    Longer answer to help clarify Arduino vs. Azure RTOS:

     

    Arduino is a term used loosely to describe several things (depending on the context): it's a company, open source hardware, open source software/middleware and a community, not just the hardware.

    You can indeed buy hardware kits from Arduino (Arduino UNO, Zero,...), but you can also purchase Arduino-compatible hardware from other vendors and distributors (Adafruit, Sparkfun, Seeed Studios,...).

    At the end of the day Arduino, as a hardware + software technology, aims at simplifying the programming of hardware (accessing and interacting with hardware and sensors resources).

    Arduino hardware and software are primarily used for prototyping and hobbyist projects. Few commercial products use Arduino hardware or software for many reasons including cost, certifiability, ...

     

    Azure RTOS is a Real Time Operating System designed for industrial or commercial scenarios and that supports a specific set of hardware. It is a set of libraries that can be used separately (Real Time scheduler, Network management, USB management, File system management, Embedded User Interface, Azure connectivity). It is licensed to hardware manufacturers and final customers usually buy the bundle (hardware + Azure RTOS) and don't pay for the Azure RTOS license as it comes with the hardware. You can find the list of our partners carrying boards supported by Azure RTOS here. You can get and use Azure RTOS for free on one of the supported hardware, but you can't ship commercial products without the license. You can also try and port Azure RTOS to hardware not in the supported list, but that's embedded developer work that is not trivial and once again won't allow you to go to production without a license. You can also find ports from communities like the one mentioned by solution-squad.

    The "Azure" in "Azure RTOS" is not making it different from other embedded operating systems like Free RTOS or middleware like Arduino in terms of connectivity to Azure as you can use our open source SDKs and libraries to connect pretty much anything that supports connecting to the Internet and can do TLS. As a matter of fact this very blog post is about introducing the library that allows connecting an Arduino-Compatible device easily to Azure IoT.

     

  • solution-squad's avatar
    solution-squad
    Copper Contributor

    This is great - well done MS & Arduino. Is there going to be a sketch for GMS - G3 as well?

  • Hi there, we don't have samples showing cellular connectivity. Soon we should have samples showing how to leverage cellular modem with the middleware for FreeRTOS, but not specifically for the Arduino Library.

  • woter's avatar
    woter
    Copper Contributor

    Please excuse my ignorance, but an Arduino is a piece of hardware that I can buy. Azure RTOS is an operating system that runs on embedded systems. Googling "Azure RTOS hardware" doesn't yield much. What do I need to search for to buy hardware to run Azure RTOS?

     

    Early days but I am designing a solution to read an M-Bus (water) meter, perform some calculations and then through a banking API, send a payment to a utility company.  I want the device to be as lightweight (and cheap) as possible, hence exploring Arduino over a Raspberry Pi, however as my day job is an Azure Engineer, Azure RTOS has sparked an interest. This will be a one-off. I'm not planning on taking it to market. I should probably mention both the Arduino and Raspberry Pi have M-Bus shield/hat that physically  connects (M-Bus supports wireless) to the meter. I guess any Azure RTOS compatible device will need M-BUS receiver hardware.

     

    What is the cost of Azure RTOS-compatible hardware? An Audino costs about £30.

    What is the cost of Azure RTOS? as I read that it requires licensing?

     

    Thanks

  • Jeff Jorczak's avatar
    Jeff Jorczak
    Copper Contributor

    Is the IOT_CONFIG_DEVICE_ID and IOT_CONFIG_DEVICE_KEY unique to each physical device, or unique to the project? In other words, would this have to change in every firmware deployed to every physical device, or can it exist once in the firmware and that be uploaded the same onto each physical device?

  • weflynnjr's avatar
    weflynnjr
    Copper Contributor

    I've started the course.  I am using an Adafruit ESP32-S2 TFT.  I have selected the board.  When I upload, it says

     

    C:\Users\wflynn\Desktop\Introduction-to-Microsoft-Azure-IoT-master\Section - 2\ESP32___DHT11___Azure_IoT_Hub\ESP32___DHT11___Azure_IoT_Hub.ino:5:10: fatal error: AzureIotHub.h: No such file or directory
    5 | #include "AzureIotHub.h"
    | ^~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1

    Compilation error: AzureIotHub.h: No such file or directory

     

    If I comment out that include, I get this:

     

    C:\Users\wflynn\Desktop\Introduction-to-Microsoft-Azure-IoT-master\Section - 2\ESP32___DHT11___Azure_IoT_Hub\ESP32___DHT11___Azure_IoT_Hub.ino:6:10: fatal error: Esp32MQTTClient.h: No such file or directory
    6 | #include "Esp32MQTTClient.h"
    | ^~~~~~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1

    Compilation error: Esp32MQTTClient.h: No such file or directory

     

    Is this course out of date?  Or am I missing a library?