LED On & OFF Problem
-
Hi All.
my code doesn't work i don't know why what is the problem can some one help me please many thanks for your help. using ESP12E with Lua.wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASS")print(wifi.sta.getip())
gpio.mode(2, gpio.OUTPUT)srv = net.createServer(net.TCP, 1)
srv:listen(80,function(conn)
conn:on("receive", function(conn,request)local buf = ""; local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end --print (_GET) buf = buf.."<h1> Web Server 87</h1>"; buf = buf.."<p>LIGHT <a href=\"?pin=ON\"><button>ON</button></a> <a href=\"?pin=OFF\"><button>OFF</button></a></p>"; local _on,_off = "","" conn:send(buf); print(_GET.pin) print('Pin 2 is:' .. gpio.read(2)) action(_GET.pin) end) conn:on("sent",function(conn) conn:close() end)end)
function action(param)gpio.write(2, gpio.HIGH); elseif(param == "OFF" ) then gpio.write(2, gpio.LOW); endend
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login