PicoMiteWEB V5.07.07a24+ - Now with TFTP


Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6527
Posted: 09:26am 14 Mar 2023      

Pluto,
Try this version.
The settick sets a flag and alternates between the two locations. My system is up to 14 reads so far. I don't have a display so all output is to PRINT.

 'openweathermap
 ' CLS
 DIM buff%(512)
 DIM APIKEY$="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 
 
 WEB ntp 2
 
 DIM report$="weather?q=Porvoo,FI"
 DIM b$= "GET /data/2.5/"+report$+"&APPID="+APIKEY$+CHR$(10)+CHR$(13)
 SETTICK 1000*120,Klocka
 Klocka
 DO
   IF update THEN getfirst
   IF update2 THEN getsecond
   
 LOOP
 
SUB getfirst
 update = 0
 report$="weather?q=Porvoo,FI"
 b$= "GET /data/2.5/"+report$+"&APPID="+APIKEY$+CHR$(10)+CHR$(13)
 WEB OPEN tcp client "api.openweathermap.org",80
 WEB TCP CLIENT REQUEST b$,buff%(),10000
 WEB CLOSE tcp client
 PRINT "Weather for " + Json$(buff%(),"name")
 PRINT "Temperature is ",VAL(Json$(buff%(),"main.temp"))-273
 PRINT "Pressure is ",Json$(buff%(),"main.pressure")
 PRINT Json$(buff%(),"weather[0].description")
 PRINT "Hemma:" ',,,2,rgb(blue),rgb(White)
 PRINT "Temperatur:"+STR$(VAL(Json$(buff%(),"main.temp"))-273)+"'C" ',,,1
 
 PRINT"Lufttryck: "+Json$(buff%(),"main.pressure")+"mBar"
 PRINT Json$(buff%(),"weather[0].description")
 WindDir
 PRINT "Vind: "+Json$(buff%(),"wind.speed")+" m/s "+riktning$
 PRINT "Regn: "+Json$(buff%(),"rain.1h")+" mm/h"
 
END SUB
 
SUB getsecond
 update2 = 0
 report$="weather?q=Kaskinen,FI"
 b$= "GET /data/2.5/"+report$+"&APPID="+APIKEY$+CHR$(10)+CHR$(13)
 WEB OPEN tcp client "api.openweathermap.org",80
 WEB TCP CLIENT REQUEST b$,buff%(),10000
 WEB CLOSE tcp client
 PRINT "Weather for " + Json$(buff%(),"name")
 PRINT "Temperature is ",VAL(Json$(buff%(),"main.temp"))-273
 PRINT "Pressure is ",Json$(buff%(),"main.pressure")
 PRINT Json$(buff%(),"weather[0].description")
 PRINT "Holmin:" ',,,2,rgb(blue),rgb(White)
 PRINT "Temperatur:"+STR$(VAL(Json$(buff%(),"main.temp"))-273)+"'C"
 PRINT "Lufttryck: "+Json$(buff%(),"main.pressure")+"mBar"
 PRINT Json$(buff%(),"weather[0].description")
 WindDir
 PRINT "Vind: "+Json$(buff%(),"wind.speed")+" m/s "+riktning$
 PRINT "Regn: "+Json$(buff%(),"rain.1h")+" mm/h"
END SUB
 
SUB WindDir
 grad=VAL(+Json$(buff%(),"wind.deg"))
 riktning$=""
 IF grad>337.5 OR grad<=22.5 THEN riktning$="Nord"
 IF grad>22.5 AND grad<=67.5 THEN riktning$="N-O"
 IF grad>67.5 AND grad<=112.5 THEN riktning$="Ost"
 IF grad>112.5 AND grad<=157.5 THEN riktning$="S-O"
 IF grad>157.5 AND grad<=202.5 THEN riktning$="Syd"
 IF grad>202.5 AND grad<=247.5 THEN riktning$="S-V"
 IF grad>247.5 AND grad<=292.5 THEN riktning$="V"
 IF grad>292.5 AND grad<=337.5 THEN riktning$="N-V"
END SUB
 
SUB Klocka
 STATIC choice
 choice = 1 - choice
 IF choice THEN
   update = 1
 ELSE
   update2 = 1
 ENDIF
 
END SUB