4 Replies Latest reply on Jan 16, 2017 8:25 AM by lpiotrowski RSS
    jjuran 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!

      • Re: Java SDK Sending Data
        ciprianote Explorer

        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
          veronicamih Creator

          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
            meghan Communicator

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

              • Re: Java SDK Sending Data
                lpiotrowski Newbie

                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.