How I connected a 7+ IoT Starter Kit to Azure IoT with no code
Updated: Jan 25, 2021
I have been playing with an IoT Starter Kit called the M5GO claiming to be accessible starting at age 7 and I have to say, I was impressed! Here is what I did and why my perspective on such kits has changed.
Me, embedded developer at heart
For you to understand where I am coming from, here is some about myself (feel free to skip to next paragraph if you are eager to get to the gist of this post).
In a previous life I was an embedded real-time developer, working on telematics devices, high speed letter folding/weighing/stamping machines, micro-seismic monitoring devices and more. The solutions I have worked on and wrote code for were powered by microcontrollers with limited resources and were bound to strict performance and determinism requirements. The tools I was using were embedded toolchains, real time operating systems, programmable chips like FPGAs, C (or even assembly) language to program. The developer kits to evaluate chips, SoCs, microcontrollers were big, heavy, and cost several thousands of dollars (yes, you read that right!).
With such a background, I have been very skeptical about cheap (under $100) hardware devkits claiming you do not even need to be a developer to create IoT devices. I am not talking about the Raspberry Pi and other mini-PC types of devices that feature a full-blown Linux OS and that are still mostly accessible to people who are somewhat technical. I am talking about kits like the one above that have a big “7+” mention on it and that say, “Let’s build our first IoT application in 60 seconds”. My reaction is “how is it possible to get data from sensors, putting together some logic based on that data, and connect the device to the Internet, without writing code? It has to be with many layers of abstractions which use precious resources!”.
As Forest said, stupid is as stupid does, so I had to try this out for myself to forge an informed opinion. Here I am online searching for such a kit and getting the M5GO IoT Starter Kit.
Unboxing and first tiny project
Unboxing this kind of kits is fun. You do not see much of the electronics as the main board is in a nice enclosure, with buttons, display and connectors all around, a long way from the huge dev kits and evaluation boards I have worked with in the past. That is certainly way less daunting for newbies 😊.
The kit comes with various sensors and actuators that are connected over Grove connectors. You cannot go wrong with these even if that is the first time you see a cable that is not a USB or a power one. In the box there are also a couple Lego pieces that allow attaching the sensors with the main unit. Fun and practical. It took me 20 seconds to assemble the humidity/temperature/pressure sensor and the main unit:
Instructions on the package told me to go to Flow.M5Stack.com (I am using a PC and I do not have an iPad, otherwise I could have used an iPad to simply scan a QRCode on the device and be sent directly to the site on the tablet).
M5Stack created a smart web interface named UiFlow. The tool offers a visual programming interface based on Google’s library Blocky, as well as a microPython programming page. The tool will automatically convert the visual programming to microPython code and vice-versa. I wanted to stay away from code for my trial, so I started playing only with the visual programming interface.
The interface allows creating programs dragging visual blocks which includes variables, operations and functions, text, and more. If you are not familiar with Blocky, I recommend checking out the MIT’s Scratch site, a great way for kids and beginners to learn programming.
The M5Stack team added blocks for operating the screen, getting data from sensors (called Units) and control actuators. They also added a visual editor for the user interface: you can just drag and drop UI components on the screen to create the front end of the app. Pretty straight forward, but a little read of the doc and getting started guide is always recommended.
I checked out the getting started doc for the board which recommends updating the firmware. My first reaction was to say, “here we go, away from the simple and easy”. How wrong was I! The team created a little flashing tool called the M5Burner that is straight forward. Install the app, plug in the device (which automatically installs the drivers), pick the firmware you would like to flash and see it happening. No bin files to go download on some random site, no file to drag and drop manually. The tool will also allow you to configure the Wi-Fi access for the device in the burning process.
The tool also lists a series of pre-backed firmware example images you can flash. There is a space invader game I will HAVE to try!
The burning process is fast and after just a few seconds, the device is fresh and ready, connected to my Wi-Fi and displaying an API Key on the screen.
Back in the UiFlow interface I can start creating my IoT application.
Clicking in the lower left corner of the tool I could enter the API Key and indicate which device to connect to. Deployment happens over the Internet, so you do not even need to have the device connected to your PC:
Because I connected the ENV II sensor (humidity, temperature, and pressure) to the Port A of the device, I added the Unit in UiFlow clicking on the big + under “Units” and selected Port A.
I added some labels on the screen to create a little UI for displaying Temperature, Humidity and Pressure.
As I added the UI element they appeared in the toolbar. From there I created the application with Blocky. It is all color coded and drag and drop. Took me minutes to put the together an infinite loop that would read temperature, humidity and pressure values from the sensor and display them in the dedicated label on the screen, then that would pause for a second.
Clicked on the Run button in the top toolbar to deploy to the device and that was it!
I could not leave it at this (too) simple sample and wanted to add some logic, so I could have something happen on the device when I blew on the sensor, spiking the humidity measure.
I added an image to the UI and the following function to my Blocky (for some reason I am starting to love this name 😊) to display a little cloud when humidity passes 40%.
Redeployed, blew on the sensor to spike humidity and here is my little cloud appearing.
Ok, it took more than 60 seconds to build all that, but it was literally minutes, and zero line of code.
How about connecting to a Cloud, like Azure IoT?
Disclaimer: here we are leaving the 7+ kids’ section as the following requires having access to an Azure subscription and manipulating some more complex concepts (mostly around security and certificates). Maybe we should consider having an Azure subscription for kids, like YouTube kids, or the Kindle FreeTime feature, right? That said we are not quite in the TV-MA section either and all the below is accessible even without development background.
Scrolling down the list of Blocks in the visual editor, I found lots of resources that can certainly prove useful to start prototyping more serious IoT devices, such as I2C, Modbus, UART, PWM and more. The one I was hoping to find, and that was in the list, was an MQTT one. With that discovery, it seemed logical to add connectivity to the Cloud… but with the same challenge as before: no code!
I added the MQTT initialization block in my Blocky app and figured I needed some credentials to connect to Azure IoT Hub.
Let me decrypt this and point to what is needed to configure an MQTT client so it can connect to Azure IoT Hub. To understand even better how Azure IoT Hub uses the MQTT protocol, I recommend reading this article.
First the client will need to establish a secure TCP connection and for that, it needs to use SSL. By just enabling the SSL option you ensure that the connection will be encrypted and that IoT Hub will accept it.
The other settings for the MQTT client are related to the MQTT broker you want to connect to, and we can get this information from the Azure IoT Hub.
With that in mind, onto creating an IoT Hub instance.
I have the chance to have access to some Azure resources for free (perks of working in one of the teams developing the thing), but did you know you can create and use Azure IoT Hub for free as well? Yes, yes, there is a free tier that gives you up to 8K messages per day (message meter size being at 0.5KB for that SKU, which means if you send messages bigger than 0.5KB, each 0.5KB will count as one message). You can find more info on the pricing for IoT Hub here.
For managing my IoT Hub and monitoring devices messages, I have installed the Azure IoT Explorer tool.
Once I had created an IoT Hub from the Azure Portal, I got the primary key connection string from the shared access policies blade.
That connection string allows to connect the Azure IoT Explorer tool to the right IoT Hub instance.
Entering the connection string in the Azure IoT Explorer tool, I was able to create a new device called myM5Stack, using the default options (particularly the symmetric key type of authentication). In the Device identity tab for the device myM5Stack, I created a Connection string with SAS token picking the primary key, setting an expiration time of 1 week (1080 minutes), clicking on generate, then copying the key. Note that the expiration time is important as you will want a token to expire and require a new token to be generated for your device. Rotating security tokens is ABC for securing IoT devices connection.
The SAS token connection string is formatted as shown below. It is the Shared Access Signature that is used as password for the MQTT client, so I just needed the part of the connection string after SharedAccessSignature= (highlighted in red below).
With that, I had all I needed to setup the MQTT client and start it as follows.
Then I needed to create a little function to format a message to send telemetry over MQTT. I put the following together to have some sort of json.
And added the MQTT publish call in the main loop.
Before deploying and run the app on the device, I started the telemetry monitoring in the Azure IoT Explorer tool to validate that data was indeed flowing into my IoT Hub. To do this you just have to go to the Telemetry tab for the device in the tool and click on Start. I then deployed the app on the device and ran it. After a second, first telemetry data points started showing up in the Azure IoT Explorer!
This little kit and the visual programming interface of the M5GO are impressive in their simplicity and intuitiveness. I was able to get sensor data, create some basic logic on the device and connect to the Cloud without writing a single line of code and in a matter of minutes!
Looking at the more advanced blocks available in the UI, there is much you can do without the need to write embedded code. I stand corrected on my first reaction and even though I would NOT recommend using such a device and this way of programming for an actual IoT device to be sent to production, it is a decent option for prototyping or creating some Proof of Concepts.
Let me know what you would build with such a kit.