Ewon TechForum
Providing technical solutions to technical requests


eWON and Tinamous
simon Offline
eWON Support
#1
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
Reply



Possibly Related Threads…
18-05-2020, 05:25 PM
Last Post: simon
16-04-2020, 09:10 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.299 Views
14-02-2020, 06:06 PM
Last Post: simon
  eWON and ThingWorx Started by simon
13 Replies - 6.945 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
  MQTT eWon Flexy 205 Started by RFreist
3 Replies - 1.764 Views
18-07-2019, 12:30 PM
Last Post: simon



Users browsing this thread:
1 Guest(s)



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