Ewon TechForum
Providing technical solutions to technical requests


eWON and Carriots
simon Offline
eWON Support
#1
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 
.png   2018-05-03_15-00-18.png (Size: 17,37 KB / Downloads: 12)
To find CARRIOTS_device (id), see
.png   2018-05-03_15-00-58.png (Size: 18,29 KB / Downloads: 10)

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

Richard Offline
Ewon Distributor
#2
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?
Thanks,
Richard
Reply

simon Offline
eWON Support
#3
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
Reply

Richard Offline
Ewon Distributor
#4
(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.
Thanks,
Richard
Reply



Possibly Related Threads…
  Ewon Stops sending data Started by dlong0
7 Replies - 302 Views
24-06-2020, 09:47 AM
Last Post: simon
15-06-2020, 01:51 PM
Last Post: simon
18-05-2020, 05:25 PM
Last Post: simon
14-04-2020, 08:53 PM
Last Post: simon
08-04-2020, 05:23 PM
Last Post: simon
  Creating Totaliser Within eWON Started by Josh
3 Replies - 1.443 Views
14-02-2020, 06:06 PM
Last Post: simon
  eWON and ThingWorx Started by simon
13 Replies - 7.360 Views
17-01-2020, 05:55 PM
Last Post: ltitel
07-01-2020, 03:34 PM
Last Post: simon
22-10-2019, 10:42 AM
Last Post: simon
03-09-2019, 02:08 PM
Last Post: simon



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy