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.

 

Launch the OPC UA client and server simulator

  1. Open a command prompt and find the client and server in <faircom>/server/opc/test/open62541_v0.30/<OS version folder>/.
  2. Run the program called server_ctt first in one command prompt window to emulate an OPC UA device and answer OPC UA requests.
  3. Run the program called client in another command prompt window to connect to server_ctt and increment the defined OPC UA variables before exiting.
    You can run it multiple times to cause the OPC UA variables to change.
  4. 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
  5. Leave the OPC UA server running.

Note The OPC UA simulator will answer OPC UA requests for the following variable:

"targetFieldName": "node1",
 "opcNamespace": 1,
 "opcNodeName": "the.answer"

 

Create a session

  1. Start the FairCom browser-based tools.
  2. Navigate to the Code section from the sidebar menu.

 

Create an Integration Table for OPC UA data

This procedure creates an Integration Table named opcTable2 to store data received from an OPC UA source. The data will be used as the input for subsequent data transformation and processing. The Integration Table automatically creates the source_payload, ts_index and error fields. The jsonToTableFields transform extracts values from source_payload and stores them in the field TheAnswerField defined in the request.

  1. Select Hub from the JSON API dropdown menu.
  2. Select "createIntegrationTable" from the JSON Actions dropdown menu.
  3. Replace the JSON in the API Request editor with the following JSON:
    {
      "api": "hub",
      "action": "createIntegrationTable",
      "params": {
        "tableName": "opcTable2",
        "fields": [
          {
            "name": "TheAnswerField",
            "type": "VARCHAR",
            "length": 128
          }
        ],
        "transformSteps": [
          {
            "transformStepMethod": "jsonToTableFields",
            "mapOfPropertiesToFields": [
              {
                "fieldName": "TheAnswerField",
                "recordPath": "source_payload.the_answer"
              }
            ]
          }
        ]
      },
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  4. Click Execute () to issue the JSON-based command.
  5. Observe the response and ensure the action is completed successfully.

Note "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.

 

Capture OPC UA data in the Integration Table

This procedure creates an input that captures data from an OPC UA source and writes the incoming data to the opcTable2 Integration Table for subsequent processing.

  1. Select Hub from the JSON API dropdown menu.
  2. Select "createInput" from the JSON Actions dropdown menu.
  3. Replace the JSON in the API Request editor with the following JSON:
    {
      "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"
      },
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  4. Click Execute () to issue the JSON-based command.
  5. Observe the response and ensure the action is completed successfully.

Note "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.

 

View the transformed data

View the transformed data that is stored in the opcTable2 table:

  1. In FairCom Edge, navigate to Data > SQL > Queries;
  2. In the Enter SELECT query code box, execute the following SQL query against the data:
    select * from opcTable2 where theAnswerField > 20;
  3. Observe the response and ensure the action is completed successfully.

 

Forward captured data to an MQTT topic

Now that the OPC UA data is flowing into a table as JSON and being transformed into discrete fields in the same table, the data can be forwarded out over MQTT.

  1. Select MQ API from the JSON API dropdown menu.
  2. Select "configureTopic" from the JSON Actions dropdown menu to send the OPC UA data to a topic in MQTT.
  3. Replace the JSON in the API Request editor with the following JSON:
    {
      "api": "mq",
      "action": "configureTopic",
      "params": {
        "topic": "opcForward",
        "databaseName": "faircom",
        "tableName": "opcTable2"
      },
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  4. Click Execute ()
  5. Observe the response and ensure the action is completed successfully.
    1. An "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
  6. Subscribe to the MQTT topic to verify that your data was forwarded. In FairCom Edge, navigate to MQ > Messages:

 

  1. Click ‘Add’ in the Subscriptions section;
  2. Choose the "opcForward" topic;
  3. Click Subscribe ();
  4. Observe your message, displayed under Messages every 10 seconds;
  5. Delete your subscription from the list clicking Unsubscribe from topic ()

 

Query captured data using the FairCom JSON DB API

  1. Select DB API from the JSON API dropdown menu.
  2. Select "getRecordsByIndex" from the JSON Actions dropdown menu.
  3. Change the "tableName" property value from "athlete" to "opctable2".
  4. Change the "indexName" property value from "id_pk" to "ts_index".
  5. Click Execute ().
  6. Observe the records from the table returning as JSON in the API Response.
     

"errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.