This tutorial demonstrates the basics of using the c-treeEDGE ThingWorx AlwaysOn connector.
c-treeEDGE provides a ThingWorx extension built using the AlwaysOn protocol. This approach links the application with ThingWorx Edge SDK (https://developer.thingworx.com/sdks) to directly push data into the platform.
If you can link your edge application with the ThingWorx Edge SDK, you can use any of the existing FairCom APIs to persist data with c-treeEDGE locally.
c-treeEDGE also provides a ThingWorx MQTT extension, as described in Installing and Configuring the c-treeEDGE MQTT ThingWorx Extension. That extension is useful if you are already using MQTT in your application and do not need the enhanced integration of the AlwaysOn protocol.
This section explains how to install c-treeEDGE on the ThingWorx platform. ThingWorx allows enterprise-scale applications to be modeled by dragging and dropping "things."
c-treeEDGE requires creation and configuration of a c-treeEDGE "thing" in ThingWorx. Please refer to the ThingWorx website and the c-treeEDGE Thing download in the ThingWorx Marketplace for more information.
You will need to install and start the c-treeEDGE MicroServer, as described in Download and Installation.
The following PLUGIN keyword has been added to the ctsrvr.cfg file:
The following directory has been added under the edgemicroserver folder:
libctthingworx.so - plug-in dynamic library
ctthingworx.json - plug-in configuration
fccert.pem - self-signed certificate for SSL
ctreeEDGE_entities.xml - required platform entities for the plug-in
This guide assumes an existing ThingWorx platform is available.
ThingWorx entity requirements - The c-treeEDGE ThingWorx plug-in requires some entities that are available in the ThingWorx platform:
These entities are available in ctreeEDGE_entities.xml provided in the package. Please import using option “From File” and type of “Entities”:
After importing, you should see the following entities in your platform:
Plug-in Configuration File
ctthingworx.json is a JSON setting file in the following format:
"thingworxHost": "ThingWorx host",
"thingworxAppkey": "ThingWorx app key",
"thingworxCACertificate": "CA Certificate",
Loading the c-treeEDGE Thing
When c-treeEDGE starts with the active plug-in set accordingly, it connects to the ThingWorx platform and creates a new "thing" with the <Thing name> set in ctthingworx.json file based on the existing <Thing creator name>. If there is already a "thing" with this same name, it tries to use it. If the template does not match, the plug-in initialization will fail.
Note that when the c-treeEDGE is down, the following icon will show that the "thing" is disconnected. During disconnection, the following message will be presented:
When the c-treeEDGE is up, the following icon will show that the "thing" is connected. During the connection, the following message will be presented:
Loading c-treeEDGE Schema
When c-treeEDGE starts, just after connecting to the ThingWorx platform, the plug-in loops through all the databases, tables, and fields and populates them in a property in the “thing.” This property name is ctEdge:
You can navigate and visualize all the databases, tables and fields on this property:
If any schema change happens after it has been loaded into the platform, it will not be automatically reloaded. So, a service is provided in the “thing” to reload this information. Go to </> Services -> GetCTEdge -> <Execute button>:
While navigating through the ctEdge property when getting into the field level, we can set how the field value from c-treeEDGE persistence should be mapped to a property in the current “thing” at the platform. Execute the following steps:
With these steps you are able to set all the mapping between the desired field data persisted in c-treeEDGE and its “thing” in the ThingWorx platform.
The table below shows the data type mapping between the c-tree fields in c-treeEDGE and ThingWorx properties:
In order to enable the mapping between the data persisted in c-treeEDGE and the “thing” in the platform, execute the server ConnectCTEdge. Go to </> Services -> ConnectCTEdge -> <Execute button>:
It loops through all the mapping set in the previous section and execute the following steps:
After these steps, no matter how the new data records are inserted in the persisted table, the last value is supposed to be populated automatically in the mapped property in the platform.
Note 1: ThingWorx may be slow refreshing existing "things" and after executing these steps new properties may not display. Close the "thing" and reopen it to see your newly-created properties.
Note 2: ThingWorx platform error messages are redirected to the c-treeEDGE MicroServer CTSTATUS.FCS log. We'll ignore several of these logged messages for now.
To disable mapping between data persisted in c-treeEDGE and the “thing” in the platform, execute the server DisconnectCTEdge. Go to </> Services -> DisconnectCTEdge -> <Execute button>: