ThingWorx Edge Java SDK > Application Details > Steam Sensor Example
Steam Sensor Example
The Steam Sensor example for the Java SDK provides a full project that you can run. It contains properties that are updated by the VirtualThing as well as properties that are updated from the thing template from which the thing representing the Steam Sensor things are derived. There are services, an event example, and a property change listener example as well.
When you extract the contents of the bundle, you will find a samples directory. Navigate to samples/src/com/thingworx/sdk/steam to locate the example. This subdirectory contains the following source code files: — This file sets up all the properties, services, and events for this example. — This file contains the user interface for the console. It configures the client based on user input (using the ClientConfigurator class), instantiates the client (ConnectedThingClient class), and starts it. As long as the connection is successful, it collects values from the steam sensors.
Use these source files to build a new console application before attempting to run the SteamSensor example.
Initial Setup
Before running the example, create a thing to represent the Steam Sensor, using the RemoteThing thing template in ThingWorx Composer. .
It is possible to create just one thing, duplicate it, and set the appropriate parameters.
SampleSteamSensor Thing
Thing Template
When you run the example, the application sends the properties and their values to ThingWorx Core. You can view these “Remote” properties through Composer
Modifying the SSL/TLS Configuration in the Source File
Depending on your use of SSL/TLS with this example, you need to make some changes in the SteamSensorClient.cs file. The steps below explain how:
1. Open the file, SteamSensorClient.cs, file.
2. Locate the following lines:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/
//config.AllowSelfSignedCertificates = true;
//config.DisableCertValidation = true;
/***** WARNING *****/
3. If you are connecting over HTTPS and using a self-signed certificate, the client configuration (ClientConfigurator) must be set up to allow self-signed certificates. Remove the comment characters (//) from the two lines that start with //config.. After you remove the comment characters, the lines should look like this:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/
config.AllowSelfSignedCertificates = true;
config.DisableCertValidation = true;
/***** WARNING *****/
These settings mean that you can use your self-signed certificate and that validation of certificates is turned off.
4. If you must use an insecure (non-SSL/TLS) connection, you need to call the disableEncryption() method on the ConnectedThingClient after instantiating the client but before calling connect on it. Locate the following lines:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/
// To connect to an insecure (non-SSL) server
/***** WARNING *****/
5. Remove the comment characters from the beginning of the line that contains the disableEncryption() method. It should now look like this:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/
// To connect to an insecure (non-SSL) server
/***** WARNING *****/
6. Save the SteamSensorClient.cs file, and run the project with the correct command line arguments as described above.
It is strongly recommended that you use SSL/TLS with a valid server certificate for connections between your devices and the ThingWorx platform. Use self-signed certificates, the AllowSelfSignedCertificates and DisableCertValidation settings of the ClientConfigurator, or the DisableEncryption method of the ConnectedThingClient for development purposes only. Do NOT use them in a production environment.
ThingWorx Composer Configuration
After running the sample client, the properties, services, and events can be added in ThingWorx Composer.
For production, an export file can be provided, but for example purposes, the steps to manually add them are defined here. This procedure can be repeated for SteamSensor2. Alternatively, you can duplicate SteamSensor1 and save it with a different Name and Identifier.
1. Open the SteamSensor1 thing.
2. Select the Properties tab.
3. Refresh the properties to verify that the isConnected property is true.
4. If the page is not in Edit mode, click the Edit button to enter Edit mode.
5. Click the Manage Bindings button to browse for the remote properties.
6. In the Manage Property Bindings page, click the Remote tab to view the remote properties.
7. Click the Add All Above Properties button to add all of the properties.
8. Click Done.
9. Click Save.
10. Refresh the properties and verify that they are changing.
11. Select the Services tab.
12. Click the Browse Remote Services button.
13. Click the Add All Above Services button to add the services.
14. Click Done.
15. Click Save.
16. Click the Test button next to the AddNumbers service and verify it is working.
17. Select the Events tab.
18. Click Browse Remote Events.
19. Click Add All Above Events.
20. Click the Create button next to the SteamSensor.Fault Data Shape if it has not already been created.
21. Click Save.
22. Select the Subscriptions tab.
23. Click Add My Subscriptions.
24. From the Select an Event drop down menu, select SteamSensorFault.
25. Select the Enabled check box.
26. Enter the following for the Script text that will write an event when there is a steam sensor fault:
logger.error("Steam Sensor 1 Fault: " + eventData.message);
27. Click Done.
28. Click Save.
The only property in the Steam Sensor example that does not update is the TemperatureLimit property. This property defines the limit for the fault of the steam sensor. The fault occurs when the value of this property is greater than zero and the temperature exceeds the limit defined by this property. If the value of this property is 0 or less, the fault does not occur.
Ranges from 400-440.
Temperature of the steam sensor.
Ranges from 18-23.
Pressure of the steam sensor.
Starts at 0 and increments by 0-1 every scan rate.
Total flow through the steam sensor.
Usually true, set to false on 15– second intervals.
Inlet valve of the steam sensor.
If this value is greater than zero and the value of Temperature rises above this value, a fault is generated in the steam sensor.
The temperature value that, when reached, causes a fault in the steam sensor.
True when a fault occurs (see what causes a fault above), false otherwise.
Indicates that a fault occurred in the steam sensor.
AddNumbers (NUMBER a, NUMBER b)
Returns the sum of two double precision numbers.
Returns a large string value of all zeros.
Returns an InfoTable that contains several readings from the steam sensor.
Stops the client process. Use this to stop the client from ThingWorx Composer or the user interface of your custom mashup.
Occurs when the value of TemperatureLimit is greater than zero and the value of Temperature is greater than TemperatureLimit.
The event data is defined by the SteamSensor. Fault data shape and contains only a single STRING field that is named message. When a fault occurs, the content of message is sent in the event data.