Sending telemetry from IoT Edge to IoT Central

After writing my last post, I kept thinking about sending messages to the Azure IoT Central Bridge from Azure IoT Edge.

Eventually, I started building this IoT Edge module which passes incoming route messages to the IoT Central Bridge of your choice.

This module is now available in Docker Hub.

Use it in your IoT device with tag:

svelde/iot-edge-ic-bridge:1.1.0-amd64

Let’s check this module out.

Introduction

Microsoft offers a bridge for third party IoT clouds to be connected with IoT Central. But this bridge is also usable by IoT Edge devices.

This module sends incoming messages to the IoT Central Bridge which is available in the Desired Properties together with a DeviceId.

Note: your IoT Edge device still needs its own IoT Hub for configuration and monitoring. Only telemetry is send to IoT Central.

If the message fails (timeout of Azure Function, blocked or unassociated in IoT Central) a message is made available in output ‘Exception’.

More information about the IoT Central Bridge using the is available here.

Input

Messages are received on input ‘input1’.

This input accepts all kinds om messages and fills it into the measurement node of the IoT Central message format:

{
    "device": {
        "deviceId": "[deviceId]"
    },
    "measurements": {
        "[key x]": [value x],
        "[key y]": [value y]
    }
}

Note: The name of the device is outputted in lowercase due to requirements of the IoT Central Bridge.

Note: IoT Central only supports one level deep key-value pair nodes within the measurements node, except for a GPS location.

Outputs

No regular output

This module does not send any messages to a regular route output.

Exceptional output

In case a message can not be parsed, the IoT Central bridge rejects the message or another excpetion occurs, a message will be put on output ‘Exception’.

This is the Exception format:

public class OutputMessage
{
  [JsonProperty(PropertyName = "status")]
  public string Status { get; set; }

  [JsonProperty(PropertyName = "result")]
  public string Result { get; set; }
}

Routes

Here is an example of how to use the Exception output for routes:

{
“routes”: {
“bridgeToEcho”: “FROM /messages/modules/icbridge/outputs/Exception INTO BrokeredEndpoint(\”/modules/echo/inputs/input1\”)”
}
}

Note: This routing image is produced with the IoT Edge Module Flow generator.

Desired properties

The module support one DeviceId and one IoT Central Bridge Uri.

Provide these values in the desired properties:

"desired": {
  "deviceId": "[Device Id]",
  "uri": "[IoT Central Bridge function URI]"
}

Direct Method

The module also supports a direct method name ‘inputMessage’.

Just pass it message like this:

{
  "[key x]": [value x],
  "[key y]": [value y]
}

You can follow the message using the logging output.

Throttling

I recently added support for throttling. If the bridge is overwhelmed by questions, it requests for a time out.

This module it honors these request by stopping sensing questions for the amount of time requests (eg. 50 seconds).

Conclusion

The code of this logic is open source and licenced under the MIT license.

Want to contribute? Throw me a pull request.

Note: As of last week, this module is made now handed over to the https://github.com/iot-edge-foundation community. Let’s add some value on the Edge with quality IoT Edge modules.