This repository contains the code of a simulated device interacting with an Azure IoT Hub.
It has been built for a blog post I have written on IoT Hub message routing for device twin change events.
To run this on your machine follow this steps:
- Install the .NET 5 SDK if you don't already have it
- Create an Azure IoT Hub on your subscription in the Free or Standard Tier
- Create a device in your hub, with SAS authentication, and copy it connection string
- Clone the repo, go in the
src/DeviceClientAppfolder and set the connection string with the following command:dotnet user-secrets set "DeviceConnectionString" "<YOUR-DEVICE-CONNECTION-STRING>" - You're ready to launch it using the
dotnet runcommand !
The first time the program is run for a device, it should give the following output:
$ dotnet run
DeviceClient created ! Getting current twin...
First time with this device, let's initialize it !
Done ! Exiting now...This first run creates two reported properties:
propertyUsedOnlyOncewhich will never be used again 😔colorset toRed
The next runs of the tool will change the value of the color property to Blue, then back to Red, then back to Blue, and so on...
But why ? Well, it's just for a demo, read the blog post to find out more !