Jump to content









Photo

Retrieving another devices data from a particular device's listener


  • Please log in to reply
4 replies to this topic

#1 tahir_sid

tahir_sid

    Member

  • Members
  • PipPip
  • 11 posts

Posted 17 July 2014 - 05:54 AM

Hi,

 

I have some questions related to creating Listener in Carriots.

 

1. Upon receiving data from devices, the listener should get all the latest data (e.g. Temperature data) from all other devices and calculate the average. how to retrieve data of another devices from specific listener?

 

2. is it possible to have general variable, that is accessible from all device's listeners ?

 

 

Thanks for ur response

 

 

 

 

 

 

 



#2 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 103 posts
  • LocationMadrid, Spain.

Posted 17 July 2014 - 06:08 AM

Hi tahir_sid!

 

You can use sdk class Stream for get all the latest data from device (more info in https://www.carriots...aries#st-findby):

import com.carriots.sdk.Stream;

def streams = Stream.findBy(["_t": "str", "device": "Your_id_developer_device"])

 

If you need have general variables the best way is to create a "device property":

import com.carriots.sdk.Device;

def device = Device.find('Your_id_developer_device');
device.device_properties.your_property=NEW_VALUE;
device.update();

 

And later you can get this value:

import com.carriots.sdk.Device;

def device = Device.find('Your_id_developer_device');
def value = device.device_properties.YOUR_PROPERTY;

 

I hope this help you!

 

 

Best regards!



#3 tahir_sid

tahir_sid

    Member

  • Members
  • PipPip
  • 11 posts

Posted 17 July 2014 - 07:39 AM

Thanks Sdeancos,

 

I understand how to use SDK class stream now. I have tested using carriots console.

 

After I run the the script, it returns JSON string, now how do I refer to a particular data attribute within this JSON (eg. data.temperature)?

I assume I have to parse the JSON result first?  

 

 

Thanks again

Tahir



#4 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 103 posts
  • LocationMadrid, Spain.

Posted 17 July 2014 - 09:25 AM

Hi,

 

I think that you can use for example this:

 

import com.carriots.sdk.Stream;


def streams = Stream.findBy(["_t": "str", "device": "Your_id_developer_device"])

def my_temperature = streams[0].data.temperature // for first streams

// or maybe for all streams and save in variable.

def my_temperatures = []
streams.each { it ->
  my_temperatures.add(it.data.temperatures)
}

 

The result from findBy its a groovy map class.

 

I hope this help you,

 

Best regards!



					
					

#5 tahir_sid

tahir_sid

    Member

  • Members
  • PipPip
  • 11 posts

Posted 17 July 2014 - 09:54 AM

gracias sdeancos,

 

it works, you're really helpful :)

 

regards,

/tahir

 




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users