-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
52 lines (46 loc) · 1.08 KB
/
main.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
local io = require("ioi2c")
print("eth init")
eth.init({phy=eth.PHY_LAN8720,
addr=1,
power=16,
clock_mode=eth.CLOCK_GPIO17_OUT,
mdc=23,
mdio=18})
file.open("eth.cfg", "r")
str = file.readline()
local t={}
sep = ","
for par in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, par)
end
file.close()
print('Boot IP settings is: '..str)
static = string.match(t[4], "stat", 1)
if static ~= nil then
cfg={}
cfg.ip=t[1]
cfg.netmask=t[2]
cfg.gateway=t[3]
cfg.dns='8.8.8.8'
eth.set_ip(cfg)
end
function ev(event, info)
print("event", event)
if event == "got_ip" then
file.open("eth.cfg","w+")
set = info.ip..','..info.netmask..','..info.gw..','..t[4]
file.write(set)
file.close()
print("ip:"..info.ip..", nm:"..info.netmask..", gw:"..info.gw)
io.led("green")
dofile('web.lua')
elseif event == "connected" then
print("speed:", eth.get_speed())
print("mac:", eth.get_mac())
end
end
eth.on("connected", ev)
eth.on("disconnected", ev)
eth.on("start", ev)
eth.on("stop", ev)
eth.on("got_ip", ev)