-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
84 lines (70 loc) · 1.99 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
local json = require "cjson"
print("Connecting to wifi...")
wifi.setmode(wifi.STATION)
wifi.sta.config("XXXX","PASSWORD")
local ip = wifi.sta.getip()
function init_spi_display()
-- Hardware SPI CLK = GPIO14-->SCL OLED
-- Hardware SPI MOSI = GPIO13-->SDA OLED
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
cs = 8 -- GPIO15, pull-down 10k to GND
dc = 4 -- GPIO2 --> D/C OLED
res = 0 -- GPIO16 --> RST OLED
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
disp = u8g.ssd1306_128x64_spi(cs, dc, res)
end
function xbm_picture()
disp:setFont(u8g.font_6x10)
disp:drawStr( 62, 10, "Ability:")
disp:drawStr( 62, 62, weather.name)
disp:drawXBM( 0, -5, 60, 60, xbm_data )
end
function bitmap_test(delay)
file.open("prueba.MONO", "r")
xbm_data = file.read()
file.close()
disp:firstPage()
repeat
xbm_picture()
until disp:nextPage() == false
tmr.wdclr()
end
function updateWeather()
local conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
print("Conn: ")
print(conn)
print("Payload: ")
-- print(payload)
local payload = string.match(payload, "{.*}")
print(payload)
weather = nil
if payload ~= nil then
weather = json.decode(payload)
print("Ability:")
print(weather.name)
bitmap_test()
end
payload = nil
conn:close()
conn = nil
end )
print(ip)
conn:connect(80, "162.243.133.52")
conn:send("GET /api/v1/ability/5/ HTTP/1.1\r\n"
.."Host: pokeapi.co\r\n"
.."Cache-Control: no-cache\r\n"
.."\r\n")
conn = nil
end
init_spi_display()
tmr.alarm(0, 1000, 1, function()
print(".")
ip = wifi.sta.getip()
if ( ( ip ~= nil ) and ( ip ~= "0.0.0.0" ) )then
print(ip)
tmr.stop(0)
updateWeather()
end
end )