DEV Community

Chris McKelt
Chris McKelt

Posted on • Originally published at blog.mckelt.com on

Azure IoT Edge - dotnet, node python

Series


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

Intro

This code will run through creating an end to end demo of building & deploying an Azure IoT Edge solution.

Code for this example lives here

https://github.com/chrismckelt/edgy

Whats the demo?

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.

  • Timestamp 
  • 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

  1. show local debug/development options &  remote/real deployment
  2. how to create and configure an Azure IOT Hub environment in Azure using Azure CLI scripts
  3. coding custom modules in .Net, Python, NodeJS (sorry Java)
  4. using existing Azure IoT Edge marketplace modules
  5. using non-edge marketplace modules (docker images) to save data with Timescale
  6. connecting a data flow engine ( Apache Nifi) to the Edge MQTT Broker
  7. viewing the data through a Grafana dashboard.

Getting started

In order to develop solutions for the edge:

  1. Read Developing custom modules
  2. Setup your machine using the Azure IoT EdgeHub Dev Tool
  3. I recommend installing these VS code extensions
  4. I recommend using Portainer for docker management both locally & on the deployed edge solution
Portainer running on http://localhost:9000/


Solution Overview

Azure Setup

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:

Modules

The code contains the docker build files , code & scripts to create the following modules

Code

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

https://docs.microsoft.com/bs-latn-ba/Azure/iot-edge/how-to-install-iot-edge-linux

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.

 

Outro

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'

Latest comments (1)

Collapse
 
_ceder profile image
Christian Eder

Hi @chris_mckelt ,

thanks for the article! I'm curious about your recommendation to use Portainer for docker management. I haven't used Portainer yet, only recently heard of it, so I'm not sure what benefits it brings in terms of managing the deployment of containers to the edge device fleet, as opposed to using Azure IoT Edge & IoT Hub for that aspect.

Also, since you wrote this article a while ago, do you have some learnings or experiences to share regarding this aspect, both positive and negative?

Thanks!