Skip to content

Container Example

The container example is located in the examples/container directory. This example shows how to manage XRT components in a container using JSON configuration.

This example illustrates the following:

  • Use of the config-loader configuration loader function to load named configuration data, which is hard-coded as string values. This is set as the global mechanism for loading configuration
  • The main configuration is represented by the name of the container passed during creation of the container. In this example, the container is created by the iot_container_alloc ("main") call, and the main configuration is called main.json
  • Global registration of component factories. The container uses component factories to manage components. The registered factories are as follows:
  • Use of Lua scripting using the Lua Transform component. The Lua Transform component modifies data generated by a Virtual Device Service component and republished on a different topic
  • Initialization of the container and all configured components in the container
  • Starting the container and all components in the container
  • Stopping and freeing the container and all components in the container. In the example, this occurs after a timeout of five seconds

The example includes the configuration of the components registered as component factories.

The directory containing the configuration must be provided when running the example. For details of the configuration for each component, see Components.

In this example, the data is published by the Virtual Device Service component to the device/data topic. The data is then transformed by the Lua Transform component and published to the device/processed topic.

Note

There are two instances of the Logger component:

  • One is configured to log Info level messages and is used by the Log Exporter component. This is used to log the messages, where are the input to, and output from, the Lua Transform component. The messages published on the device/data topic by the Virtual Device Service is the input, and the processed message published to the device/processed topic is the output from the Lua Transform component.
  • The other instance is configured to log Warning level messages for reduced verbosity and is used by the other components in this example.

To run the Container example for five seconds, enter the following commands:

cd examples/container
xrt config 5
After five seconds, the output is similar to the following:
[iot-0-0:1611149444:console:Info] device/data:{"device":"xrt-example-device1","resource":"SensorOne","readings":{"Origin": {"value":"Sensor54","type":"string"},"Temp":{"value":123,"type":"uint32"},"Uptime": {"value":456789,"type":"uint64"}}}
[iot-0-0:1611149444:console:Info] device/processed:{"resource":"SensorOne","readings": {"Origin":{"type":"string","value":"Sensor54"},"Temp": {"type":"uint32","value":123},"Uptime":{"type":"string","value":"0.0 seconds"}},"device":"xrtexample-device-1"}
[iot-0-1:1611149447:console:Info] device/data:{"device":"xrt-example-device1","resource":"SensorOne","readings":{"Origin": {"value":"Sensor54","type":"string"},"Temp":{"value":122,"type":"uint32"},"Uptime": {"value":456790,"type":"uint64"}}}
[iot-0-1:1611149447:console:Info] device/processed:{"resource":"SensorOne","readings": {"Origin":{"type":"string","value":"Sensor54"},"Temp": {"type":"uint32","value":122},"Uptime":{"type":"string","value":"0.5 seconds"}},"device":"xrtexample-device-1"}
...
...

Back to top