Skip to content

Azure Exporter Example

The Azure Exporter example is located in the examples/azure_exporter directory. This example shows how to use the Azure Exporter component from inside a container using JSON configuration files.

When the example is run, a container is instantiated and populated with components. The container uses component factories to manage components, which are specified in the config/main.json file. Each entry for a component in this file specifies the following:

  • The name of the component, for example: azure
  • The name of the registered factory used to create the component, for example: XRT::AzureExporter

The components used in this example are as follows:

  • Logger component
  • ThreadPool component
  • Scheduler component
  • Core Bus component
  • Virtual Device Service component. This publishes data on the Bus
  • Azure Exporter component. This subscribes to the Bus, receives data that matches the subscription pattern, exports it to Azure cloud, and receives data from the device twin to publish back to the bus
  • Log Exporter component. This subscribes to the data published by the Virtual Device Service on the same topic set by the Azure Exporter component, and outputs it to the log

Each component can be configured using the associated JSON file; for example, the Azure Exporter component is configured using the azure.json file. For further information on configuration of the Azure Exporter component, see Azure Exporter Component.

Note

There are three instances of the Logger component. One is configured to Info level and is used by the Log Exporter component that logs the messages available to the Azure exporter as input. The second is configured to log Debug level messages and is used by the Azure exporter. The third is configured to log Warning level messages for reduced verbosity and is used by the other components in this example.

In this example, the Virtual Device Service is configured to generate a reading event every five seconds and publish it to the Bus using the device/virtual/output topic. The Azure Exporter component is configured to subscribe to device/virtual/output and publish on device/virtual/input.

To provision a device and use it to communicate with the IoT Hub, you must set the following environment variables:

Environment Variable Description
AZURE_EXPORTER_DEVICE_ID The name of the device to provision
Set to the device name matching the name provided during certificate creation
AZURE_EXPORTER_CERTIFICATE The full-chain certificate
Set to the full-chain certificate created for the device in PEM format
AZURE_EXPORTER_KEY The private key
Set to the private key for the device in PEM format

To run the Azure Exporter component example for five seconds, enter the following commands:

cd examples/azure_exporter
xrt config 5

The output is similar to the following:

[xrt:1618316655:console:Debug] xrt_azure_exporter_alloc (Host:IOTechHub.azuredevices.net Scope:0ne0017479D ID:custom-hsm-device-01)
[xrt:1618316655:console:Debug] Loading device profile from: device-virtual
[xrt:1618316655:console:Debug] Init Virtual Device Service
[iot-0-1:1618316655:console:Debug] GET on device:
[iot-0-1:1618316655:console:Debug] Requested reading 0:
[iot-0-1:1618316655:console:Debug] publish: {"device":"devicevirtual","resource":"InputBool","readings":{"InputBool":{"value":true,"type":"bool"}}}
[iot-0-1:1618316655:console:Debug] Provisioning Status: CONNECTED
[iot-0-1:1618316656:console:Debug] Provisioning Status: ASSIGNING
[iot-0-1:1618316658:console:Debug] Registration Information received from service: IOTechHub.azure-devices.net, device_id: custom-hsm-device-01
[iot-0-1:1618316659:console:Debug] Client setup for Azure IoTHub
[iot-0-1:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-0:1618316659:console:Debug] GET on device:
[iot-0-0:1618316659:console:Debug] Requested reading 0:
[iot-0-0:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputInt8","readings":{"InputInt8":{"value":2,"type":"int8"}}}
[iot-0-0:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-1:1618316659:console:Debug] GET on device:
[iot-0-1:1618316659:console:Debug] Requested reading 0:
[iot-0-1:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputInt16","readings":{"InputInt16":{"value":-22550,"type":"int16"}}}
[iot-0-1:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-0:1618316659:console:Debug] GET on device:
[iot-0-0:1618316659:console:Debug] Requested reading 0:
[iot-0-0:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputInt32","readings":{"InputInt32":{"value":-39480594,"type":"int32"}}}
[iot-0-0:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-1:1618316659:console:Debug] GET on device:
[iot-0-1:1618316659:console:Debug] Requested reading 0:
[iot-0-1:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputUint8","readings":{"InputUint8":{"value":80,"type":"uint8"}}}
[iot-0-1:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-0:1618316659:console:Debug] GET on device:
[iot-0-0:1618316659:console:Debug] Requested reading 0:
[iot-0-0:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputUint16","readings":{"InputUint16": {"value":45264,"type":"uint16"}}}
[iot-0-0:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-1:1618316659:console:Debug] GET on device:
[iot-0-1:1618316659:console:Debug] Requested reading 0:
[iot-0-1:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputFloat32","readings":{"InputFloat32": {"value":2.37433675e+38,"type":"float32"}}}
[iot-0-1:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[iot-0-0:1618316659:console:Debug] GET on device:
[iot-0-0:1618316659:console:Debug] Requested reading 0:
[iot-0-0:1618316659:console:Debug] publish: {"device":"devicevirtual","resource":"InputFloat64","readings":{"InputFloat64": {"value":4.1561699980665794e+307,"type":"float64"}}}
[iot-0-0:1618316659:console:Debug] xrt_azure_exporter_connect Waiting for connection
...
[xrt:1618316659:console:Debug] Azure IoT client DPS connection result: AUTHENTICATED reason: OK
[xrt:1618316660:console:Info] xrt_azure_exporter_twin_callback: (COMPLETE) {"desired": {"$version":1},"reported":{"$version":1}}
[xrt:1618316660:console:Debug] xrt_azure_exporter_publish_values: (null)

Back to top