Skip to main content
1-Visitor
March 17, 2016
Question

Java SDK Sending Data

  • March 17, 2016
  • 3 replies
  • 2789 views

Hello all,

I currently got the SDK set up similar to the steam sensor example sending data to our instance. However, is there a way to just send data once and stop? Sorta like a switch. Once it is triggered send one piece of data then wait for the next trigger.

I've tried a few ways and I can't seem to get it to work without sending a constant change in data. Is there a way? Thanks!

3 replies

1-Visitor
March 18, 2016

Hello John,

You could try creating a remote service which actually triggers the simulator to send the data.

The remote service will be called in ThingWorx and it will basically ask the simulator to push the data once.

Ciprian

1-Visitor
March 21, 2016

Hi John,

The sending of data is done in a while loop  in the main method of the SteamSensorClient :

   // As long as the client has not been shutdown, continue  


while(!client.isShutdown()) {

// Only process the Virtual Things if the client is connected  

if(client.isConnected()) {

   // Loop over all the Virtual Things and process them   

   for(VirtualThing thing : client.getThings().values()) {

     try {

        thing.processScanRequest();

    } catch(Exception eProcessing) {

       System.out.println("Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.getMessage());

     }

  }

}

   // Suspend processing at the scan rate interval   

   Thread.sleep(scanRate);

}


If you'd like to send data only once remove this code and replace it with this :


if(client.isConnected()) {

   // Loop over all the Virtual Things and process them   

   for(VirtualThing thing : client.getThings().values()) {

     try {

        thing.processScanRequest();

    }  catch(Exception eProcessing) {

       System.out.println("Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.getMessage());

     }

  }

}

You could also have a remote method like Ciprian suggested with this

if(client.isConnected()) {

   // Loop over all the Virtual Things and process them   

   for(VirtualThing thing : client.getThings().values()) {

     try {

        thing.processScanRequest();

    }  catch(Exception eProcessing) {

       System.out.println("Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.getMessage());

     }

  }

}

and call it only once in a ThingWorx Mashup or script.

I hope this helps,

Thank you,

Veronica




5-Regular Member
April 5, 2016

John, Did Veronica's suggestion resolve your issue? If so please mark it as the correct answer. Regards, Meghan

1-Visitor
January 16, 2017

Hello,

I´m an absolute beginner in ThingWorx.

I started with PTC University Introduction to ThingWorx 6.5 courses.

In Part 4 there is a "Binding to a Remote Thing and Logging Its Values" challenge.

If I try to solve this challenge I get that error:

error.PNG

My remote Speed property dont change,

Properties.PNG

Anybody has an Idea what is the problem in this case ?

Many thanks in advance.