JSON DB API tutorial
FairCom's JSON DB API can be used to query MQTT data captured from IoT devices
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.
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.
Ensure the FairCom server is installed and running.
Confirm server access by running the FairCom API Explorer (see API Explorer to learn about the user interface).
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 ().
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:
{ "authToken": "ReplaceWithValidToken", "api": "mq", "action": "configureTopic", "params": { "topic": "MyTopic", "databaseName": "faircom", "tableName": "MyTopicTable" } }
Note
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.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Start the FairCom Browser-Based tools.
Select MQ Explorer.
Select MQTT Management from the menu ().
Click the Publish tab.
Enter
MyTopic
in the Topic text box.In the Message text box enter:
{ "Property1": "Stuff goes here", "Property2": 39 }
Click
().
Access the FairCom database in the FairCom Data Explorer.
Navigate to and select mytopictable in the Server navigation window through
faircom>admin>Tables
.Click the Table Records tab ().
Note
Table records are displayed one record per row.
Click the source_payload field for one of the listed records.
Observe the pop-up window with the contents of the selected record.
Click
() to close the window.
Select the Hub 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:
{ "authToken": "ReplaceWithValidToken", "api": "hub", "action": "createTransform", "params": { "transformName": "MyTopicTransform", "transformActions": [ { "inputFields": [ "source_payload" ], "transformActionName": "jsonToDifferentTableFields", "transformParams": { "targetDatabaseName": "ctreeSQL", "targetTableName": "MyTopicTransformed", "mapOfPropertiesToFields": [ { "propertyPath": "Property1", "name": "property_1", "type": "VARCHAR", "length": 300 }, { "propertyPath": "Property2", "name": "property_2", "type": "DOUBLE" } ] } } ] } }
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
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:
{ "authToken": "ReplaceWithValidToken", "api": "mq", "action": "configureTopic", "params": { "topic": "MyTopic", "databaseName": "faircom", "tableName": "MyTopicTable", "transformName": "MyTopicTransform" } }
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Select the Publish tab ().
Enter
MyTopic
in the Topic textbox.In the Message textbox enter:
{ "Property1": " More stuff here", "Property2": 39.39 }
Click
().
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.
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.
Click the Api Explorer tab ().
Select DB API from the Select API dropdown menu.
Select
getRecordsByIndex
from the JSON Actions dropdown menu.Click the Property Display icon ().
Click the Insert icon () next to the
databaseName
property to insertdatabaseName
into 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"
.
Click Send request ().
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.