cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Observe Thingworx Property Change with Java SDK

kbutz
1-Visitor

Observe Thingworx Property Change with Java SDK

Hi all,

I'd like to observe a specific property of my Thingworx Thing via Java SDK. Therefore I've created a Thingworx Client, which is connected to Thingworx. After this, I've created a Virtual Thing with my Thingname and added a propertyChangeListener. Unfortunately, the listener does not get fired, as soon as I change the property in Thingworx. Does anyone know where's the problem or where to find an example for this?

Here's my Code Snippet:

ClientConfigurator config = new ClientConfigurator();

config.setUri("http://xxx.xxx.xxx.xxx:8080/Thingworx/WS");

config.setAppKey("xxx");

config.ignoreSSLErrors(true);

try {

  TwxClient client = new TwxClient(config);

  client.start();

  boolean isConnected = client.waitForConnection(30000);

  System.out.println("Client is connected:"+isConnected);

  String thingName = "ThingWatcherThing";

  VirtualThing thing = new VirtualThing(thingName, "", thingName, client);

  thing.addPropertyChangeListener(new VirtualThingPropertyChangeListener() {

     @Override

     public void propertyChangeEventReceived(VirtualThingPropertyChangeEvent event) {

        Property property = event.getProperty();

        String name = property.getPropertyDefinition().getName();

        if(name.equals("TestProp") == false){

           return;

        }

     }

  } );

  client.bindThing(thing);

} catch (Exception e1) {

  e1.printStackTrace();

}

So, where's the problem? Is ist the correct approach?

Many Greets, Korbinian

1 REPLY 1
supandey
19-Tanzanite
(To:kbutz)

Hi Korbinian,

Won't it be easier to create subscription to the data change event happening on the platform? There's something discussed about this on the community, please check this thread Extension : Thingworx Event Subscription

I think with Event and Subscribing to that event would be an efficient approach. Please do correct me if this is a wrong understanding

Hope this helps.

Announcements


Top Tags