Still technically a server by all rights but just hosted a single page to do some on off with GPIO technically not a hijack but it is a good base to start with when messing around and trying to figure stuff out.
-- figure out how to read and display output
-- when you run gpio.write(3,gpio.high) It is actually turning gpio 0 on!!!
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","pass")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf3 = "<p>on</p>";
local buf2 = "<p>off</p>";
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> ESP8266 Web Server</h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=OFF1\"><button>OFF</button></a> <a href=\"?pin=ON1\"><button>ON</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=OFF2\"><button>OFF</button></a> <a href=\"?pin=ON2\"><button>ON</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.LOW) do client:send(buf3) ; end
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.HIGH) do client:send(buf2) ; end
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.LOW) do client:send(buf3) ; end
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.HIGH) do client:send(buf2) ; end
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
Where I buy my ESP8266 boards from... (Banggood)