Binding to ThingWorx Platform
For the ThingWorx Platform to interact with a Virtual Thing, the WebSocket over which the Virtual Thing connects to ThingWorx Platform must be bound to the corresponding Remote Thing on the server instance. Use the ConnectedThingClient.bind() method to tell the platform to make this binding. The platform can then send request messages to your Virtual Thing, over the WebSocket. The bind action also changes the value of the isConnected property (to true) and the time value of the lastConnection property for the newly bound Virtual Thing. Your application can also call ConnectedThingClient.unbind() to tell the platform to remove the association between the Remote Thing and the WebSocket. The platform changes the value of the isConnected property to false.
Click a section title below to display its content:
Identifiers 
Identifiers provide an alternate way to associate a Virtual Thing with a Remote Thing in the ThingWorx Platform and at the device. It is important to remember that if you assign an identifier to the Remote Thing at the platform, you must use that identifier in your client application because the platform uses the identifier instead of the name to match a Virtual Thing connection to a Remote Thing. If you do not use the identifier in the client application, the platform returns an error. It cannot match the client to the Remote Thing by the ThingName once an identifier is configured for the Remote Thing on the platform.
Using Overrides After Binding 
To customize a client application, you can take advantage of overridable callback methods for a Virtual Thing. These callback methods are not required; rather you may want to use them to add custom processes to your application. The following callback methods are available:
Callback Method
Description
afterBinding()
Call this method after the binding of the Virtual Thing is complete.
afterUnbinding()
Call this method after the unbinding of the Virtual Thing is complete.
afterEnable()
Call this method after the Virtual Thing has been enabled.
afterDisable()
Call this method after the Virtual Thing has been disabled.
processScanRequest()
This method performs no operations and is empty (a “no-op”). It provides a common interface for a callback method for customizing the scan cycle of a Virtual Thing. You can then set up a thread to execute this function periodically and drive scheduled activities. One example would be reading a sensor value, setting a property with the new value, and then pushing the updated property to the server. Here is an example of using the processScanRequest() method from the SteamThing.java source file for the SteamSensor example application:

// The processScanRequest is called by the SteamSensorClient every scan cycle
@Override
public void processScanRequest() throws Exception {

// Execute the code for this simulation every scan
if(readyToSend) {
try {
this.fetchInitialSettingsFromServer();
}
catch(Exception e){
LOG.info("Could not read initial setting from the server");
}

this.scanDevice();
}
}
The IPasswordCallback() callback provides the mechanism to use when an application needs to pass an application key or other secret, such as a proxy password. For details, refer to Password Callbacks.
Synchronizing State 
Until the synchronize state event occurs for the first time after binding, do not make any property pushes because they will not be sent to the ThingWorx Platform. Later, when a bind or a configuration of the bound properties on a Thing has changed on the ThingWorx Platform, the synchronizeState() method is called. Here is an example of this method from the SteamSensor application, SteamThing.java file:

public void synchronizeState() {
readyToSend = true;
// Send the property values to ThingWorx when a synchronization is required
// This is more important for a solution that does not push its properties on a regular basis
super.syncProperties();
}
Was this helpful?