this is my script
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid", "password")
print(wifi.sta.getip())
led1 = 3
pin = 4
orstate=0
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(pin, gpio.INPUT)
print( gpio.read(pin))
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,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
buf = buf.."<h1> LIGHTS CONTROL</h1>";
buf = buf.."<p> LIGHT1 <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
local _on,_off = "",""
if((_GET.pin == "ON1" and orstate==0 ))then
gpio.write(led1, gpio.HIGH) orstate=1;
elseif((_GET.pin == "OFF1" and orstate==1))then
gpio.write(led1, gpio.LOW) orstate=0;
elseif ((gpio.read(pin)==1 and orstate==0) )then
gpio.write(led1,gpio.HIGH) orstate=1 ;
elseif ((gpio.read(pin)==0 and orstate==1))then
gpio.write(led1,gpio.LOW) orstate=0 ;
end
client:send(buf);
client:close();
collectgarbage();
end)
end)