ThingWorx Edge SDKs: Tutorial > Property Subscriptions
Property Subscriptions
Posting data to the ThingWorx Platform would get really complex if you just made service calls to update your data. Property subscription allows your ThingWorx Platform to ask for property values it wants and update them automatically. The subscribed property management tools of the ThingWorx Edge SDKs also provide convenient features such as:
Storing property changes when offline to be delivered later (not supported by the Java SDK)
Allowing changes to be delivered in batches
Pushing changes only when values change, based on a configurable threshold
Allowing changes to be folded or reduced
Your SDK-based application must register the properties you want to communicate to the platform. Pushing is the process of sending queued batches of updates to the ThingWorx Platform.
Registering Properties
The ThingWorx Edge Java SDK uses an object-oriented approach to registering properties. Java annotations map Java Bean properties. Class instances map to Things on the platform. You bind instances. The ThingWorx Edge C SDK uses a declarative approach. Each ThingName, property name, and Type must be declared. Binding is done with only the ThingName or Identifier of a Thing.
Note that it does not matter when you bind an edge device to a Thing. It can be done before or after connecting. If you are binding multiple things, it is faster to bind before connecting.
Here are examples of registering properties.
Example 5. Registering Properties in Java
In Java, just create and annotate a Class:

package com.thingworx.sdk.steam;

import com.thingworx.communications.client.ConnectedThingClient;
import com.thingworx.communications.client.things.VirtualThing;
import com.thingworx.metadata.annotations.ThingworxPropertyDefinition;
import com.thingworx.metadata.annotations.ThingworxPropertyDefinitions;

@ThingworxPropertyDefinitions(properties = {
@ThingworxPropertyDefinition(name="Temperature", baseType="NUMBER"),
@ThingworxPropertyDefinition(name="SerialNumber", baseType="STRING")
})
public class JavaSDKExampleThing extends VirtualThing {
public JavaSDKExampleThing(final String name,final ConnectedThingClient client) {
super(name, null, client);
}
}
...
JavaSDKExampleThing steamSensorThing = new JavaSDKExampleThing("SdkSampleThing",client);
client.bindThing(steamSensorThing);
Example 6. Registering Properties in C
In C, register your properties using API calls:
/* Register our properties */
twApi_RegisterProperty(TW_THING, thingName, "FaultStatus",
TW_BOOLEAN, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "InletValve",
TW_BOOLEAN, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "Pressure",
TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "Temperature",
TW_NUMBER, NULL, "VALUE", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "TemperatureLimit",
TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "TotalFlow",
TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "BigGiantString",
TW_STRING, NULL, "ALWAYS", 0, propertyHandler, NULL);
twApi_RegisterProperty(TW_THING, thingName, "Location",
TW_LOCATION, NULL, "ALWAYS", 0, propertyHandler, NULL);

/* Bind our thing */
twApi_BindThing(thingName);
Was this helpful?