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



eWON and Facebook - simon - 23-05-2016

Hi Guys,

I have recently created a Facebook page for publishing the data of the Weather Station (connected to eWON) that we have here (https://www.facebook.com/EWON-Weather-Station-1724188781137106/)
This to demonstrate that the eWON is able to post data to Facebook thanks to the graph API.

The eWON creates a new post on the Facebook page every 4 hours. It actually sends some Weather data like the Temperature, Humidity...

Here is my code :



Code:
Rem --- eWON start section: Init Section
ewon_init_section:
Rem --- eWON user (start)
ONDATE 1,"0 */4 * * *","GOTO FACEBOOK"
ONSTATUS "GOTO FACEBOOK_CALLBACK"
END


FACEBOOK:
u$ = "https://graph.facebook.com/v2.6/1724188781137106/feed"

m$ = "POST"

emoticon$ = @GETEMOTICON$()

d$ = 'message=Belgium Weather (Nivelles) : ' + emoticon$
d$ = d$ + '%0A Local Time : ' + TIME$
d$ = d$ + '%0A Temperature : ' + STR$ outTemp@ + ' DegC '
d$ = d$ + '%0A Humidity : ' + STR$ outHumi@ + ' %'
d$ = d$ + '%0A Wind Speed : ' + STR$ avgwind@ + ' km/h'
d$ = d$ + '%0A Atmospheric Pressure : ' + STR$ AbsPress@ + ' hpa'

d$ = d$ + '&access_token=EAAQTts8JDb0BAHYeAZBA6BO0Smva8vQ4OmRK2PPE6Co1ZAbLAqrqG6ZBoZCFAG6lNdaeRTs8ZCKiJmZBcNQIL7ZBoth'
d$ = d$ + 'tRPaYRewp0tKA5soDzdHYGhevN3EtZAG3yJGIeRsIbzLaKBcsgMYQp5Am0wopQQ5qLEIJWranDa8FAAZD'

REQUESTHTTPX u$, m$, "Content-Type=application/x-www-form-urlencoded;", d$

ACTIONID% = GETSYS PRG, "ACTIONID"

END

FACEBOOK_CALLBACK:

eventId%= GETSYS PRG,"EVTINFO"
If eventId%=ACTIONID% Then
 SETSYS PRG, "ACTIONID", eventId%

 stat%=Getsys PRG,"ACTIONSTAT"
 If (stat%=0) Then
   answer$ = RESPONSEHTTPX "RESPONSE-BODY"    
   Print "FACEBOOK POST RESPONSE :" + answer$
 Endif
Endif

END

FUNCTION GETEMOTICON$()
//icon from http://fbicons.net/
 $curtime$ = TIME$
 $curhour$ = $curtime$(12 To 13)
 $curhour_int% = VAL($curhour$)
 
 IF $curhour_int% = 8 THEN
   $GETEMOTICON$ = CHR$(239) + CHR$(187) + CHR$(191) + CHR$(240) + CHR$(159) + CHR$(140) + CHR$(133) //sunrise
   RETURN
 ENDIF
 IF $curhour_int% = 20 THEN
   $GETEMOTICON$ = CHR$(239) + CHR$(187) + CHR$(191) + CHR$(240) + CHR$(159) + CHR$(140) + CHR$(135) //sunset
   RETURN
 ENDIF
 
 IF $curhour_int% > 20 OR $curhour_int% < 8 THEN
   $GETEMOTICON$ = CHR$(240) + CHR$(159) + CHR$(140) + CHR$(131) //night
   
 ELSE
 
   IF solarrad@ < 200 THEN
     $GETEMOTICON$ = CHR$(239) + CHR$(187) + CHR$(191) + CHR$(226) + CHR$(152) + CHR$(129) //cload
   ELSE
     $GETEMOTICON$ =  Chr$(226) + Chr$(152) + Chr$(128) //Sun
   ENDIF
 ENDIF
 
 IF rainofhourly@ > 0 THEN
    $GETEMOTICON$ = CHR$(239) + CHR$(187) + CHR$(191) + CHR$(226) + CHR$(152) + CHR$(148) //umbrella
 ENDIF
 

ENDFN



Rem --- eWON user (end)
End
Rem --- eWON end section: Init Section

By the way, the Weather Station I have connected to my eWON is this one : http://www.conrad.be/ce/nl/product/1267654/renkforce-WH2600-Internet-weerstation-WH2600
This Weather station is quite cheap and features a Web Server.  So pretty easy to read the data using BASIC or JAVA.
In my case, I have developed the following Java IoServer to get the Data from it : https://developer.ewon.biz/content/weather-station-java-io-server