Skip to content

AWS SiteWise Exporter Example

The AWS SiteWise exporter example is located in the examples/sitewise_exporter directory. This example shows how to use the AWS SiteWise 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: sitewise
  • The name of the registered factory used to create the component, for example: XRT::SiteWiseExporter

The components used in this example are as follows:

Each component can be configured using the associated JSON file; for example, the AWS SiteWise component is configured using the sitewise.json file. For further information on configuration of the AWS SiteWise Exporter component, see AWS SiteWise 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 SiteWise Exporter as input. The second is configured to log Debug level messages and is used by the AWS SiteWise 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 second and publish it to the Bus using the device/data topic, which is the default topic for events. The AWS SiteWise Exporter component is configured to subscribe to, and publish, all messages with device/ topics.

To authenticate with AWS, you must set the following environment variables:

Environment Variable Description
AWS_SITEWISE_ACCESS_KEY The access key to use when authenticating with AWS

Set to a valid access key
AWS_SITEWISE_ACCESS_SECRET_KEY The secret key to use when authenticating with AWS

Set to a valid secret key

This example attempts to publish readings to the following AWS property aliases:

  • IoTech/demos/aws/xrt-example-device-1/Voltage
  • IoTech/demos/aws/xrt-example-device-1/Current

You must create an AWS asset with these properties. For further information on Assets, Properties and Aliases, see the AWS documentation.

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

cd examples/sitewise_exporter
xrt config 5
The output is similar to the following:
[xrt:1611166098:console:Info] Component XRT::SiteWiseExporter license check successful
[xrt:1611166098:console:Info] No CA certificates found or CA path set
[iot-0-1:1611166098:console:Info] device/data:{"device":"xrt-example-device1","resource":"SensorOne","readings":{"Voltage":{"value":1.0000000000000000e+02,"type":"float64"},"Current":{"value":1.2300000000000000e+02,"type":"float64"}}}
[iot-0-1:1611166098:console:Debug] sitewise: data to export: {"entries":[{"propertyValues":[{"value":{"doubleValue":1.0000000000000000e+02},"timestamp":{"timeInSeconds":1611166098,"offsetInNanos":514969117}}],"entryId":"0","propertyAlias":"IoTech/demos/aws/xrt-example-device-1/Voltage"},{"propertyValues":[{"value":{"doubleValue":1.2300000000000000e+02},"timestamp":{"timeInSeconds":1611166098,"offsetInNanos":514976893}}],"entryId":"1","propertyAlias":"IoTech/demos/aws/xrt-example-device-1/Current"}]}
[iot-0-1:1611166099:console:Debug] sitewise returns: {"errorEntries":[]}
[iot-0-1:1611166099:console:Debug] sitewise: export successful
[iot-0-0:1611166101:console:Info] device/data:{"device":"xrt-example-device1","resource":"SensorOne","readings":{"Voltage":{"value":9.9000000000000000e+01,"type":"float64"},"Current":{"value":1.2400000000000000e+02,"type":"float64"}}}
[iot-0-0:1611166101:console:Debug] sitewise: data to export: {"entries":[{"propertyValues":[{"value":{"doubleValue":9.9000000000000000e+01},"timestamp":{"timeInSeconds":1611166101,"offsetInNanos":15152134}}],"entryId":"2","propertyAlias":"IoTech/demos/aws/xrt-example-device-1/Voltage"},{"propertyValues":[{"value":{"doubleValue":1.2400000000000000e+02},"timestamp":{"timeInSeconds":1611166101,"offsetInNanos":15160512}}],"entryId":"3","propertyAlias":"IoTech/demos/aws/xrt-example-device-1/Current"}]}
[iot-0-0:1611166101:console:Debug] sitewise returns: {"errorEntries":[]}
[iot-0-0:1611166101:console:Debug] sitewise: export successful
In this output, the messages available on the device/data topic are the input to the SiteWise Exporter component.

Back to top