Siemens S7 connector tutorials

Requirements:

  • Ensure the FairCom server is installed and running.
  • Ensure that Siemens S7 connector is enabled.
  • Confirm server access by running the FairCom API Explorer. The typical URL is https://localhost:8443/.

 

Initialize the Siemens S7 simulator

For this tutorial, we are using an open-source Siemens S7 simulator available with the snap7 package.

  1. Download and extract the full snap7 package from this website: https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download or by searching for "snap7 full download" and downloading the most current version.
  2. Launch the open-source Siemens S7 server simulator that is included with the package.
    1. Open a command prompt.
    2. Navigate to the folder of the server executable for the OS being used.
      1. For Windows: \examples\cpp\win64\
      2. For Linux: /examples/cpp/x86_64-linux/
    3. If the server executable is not available, follow the README.txt file to build it.
    4. Execute Siemens S7 server simulator running the srv_resourceless.exe file. Leave it running.

Note This server creates a DBArea number 3.

 

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 Siemens S7 data

This procedure creates a transform that will convert the JSON-based data from the "siemensS7Table" Integration Table into fields in the same table.

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 flag1 defined in the request.

  1. Select Hub API from the JSON API dropdown menu.
  2. Select "createIntegrationTable" from the JSON Actions dropdown menu. Post the following JSON:
{
  "api": "hub",
  "action": "createIntegrationTable",
  "params": {
    "tableName": "siemensS7Table",
    "fields": [
      {
        "name": "flag1",
        "type": "integer"
      }
    ],
    "transformSteps": [
      {
        "transformStepMethod": "jsonToTableFields",
        "mapOfPropertiesToFields": [
          {
            "fieldName": "flag1",
            "recordPath": "source_payload.flag1"
          }
        ]
      }
    ]
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

 

Capture Siemens S7 data in the Integration Table

This procedure creates an input named "mysiemensS7" that takes Siemens S7 data and stores it in JSON format in the payload field of records in a table named "siemensS7Table" in the "faircom" database.

  1. Select Hub API 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",
      "action": "createInput",
      "params": {
        "inputName": "mysiemensS7",
        "serviceName": "siemensS7",
        "tableName": "siemensS7Table",
        "databaseName": "faircom",
        "dataCollectionIntervalMilliseconds": 5000,
        "settings": {
          "ipAddress": "127.0.0.1",
          "rack": 0,
          "slot": 2,
    
          "propertyMapList": [
            {
              "propertyPath": "flag1",
              "memoryArea": "db",
              "dataBlockNumber": 3,
              "offset": 0,
              "dataType": "word"
            }
          ]
        }
      },
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  4. Click Execute () to issue the JSON-based command.

     5. Observe the response and ensure the action is completed successfully.

Note An "errorCode" with a value of 0 indicates success. An "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 "siemensS7Table" table in the "faircom" database for the transformed data.

Both of the following procedures will let you view the transformed data. You can use either of these procedures to view the transformed data.

 

View transformed data through the Server navigation window

  1. In FairCom Edge, navigate to IoT > Tables.
  2. Navigate to and select the siemensS7Table.
  3. Click the Records tab.
  4. Observe the table records.

 

View transformed data through a SQL query

  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 id, flag1 from siemenss7table where flag1>2000

  3. Observe the response and ensure the action is completed successfully.

 

Forward captured data to an MQTT topic

Once Siemens S7 data is flowing into a table as JSON and is being transformed into discrete fields in the same table, forward the data out over MQTT.

  1. Select MQ API from the JSON API dropdown menu.
  2. Select configureTopic from the JSON Actions dropdown menu.
  3. Replace the JSON in the API Request editor with the following JSON:
    1. {
        "api": "mq",
        "action": "configureTopic",
        "params":
        {
          "topic": "siemensTopic",
          "databaseName": "faircom",
          "tableName": "siemensS7Table"
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }
  4. Click Execute ().
  5. Observe the response and ensure the action is completed successfully.

 

 

Subscribe to the MQTT topic to verify that data was forwarded

  1. Subscribe to the MQTT topic to verify that your data was forwarded. In FairCom Edge, navigate to MQ > Messages:

       2. Click Add in the Subscriptions section;

       3. Choose the "siemensTopic" topic;

        4. Click Subscribe ();

        5. Observe your message, displayed under Messages every 10 seconds;

        6. Delete your subscription from the list clicking Unsubscribe from topic ()

 

Query captured Siemens S7 data using the JSON DB API

  1. Select DB API from the JSON API dropdown menu.
  2. Select the getRecordsByIndex from the JSON Actions dropdown menu.
  3. Replace the JSON in the API Request editor with the following JSON:
    1. {
        "api": "db",
        "action": "getRecordsByIndex",
        "params": {
          "databaseName": "faircom",
          "tableName": "siemensS7Table",
          "indexName": "ts_index"
        },
        "authToken": "replaceWithAuthTokenFromCreateSession"
      }
      
  4. Click Execute ().
  5. Observe the API Response response and ensure the action is completed successfully.

 

Send data to the Siemens S7 simulator

It is also possible to send data back to the the Siemens S7 server simulator. For instance, we can take the value from the flag1 field at the table siemensS7Table, and write the same value at a different memory offset. 

Create an output using the JSON action:

{
 "api": "hub",
 "action": "createOutput",
 "params": {
   "outputName": "siemensS7Output",
   "serviceName": "siemensS7",
   "tableName": "siemensS7Table",
   "databaseName": "faircom",
   "settings": {
     "ipAddress": "127.0.0.1",
     "rack": 0,
     "slot": 2,
     "propertyMapList": [
       {
         "propertyPath": "flag1",
         "memoryArea": "db",
         "dataBlockNumber": 3,
         "offset": 32,
         "dataType": "word"
       }
     ]
   }
 },
 "authToken": "replaceWithAuthTokenFromCreateSession"
}

At the command prompt window that was used to run command srv_resourceless.exe, you should see the data being read from offset 0 and written back at offset 32:

Read Request
Area : DB3, Start : 0, Size : 1

Write Request
Area : DB3, Start : 32, Size : 1
0x0000: 19                                              .

 

Startup configuration

Verify that the Siemens S7 service is enabled in the FairCom Edge server
  1. Edit the <faircom>\config\services.json configuration file.
  2. In the "siemensS7" object of the "integrationServices" object, set the "enabled" property to true to enable the Siemens S7 connector or false to disable the Siemens S7 service.
  3. Save the changes.
  4. Restart the server for the change to take effect.
Example 1. Windows
"integrationServices": [
 {
   "serviceName": "siemensS7",
   "serviceLibrary": "siemenss7service.dll",
   "enabled": true
 }
]
Example 2. Unix/Linux
"integrationServices": [
 {
   "serviceName": "siemensS7",
   "serviceLibrary": "siemenss7service.so",
   "enabled": true
 }
]
Example 3. MAC
"integrationServices":
{
   "serviceName": "siemensS7",
   "serviceLibrary": "siemenss7service.dylib",
   "enabled": true
}