Skip to main content
Version: v5.0

Telemetry channel

You can create a telemetry channel for a sensor on the Model Elements page at the click of a button. You can then select a metric and publish data for that metric and view the source readings on a graph in the telemetry Channel Support panel.

CalloutDescription
ATelemetry Channel Support option
BCREATE TELEMETRY CHANNEL button

Creating a telemetry channel and publishing data for a sensor#

To create a telemetry channel and publish the data, do the following:

  1. On the Model Elements page, in the Fetch pane, select a sensor to fetch from the ElementCategory and ElementType dropdowns.
  2. On the Elements pane, click the sensor element you want.
  3. On the Related Items pane, click Telemetry Channel Support.
  4. To create the telemetry channel, on the Telemetry Channel Support pane, click CREATE TELEMETRY CHANNEL.
  5. To publish telemetry data, from the metric dropdown, select the metric you want, then click PUBLISH DATA.

Result: After data streaming starts, 10 readings are displayed in the Telemetry Channel Support pane.

Create telemetry channel button#

When the user clicks the the CREATE TELEMETRY CHANNEL button, the following cascade of events occur.

Button component and onClick handler#

Clicking the CREATE TELEMETRY CHANNEL button in app/ipaCore/components/TelemetryChannel.jsx triggers the onClick function handleCreateChannel:


<GenericMatButton onClick={() => handleCreateChannel()}>  CREATE TELEMETRY CHANNEL</GenericMatButton>

handleCreateChannel#

Before handleCreateChannel creates a telemetry config, it checks if the following exist in the project:

  • Telemetry collection
  • Sensors as related items
  • Parent-child relationship between the telemetry collection and the sensor related items
  • Parent-child relationship between the telemetry model element, such as a device, and the sensor related items

Note: These are created in the setup script createOtherCollections.js. If these don't exist, the handleCreateChannel function creates them in the same manner as the setup script. To walkthrough the setup script, see Setting up a telemetry collection

handleCreateChannel creates telemetry config#

Checks if a telemetry config of userType "telconfig" already exists and if not, it creates one:

  ...    ...    // Fetches all telemetry configs    let telemetryConfigs = await IafItemSvc.getTelemetryConfigs(      undefined,      ctx,      undefined    );    // Checks if the telemetry config already exists    let telemetryConfigsIot = telemetryConfigs._list.find(      (item) => item._shortName === "telconfig"    );
    // If not, it defines a telemetry config    if (!telemetryConfigsIot) {      let telemetryConfig = {        _namespaces: _namespaces,        _shortName: "telconfig",        _name: "Project A Telemetry Config",        _userType: "telemetry_config",        _configData: {          _normalizationScript: {            _userType: "telemetry_parser_script",          },          _bindings: [            {              collectionDesc: {                _id: telCollections._id,              },              query: {                _sourceId: "e3e052f9-0156-11d5-9301-0000863f27ad-00000131",              },            },          ],        },      };      ...    };      ...  ...  

For the binding, pass the source id as the query. The source id should match the source id used to create the telemetry item:


_bindings: [  {    collectionDesc: {      _id: telCollections._id,    },    query: {      _sourceId: "e3e052f9-0156-11d5-9301-0000863f27ad-00000131",    },  },],

The normalization script that _configData._normalizationScript._userType points to is in scripts/NextScriptEngine/scripts/js/iot_normalization.js - it normalizes sensor data from the ActiveMQ orchestrator:


var functions = {  normalize: function(strMessage){    var payload = JSON.parse(strMessage);    var payloadJson = JSON.parse(payload.payloadText);    var data = payloadJson.data.value.device_list;    
    var readings = [];      data.forEach(d => {        var readingsObj = {...d, ...this.constructReadings(d.Board_id, d.scan_time)};        readings.push(readingsObj)    });
    var result = {readings};    return JSON.stringify(result);  },  constructReadings: (sourceId, ts) => {    var date = new Date(ts*1000);    var readingsObj = {      "_ts": date.toISOString(),      "_tsMetadata":{          "_sourceId":sourceId      }    };    return readingsObj;  }}

After defining the telemetry config, it creates the telemetry config in the Item Service and completes the steps to create the telemetry channel:

  ...    ...    if (!telemetryConfigsIot) {      ...      let options = { transactional: false };      try {        //Create new telemetry config        telemetryConfigsIot = await IafItemSvc.createTelemetryConfig(          telemetryConfig,          ctx,          options        );      } catch (error) {        console.error("An error occurred:", error);      }      ...    };      ...  ...  

Cancelling the telemetry channel#

After a telemetry channel is created, users can cancel the channel with the following interface element:

CalloutUI elementDescription
ACANCEL TELEMETRY CHANNEL buttonCancels the telemetry channel by deleting the telemetry config and its corresponding orchestrator.

When the user clicks the CANCEL TELEMETRY CHANNEL button, the deleteTelemetryConfig function in IotChannel.jsx deletes the telemetry config and its corresponding orchestrator:


let deleteTelemetryConfig = await IafItemSvc.deleteTelemetryConfig(telemetryConfigsIot._id, ctx, undefined);