OPC UA tutorials

FairCom Edge tutorials detailing ways to interact with an OPC UA simulator

This tutorial you will show how interact with the FairCom Edge server to capture, store, transform, forward and query data from an OPC UA simulator.

Requirements:

  • Ensure the FairCom server is installed and running.
  • Verify that the OPC service is enabled in the FairCom Edge server.
  1. Edit the services.json file in the config folder.
  2. Locate the "integrationServices" object of the service for the desired platform.
  3. Set "enabled" to "true".
    1. Windows
      "integrationServices": [
      {
      	"serviceName": "opcua",
      	"serviceLibrary": "opcservice.dll",
      	"schemaName": "opcua",
      	"enabled": true
      },
    2. Unix/Linux
      "integrationServices": [
      {
        "serviceName": "opcua",
        "serviceLibrary": "libopcservice.so",
        "schemaName": "opcua",
        "enabled": true
      },
    3. MAC
      "integrationServices": [
      {
        "serviceName": "opcua",
        "serviceLibrary": "libopcservice.dylib",
        "schemaName": "opcua",
        "enabled": true
      },
  4. Save any changes. Restart FairCom Edge server.
  • Confirm server access by running the FairCom Control Center. The typical URL is https://localhost:8443/. 

 

Run the OPC UA simulator

Launch the open-source OPC UA server and client simulators that are included with the package to simulate data from an OPC UA device.

  1. Open a command prompt.
  2. Navigate to the simulator directory in <faircom>/server/opc/test/open62541_v0.30/<OS version folder>/.
  3. Run the program called server_ctt first in one command prompt window to emulate an OPC UA server and answer OPC UA requests. Leave this program running.
  4. Open a second command prompt and navigate to the same simulator directory.
  5. Run the program called client 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.
  6. Observe the results, which should be similar to the following. (Note: The values displayed may not be the same as this.)
    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

 

Create a session

  1. Start the FairCom Control Center.
  2. Sign in with the username and password. FairCom's default username is ADMIN (case-insensitive) and the password is ADMIN (case-sensitive).

Note When you log into the FairCom Control Center, a session is automatically created. Any request submitted in the API Console will have the "authToken" property automatically populated with that session's auth token. If you aren't following this tutorial inside the FairCom Control Center, you must first execute the createSession action and set the "authToken" property manually. 

 

Create an Integration Table for OPC UA data

This procedure creates an Integration Table named opcTable 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 JSON fields.

  1. Navigate to the Code tab from the sidebar menu and select API Console.
  2. Copy and paste the following code into the API Console request:
    1. 
      {
        "action": "createIntegrationTable",
        "params": {
          "tableName": "opcTable"
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }
  3. Click Run button.
  4. Observe the response in the Output section 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.


Create Tags for the Integration Table

This procedure creates a tag, representing a property in table opcTable, field source_payload. The tag is also assigned to a user-defined field named "the_answer", and its values are automatically synchronized with the source_payload properties.

  1. Copy and paste the following code into the API console request:
    1. {
        "action": "createTag",
        "params": {
          "tagName": "theanswer",
          "tableName": "opcTable",
          "tagDataType": "number",
          "sourcePayloadPath": "the_answer",
          "sourceFieldName": "the_answer",
          "sourceFieldType": "integer",
          "sourceFieldLength": 4
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }

 

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 opcTable Integration Table for subsequent processing.

  1. Copy and paste the following code into the API Console request:
  2. Replace the JSON in the API Request editor with the following JSON:
    1. {
        "action": "createInput",
        "params": {
          "inputName": "opcInput",
          "serviceName": "opcua",
          "dataCollectionIntervalMilliseconds": 10000,
          "settings": {
            "opcServerUrl": "opc.tcp://localhost:4840",
            "propertyMapList": [
              {
                "tagName": "theanswer",
                "opcNamespace": 1,
                "opcNodeName": "the.answer"
              }
            ]
          },
          "ownerName": "admin",
          "tableName": "opcTable",
          "databaseName": "faircom"
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }
  3. Click the Run button.
  4. Observe the response in the Output section 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 opcTable table data in the faircom database to see the transformed data.

You can use either of the following procedures to view the transformed data.

 

View collected data through the Integration Tables navigation window

  1. Navigate to the Data tab from the sidebar menu and select Integration Tables.
  2. Click on the opctable table.
  3. Click on the fields section.
  4. Search for and enable the field the_answer.
  5. For each piece of data collected, it is possible to see its values and information. For example, in the last record collected the field the_answer is 42.

 

View collected data executing a SQL query

  1. Navigate to the Data tab from the sidebar menu and select SQL Commands.
  2. In the Statement section, enter and run the following SQL query:
    1. select * from opcTable where the_answer > 20;
  3. Observe the response and ensure the action is completed successfully.

 

Forward captured data to an MQTT topic

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

  1. Navigate to the Code tab from the sidebar menu and select API Console.
  2. Copy and paste the following code into the API Console request:
    1. {
        "api": "mq",
        "action": "configureTopic",
        "params": {
          "topic": "opcForward",
          "databaseName": "faircom",
          "tableName": "opcTable"
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }
  3. Click the Run button. 
  4. Observe the response and ensure the action is completed successfully.
  5. Subscribe to the MQTT topic to verify that your data was forwarded.
    1. Navigate to the MQ tab from the sidebar menu and select Messages.
    2. Click the Add Subscription button. In the Topic filter search bar, select "opcForward" and click Subscribe. As soon as new data is read, messages will appear in the Messages section.

 

Tutorial for reading data from Modbus and writing to OPC 

It is possible to read data from a Modbus server and write it to an OPC server. To do so, use the following:

  1. Launch the Modbus server simulator
    1. Open a command prompt.
    2. Navigate to <FairCom Folder>/server/modbus/test/<OS folder>/diagslave.<#.##>/<OS version folder>/.
    3. Run the following command:
    4. .\diagslave.exe -m tcp -p 502
  2. Write data to the Modbus address 1200
    1. Open a new command prompt.
    2. Navigate to <FairCom Folder>/server/modbus/test/<OS folder>/modpoll-<#.##>/<OS version folder>/.
    3. Run the following command:
    4. .\modpoll -m tcp -p 502 -r 1200 -c 1 -a 5 -t 4 localhost 65
  3. Start the FairCom server, if it is not already running.
  4. Capture data from Modbus with the following API request:
    1. {
       "action": "createInput",
       "params": {
         "inputName": "modbusTCP",
         "serviceName": "modbus",
         "tableName": "integrationDataTable",
         "settings": {
           "modbusProtocol": "TCP",
           "modbusServer": "127.0.0.1",
           "modbusServerPort": 502,
           "propertyMapList": [
             {
               "propertyPath": "the_answer",
               "modbusDataAccess": "holdingregister",
               "modbusDataAddress": 1199,
               "modbusUnitId": 5,
               "modbusDataLen": 1
             }
           ]
         }
       },
       "authToken": "replaceWithAuthTokenFromCreateSession"
      } 
  5. Launch the OPC UA simulator
    1. Open a new command prompt
    2. Navigate to <Faircom Folder>/server/opc/test/open62541_v0.30/<OS version folder>/.
    3. Run the following command:
    4. .\server_ctt.exe
  6. Send data from the table integrationDataTable to the OPC server using the following API request:
    1. {
       "action": "createOutput",
       "params": {
         "outputName": "opcOutput",
         "serviceName": "opcua",
         "databaseName": "faircom",
         "tableName": "integrationDataTable",
         "settings": {
           "opcServerUrl": "opc.tcp://localhost:4840",
           "propertyMapList": [
             {
               "propertyPath": "the_answer",
               "opcNamespace": 1,
               "opcNodeName": "the.answer"
             }
           ]
         }
       },
       "authToken": "replaceWithAuthTokenFromCreateSession"
      }