OPC-UA Connector for easy Integration - TeamViewer Support
<main>
<article class="userContent">
<p><em>This article applies to TeamViewer IoT users who monitor their OPC-UA IoT networks.</em></p><p><em>The solution presented in this article requires TeamViewer IoT Agent v 1.1.102 (or higher). To identify the version of your agent, run: </em><strong><em>sudo teamviewer-iot-agent info </em></strong><em>(an error, or no result, indicates an older version of the agent is installed).</em></p><h4 data-id="description"><strong>Description</strong></h4><p>As described in the <a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Labs/Custom-Plugin-Connector-How-to-easily-integrate-your-IoT-Sensors/td-p/36439" rel="nofollow noreferrer ugc">Custom Plugin Connector</a> article, it's quite easy to monitor your sensor network via TeamViewer IoT. This article extends the integration approach to monitor <strong><em>OPC-UA</em></strong> server node values. For more about<strong><em> OPC-UA</em></strong> reference the <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fopcfoundation.org%2Fabout%2Fopc-technologies%2Fopc-ua%2F" rel="nofollow noreferrer ugc">OPC Foundation</a>.</p><h4 data-id="step-1-install-dependencies"><strong>Step 1 - Install dependencies</strong></h4><p>The connector requires the following to be installed on the device:</p><ul><li>TeamViewer IoT Agent v 1.1.12 or greater</li><li>For details, reference: <a href="https://teamviewer-iot.com/" rel="nofollow noreferrer ugc">https://teamviewer-iot.com/</a></li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">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
</pre><ul><li>python (either v2 or v3)<ul><li>For details, reference: <a href="https://www.python.org/downloads/" rel="nofollow noreferrer ugc">https://www.python.org/downloads/</a></li></ul></li><li>pip<ul><li>if you are not familiar with <strong><em>pip </em></strong>please visit the <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fpackaging.python.org%2Fguides%2Finstalling-using-linux-tools%2F" rel="nofollow noreferrer ugc">python download page</a> to choose the prefered installation for your OS. </li><li>While <strong><em>pip</em></strong><em> </em>alone is sufficient to install from pre-built binary archives, up to date copies of the <em>setuptools </em>and <em>wheel</em> projects are useful to install from source archives:</li></ul></li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">python -m pip install --upgrade pip setuptools wheel
</pre><ul><li>freeopcua python library <ul><li>freeopcua can be installed via pip</li></ul></li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">pip install freeopcua
</pre><ul><li><ul><li>For details, reference <a href="https://github.com/FreeOpcUa/python-opcua" rel="nofollow noreferrer ugc">https://github.com/FreeOpcUa/python-opcua</a></li></ul></li></ul><h4 data-id="step-2-download-and-extract-the-opc-ua-connector"><strong>Step 2 - Download and extract the OPC-UA Connector</strong></h4><ul><li>From your device running the TeamViewer IoT Agent, download the connector: </li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">wget https://download.teamviewer-iot.com/connectors/teamviewer-iot-opcua/1.0.0/teamviewer_iot_opcua-1.0.0.tar.gz
</pre><ul><li>Upon download completion, extract the contents of the connector:</li></ul><pre class="code codeBlock" spellcheck="false" tabindex="0">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
</pre><h4> </h4><h4 data-id="step-3-integrate-the-opc-ua-monitoring-script-with-the-teamviewer-iot-agent"><strong>Step 3 - Integrate the OPC-UA monitoring script with the TeamViewer IoT Agent</strong> </h4><p>The TeamViewer IoT 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 <strong><em>create a backup of the file in the case the file gets corrupted by user error.</em></strong></p><ol><li>Open for editing the TeamViewer IoT Agent monitoring configuration file located at:<ul><li>/var/lib/teamviewer-iot-agent/system_monitors.conf</li><li>sensors are hosted under the "sensors" node of the configuration file</li></ul></li><li>For each <strong>OPC-UA </strong>sensor you want to integrate, append its registration information to the configuration file. Reference the template below and replace the placeholders with your <strong>OPC-UA </strong>node details.</li><li>Save the configuration file.</li><li>Restart the agent to reload the configuration file.<ul><li>teamviewer-iot-agent restart</li></ul></li><li> Log into your <a href="https://community.teamviewer.com/English/home/leaving?target=https%3A%2F%2Fteamviewer-iot.com%2F" rel="nofollow noreferrer ugc">TeamViewer IoT dashboard</a> and verify that the Sensors/Metrics added to the configuration file now appear on your <strong><em>Metrics </em></strong>tab.<ul><li>Pin the metrics to your dashboard and ensure the data is being updated per the frequency specified in the config file</li></ul></li></ol><h4 data-id="opc-ua-template">OPC-UA Template</h4><p>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:</p><ul><li>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</li><li>monitoringParams - url, nodeId, frequency</li><li>metrics - name, key, valueType, valueAnnotation<ul><li>Note: the metric name should be same as the nodeId</li></ul></li></ul><p>More details about the JSON schema can be found in the <a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Labs/Custom-Plugin-Connector-How-to-easily-integrate-your-IoT-Sensors/td-p/36439" rel="nofollow noreferrer ugc">Custom Plugin Connector</a> article.</p><pre class="code codeBlock" spellcheck="false" tabindex="0">{
"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": ""
}
]
},
...
]
}
</pre><p><em>The monitoringParams </em>field contains additional arguments required by the script. Here is the table of available arguments.</p><p><strong>Paramater</strong></p><p> <strong>Type</strong></p><p> <strong>Required</strong></p><p> <strong>Description</strong></p><p> url</p><p> String</p><p> True</p><p> OPC UA server url</p><p> nodeId</p><p> String</p><p> True</p><p> Id of the node specified by the given OPC UA server.</p><p> frequency</p><p> Integer</p><p> False</p><p> The frequency (in seconds) to poll for new node values.</p><p>If not set, frequency defaults to 1-time execution.</p><p> </p><h4 data-id="monitoring-frequency">Monitoring Frequency</h4><p>As described in the <strong>Monitoring Frequency</strong> section of the <a href="https://community.teamviewer.com/t5/TeamViewer-IoT-Labs/Custom-Plugin-Connector-How-to-easily-integrate-your-IoT-Sensors/td-p/36439" rel="nofollow noreferrer ugc">Custom Plugin Connector</a><strong> </strong>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.</p><p>In the template above, frequency is set within the <em>monitoringParams </em>as part of the script parameter. This approach is recommended for monitoring frequencies of <strong>less than 1 minute. </strong>The TeamViewer IoT 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). </p><p>In cases where the monitoring frequency is slower than 1 per minute, the <em>frequency </em>can be specified as part of the template, which will result in the TeamViewer IoT Agent executing the referenced script at the frequency specified.</p><p>In the example below, the <strong><em>frequency</em> </strong>parameter is<em> set to </em><strong><em>120, </em></strong> which will trigger the agent to execute the script referenced by <em>monitoringScript </em>every 120 seconds.</p><p><br></p><p><br></p><pre class="code codeBlock" spellcheck="false" tabindex="0">{
"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": ""
}
]
},
...
]
}
</pre><p><br></p>
</article>
</main>