Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1.  
  2. -- Conexao na rede Wifi
  3. wifi.setmode(wifi.STATION)
  4. wifi.sta.config("000000000000","000000000000")
  5. print(wifi.sta.getip())
  6. -- Definicoes do pino do led
  7. led1 = 1
  8. gpio.mode(led1, gpio.OUTPUT)
  9. -- Definicoes do Web Server
  10. srv=net.createServer(net.TCP)
  11. srv:listen(80,function(conn)
  12. conn:on("receive", function(client,request)
  13. local buf = "";
  14. local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
  15. if(method == nil)then
  16. _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
  17. end
  18. local _GET = {}
  19. if (vars ~= nil)then
  20. for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
  21. _GET[k] = v
  22. end
  23. end
  24. buf = buf.."<h1><u>FILIPEFLOP</u></h1>";
  25. buf = buf.."<h2><i>ESP8266 Web Server</i></h2>";
  26. buf = buf.."<p><a href=\"?pin=LIGA1\"><button><b>LED 1 LIG</b></button></a> <br/><br/><a href=\"?pin=DESLIGA1\"><button><b>LED 1 DES</b></button></a></p>";
  27. local _on,_off = "",""
  28. if(_GET.pin == "LIGA1")then
  29. gpio.write(led1, gpio.HIGH);
  30. elseif(_GET.pin == "DESLIGA1")then
  31. gpio.write(led1, gpio.LOW);
  32. end
  33. client:send(buf);
  34. client:close();
  35. collectgarbage();
  36. end)
  37. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement