This solution is an end-to-end solution to test a full Azure IoT Edge setup. It consists of two parts:
- Two Azure Functions that run in the cloud
- Two custom modules running on the Edge
The testing loop is started by a timer-triggered (every couple of minutes) Azure Function (Direct Method Caller), which attempts to execute a direct method on a module running in IoT Edge (Direct Method Receiver). This module creates a new IoT messages and sends it to the Edge Hub. The message gets routed to the next module (Message Forwarder). This one forwards the message back to the Edge Hub where another route sends the message to the IoT Hub back in Azure ("$upstream"). In the cloud, a second Function is triggered by new telemetry messages on the IoT Hub. This concludes the complete loop.
All steps in the cycle are getting logged into Application Insights. This enables reporting and alerting if there are any errors at any point in the loop - and also about the end to end duration of the message from the start in the cloud until it is being received again in the cloud.
- Create an Azure Function instance. Also create an Application Insights instance.
- Create an Azure IoT Hub
- Create a consumer group on the Event Hub compatible endpoint call receiverfunction
- Create an Edge device in the IoT Hub
- Deploy the two modules to your Edge device (folder EdgeModules) and set the routing accordingly (see deployment.template.json for reference). Make sure to set the instrumentation key of your Application Insights instance.
- Set the following settings in the Azure Function Application settings:1
- iothubowner_cs => The IoT Hub Owner connection string of your IoT Hub
- iothubevents_cs => The connection string of the built-in Event Hub compatible endpoint of your IoT Hub
- destinationmodules => Comma-separates list of Edge module IDs of Direct Method Receiver modules, e.g. ("edgedevice1/DirectMethodReceiver")
- Deploy the two Functions (folder CloudFunctions)
Now, the Function should trigger (default: every 2 minutes) and start the flow. After a few minutes, you should be able to see log messages in Application Insights. If you run into any problems or have questions, feel free to open an issue here in the repo.
1: I recommend to use Azure Key Vault to store your secret app settings such as connections strings