Switch to desktop version  
eWON and Carriots - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: BASIC Script (https://techforum.ewon.biz/forum-52.html)
+--- Thread: eWON and Carriots (/thread-146.html)



eWON and Carriots - simon - 18-10-2016

Hey!

Here is an example of BASIC script to push your Tag Values to Carriots (https://www.carriots.com) :

Code:
//This BASIC code pushes the Tag named "OutTemp" to Carriot
ONTIMER 1,"@CARRIOTS_weather_push()"
TSET 1,5

END

Function CARRIOTS_weather_push()
 
 ONSTATUS "GOTO CARRIOTS_Callback"  
 @CARRIOTS_push("temperature",outTemp@)
 
EndFn

Function CARRIOTS_init()
 CARRIOTS_apikey$ = "c8bef75fa03c62f449e87494292bbf44cd38a222e7a36d0a5b7e9dc942f7"
 CARRIOTS_device$ = "defaultDevice@SDRIOT.SDRIOT"
EndFn

Function Log($message$, $error%)

  IF $error% = 0 THEN
    LogEvent $message$,102
  ELSE
    LogEvent $message$,99
  ENDIF
    
  Print $message$
EndFn


Function CARRIOTS_push($dataName$, $value)
 @CARRIOTS_init()

 $myData$ = '{"protocol": "v1", "device": "' + CARRIOTS_device$ + '", "at": "now",'
 $myData$ = $myData$ + ' "data": {"'+$dataName$+'": '+STR$($value)+'}}'

 $url$ = "http://api.carriots.com"
 $cmd$ = "/streams"
 $header$ =            "User-Agent="+CARRIOTS_device$
 $header$ = $header$ + "&Content-Type=application/json"
 $header$ = $header$ + "&carriots.apikey="+CARRIOTS_apikey$

 REQUESTHTTPX $url$+$cmd$,"POST",$header$,$myData$

 actionID% = GETSYS PRG,"ACTIONID"
EndFn
END

CARRIOTS_Callback:
 EventId%=Getsys PRG,"EVTINFO"

 IF EventId%=ActionID% THEN
   SETSYS PRG,"ACTIONID",EventId%
   CurrentStatus%=GETSYS PRG,"ACTIONSTAT"
   Body$ = RESPONSEHTTPX "RESPONSE-BODY"
   IF CurrentStatus% = 0 THEN
    IF Body$ = '{ "response": "OK" }' THEN
      @Log("CARRIOTS Updated successfully", 0)
    ELSE
      @Log("Error when sending data to CARRIOTS :" + Body$, 1)
    ENDIF
   ELSE
      @Log("Error when sending data to CARRIOTS", 1)
   ENDIF
 ENDIF
END

To find CARRIOTS_apikey, see 
  2018-05-03_15-00-18.png (Size: 17,37 KB / Downloads: 15)
To find CARRIOTS_device (id), see
  2018-05-03_15-00-58.png (Size: 18,29 KB / Downloads: 11)

When you script is running go to "Data > Data Stream", you should find the data posted by your device


RE: eWON and Carriots - Richard - 29-04-2018

Hi Simon,
I was trying this example but I do not get it to work nor see anything happening. In the script I have put the API key and device but nothing happens. I have made a Modbus tage called temperature just like your exmple but it does not do any thing with it.
Could you give an explanation about getting the temperature tag out of the Flexy into the Carriots IOT step by step please?


RE: eWON and Carriots - simon - 03-05-2018

Richard,

I have updated the first post with some snapshot. I have also modified the script a little bit so that it pushes the value automatically


RE: eWON and Carriots - Richard - 03-05-2018

(03-05-2018, 03:06 PM)Simon Wrote: Richard,

I have updated the first post with some snapshot.  I have also modified the script a little bit so that it pushes the value automatically

Thanks I will try it out the coming days.