--*** Server ***********
sv=net.createServer(net.TCP,30)
sv:listen(80,function(c)
c:on("receive", function(c, pl)
print(pl)
--*** turn on/off gpios
_, j = string.find(pl,'GPIO_2_switch=')
if j ~= nil then
print(string.sub(pl,j+1))
if string.sub(pl,j+1) == "on" then
gpio.write(2,1)
else
gpio.write(2,0)
end
end
--*** HTMP web page header ***---
c:send('<!DOCTYPE html>')
-- c:send("HTTP/1.1 200 OK\r\n")
-- c:send("Connection: close\r\n\r\n")
c:send("<html lang='en'> ")
c:send("<body> ")
c:send("<h1>ESP8266 Wireless control setup</h1> ")
--*** HTML buttons
c:send('<p>GPIO 2 is: '..gpio.read(2)..'</p>')
c:send('<form method="post" >')
c:send('<input type="radio" name="GPIO_2_switch" value="on"> ON </input> <br />')
c:send('<input type="radio" name="GPIO_2_switch" value="off"> OFF </input> <br />')
c:send('<input type="submit" value="Light Switch" />')
c:send('</form></body></html>')
c:close()
end)
end)