Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wifi.setmode(wifi.STATION)
- wifi.sta.config("mySSID","password")
- wifi.sta.connect();
- wifi.sta.autoconnect(1)
- mac=wifi.sta.getmac();
- print("mac: "..mac.."\n");
- cnt=0;
- tmr.alarm(0, 1000, 1, function()
- if wifi.sta.status() ~= 5 then
- cnt = cnt + 1;
- if cnt > 30 then
- print("Failed to connect AP")
- tmr.stop(0)
- dofile("uploaded.lua")
- end
- else
- tmr.stop(0)
- proceed()
- end
- end)
- function proceed()
- ip=wifi.sta.getip();
- print("ip: "..ip.."\n");
- res="";
- sk=net.createConnection(net.TCP, 0)
- sk:on("receive",
- function(sck, c)
- res=res..c;
- end
- )
- sk:on("disconnection",
- function()
- res=string.gsub(res, "\r\n", "\n")
- if string.find(res, "200 OK\n") then
- b, e = string.find(res, "\n\n")
- res = string.sub(res, e, -1);
- print(res.."\n");
- file.open("uploaded.lua", "w")
- file.write(res);
- file.close();
- -- node.compile("uploaded.lua")
- end;
- dofile("uploaded.lua")
- end
- );
- sk:connect(80,"192.168.1.1")
- sk:send("GET /"..ip..".lua HTTP/1.1\r\nHost: esp\r\nConnection: close\r\nAccept: */*\r\n\r\n")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement