In this blog post I will walk you through
how and IoT device (for IoT Hub and IoT Edge gateway) can be created.
The simulated device will generate
telemetry data that will be used by IoT Edge Module (e.g. Clustering) to find
out which device need to be replace or restart it etc.
I will be posting few more blogs to achieve
below:
We can see from above diagram, the main
components are:
- IoT Hub
- Configuration of IoT Edge device as gateway
- IoT Edge Module
- Downstream devices
I will develop a Machine Learning model
(k-means clustering) in R and will leverage in MachineLearningModel Edge Module
to find which device need to be replaced or need to restart etc.
For the simplicity, the downstream device
will generate following telemetry data:
- Temperature
- Humidity
- Pressure
Let’s
develop a downstream device that generates above random data. Follow https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-getstarted
to setup you IoT Hub. I have got my IoT Hub setup now, I am creating a .Net
console app that acts as device which generates some random data.
Here are
some code snippets:
Here is the Main method:
Here is an example batch file to run as device1:
Now you
need to register 3 devices in Azure Portal in IoT Hub here are the steps:
- Navigate to Azure Portal then your IoT Hub
- Navigate to IoT Devices
- Click on Add button and fill the details for the device like shown below:
- Now, go to the device you just created and copy the primary connection string to respective .bat file.
- Repeat for 3 times to create 3 devices.
Once you have created three devices, start
running device1.bat, device2.bat and device3.bat. It will start sending data to
IoT Hub like shown below:
And your IoT Hub will show number of
messages received like shown below:
So far we have created/simulated 3 devices that started sending temperature and other data to IoT Hub. These devices will be used to send the data to IoT Edge gateway (by appending GatewayHostName=<your-gateway-host-name> to device connection string) and I will explain in next blog so stay tuned.