Easily Connect Espressif Devices to Azure IoT
Published Jan 21 2020 07:40 PM 9,942 Views
Microsoft

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:

 

  • Ready to use Espressif IoT Development Framework (ESP-IDF) components for Azure IoT with & without Plug and Play functionality that you can drag and drop into your ESP32 or ESP8266 project
  • Dev Environment setup scripts for Windows Subsystem for Linux (WSL) to get the ESP toolchain and development framework quickly setup on your machine. This includes an optional shell script that will conveniently allow you to switch between versions of the ESP-IDF and ESP8266 development framework ESP-IDF stable version 3.3 or latest version 4.x
  • Azure IoT Samples for ESP32 and ESP8266 using various sensors and connecting to Azure IoT Hub
  • Detailed guidance on setting up and connecting your Espressif boards to Azure IoT so you can successfully build your targeted solution

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.

 

Let’s get ready to ESP

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.

Introducing the ESP32-Azure IoT Kit

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.

 

clipboard_image_0.png

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.

  

clipboard_image_1.png

With my serial port information in hand, it’s time to set up the ESP development environment on my machine.

 

Setting up WSL for ESP Development

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.

clipboard_image_1.png


Once you see the magic words Dev Environment Setup Completed, you are ready to build and run the samples.

 

Ready, Set, Build

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.

 

clipboard_image_0.png

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.

clipboard_image_1.png

 

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.

clipboard_image_2.png

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.

clipboard_image_3.png

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.

clipboard_image_4.png

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.

clipboard_image_0.png

 

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.

clipboard_image_1.png

 

clipboard_image_0.png

 

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.

clipboard_image_1.png

clipboard_image_2.png

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.

clipboard_image_0.png

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.

 

Devices & Data In the Cloud

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.

clipboard_image_1.png

clipboard_image_0.png

Finally here is a snapshot of the ESP32 sensor data being routed and stored in storage account within Azure.

 

clipboard_image_1.png

 

clipboard_image_0.png

clipboard_image_2.png

 

Summary

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!

 

4 Comments
Version history
Last update:
‎Jan 22 2020 04:10 PM
Updated by: