Connecting your project to the Cloud sounds cutting-edge, it’s really practical, and saves a lot of time in the long run. But once you actually need to do it, there are always a few problems to solve.
That is why we have made an article that explains in detail how to connect your Zerynth Studio project to the Microsoft Azure Cloud services.
Cloud platforms and IoT projects
IoT cloud platforms give you the possibility to empower your IoT projects thanks to their advanced and easy-to-use tools such as data storage and real-time data visualization. In this post, we’re going to see how to connect our Zerynth powered board to Microsoft Azure, which is one of the most popular IoT cloud platforms today. Follow these steps!
1. Download Zerynth Studio
First of all, you need to download and install Zerynth Studio, our free and cross-platform IDE for programming microcontrollers in Python or C/Python language.
2. Create a Microsoft Azure account
A Microsoft Azure account is required to use the Azure IoT cloud platform: you can register here and start a free trial or make a paid subscription plan.
3. Get your board
You can use one of the Zerynth supported devices (you can find a list here). In this example, we used an ESP32 DevKitC by Espressif, a development board based on the ESP32 microcontroller that also has an integrated WiFi chip. You can find more information about this board here.
Do not forget to register and virtualize your board with Zerynth Studio.
4. Create your IoT Hub
Once you have logged in into the Microsoft Azure Portal, click on the “Create a resource” button with a green plus sign on its left. A menu will appear on your screen, type “IoT Hub” in the search field on the top and click on the first result, then fill the form needed for the creation of your new IoT Hub as shown in the picture below.
5. Create your IoT device
Open the IoT Hub you’ve just created and go to the IoT devices section (left side scrollbar). There you can manage your existing IoT devices and create new ones. You can do it by just clicking on the “+ Add” button on the top and filling the form that appears on the right side of the screen.
6. Clone the “Controlled publish period” example
Zerynth Studio includes a well-stocked collection of useful examples that you can clone (copy) in a few clicks. In this case, you have to clone the “Controlled publish period” example from the “Example Browser” panel on the left.
7. Set up your hardware
In our example, we are going to send brightness data instead of sample random values. The analog sensor we are going to use is the analog light sensor ALS-PT19 (you can find details about this sensor here). Connect your analog sensor to your board as shown in the schematics below.
8. Configure your project
To configure your project correctly, you have to edit main.py.
The main steps are:
- Configure the WiFi credentials
- Import the ADC library (analog to digital converter)
- Edit the threshold value
- Modify the main loop to get the sensor data and send it to Azure
You also have to edit the content of device.conf.json to make your project work correctly.
9. Add your private device key
Create a new file into your project named private.base64.key.
In your IoT device “Device Details” section you can find your primary key, copy it and paste it into the file you just created.
Uplink your project to your board and open the serial monitor.
IMPORTANT! Do not close the serial monitor to see the results of the next step.
11. Change the publish period
Open the “Device Twin” section from your IoT device panel and edit it as follows to change the publish period. Then go back to the serial monitor to see the results of the changes.
We hope that this tutorial was easy enough to follow and that you have successfully connected Zerynth powered board to Microsoft Azure.
Stay tuned for more articles coming your way.
Until next time,
The Zerynth team
Written by Tommaso Martorella