OPC UA tutorials
FairCom Edge tutorials detailing ways to interact with an OPC UA simulator
In these tutorials, you will interact with the FairCom Edge database server using the FairCom Explorer Web Utility to pull, store, view, and use data from an OPC UA simulator
In these tutorials, you will interact with the FairCom Edge database server using the FairCom Explorer Web Utility to pull, store, view, and use data from an OPC UA simulator.
Ensure the FairCom server is installed and running.
Confirm server access by running the FairCom API Explorer (see API Explorer to learn about the user interface).
Complete the tutorial requirements before this procedure.
Open a command prompt and find the client and server in
<faircom>/server/opc/test/open62541_v0.30/<OS version folder>/
.Run the program called server_ctt first in one command prompt window to emulate an OPC UA device and answer OPC requests.
Run the program called client in another command prompt window to connect to server_ctt and increment the defined OPC variables before exiting.
You can run it multiple times to cause the OPC variables to change.
Observe the results:
1 endpoints found
URL of endpoint 0 is opc.tcp://localhost:4840
Browsing nodes in objects folder:
…
Reading the value of node (1, "the.answer"):
the value is: 60
Writing a value of node (1, "the.answer"):
the new value is: 61
Subscription removed
Method call was successful, and 1 returned values available.
Created 'NewObject' with numeric NodeID 442
Created 'NewVariable' with numeric NodeID 443
Leave the OPC server running.
Note
The OPC simulator will answer OPC requests for the following variable:
"targetFieldName": "node1", "opcNamespace": 1, "opcNodeName": "the.answer"
Complete the tutorial requirements before this procedure.
Start the FairCom browser-based tools.
Select and log into the Data Explorer.
Click the API Explorer tab ().
This procedure creates an input named opcDS2
. The opcDS2
input takes OPC UA data and stores it in JSON format in the payload field of records in a table. The table is named opctable2
in the FairCom database.
Select Hub API from the Select API dropdown menu.
Select
"createInput"
from the JSON Actions dropdown menu.Replace the JSON in the API Request editor with the following JSON:
{ "requestId": "19", "authToken": "MyTokenHere", "api": "hub", "apiVersion": "1.0", "action": "createInput", "params": { "inputName": "opcDS2", "serviceName": "opcua", "settings": { "opcServerUrl": "opc.tcp://localhost:4840", "opcDataCollectionIntervalMilliseconds": 10000, "propertyMapList": [ { "propertyPath": "the_answer", "opcNamespace": 1, "opcNodeName": "the.answer" } ] }, "ownerName": "admin", "tableName": "opcTable2", "databaseName": "faircom", "retentionPolicy": "autoPurge", "retentionPeriod": 30, "retentionUnit": "day", "metadata": { } } }
Click Apply defaults to JSON request () to replace the
"authToken"
with a valid token from your session.Click Send request () to issue the JSON-based command.
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Start the FairCom Data Explorer.
In the Server navigation window, right-click faircom to select Connect () from the dropdown menu.
Navigate to and select opctable2 in the Server navigation window through
faircom>admin>Tables>opctable2
.Click the Table Records tab ().
Click the
"source_payload"
field for the record you wish to view.Observe the JSON contents of the field in the Edit Record window by clicking "open Edit" on the
"source_payload"
field.
The table records are displayed as one record per row.
If you don't see the column
"source_payload"
in your visualization, click on the right of any of the presented columns (create_ts
orerror
) and select "Columns". Then, select"source_payload"
in the "hidden columns" and move to the "Visible Columns" using the right arrow. Then click "Save" to return to data visualization.
This procedure creates a transform named transform_opc2
. The transform_opc2
will transform the JSON-based data from opctable2
into fields in a new table called opc_sensor2
in the ctreeSQL database.
Select
"createTransform"
from the JSON Actions dropdown menu.Add the
"debug"
property.Replace the JSON in the API Request editor with the following JSON:
{ "requestId": "18", "authToken": "MyTokenHere", "api": "hub", "apiVersion": "1.0", "action": "createTransform", "debug": "min", "params": { "transformName": "transform_opc2", "transformActions": [ { "inputFields": [ "source_payload" ], "transformActionName": "jsonToTableFields", "transformParams": { "targetDatabaseName": "faircom", "targetTableName": "opc_sensor2", "mapOfPropertiesToFields": [ { "propertyPath": "the_answer", "name": "theAnswerField", "type": "VARCHAR", "length": 128 } ] }, "outputFields": [ "theAnswerField" ] } ] } }
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Now that the transform has been created, this procedure shows how you can alter the input to use it so that data added to the opctable2
table will also be transformed into rows in the opc_sensor2
table.
Select
"alterInput"
from the JSON Actions dropdown menu.Replace the JSON in the API Request editor with the following JSON:
{ "authToken": "", "api": "hub", "action": "alterInput", "params": { "inputName": "opcDS2", "transformName": "transform_opc2" } }
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
opc_table2
table:Start the FairCom Data Explorer.
In the Server navigation window, right-click faircom to select Connect () from the dropdown menu.
Navigate to and select opctable2 in the Server navigation window through
faircom>admin>Tables>opctable2
.Select the Table Records tab.
Perform a SQL query against the data.
Select the SQL Queries tab.
Enter and run the following SQL query in the code box.
select * from opc_table2 where theAnswerField > 20;
Observe the response and ensure the action completed successfully.
The table records are displayed as one record per row.
Staying connected to the Data Explorer throughout the entire tutorial could result in error 17799 (file block cleared) if your table was open when you added your transform. Click to visualize your data.
Now that the OPC data is flowing into a table as JSON and being transformed into discrete fields in another table, the data can be forwarded out over MQTT.
Select MQ API from the Select API dropdown menu.
Select
"configureTopic"
from the JSON Actions dropdown menu to send the OPC UA data to a topic in MQTT.Replace the JSON in the API Request editor with the following JSON:
{ "authToken": "", "api": "mq", "action": "configureTopic", "params": { "topic": "opcForward", "databaseName": "faircom", "tableName": "opcTable2" } }
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.Subscribe to the MQTT topic to verify that your data was forwarded.
Open the FairCom MQ Explorer (https://localhost:8443//MQExplorer/index.html).
Select MQTT Management from the Control menu ().
Click Manage Subscriptions window.
() to open theSelect the topic you subscribed to from the Topic dropdown menu.
Click
().Close the Manage Subscriptions window.
Observe your message, displayed under Incoming Messages every 10 seconds.
Click
().Delete your subscription from the list.
Select DB API from the Select API dropdown menu.
Select
"getRecordsByIndex"
from the JSON Actions dropdown menu.Change the
"tableName"
property value from"athlete"
to"opc_table2"
.Change the
"indexName"
property value from"id_pk"
to"ts_index"
.Click Send request ().
Observe the records from the table returning as JSON in the API Response.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.