- 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.
- 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.
- Launch the open-source Siemens S7 server simulator that is included with the package.
- Open a command prompt.
- Navigate to the folder of the server executable for the OS being used.
- For Windows:
\examples\cpp\win64\ - For Linux:
/examples/cpp/x86_64-linux/
- For Windows:
- If the server executable is not available, follow the
README.txtfile to build it. - Execute Siemens S7 server simulator. Leave it running.
Note
This server creates a DBArea number 3.
Create a session
- Start the FairCom browser-based tools.
The tools icons appear. - Select and log into Data Explorer.
The Data Explorer interface window appears. - Click the API Explorer tab.
The API Explorer interface opens, and the Server navigation window shows that you are connected to the"faircom"database and the FairCom server. Use the"faircom"database or another database you create to store the"customer tables".
Capture Siemens S7 data as JSON records in a 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.
- 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:
{ "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" } - Click Apply defaults to JSON request (
) to replace the "authToken"value with the valid one from your session. - Click Send request (
) to issue the JSON-based request. - 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 captured Siemens S7 data in the "siemensS7Table" table
- Start the FairCom Data Explorer.
- Navigate to and select siemensS7Table in the Server navigation window through
faircom>admin>Tables. - Click the Table Records tab (
). - Select a record and click the
source_payloadfield. - Observe the JSON contents of the field. Click the "edit" icon of the
source_payloadfield to see the content formatted as JSON.
The value should look like this:
{
"create_ts":"2025-04-25T14:03:59.857Z",
"flag1":1799
}
This Siemens S7 server simulator will keep changing data.
Note
If the table has no records, look at <faircom>/data/CTSTATUS.FCS to see errors related to the connector.
Create a transform to extract the captured data into table fields
This procedure creates a transform named "transform_siemens1" that will transform the JSON-based data from the "siemensS7Table" table into fields in a new table called "siemens1" in the "faircom" database.
- Select Transform API from the Select API dropdown menu.
- Select "createTransform" from the JSON Actions dropdown menu.
- Replace the JSON in the API Request editor with the following JSON:
{ "api":"hub", "action":"createTransform", "params": { "transformName":"transform_siemens1", "transformActions":[ { "inputFields":["source_payload"], "transformActionName":"jsonToDifferentTableFields", "outputFields":[ "flag1" ], "transformParams": { "targetTableName":"siemens1", "mapOfPropertiesToFields":[ { "propertyPath":"flag1", "name":"flag1", "type":"integer" } ] } } ] }, "authToken": "replaceWithAuthTokenFromCreateSession" } - Click Send request (
). - 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.
Attach the transform to the input
Once the transform has been created, alter the input so that data added to the "siemensS7Table" table will also be stored in rows in the "siemens1" table.
- Select Hub API from the Select API dropdown menu.
- Select alterInput from the JSON Actions dropdown menu.
- Replace the JSON in the API Request editor with the following JSON:
{ "api": "hub", "action": "alterInput", "params": { "inputName": "mysiemensS7", "transformName": "transform_siemens1" }, "authToken": "replaceWithAuthTokenFromCreateSession" } - Click Send request (
). - Observe the response and ensure the action is completed successfully.
View the transformed data
View the "siemens1" 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
- Select the
"faircom"database in the Server navigation window. - Select Connect from the JSON Actions dropdown menu.
- Navigate to and select the siemens1 table in the Server navigation window through
faircom>admin>Tables>. - Click the Table Records tab (
). - Observe the table records.
View transformed data through a SQL query
- Click the SQL Queries tab (
). - Enter the following SQL query in the textbox.
SELECT id, flag1 from siemens1 where flag1>2000 - Click the Execute SQL statement button (
). - 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 another table, forward the data out over MQTT.
- Select MQ API from the Select API dropdown menu.
- Select configureTopic from the JSON Actions dropdown menu.
- Replace the JSON in the API Request editor with the following JSON:
{ "api": "mq", "action": "configureTopic", "params": { "topic": "siemensTopic", "databaseName": "faircom", "tableName": "siemensS7Table" }, "authToken": "replaceWithAuthTokenFromCreateSession" } - Click Send request (
). - Observe the response and ensure the action is completed successfully.
Subscribe to the MQTT topic to verify that data was forwarded
- Start the FairCom Browser-Based tools.
- Select and connect to MQ Explorer.
- Select MQTT Management from the Control menu (
). - Click Subscribe (
) to open the Manage Subscriptions window. - Select the topic you subscribed to from the Topic dropdown menu.
- Click + Subscribe (
). - Close the Manage Subscriptions window.
- Observe your message, displayed under Incoming Messages every 10 seconds.
- Click Subscribe (
). - Delete your subscription from the list.
Query captured Siemens S7 data using the JSON DB API
- Select DB API from the Select API dropdown menu.
- Select the getRecordsByIndex from the JSON Actions dropdown menu.
- Replace the JSON in the API Request editor with the following JSON:
{ "api": "db", "action": "getRecordsByIndex", "params": { "databaseName": "faircom", "tableName": "siemensS7Table", "indexName": "ts_index" }, "authToken": "replaceWithAuthTokenFromCreateSession" } - Click Send request (
). - Observe the API Response response and ensure the action is completed successfully.