Microcontrollers have come a long way since Texas Instruments created the first microcontroller for their calculator and discovered widespread possibilities for their chip creation. Today, with read/write flash memory and their ability to be programmed with higher end languages like C, microcontrollers are the most widely used chip in the industry. Recently our team has been working with Espressif low-power system-on-chip microcontroller devices. If you haven’t heard of Espressif or if the name seems somewhat familiar, it’s because Espressif is the semiconductor company that created the wildly popular ESP32 and ESP8266 chips, modules and boards. Lately my mission has been to make it easier to connect the ESP brand of microcontrollers to Azure IoT leveraging the Azure IoT C SDK port.
Today, we are excited to share to resources to make building and connecting your production level ESP32 and ESP8266 RTOS applications to Azure IoT “like a breeze”. These resources include:
You can checkout these ESP IDF style resources on GitHub in the Azure ESP-Samples repo. Never fear, if you are into tinkering with ESP and Azure using Arduino, you can check out our step-by-step tutorial for ESP32 using Azure IoT Device Workbench here.
As an engineer, there is simply no way to share the great news about this Azure Espressif resource without also walking through building code and kicking off your ESP journey with Azure IoT the right way.
The first thing is to do when starting our ESP journey is to decide which Espressif board to utilize. Luckily last year, Espressif released an Azure IoT Certified Plug and Play board, the ESP32-Azure IoT Kit. This is an impressive development board powered by a ESP32-WROVER-B MCU module, with built in Wi-Fi, BLE, OLED, button, and sensors for humidity, temperature, light, barometer, and more. You can learn more about this board’s hardware and view the schematic by taking a look its Hardware Design Guide. As you can see from the picture below I’ve already connected my ESP32 Azure IoT device to my computer and it’s ready to go.
Since I’m on a Windows 10 machine, let’s go to Device Manager and find out what serial port the ESP32 device is connected on. In Device Manager, under Ports there will be an USB to UART virtual COM port driver shown, which the associated COM port the board is connected on. It’s key to take note of the connected port, as it will be essential later.
With my serial port information in hand, it’s time to set up the ESP development environment on my machine.
I’ve already cloned the repo and I have the Ubuntu distro of the Windows Subsystem for Linux on my machine. Given this, I just need to run the development setup script provided in the repo by going to the install-script folder and running source ./esp-setup.sh
This script will update your WSL packages, install the ESP toolchain and development framework, as well as set the environment variables that are needed.
Once you see the magic words Dev Environment Setup Completed, you are ready to build and run the samples.
Let's take one of the samples in the SDK and run it. First thing I should do is copy one of the versions of the Azure IoT ESP component I want into the desired sample’s component directory. I have 2 options; Azure IoT ESP component with PnP (esp-azure-pnp) and Azure IoT ESP component without PnP (esp-azure). These components can be found within the repo under the components folder.
I’ll go with the esp-azure component so we can build the azure-esp-starter sample. I’ll navigate to the samples folder within the repo directory and going to that sample’s folder. Next I’ll copy the esp-azure component into the sample’s components directory. These are the same steps you would follow if you were building your own ESP application using the Azure IoT ESP component.
With the component copied, I will naviagate back to azure-esp-starter folder to configure and build this sample. To configure the sample I will run make menuconfig
. If I choose to use Cmake instead of Make, I would run idf.py menuconfig
.
Upon running this command, I will see the Espressif IoT Development Framework configuration window come up.
Remember I noted that ESP32 board COM port was important, well within configuration is where we will use the the COM port information. I will select the Serial Flash config option on the menu, then select the first menu option Default serial port.
Once I’m in the Default serial port window, I will delete the USB0
at the end of this path and replace it with a capital S and the number of my COM port. Which in my case my device was on COM 5, so my serial port should be /dev/ttyS5
. Upon completion I’ll choose Ok, and then select Exit two (2) more times to return to the first configuration screen.
Now I need to add my Azure IoT Hub Device information to the configuration, so I will select the ESP32 App Config menu option. This is where I am going to add the Wi-Fi information and the Azure IoT Hub Device Connection string to the ESP32 configuration.
Once I Exit (and Exit again) the configuration is saved, and now comes the fun part; Building and Flashing to the ESP32 Azure board! To compile the code, build/link the binary and flash to the board usually I would run the command: make flash
. But since I’m sharing the fun with you all reading this blog post, I will run the command: make flash monitor
which will in addition to building and flashing, will show the log and information from the board coming across the serial port connection.
After successfully building and flashing code to the board, you will see on the console information about the data coming from the sensors and the confirmation of that data being written to Azure IoT.
My sensor data for Temperature, Humidity and Light is also being written to the OLED on the board. In the code there are functions that you can alter to write the data that you desire to the OLED instead.
Last thing I will do is go to the Azure portal and show that the ESP32 sensor data is indeed coming into my Azure IoT Hub and and with the route I configured; it is being sent into data storage.
As shown below, this is my IoT Hub and a graphical representation of the messages being received from my ESP32 Azure IoT device, as well as, it’s device twin information.
Finally here is a snapshot of the ESP32 sensor data being routed and stored in storage account within Azure.
Espressif boards are great devices to build the IoT solution of your dreams with the Azure cloud. We hope that this Azure IoT ESP resource kit helps you to quickly and easily start your development journey with Azure IoT and ESP devices. Remember you can check out all the samples and helper scripts inside this kit on the GitHub repo at https://aka.ms/espazure-1staidkit.
Finally, don’t let your Azure IoT journey stop here. To dig deeper into all the Azure IoT services, you can review loads of great IoT technical content like the Azure IoT documentation, the IoT Show on Channel 9, MS Learn resources for Azure IoT, and the Microsoft Tech Community IoT group.
Happy Coding!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.