Part 1 – dotnet vs python vs node – temperature emission – who is cooler?
Part 2 – Developing modules
Part 3 – Custom Containers using Apache Nifi
Part 4 – Custom Module using TimescaleDB
Part 5 – Custom Module using Grafana
This code will run through creating an end to end demo of building & deploying an Azure IoT Edge solution solution.
Code for this example lives here
What are we building?
This solution demonstrates an air-conditioning monitoring system where 3 room sensors are publishing their temperature over time. When a room gets too hot the air conditioner for that room is turned on. Once the room is cooled it is turned off.
Three ‘data generator’ modules publish a message with the following properties.
- Temperature – room temp in Celsius
- IsAirConditionerOn – true/false
- TagKey – room name (in this case dotnet, node, python)
Three ‘data recorder’ modules subscribe to the published temperature messages and save the data in a time series database.
A custom module will listen to all temperature messages and analyse when a room is too hot. Sending a message to turn the rooms air conditioner on.
Demo Focus Areas
- show local debug/development options & remote/real deployment
- how to create and configure an Azure IOT Hub environment in Azure using Azure CLI scripts
- coding custom modules in .Net, Python, NodeJS (sorry Java)
- using existing Azure IoT Edge marketplace modules
- using non-edge marketplace modules (docker images) to save data with Timescale
- connecting a data flow engine ( Apache Nifi) to the Edge MQTT Broker
- viewing the data through a Grafana dashboard.
In order to develop solutions for the edge:
- Read Developing custom modules
- Setup your machine using the Azure IoT EdgeHub Dev Tool
- I recommend installing these VS code extensions
- I recommend using Portainer for docker management both locally & on the deployed edge solution
Portainer running on http://localhost:9000/
You will need an Azure IoT Hub setup in Azure. For this demo I am using the free tier
The IoT Hub Free Edition is intended to encourage proof of concept projects. It enables you to transmit up to a total of 8,000 messages per day, and register up to 500 device identities. The device identity limit is only present for the Free Edition.
To build the environment I have used the Azure CLI and created scripts found here. Run the top 3 on your selected subscription to create the artefacts in Azure below:
The code contains the docker build files , code & scripts to create the following modules
Descriptions of folders and files
|Folder / File||Description|
|config||automatically generate files from the deployment.templates.json (debug or prod) that are used to deploy the solution|
|modules||custom code, docker images for your IOT Edge solution|
|scripts||code to create the environment, build the code/docker images and deploy the solution|
|tools||certificate generator and other tools for solution support|
|.env||holds environment variables that populate the generated config files from the templates|
|deployment.debug.template.json||creates a file in the /config folder called ‘deployment.debug.json’ that populates environment variables, used for local development|
|deployment.prod.template.json||creates a file in the /config folder called ‘deployment.prod.json’ that populates environment variables, used for production like deployment|
Solution Structure Overview
Azure IOT Edge Devices
The solution used 3 devices which will be setup in a future post.
1. Local Simulator
A simulated local environment using the Azure IoT Edge Hub Development simulator to run against the IOT Hub. When developing for the edge it is recommended not to install the real ‘IOT edge runtime’ on your machine but instead use the simulator.
2. Local Device
Linux Ubuntu machine hosted in VMWare on my local machine using Hyper V
3. Cloud Device
Linux Ubuntu hosted on Azure in our resource group created using this script
This uses the pre-existing Linux Ubuntu image from the Azure Marketplace with the runtime installed.
Once up and running VS Code will show the devices below.
Now we have a view of the setup, development environment & code, we can move onto the next post ‘Developing custom modules for Azure IoT Edge’