These tutorials show how to interact with the FairCom Edge database server using the FairCom API Explorer web utility to pull, store, view, and use data from MQTT messages.
Requirements:
- Ensure the FairCom server is installed and running.
- Confirm server access by running the FairCom API Explorer. The typical URL is
https://localhost:8443/.
Create a session
- Start the FairCom Browser-Based tools.
- Select Data Explorer.
- Connect to the server as user Admin.
- In the Server navigation window, right-click faircom to select Connect from the dropdown menu.
- Click the API Explorer tab.
Configure an MQTT topic to store JSON records
This procedure configures FairCom Edge to capture JSON-based MQTT data from the topic "MyTopic" and store it in the payload field of records in a table named "MyTopicTable" in the "faircom" database.
- Replace the JSON in the API Request editor with the following JSON:
{ "api": "mq", "action": "configureTopic", "params": { "topic": "MyTopic", "databaseName": "faircom", "tableName": "MyTopicTable" }, "authToken": "replaceWithAuthTokenFromCreateSession" }- The data we publish will be sent to the
"MyTopic"topic and stored in the"MyTopicTable"of the"faircom"database.
- 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 completed successfully.
-
"errorCode"with a value of0indicates success."errorCode"with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
-
Access MQTT management
- Start the FairCom Browser-Based tools.
- Select MQ Explorer.
- Select MQTT Management from the Control menu.
Publish JSON data to an MQTT topic
- Click the Publish tab.
- Enter
MyTopicin the Topic text box. - In the Message text box enter:
{ "Property1": "Stuff goes here", "Property2": 39 }
- Click +Publish.
View captured MQTT data
- Access the FairCom database in the FairCom Data Explorer.
- Navigate to and select
mytopictablein theServernavigation window through faircom>admin>Tables. - Click the
Table Recordstab.- Table records are displayed one record per row.
- Click the
source_payloadfield for one of the listed records. - Observe the pop-up window with the contents of the selected record.
- Click
Cancelto close the window.
Create a transform to extract captured data into table fields
- Access the API Explorer.
- Select the Transform API from the Select API dropdown menu.
- Select
createTransformfrom the JSON Actions dropdown menu. - Replace the JSON in the API Request editor with the following JSON:
{ "api": "transform", "action": "createTransform", "params": { "transformName": "MyTopicTransform", "transformActions": [ { "inputFields": [ "source_payload" ], "transformStepMethod": "jsonToDifferentTableFields", "transformParams": { "targetDatabaseName": "ctreeSQL", "targetTableName": "MyTopicTransformed", "mapOfPropertiesToFields": [ { "propertyPath": "Property1", "name": "property_1", "type": "varchar", "length": 300 }, { "propertyPath": "Property2", "name": "property_2", "type": "float" } ] } } ] }, "authToken": "replaceWithAuthTokenFromCreateSession" }
- Click Send Request.
- Observe the response and ensure the action completed successfully.
-
"errorCode"with a value of0indicates success."errorCode"with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
-
Configure an MQTT topic to implement a transform
- Select MQ API from the Select API dropdown menu.
- Select
configureTopicfrom the JSON Actions dropdown menu. - Replace the JSON in the API Request editor with the following JSON:
{ "api": "mq", "action": "configureTopic", "params": { "topic": "MyTopic", "databaseName": "faircom", "tableName": "MyTopicTable", "transformName": "MyTopicTransform" }, "authToken": "replaceWithAuthTokenFromCreateSession" }
- Click Send Request.
- Observe the response and ensure the action completed successfully.
-
"errorCode"with a value of0indicates success."errorCode"with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
-
Publish JSON data to an MQTT topic to be transformed
- Select the Publish tab.
- Enter
MyTopicin the Topic textbox. - In the Message textbox enter:
{ "Property1": " More stuff here", "Property2": 39.39 }
- Click +Publish.
View transformed data
- Open the Data Explorer.
- Select the ctreeSQL database in the Server navigation window.
- Select Connect from the JSON Actions dropdown menu to connect to the ctreeSQL server.
- Navigate to and select mytopictransformed in the Server navigation window through
ctreeSQL>admin>Tables. - Click the Table Records tab.
- Observe a new row that contains the published values of the second message in the property_1 and property_2 fields.
Query captured MQTT data using SQL
- Click the SQL Queries tab.
- Enter the following SQL query in the textbox: JSON APIs
select * from mytopictransformed where property_2 > 30;
- Click Send request.
- Observe data in the Results window.
Query captured MQTT data using the JSON DB API
- Click the Api Explorer tab.
- Select DB API from the Select API dropdown menu.
- Select
getRecordsByIndexfrom the JSON Actions dropdown menu. - Click the Property Display icon.
- Click the Insert icon next to the
databaseNameproperty to insertdatabaseNameinto the API Request. - Update the API Request:
- Make the tableName
"tableName":"mytopictransformed". - Make the indexName
"indexName":"admin_mytopictransformed_ts_index". - Make the databaseName
"databaseName:"ctreeSQL".
- Make the tableName
- Click Send request.
- Observe the response and ensure the action completed successfully.
-
"errorCode"with a value of0indicates success."errorCode"with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
-