Jump to content









Photo

How to use Console ?


  • Please log in to reply
3 replies to this topic

#1 jcodatalog

jcodatalog

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 16 March 2018 - 09:07 PM

Hello Carriots users,

 

I would appreciate to have some examples of the console use :

 

For example, when I write in 'Write your code here:'

 

context.hierarchy.device

 

the answer in 'SDK engine response:' is

 

Message: exception
Details: 'Cannot get property \'device\' on null object'

 

I have the same error for all similar commands :

 

context.data

context.data.Vbat

 

answer :

 

Message: exception
Details: 'Cannot get property \'Vbat\' on null object'

 

Could you please help me to write the missing command to access the stream data  ('Vbat' for example) ?

 

What I want to do is to send an Email alert when the low battery voltage of my Arduino sending data to Carriots is detected.

To do that I use the if expression :

context.data.Vbat.toBigDecimal()<3.0

 

The Email is sent. That works.

 

I need also to add in the Email message an old data from my stream :

 

For example :

At 09:00 I send "Vbat":3.1

At 10:00 I send "test":"Ok"

At 10:30 I send "Vbat":3.1

At 11:00 I send "Vbat":2.9

 

At this moment, The Email alert is sent because Vbat<3.0 ,

In the email.message , I added these lines :

...

email.message+="Data 'test' = ";

email.message+=context.data.test;

...

 

But I get in the Email :

Data 'test'=null

 

How can I access to 'old' data in the stream ?

 

 

 

 

Thanks

JC



#2 jpastor

jpastor

    Development leader

  • Administrators
  • 176 posts

Posted 26 March 2018 - 09:55 AM

Hi Friend

 

In the console you could run all the operations that you want, but keep in mind that you do not have context (because there is no stream). So you will have to replace this context with real values.

 

Regarding your question, you can get the stored data, an example would be:

 

import com.carriots.sdk.Stream

def streams = Stream.findBy(["_t": "str", "device": "defaultDevice@userdemo.userdemo", "max": "3", "order": "-1"])
//return streams[1].data
return streams

 

 

Run this example in the console to check the results

Hope it helps!



#3 jcodatalog

jcodatalog

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 23 April 2018 - 06:57 PM

Hi jpastor,

 

Thanks for your answer.

I will try the console again asap !

 

Regards

JC



#4 jcodatalog

jcodatalog

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 05 May 2018 - 09:41 AM

Hi all,

 

Just to give you a feedback :

With the above hints, the console works perfectly and allow to test the power of the groovy script.

I am discovering the possibilities of complex listener condition : an alert can be sent from the result of the stream data postprocessing, not just from the last data received. 

 

Many thanks,

JC






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users