Advertisement
Guest User

Rui's sketch modified by John

a guest
Nov 2nd, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. wifi.setmode(wifi.STATION)
  2. wifi.sta.config("jk2stars","m0rningside")
  3. print(wifi.sta.getip())
  4. led1 = 2
  5. led2 = 4
  6. gpio.mode(led1, gpio.OUTPUT)
  7. gpio.mode(led2, gpio.OUTPUT)
  8. srv=net.createServer(net.TCP)
  9. srv:listen(80,function(conn)
  10.     conn:on("receive", function(client,request)
  11.         local buf = "";
  12.         local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
  13.         if(method == nil)then
  14.             _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
  15.         end
  16.         local _GET = {}
  17.         if (vars ~= nil)then
  18.             for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
  19.                 _GET[k] = v
  20.             end
  21.         end
  22.         buf = buf.."<h1> ESP Web Controller</h1>";
  23.         buf = buf.."<p>Switch 1 <a href=\"?pin=ON1\"><button style= \"width:150px;height:150px;font-size:100px;\">On</button></a>&nbsp;<a href=\"?pin=OFF1\"><button style= \"width:150px;height:150px;font-size:100px;\">Off</button></a></p>";
  24.         buf = buf.."<p>Switch 2 <a href=\"?pin=ON2\"><button style= \"width:150px;height:150px;font-size:100px;\">On</button></a>&nbsp;<a href=\"?pin=OFF2\"><button style= \"width:150px;height:150px;font-size:100px;\">Off</button></a></p>";
  25.         local _on,_off = "",""
  26.         if(_GET.pin == "ON1")then
  27.               gpio.write(led1, gpio.HIGH);
  28.         elseif(_GET.pin == "OFF1")then
  29.               gpio.write(led1, gpio.LOW);
  30.         elseif(_GET.pin == "ON2")then
  31.               gpio.write(led2, gpio.HIGH);
  32.         elseif(_GET.pin == "OFF2")then
  33.               gpio.write(led2, gpio.LOW);
  34.         end
  35.         client:send(buf);
  36.         client:close();
  37.         collectgarbage();
  38.     end)
  39. end)
  40. --This works but if I add to the button style "background-color:green;" without quotes. it doesn't
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement