Reputation: 5805
Is it possible to use Azure Functions to simulate a device connected to an Azure IoT Hub? (So far I have only found samples of Azure Functions that process data received by the hub.)
More precisely, the Azure Functions should perform the following two tasks, as if it were a device:
Periodically send telemetry data to the IoT Hub.
Get triggered on device twin property change, and do something with the new device twin properties.
Any code snippets or pointers to samples would be helpful!
Upvotes: 1
Views: 565
Reputation: 4085
Device simulations for Azure IoT Hub are usually long-running processes, hence you won't find many Azure Functions implementations with this purpose. That doesn't mean it's impossible. Like you suggested, a timer trigger could be used to periodically send telemetry to Azure IoT Hub. You can then send one or more messages, close the connection (if using MQTT or AMQP) and the function will stop. You can also use the REST API for this.
Normally, a device will react to changed desired properties events of its Device Twin by keeping a bi-directional connection open (again through MQTT or AMQP). Because your Function isn't always running, you would need to accomplish this in a different way. A solution would be to route Device Twin Change events to an EventHub that your Function is listening to.
Upvotes: 1
Reputation: 8235
Yes, it can be done using the following functions:
Upvotes: 1