Jump to content









Photo

Listen more than one parameter to Initial State

Listener InitialState

  • Please log in to reply
1 reply to this topic

#1 pinfocal

pinfocal

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 29 July 2017 - 11:34 AM

Hi, 

I'm trying to send more than one parameter to initialstate using listeners, but I can't find the way to do that. 

The code that is required by the initialstate api is:

.....

   + Body
   
            [
                {
                    "key": "temperature",
                    "value": "1",
                    "epoch": 1419876021.778477
                },
                {
                    "key": "temperature",
                    "value": "2",
                    "epoch": 1419876022.778477
                },

 

but I am not able to send it as required. An alarm with the text: "... failed RestrictedScript 21 expecting found r line 21 column 96 data Temperatura 1 error"

 

The code I'm using is:

 

 

import com.carriots.sdk.utils.BasicHttp;
def basicHttp = new BasicHttp();
basicHttp.verb ="POST";
def access_key = "MY_ACCESS_KEY";
def content_type = "application/json";
def bucketKey = "MY_BUCKET_KEY";
map= ["X-IS-AccessKey" : access_key,
"X-IS-BucketKey": bucketKey,"Content-Type":content_type];
basicHttp.headers=map;
// basicHttp.payload ='[{"key":"Temperatura_1","value":"' + context.data.Temperatura + '"},
//                      {"key":"PresiĆ³n_1","value":"' + context.data.Presion + '"}]';
basicHttp.payload  ='[{"key":"Temperatura_1","value":"' + context.data.Temperatura + '"},]';
basicHttp.payload +='[{"key":"Temperatura_2","value":"' + context.data.Temperatura + '"}]';
 
basicHttp.send();
 
Thank you in advance for your answers.


#2 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 31 July 2017 - 01:12 PM

Hello pinfocal,

We have tried to reproduce your error and we have detected that the structure of data that you send in the payload is malformed. Please try with:

 

basicHttp.payload  ='[{"key":"Temperatura_1","value":"' + context.data.Temperatura + '"}, {"key":"Temperatura_1","value":"' + context.data.Temperatura + '"}]';

 

If you continue having problems do not hesitate to ask us.

Regards







Also tagged with one or more of these keywords: Listener, InitialState

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users