The solution presented in this article requires TeamViewer Embedded Agent v 1.1.102 (or higher). To identify the version of your agent, run: sudo teamviewer-iot-agent info (an error, or no result, indicates an older version of the agent is installed).

This article applies to TeamViewer Embedded users who monitor their OPC-UA IoT networks.

Description

As described in the Custom Plugin Connector article, it's quite easy to monitor your sensor network via TeamViewer Embedded. This article extends the integration approach to monitor OPC-UA server node values. For more about OPC-UA reference the OPC Foundation.

Step 1 - Install dependencies

The connector requires the following to be installed on the device:

To identify the installed version, run the following command: (an error, or no result, indicates an older version of the agent is installed)sudo teamviewer-iot-agent info
  • python (either v2 or v3)
  • pip
    • if you are not familiar with pip please visit the python download page to choose the prefered installation for your OS. 
    • While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to install from source archives:
python -m pip install --upgrade pip setuptools wheel
  • freeopcua python library 
    • freeopcua can be installed via pip
pip install freeopcua

Step 2 - Download and extract the OPC-UA Connector

  • From your device running the TeamViewer Embedded Agent, download the connector: 
wget https://download.teamviewer-iot.com/connectors/teamviewer-iot-opcua/1.0.0/teamviewer_iot_opcua-1.0.0.tar.gz
  • Upon download completion, extract the contents of the connector:
sudo mkdir -p /usr/local/teamviewer-iot-agent/monitoring/
tar -xzvf teamviewer_iot_opcua-1.0.0.tar.gz -C /usr/local/teamviewer-iot-agent/monitoring/opc-ua

 

Step 3 - Integrate the OPC-UA monitoring script with the TeamViewer Embedded Agent

The TeamViewer Embedded Agent includes its own system monitoring configuration file. This configuration file will be extended to include the opc-ua monitoring script. As you are going to maually edit a system configuration file, ensure to create a backup of the file in the case the file gets corrupted by user error.

  1. Open for editing the TeamViewer Embedded Agent monitoring configuration file located at:
    • /var/lib/teamviewer-iot-agent/system_monitors.conf
    • sensors are hosted under the "sensors" node of the configuration file
  2. For each OPC-UA sensor you want to integrate, append its registration information to the configuration file. Reference the template below and replace the placeholders with your OPC-UA node details.
  3. Save the configuration file.
  4. Restart the agent to reload the configuration file.
    • teamviewer-iot-agent restart
  5.  Log into your TeamViewer Embedded dashboard and verify that the Sensors/Metrics added to the configuration file now appear on your Metrics tab.
    • Pin the metrics to your dashboard and ensure the data is being updated per the frequency specified in the config file

OPC-UA Template

Use the following template to add your OPC-UA sensor nodes to the monitoring configuration file. Ensure to replace the following placeholders with the specifics of your OPC-UA node:

  • Note: the monitoringService parameters identifies the path of the connector installed in Step 1. Ensure the path you installed the connector matches the path specified here
  • monitoringParams - url, nodeId, frequency
  • metrics - name, key, valueType, valueAnnotation
    • Note: the metric name should be same as the nodeId

More details about the JSON schema can be found in the Custom Plugin Connector article.

{
    "sensors": [
        {
            "name": "opcua_node_aa",
            "monitoringService": "python /usr/local/teamviewer-iot-agent/monitoring/opc-ua/opc_ua_connect.py",
            "monitoringParams": "--url opc.tcp://myopcuahost:26543 --nodeId \"opcua_node_id\" --frequency 2",
            "metrics": [
                {
                    "name": "opcua_node_id",
                    "key": "opcua_node_id",
                    "valueType": "double",
                    "valueAnnotation": ""
                }
            ]
        },
        ...
    ]
}

The monitoringParams field contains additional arguments required by the script. Here is the table of available arguments.

Paramater

Type

Required

Description

url

String

True

OPC UA server url

nodeId

String

True

Id of the node specified by the given OPC UA server.

frequency

Integer

False

The frequency (in seconds) to poll for new node values.

If not set, frequency defaults to 1-time execution.

Monitoring Frequency

As described in the Monitoring Frequency section of the Custom Plugin Connector article, monitoring frequency can be either managed by the agent by specifying it as a standalone parameter, or managed by the opc-ua monitoring script itself by passing the parameter directly to the script.

In the template above, frequency is set within the monitoringParams as part of the script parameter. This approach is recommended for monitoring frequencies of less than 1 minute. The TeamViewer Embedded Agent will execute the opc-ua monitoring script once - at startup, allowing the script to run indefinitely; while the script itself will execute in a loop polling for new data every 2 seconds (as specified by the frequency parameter). 

In cases where the monitoring frequency is slower than 1 per minute, the frequency can be specified as part of the template, which will result in the TeamViewer Embedded Agent executing the referenced script at the frequency specified.

In the example below, the frequency parameter is set to 120, which will trigger the agent to execute the script referenced by monitoringScript every 120 seconds.

{
    "sensors": [
        {
            "name": "opcua_node_aa",
            "monitoringScript": "python /usr/local/teamviewer-iot-agent/monitoring/opc-ua/opc_ua_connect.py",
            "monitoringParams": "--url opc.tcp://myopcuahost:26543 --nodeId \"opcua_node_id"",
            "frequency": 120,
            "metrics": [
                {
                    "name": "opcua_node_id",
                    "key": "opcua_node_id",
                    "valueType": "double",
                    "valueAnnotation": ""
                }
            ]
        },
        ...
    ]
}