Installing the ThingWorx Edge .NET SDK > Steam Sensor Example for the .NET SDK
  
Steam Sensor Example for the .NET SDK
The .NET SDK installation includes a 64-bit binary file for the Steam Sensor example that you can run "out-of-the-box". This example provides properties that are updated by the VirtualThing as well as properties that are updated from the ThingWorx Platform. There are services and an event example as well.
The general steps for using the Steam Sensor Example follow:
1. Initial Setup in ThingWorx Composer
2. Running the SteamSensor Example
3. Managing Bindings in ThingWorx Composer
4. Source Files
5. Modifying the SSL/TLS Configuration in the Source Files
6. Operation
Initial Setup in ThingWorx Composer
Before you can run the example, you need to create the entities for the Steam Sensor example in your ThingWorx Platform by importing the Entities_SteamSensor.xml file stored in the C:\Program Files (x86)\tw-dotnet-sdk-v.v.v\SteamSensor\import\ subdirectory of the .NET SDK installation. To import the entities file, follow these steps:
1. Log in to ThingWorx Composer. The rest of the steps are derived from the new Composer, v.8.4.0.
2. From the Import/Export menu of Composer, select Import, as shown here:
3. From the Import Option menu, select From File:
4. From the Import Type menu, select Entity.
5. Skip the two check boxes, and under Import Source, select Single File.
6. Click Browse, and navigate to the import subdirectory in C:\Program Files (x86)\tw-dotnet-sdk\SteamSensorConsole\, and select the Entities_SteamSensor.xml file.
7. After selecting the file, click Open, and when you return to the Import dialog, click Import.
8. When the import completes, click Close, and select Browse > Things. The new Things for this example appear at the top of the list.
Back to top
Running the SteamSensor Example
At the top of the .NET SDK installation directory are the SteamSensorConsole executable files. To run this example:
1. Open a Command Prompt.
2. Navigate to C:\Program Files (x86)\tw-dotnet-sdk\.
3. At the prompt, enter
SteamSensorConsole <url_to_ThingWorx_platform> <application_zey> <scan_rate_ms>
where:
<url_to_ThingWorx_platform> is the address (IP or host name and port number) for connecting to the ThingWorx Platform. The following example will connect to a platform that is running on the local machine, using port 8443 (using SSL/TLS):
wss://localhost:8443/Thingworx/WS
<application_key> is the application key for authentication and authorization with the ThingWorx Platform. An application key needs to be created, using ThingWorx Composer. The format of an application key follows:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<scan_rate_ms> is the interval (in milliseconds) that the example waits between scans for properties and events. To scan every second, the value is 1000.
Back to top
Managing Bindings in ThingWorx Composer
After starting the Steam Sensor, you can manage the bindings for the properties, services, and events using ThingWox Composer:
1. Log in to ThingWorx Composer.
2. Navigate to the SteamSensor1 Thing.
3. Go to the Properties page.
4. Refresh the properties to verify that the isConnected property is true.
5. Click Edit to enter Edit mode.
6. Click Manage Bindings to browse for the remote properties.
7. In the Manage Property Bindings page, click the Remote tab to view the remote properties.
8. Click Add All Above Properties to add all of the properties.
9. Click Done.
10. Click Save.
11. Refresh the properties and verify that they are changing.
12. Go to the Services page.
13. Click Browse Remote Services.
14. Click Add All Above Services to add the services.
15. Click Done.
16. Click Save.
17. Next to the AddNumbers service, click Test and verify the service is working.
18. Go to the Events page.
19. Click Browse Remote Events.
20. Click Add All Above Events.
21. If the SteamSensor.Fault Data Shape has not been created already, click Create.
22. Click Save.
23. Go to the Subscriptions page.
24. Click Add My Subscriptions.
25. From the Select an Event menu, select SteamSensorFault.
26. Select the Enabled check box.
27. 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);
* 
As of v.5.8.0 of the .NET SDK, the logging library is log4net. If you upgraded to this version, you need to modify your application to use the new library. The following examples are taken from the SteamSensorClient.cs file in the Steam Sensor example included with the SDK:
a. Replace the existing logging library by removing the existing statement and adding the following:
using log4net;
b. Start with getting the logging library:

namespace SteamSensorConsole
{
public class SteamSensorClient : ConnectedThingClient
{
private static ILog LOG = LogManager.GetLogger(typeof(SteamSensorClient));
28. Click Done.
29. Click Save.
Back to top
Source Files
The source files for this binary are in the SteamSensor subdirectory of the installation:
SteamSensorConsole.csproj—The project file for the Steam Sensor Console example.
SteamSensorConsole.sln—The solution file for the project.
SteamThing.cs—This file sets up all the property, service, and event definitions for this example.
SteamSensorClient.cs—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.
Back to top
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:


//Set the required configuration information
var config = new ClientConfigurator
3. Within this configuration block for the ClientConfigurator are the lines for SSL/TLS:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/
//config.AllowSelfSignedCertificates = true;
DisableCertValidation = true;
/***** WARNING *****/
In this example, certificate validation is disabled.
* 
Never use this setting in a production environment. To use any certificate in production, set this value to false or comment out the line in your code. To use a self-signed certificate for the purposes of this example, continue to the next step.
4. 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 //config. characters from the AllowSelfSignedCertificates true; line. Since you want to use a certificate, comment out the DisableCertValidation line. After you change these characters, the lines should look like this:
/***** WARNING: For Development purposes only. *****/
/***** Do not use these settings in a production environment. *****/.
AllowSelfSignedCertificates = true;
//DisableCertValidation = true;
/***** WARNING *****/
5. 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
//ConnectedThingClient.disableEncryption();
/***** WARNING *****/
6. 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
ConnectedThingClient.disableEncryption();
/***** WARNING *****/
7. Save the SteamSensorClient.cs file, and run the project with the correct command line properties 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 for development purposes only. Never use them in a production environment.
Back to top
Operation
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.
Properties
Name
Function
Description
Temperature
Ranges from 400-440.
Temperature of the steam sensor.
Pressure
Ranges from 18-23.
Pressure of the steam sensor.
TotalFlow
Starts at 0 and increments by 0-1 every scan rate.
Total flow through the steam sensor.
InletValve
Usually true, set to false on 15– second intervals.
Inlet valve of the steam sensor.
TemperatureLimit
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.
FaultStatus
True when a fault occurs, false otherwise. Determine what can cause a fault above.
Indicates that a fault occurred in the steam sensor.
Services
Name
Function
AddNumbers (NUMBER a, NUMBER b)
Returns the sum of two double precision numbers.
GetBigString
Returns a large string value of all zeros.
GetSteamSensorReadings
Returns an InfoTable that contains several readings from the steam sensor.
Events
Name
Function
SteamSensorFault
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.
Back to top