Switch to desktop version  
eWON and Tinamous - 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 Tinamous (/thread-148.html)



eWON and Tinamous - simon - 18-10-2016

Hi eWON buddies,

Here is a piece of Script that allows to push Tag values to the Tinamous IOT Cloud platform.


Code:
Function TINAMOUS_weather_push()
 
 ONSTATUS "GOTO TINAMOUS_Callback"  
 @TINAMOUS_push("Temperature",outTemp@, "DegC")
 
EndFn

Function Log($message$, $error%)

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

Function TINAMOUS_init()
 TINAMOUS_auth$ = "Authorization= Basic ZXdvbjE6cHddNGV3b24%3D"
 //TINAMOUS_device$ = "eWON1"
 //TINAMOUS_deviceId$ = "818f1ca3-6892-4ea1-91c1-305a54e737e2"
EndFn

Function TINAMOUS_push($dataName$, $value, $units$)
 @TINAMOUS_init()
 
 $url$ = "https://myewon.tinamous.com/api/v1/senml"
 
 $header$ = "Content-Type=application/json"
 $header$ = $header$ + "&"+TINAMOUS_auth$

 $myData$ = "{e:[{'n':'"+$dataName$+"','v':'"+STR$($value)+"','u':'"+$units$+"'}]}"

 //Print $header$
 REQUESTHTTPX $url$,"POST",$header$,$myData$

 actionID% = GETSYS PRG,"ACTIONID"
EndFn

TINAMOUS_Callback:
 EventId%=Getsys PRG,"EVTINFO"

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



To identify an eWON on Tinamous, a BASIC auth is used (see below).
Tinamous provides a tool to compute the authentication value.
Be careful that if your Auth value ends with a "=" sign, it must be replaced by "%3D"

Code:
TINAMOUS_auth$ = "Authorization= Basic ZXdvbjE6cHddNGV3b24%3D"


To connect the eWON to your Tinamous account, you just have to create a device. The "Tags" (called "Fields") are created on the fly when the device pushes new data.

See Tinamous help : http://tinamous.com/swagger/ui/index#!/SenML/SenML_Post