data "A", "B", "C", "D", "E", "F", "G", "H"
data "I", "J", "K", "L", "M", "N", "O", "P"
data "Q", "R", "S", "T", "U", "V", "W", "X"
data "Y", "Z", "a", "b", "c", "d", "e", "f"
data "g", "h", "i", "j", "k", "l", "m", "n"
data "o", "p", "q", "r", "s", "t", "u", "v"
data "w", "x", "y", "z", "0", "1", "2", "3"
data "4", "5", "6", "7", "8", "9", "+", "/"
dim decoding_table(256)
for i=0 to 63
read a$
a = asc(a$)
decoding_table(a) = i
next i
ms$ = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyAxMjM0NTY3ODkwDQpUaGlzIGlzIG1lc3NhZ2UgZW5jb2RlZCB1c2luZyBiYXNlNjQNCkl0IGNvbnRhaW5zIHRleHQgY2hhcmFjdGVycyByZXByZXNlbnRpbmcgNiBiaXRzIGVhY2ggc28sIHRvDQpjb21wb3NlIDMgYnl0ZXMsIDQgY2hhcmFjdGVycyBhcmUgcmVxdWlyZWQgKDYqNCA9IDI0ID0gOCozKQ=="
decode2 ms$
sub decode2(c$)
for i=0 to len(c$) step 4
b$ = mid$(c$, i+1, 4)
b = 0
for k = 0 to 3
c = asc(mid$(b$, k+1, 1))
b = b + (decoding_table(c) << ((3-k)*6))
next k
print chr$(b >> 16); chr$((b >> 8) and 255); chr$(b and 255);
next i
print
end sub
end
'set the GUI
tft.init 1
gui.init 30, 0
'gui.image( 0,0,320,240, "/img/landscapes/landscape15.jpg")
print file.rename("/classic.txt", "/landscape15.bmp")
gui.image( 0,0,320,240, "/landscape15.bmp")
gui.textline 40, 5, 250, 20, "OpenWeatherMap Demo using Annex32 GUI", 1
gui.box 240, 35, 70, 70, tft.color(black)
img1 = gui.image( 250, 45,50,50, "/img/Weather/bubble/na.jpg")
gui.textline 10, 35, 80, 20, "Town"
gui.textline 10, 57, 80, 20, "Description"
gui.textline 10, 79, 80, 20, "Temperature"
gui.textline 10, 101, 80, 20, "Pressure"
gui.textline 10, 123, 80, 20, "Humidity"
gui.textline 10, 145, 80, 20, "Wind"
gui.textline 10, 167, 80, 20, "Updated"
town = gui.textline( 100, 35, 130, 20, "N/A" )
desc = gui.textline( 100, 57, 130, 20, "N/A" )
temp = gui.textline( 100, 79, 130, 20, "N/A" )
press= gui.textline( 100, 101, 130, 20, "N/A" )
hum = gui.textline( 100, 123, 130, 20, "N/A" )
wind = gui.textline( 100, 145, 130, 20, "N/A" )
updt = gui.textline( 100, 167, 130, 20, "N/A" )
dte = gui.textline( 240, 107, 70, 20, "N/A" )
tme = gui.textline( 240, 129, 70, 20, "N/A" )
gui.setcolor dte, tft.color(green)
gui.setcolor tme, tft.color(green)
but1 = gui.button( 10, 200, 80, 40, "Toulouse", 1, 20)
but2 = gui.button(120, 200, 80, 40, "Napoli", 1, 20)
but3 = gui.button(230, 200, 80, 40, "London", 1, 20)
but4 = gui.button(240, 150, 80, 40, "Singapore", 1, 20)
gui.setevent but1, 1, set_toulouse
gui.setevent but2, 1, set_napoli
gui.setevent but3, 1, set_london
gui.setevent but4, 1, set_singapore
gui.autorefresh 50, 1
onWgetAsync asynco
appid$ = "1f7dd1b2a6ffcf80c1e20b5d5365f545"
city$ = "Toulouse,fr"
gosub update_time
gosub get_OpenWeatherMap
timer0 500, update_time
timer1 5000, get_OpenWeatherMap
wait
get_OpenWeatherMap:
wgetasync("http://api.openweathermap.org/data/2.5/weather?q=" + city$ + "&appid=" + appid$ + "&units=metric")
return
asynco:
z$ = wgetresult$
print z$
gui.settext town, json$(z$,"name") + "," + json$(z$,"country")
gui.settext desc, json$(z$,"description")
gui.settext temp, json$(z$,"temp") + " " + chr$(247) + "C (" + json$(z$,"temp_min") + "/" + json$(z$,"temp_max") + ")"
gui.settext press, json$(z$,"pressure") + " mB"
gui.settext hum, json$(z$,"humidity") + " %"
gui.settext wind, json$(z$,"wind.speed") + " m/s - " + json$(z$,"wind.deg") + chr$(247)
gui.settext updt , unixdate$(json$(z$,"dt")) + " " + unixtime$(json$(z$,"dt"))
icon$ = json$(z$,"icon")
gui.setimage img1, "/img/Weather/bubble/" + icon$ + ".jpg"
'gui.refresh 1
print
return
update_time:
gui.settext dte, date$
gui.settext tme, time$
return
set_toulouse:
city$ = "Toulouse,fr"
gosub get_OpenWeatherMap
return
set_napoli:
city$ = "Napoli,it"
gosub get_OpenWeatherMap
return
set_london:
city$ = "London,uk"
gosub get_OpenWeatherMap
return
set_singapore:
city$ = "Singapore,sg"
gosub get_OpenWeatherMap
return