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



eWON and OpenSensors.io - simon - 18-10-2016

Hey!

Opensensors.oi is an simple free-of-charge IOT cloud platform that mainly allows to concentrate the data on a server and then share them with a predefined screen generated from a given template. You can then decide to share them publicly or not. Opensensors.io does not support dashboards or other data analysis tools (trends,...).

Here is an example of BASIC script to push your Tag values to Opensensors.io


Code:
Function OPENSENSORS_weather_push()
 
 ONSTATUS "GOTO OPENSENSORS_Callback"  
 @OPENSENSORS_push("temperature",outTemp@)
 
EndFn

Function Log($message$, $error%)

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


Function OPENSENSORS_init()

 OPENSENSORS_apikey$ = "35639f73-2446-423d-8687-35229a59f7ed"
 OPENSENSORS_clientId$ = "4478"
 OPENSENSORS_devicePwd$ = "Jffdsn"
EndFn

Function OPENSENSORS_push($dataName$, $value)
 @OPENSENSORS_init()
 
 $url$ = "https://realtime.opensensors.io/v1/topics//users/prk4iot/"+$dataName$
 $url$ = $url$+"?client-id="+OPENSENSORS_clientId$+"&password="+OPENSENSORS_devicePwd$
 
 $header$ =            "Accept=application/json"
 $header$ = $header$ + "&Content-Type=application/json"
 $header$ = $header$ + "&Authorization=api-key "+OPENSENSORS_apikey$

 $myData$ = '{"data": "'+STR$($value)+'"}'

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

 actionID% = GETSYS PRG,"ACTIONID"

EndFn

OPENSENSORS_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$ = '{"message":"Message sent"}' THEN
      @Log("OPENSENSORS Updated successfully", 0)
    ELSE
      @Log("Error when sending data to OPENSENSORS :" + Body$, 1)
    ENDIF
   ELSE
      @Log("Error when sending data to OPENSENSORS", 1)
   ENDIF
 ENDIF
END