Defining Properties
You can define properties by using annotations or by calling the methods of the VirtualThing class directly. Use annotations for properties that are static, and methods for properties whose definitions are expected to change.
Click a section title below to display its content:
Property Definitions Example 
Here is an example of property definitions from the SteamThing.java source file for the SteamSensor example:

// Property Definitions
@SuppressWarnings("serial")
@ThingworxPropertyDefinitions(properties = {
@ThingworxPropertyDefinition(name = "Temperature", description = "Current Temperature",
baseType = "NUMBER", category = "Status", aspects = { "isReadOnly:true" }),
@ThingworxPropertyDefinition(name = "Pressure", description = "Current Pressure",
baseType = "NUMBER", category = "Status", aspects = { "isReadOnly:true" }),
@ThingworxPropertyDefinition(name = "FaultStatus", description = "Fault status",
baseType = "BOOLEAN", category = "Faults", aspects = { "isReadOnly:true" }),
@ThingworxPropertyDefinition(name = "InletValve", description = "Inlet valve state",
baseType = "BOOLEAN", category = "Status", aspects = { "isReadOnly:true" }),
@ThingworxPropertyDefinition(name = "TemperatureLimit",
description = "Temperature fault limit", baseType = "NUMBER", category = "Faults",
aspects = { "isReadOnly:false" }),
@ThingworxPropertyDefinition(name = "Location", description = "location of sensor",
baseType = "LOCATION", category = "Status", aspects = { "isReadOnly:true" }),
@ThingworxPropertyDefinition(name = "TotalFlow", description = "Total flow",
baseType = "NUMBER", category = "Aggregates", aspects = { "isReadOnly:true" }), })
Your Java SDK-based application must register the properties that you want to communicate to the ThingWorx Platform. The Java SDK uses an object-oriented approach to registering properties. Java Annotations map Java Bean properties. Class instances map to Things on the ThingWorx Platform . You bind instances to Things on the platform. Here is an example of creating the client and then binding the SteamThing from the SteamSensorClient.java file of the SteamSensor example:

// Create the client passing in the configuration from above
SteamSensorClient client = new SteamSensorClient(config);

String thingBaseName = "SteamSensor";
if(cmd.hasOption("t")) {
thingBaseName = cmd.getOptionValue("t");
}

for (int sensor = 0; sensor < nSensors; sensor++) {
int sensorID = startSensor + sensor;
String thingName = thingBaseName + sensorID;
if(1==nSensors)
thingName = thingBaseName;
final SteamThing steamSensorThing =
new SteamThing(thingName, "Steam Sensor #" + sensorID, null, client,fileLogAppender);
client.bindThing(steamSensorThing);
Responding to Changes from the ThingWorx Platform 
Values can be pushed from the ThingWorx Platform down to the edge device. In Java, the response to the push from the platform is handled automatically. This automatic response requires a listener for changes sent from the platform. Here is an example of adding a listener from the SteamSensorClient.java file for the SteamSensor example:

steamSensorThing.addPropertyChangeListener(new VirtualThingPropertyChangeListener() {
@Override
public void propertyChangeEventReceived(VirtualThingPropertyChangeEvent evt) {
if ("TemperatureLimit".equals(evt.getPropertyDefinition().getName())) {
System.out.println(String.format("Temperature limit on %s has been changed to %s°.", steamSensorThing.getName(),
evt.getPrimitiveValue().getValue()));
}
}
});
}
Managing Property Bindings in ThingWorx 
The SteamSensor example provides entities that are set up as already bound by the Entities.xml file that you import into the ThingWorx Platform. It is not necessary to set that up in your application; it is a convenience for developers new to ThingWorx and the Edge Java SDK.
To learn how the properties can be bound to the Remote Thing on the ThingWorx Platform through ThingWorx Composer, follow these steps:
1. Log in to ThingWorx Composer and select Browse > Modeling > Things.
2. From the list of Things, select the Thing for which you want to bind remote properties.
3. When the General Information page for the Thing appears, click Properties and Alerts to display the Properties page for the Thing. Here, you should find that the isConnected property shows a dimmed checkmark in a checkbox. This icon represents a value of true for the property, indicating that your Thing connected successfully.
4. Select Manage Bindings. The Remote tab displays the configured properties of your Thing.
5. Drag the property from the Remote list to the My Properties list to bind to that property, and click Done.
* 
You can also click the Add all properties option to add all the properties in the Remote list.
6. Optionally, to view the bound and unbound properties, click the buttons at the top right-hand side of the screen.
7. Click Save to save your new bindings and return to the Properties page.
8. Click the Refresh button in the Properties page to view values sent from your remote Thing.
Evaluating Changes in Property Values 
Suppose you want to know whenever a temperature changes by more than five degrees. You can set up your application to check the temperature value every ten seconds and evaluate how much it has changed. If it has changed more than five degrees, you want to push that individual property value to the ThingWorx Platform. You can also create a mashup that displays the temperature change and triggers alerts based on the change.
Alternatively, your application could look at all properties for the machine, detect that the temperature changed by more than five degrees, and then push all the properties to the platform.
The Edge Java SDK can do much of this work for you. All your application needs to do is to set the new value when it changes and set up the property so that it is pushed to the platform when you want to push it, and the SDK does everything else.
What's Next 
The rest of this section explains aspects of properties and how to use them to further define a property and how the ThingWorx Platform will behave when it needs to read the value of a property. It then explains how to use annotations, with examples. Finally, it explains how to use methods of the VirtualThing class to define properties. Continue to:
Was this helpful?