SteamSensor Example
The Steam Sensor example uses macros that were introduced with the Edge Extensions The ./examples/SteamSensor/ directory has two main subdirectories and the CMakeLists.txt file that you can use to build the example using CMake. The ./examples/SteamSensor/import/ directory contains the SteamSensor_Entities.xml file that you must import into your instance of ThingWorx Platform so that all entities needed when running this example exist in your instance. The ./examples/SteamSensor/src/ directory for this example contains the following files:
main.c—Contains the code that starts a connection to ThingWorx Platform and binds a single Thing (SteamThing). The code that adds a path to load Edge Extensions at runtime follows:
putenv("TWXLIB=../ExtUseExample/ext");
SteamThing.c—Contains the onSteamSensorProcessScanRequest for setting properties of the Steam Thing, determining if there is a fault, and if so, sending an event, and opening the steam release valve. This function uses multiple macros for all this processing, includingTW_SET_PROPERTY, TW_GET_PROPERTY, TW_FIRE_EVENT, TW_PUSH_PROPERTIES, TW_MAKE_BOOL, TW_MAKE_NUMBER, and TW_MAKE_LOC macros (among others).
SteamThing.h—Contains the definitions for this example, including the function that creates the Steam Sensor Thing.
gpsroute.h—Contains the definitions for the locations along the route (based on a GPS) and a variable that contains the number of steps along the route.
To build this example, follow the instructions for building with CMake in How to Build an Edge Application with CMake. This topic explains where to obtain CMake and other documentation for it. Once you have set up CMake, you will find instructions for building on Windows (Building for Windows Platforms with CMake) and on Linux (Building for Linux Platforms with CMake). Once you have built this application, make sure that you have imported the entities in the SteamSensor_Entities.xml file, and you are ready to run it.
Running the Steam Sensor Example from the Command Line
To run the Steam Sensor example from the command line, open a shell or command prompt, and navigate to the directory in which the executable is stored. Then enter the following at the command line:
SteamSensor [-h hostname] [-p port] [-k key] [-n thingname] [-s] [-c] [-u]
Where:
-h—The host name or IP address of your ThingWorx Platform.
-p—The port number on the platform for the SteamSensor application to use when connecting to the platform.
-k—The application key that you created for this application. The default is set to an invalid key. In production, this key should not be passed into the command line.
-n—The thingName of the SteamSensor Thing (imported by the SteamSensor_Entities.xml file).
-s—Allows self-signed certificates from the server. It is set to false by default. In production, this should not be set to true.
-c—Disables the server certificate validation. It is set to false by default.
-u—Using this argument with just SteamSensor displays the help for the syntax.
If you enter the syntax incorrectly, helpful messages are displayed to help you fix the error. If you want to display the help text, type SteamSensor-u, where -u is for "usage".
Command Line Switches for Client Keys
To use command line switches for client keys, open a shell or command prompt, navigate to the directory in which the executable is stored, and enter the following:
SteamSensor -s -r key.pem -j mypassphrase -q cert.pem
Where:
-s—Allows self-signed certificates from the server. It is set to false by default. In production, this should not be set to true.
-r—The path to the client SSL private key PEM file.
-j—The passphrase used to open the client SSL private key file.
-q—The path to the client SSL certificate PEM file.
The other options are:
-f—Redirects the log output to the file provided.
-x—Disables a web socket compression. It is set to true by default. In production, this should not be set to true.
Was this helpful?