Advertisement
Guest User

init.lua

a guest
May 12th, 2015
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. wifi.setmode(wifi.STATION)
  2. wifi.sta.config("mySSID","password")
  3. wifi.sta.connect();
  4. wifi.sta.autoconnect(1)
  5. mac=wifi.sta.getmac();
  6. print("mac: "..mac.."\n");
  7.  
  8. cnt=0;
  9. tmr.alarm(0, 1000, 1, function()
  10.     if wifi.sta.status() ~= 5 then
  11.         cnt = cnt + 1;
  12.         if cnt > 30 then
  13.             print("Failed to connect AP")
  14.             tmr.stop(0)
  15.             dofile("uploaded.lua")
  16.         end
  17.     else
  18.         tmr.stop(0)
  19.         proceed()
  20.     end
  21. end)
  22.  
  23. function proceed()
  24.     ip=wifi.sta.getip();
  25.     print("ip:  "..ip.."\n");
  26.  
  27.     res="";
  28.     sk=net.createConnection(net.TCP, 0)
  29.     sk:on("receive",
  30.         function(sck, c)
  31.             res=res..c;
  32.         end
  33.     )
  34.     sk:on("disconnection",
  35.         function()
  36.             res=string.gsub(res, "\r\n", "\n")
  37.             if string.find(res, "200 OK\n") then
  38.                 b, e = string.find(res, "\n\n")
  39.                 res = string.sub(res, e, -1);
  40.                 print(res.."\n");
  41.                 file.open("uploaded.lua", "w")
  42.                 file.write(res);
  43.                 file.close();
  44. --              node.compile("uploaded.lua")
  45.             end;
  46.             dofile("uploaded.lua")
  47.         end
  48.     );
  49.     sk:connect(80,"192.168.1.1")
  50.     sk:send("GET /"..ip..".lua HTTP/1.1\r\nHost: esp\r\nConnection: close\r\nAccept: */*\r\n\r\n")
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement