4. Add your own Device Connector

By developing a Device Connector that reads data from a device and passes it to the Agent, you can send the data retrieved from any device to the intdash server. The transfer of data between the Device Connector and the Agent is done using FIFO.

4.1. Configure to use your own Device Connector

The Agent and the Device Connector are connected by a FIFO. When data from the device is sent to the Agent, the Device Connector writes the data to the FIFO in a given format and the Agent reads it. Conversely, when the Agent sends data to the device, the Agent writes the data to the FIFO in a given format and the Device Connector reads it.

The FIFO is provided by the plug-in. To add the FIFO plug-in, add the following items to the configuration file. If you start the Agent with the FIFO plug-in added, a FIFO file for communication between the Device Connector and the plug-in will be generated.

Note

However, the Device Connector intdash-edge-logger provided by Aptpod does not use the FIFO plugin. Therefore, when using intdash-edge-logger, it is not necessary to include plugin in the configuration file.

Example (Adding a FIFO for channel 2):

{
  ...
  loggers: [{
      "connections": [{
        "channel": 2,
        "fifo_tx": "/var/run/intdash/logger_002.tx",
        "fifo_rx": "/var/run/intdash/logger_002.rx"
      }],
      "details": {
        "plugin": "fifo"
      },
  }],
  ...
}

Note

The "logger" in the configuration file refers to the Device Connector.

When you start the Agent with this setting, two FIFO files /var/run/intdash/logger_002.tx and /var/run/intdash/logger_002.rx are created for communication between the Agent and the Device Connector. The Device Connector must write data to /var/run/intdash/logger_002.tx when sending data to the Agent. The Device Connector must read data from /var/run/intdash/logger_002.rx when receiving data from the Agent.

Note

When the Agent sends data to the intdash server, the channel set in the configuration file is used as the channel number.

4.2. Write to FIFO from Device Connector

To send data from the Device Connector to the Agent, the Device Connector needs to write the data to the FIFO generated by the Agent.

4.2.1. Writing data

The data to be written to the FIFO must follow a pre-defined format. Check FIFO data format used between Agent and Device Connector for the format.

4.3. Read data from FIFO

To set up downstream, you need to add a Control client to the clients section of the configuration file. The data that the Device Connector can read from the FIFO is the data on the channels that are configured for downstream in the Control client and that are configured for the Device Connector.

Example (Device Connector settings):

{
  ...
  loggers: [{
      "connections": [{
        "channel": 2,
        "channel_rx": -1,
        "receive_basetime": true,
        "fifo_tx": "/var/run/intdash/logger_002.tx",
        "fifo_rx": "/var/run/intdash/logger_002.rx"
      }],
      "details": {
        "plugin":"fifo"
      },
  }],
  ...
}

The format of data to be read from the FIFO is the same as the format for writing ( FIFO data format used between Agent and Device Connector ).

The data received by one Device Connector is limited to the data on one channel. If channel_rx does not exist or -1 is set, the channel number set in channel will be received. If channel_rx is set to a value between 0 and 255, the channel number set in channel_rx will be received.

Whenever a downstream connection is made to the intdash server (including a reconnection), the base time is received. If the Device Connector does not want to receive the base time data, specify false for receive_basetime.

Example (Settings for Control client):

{
  "clients": [{
    "protocol": "mod_websocket.v2",
    "my_id": "c35618bf-aa2c-4abc-8a4e-5b157b90c9ef",
    "my_secret": "hsNxJhvDNHR2QcXbXl..........................Z0RWKvfPs_neAkjTNSO5",
    "down_dst_id": "00000000-0000-0000-0000-000000000000",
    "ctlr_id": "9defc535-4640-4c5e-934a-bb435a89a64f",
    "ctlr_flts": [
      {
        "channel": 2,
        "dtype": 10,
        "ids": ["string_a", "string_b"]
      },
      {
        "channel": 3,
        "dtype": 14,
        "ids": ["data_a", "data_b"]
      }
    ],
    "type": "control",
    "connection": {
      "path": "/api/v1/ws/measurements",
      ...
    },
    ...
  }],
  ...
}

In this Control client configuration example, the following two types of data sent from the edge UUID 9defc535-4640-4c5e-934a-bb435a89a64f are received via the downstream.

  • Channel number: 2, iSCP data type: String (10), data ID: "string_a" or "string_b"

  • Channel number: 3, iSCP data type: Bytes (14), data ID: "data_a" or "data_b"

When the Device Connector and Control client are configured as above, the Device Connector receives the data sent from the edge UUID 9defc535-4640-4c5e-934a-bb435a89a64f, channel number: 2, iSCP data type: String (10), data ID: "string_a" or "string_b". Since only channel 2 is specified in the Device Connector settings, data with channel number 3 cannot be received.

4.4. Automatic startup and termination of Device Connectors

The Device Connector can be started and shut down at any time. If you want the Device Connector to start and end together with the Agent, you can do it in the following ways.

4.4.1. Automatically start the Device Connector when the Agent starts

You can configure the Device Connector to start when the Agent starts.

Specify the Device Connector startup command in path of the configuration file, and specify the Device Connector configuration file in conf. With this setting, when the Agent starts, the command to start the Device Connector is executed in the form of path -C conf.

"loggers": [{
  "path": "/opt/vm2m/sbin/test-logger",
  "conf": "/etc/opt/intdash/test-logger.conf",
  "connections": [{
    "channel": 3,
    ...
  }],
  ...
}]

4.4.2. Terminate the Device Connector with a signal from the Agent

When exiting the Agent, the Agent sends a SIGTERM to the Device Connector. Make sure that your Device Connector detects the signal and performs the termination process.