-
Notifications
You must be signed in to change notification settings - Fork 24
/
init.lua
49 lines (38 loc) · 1.31 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
host="i.nodeusb.com"
function getFile(p,f)
local strPost = "GET /"..p.."f="..f.." HTTP/1.0\r\nHost: "..host.."\r\n\r\n"
local sk=net.createConnection(net.TCP, 0)
local s=0
file.remove(f)
file.open(f,"a")
sk:on("connection", function(sck) sk:send(strPost) end)
sk:on("receive", function(sck, res)
local pos=string.find(res,"%c%c%c")
if pos~=nil then
s=1
pos=pos+4
else
pos=0
end
if s==1 then
file.write(res:sub(pos))
end
res=nil
collectgarbage()
end)
sk:dns(host,function(conn,ip) sk:connect(80,ip) end)
tmr.alarm(5,2000,0,function() sk:close() sk=nil strPost = nil file.close() collectgarbage() end)
end
tmr.alarm(0,3000,1,function()
ip = wifi.sta.getip()
if(ip==nil) then
print("Offline")
else
print('downloading\r\nd.lua')
tmr.stop(0)
getFile('e?','d.lua')
tmr.alarm(1,4000,0,function() collectgarbage() node.compile('d.lua') print('i.lua') getFile('e?','i.lua') collectgarbage() end)
tmr.alarm(2,8000,0,function() collectgarbage() node.compile('i.lua') print('init.lua') getFile('e?','init.lua') collectgarbage() tmr.alarm(3,5000,0,function() print("Done,reboot") node.restart() end) end)
collectgarbage()
end
end)