Ewon TechForum
Providing technical solutions to technical requests


eWON and EMONCMS
simon Offline
eWON Support
#1
Hi everybody,

Here is an example of BASIC script for publishing the eWON Tag values to the EMONCMS IoT Web Platform (http://emoncms.org).


.png   2016-10-12_10-01-16.png (Size: 89,87 KB / Downloads: 25)

Code:
ONDATE 1,"*/5 * * * *", "@weather_push()"
END

Function weather_push()
 
  ONSTATUS "GOTO EMONCMS_Callback"  
  @EMONCMS_push("outTemp",outTemp@)
 
EndFn

Function EMONCMS_init()
  EMONCMS_apikey$ = "4263b1bf8f7ecd4c6ecb1ea373974b4b"
  apikey$ = "&apikey=" + EMONCMS_apikey$
EndFn

Function EMONCMS_push($dataName$, $value)  
  @EMONCMS_init()
 
  //REQUESTHTTPX "https://emoncms.org/input/post.json?json={temperature:20.5}&apikey=4263b1bf8f7ecd4c6ecb1ea373974b4b","GET"
  $url$ = "https://emoncms.org"
  $cmd$ = "/input/post.json"
  $param$ = 'json={'+ $dataName$ + ":" + STR$ $value +'}'+ apikey$
  REQUESTHTTPX $url$+$cmd$+'?'+$param$,'GET'
 
  ActionID% = GETSYS PRG,"ACTIONID"
 
EndFn

Function Log($message$, $error%)

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

EMONCMS_Callback:
  EventId%=Getsys PRG,"EVTINFO"

  IF EventId%=ActionID% THEN
    SETSYS PRG,"ACTIONID",EventId%
    CurrentStatus%=GETSYS PRG,"ACTIONSTAT"
    IF (CurrentStatus%=0) THEN
     StatusCode$ = RESPONSEHTTPX "STATUSCODE"
     StatusCode$ = RTRIM statusCode$
     Body$ = RESPONSEHTTPX "RESPONSE-BODY"
     Body$ = RTRIM Body$
     IF StatusCode$ = "200" AND Body$ = "ok" THEN
       @Log("EMONCMS Updated successfully", 0)
     ELSE
       @Log("Error when sending data to EMONCMS :" + Body$, 1)
     ENDIF
    ELSE
       @Log("Error when sending data to EMONCMS", 1)
    ENDIF
  ENDIF
END
Reply



Possibly Related Threads…
  Ewon Stops sending data Started by dlong0
7 Replies - 233 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.421 Views
14-02-2020, 06:06 PM
Last Post: simon
  eWON and ThingWorx Started by simon
13 Replies - 7.293 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