The whole goal of this application is to scale out IoT device simulation to allow for downstream reporting and machine learning tasks.
The current architecture comprises of a few Azure Functions. The first called Registration Generation, essentially parses through the HTTP POST message (see example below) and generates a durable function to iterate through each device instance and send it individually on to the second function. The second function is called the Registration Consumer function. This function essentially uses the EventGridTrigger to take an event from Event Grid and run the Device Client SDK methods to Add a Device and to update the device twin. Then it finally submits the first telemetry message to the Send Event Consumer function. This functions job is to send a message to IoT Hub, tweak the values, re-submit a message to the Event Grid for the Send Event Consumer function.
It is using Antlr 4 (see above) to take a dynamic language specification and run it against business logic built to tweak the value of the IoT Message.
Please reference the below diagram for further information.
curl --request GET \
--url http://localhost:7071/api/RegistrationGenerator \
--header 'content-type: application/json' \
--data '[
{
"id": "bf9260c5-54ff-436c-933c-9cb26f7a3121",
"name": "Fridge Simulation",
"deviceNamePattern": "Fridge-{0}-{1}",
"deviceType": "Fridge",
"messageType": "Telemetry",
"initialState": "{ '\''temperature'\'': 70 }",
"deviceInterval": 1,
"numberOfDevices": 1,
"propertyValues": {
"temperature": "3+3"
},
"properties": {}
}
]'
We don't "commit" this into the repo, so be sure to create this file and add the following json to it.
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"APPINSIGHTS_INSTRUMENTATIONKEY": "___",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"DurableTaskStorage": "UseDevelopmentStorage=true",
"IoTHubConnectionString": "___",
"IoTHubName": "___",
"TopicEndpoint": "___",
"TopicKey": "___"
}
}
Debugging this application locally requires the use of NGrok because of the EventGrid subscriptions. To do this, essentially open a dos prompt where you saved NGrok and type in the below command.
ngrok http --host-header=localhost 7071
Then take the url that's generated (the https one) and create an Event Grid subscription using that url.