IoT Edge MQTT subscriber module

Summary

This sample for an IoT Edge module sends data from a (local) MQTT server via edgeHub to an Azure IoT Hub.

Description

IoT is the combination of data. For that, data from multiple sources are sent to a central platform for further analysis. In case of an existing MQTT broker, this module let’s you subscribe to multiple topics and leverage the IoT Edge store and forward mechanism for uploading data to IoT Hub.

The module can be used in combination with an (external) MQTT broker to leverage the IoT Edge store and forward functionality to send data to Azure.

MQTT Subscriber overview

The module supports multiple topics (incl. wildcards) and authentication. The architecture overview shows an MQTT broker deployed as container on the edge device, which is one option. It can be an external server.

In case you need to subscribe to multiple servers, the module can be deployed multiple times with a different configuration.

Configuration

The configuration of the module is done via the module twin.

"properties": {
		"desired": {
			"MqttServer": "mqtt.fqdn",
			"MqttTopics": "['topicOne','topicTwo/#']",
			"MqttMessageTemplate": "{\"[topic]\":\"[message]\"}",
			"MqttUser": "optional username",
			"MqttPassword": "super secret password",
			"$metadata": {

Whenever the desired properties are changed, they are applied without the need to restart the module.

The sourcecode is available here ReneHezser/MqttSubscriber and an image to use for testing here iot-edge/mqttsubscribermodule.