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

Java SDK Sending Data

Highlighted
Newbie

Java SDK Sending Data

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!

Tags (2)
4 REPLIES 4

Re: Java SDK Sending Data

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

Re: Java SDK Sending Data

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




Re: Java SDK Sending Data

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

Re: Java SDK Sending Data

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.

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________