wifi.setmode(wifi.SOFTAP)
cfg={}
cfg.ssid="myssid"
cfg.pwd="mypassword"
wifi.ap.config(cfg)
afg =
{
ip="192.168.1.1",
netmask="255.255.255.0",
gateway="192.168.1.1"
}
wifi.ap.setip(afg)
GPIO14 = 5
GPIO12 = 6
GPIO13 = 7
GPIO15 = 8
gpio.mode(5, gpio.OUTPUT)
gpio.mode(6, gpio.OUTPUT)
gpio.mode(7, gpio.OUTPUT)
gpio.mode(8, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
local srv=net.createServer(net.TCP)
local function receiver(sck,numbers)
local p={}
for v,n in (numbers or ''):gmatch("([x-z])=(%d+)") do
print (("%s=%s"):format(v,n))
p[v]=n+0
end
end
if svr then
srv:listen(80,function(conn) conn:on("receive",receiver) end)
end
html_buffer = html_buffer.."<head><meta name='viewport' content='width=200px, initial-scale=1.0'/>"
html_buffer = html_buffer.."<style>body { background-image: url('https://i.hizliresim.com/5dxJbL.png');background-repeat: no-repeat;background-position: 0px 150px;}</style>"
html_buffer = html_buffer.."<font face='verdana'><h1> ESP8266 Wifi PowerSwitch by CBILAB</h1>";
html_buffer = html_buffer.."<h2><p>Left Side<a href=\"?pin=ON1\"> <button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
html_buffer1 = html_buffer1.."<p>Right<br>(Mosquito) <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p></font></head>";
html_buffer1 = html_buffer1.."<h2><p>Left Side<a href=\"?pin=ON3\"> <button>ON</button></a> <a href=\"?pin=OFF3\"><button>OFF</button></a></p>";
html_buffer1 = html_buffer1.."<p>Right<br>(Mosquito) <a href=\"?pin=ON4\"><button>ON</button></a> <a href=\"?pin=OFF4\"><button>OFF</button></a></p></font></head>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(GPIO14, gpio.HIGH);
elseif(_GET.pin == "OFF1")then
gpio.write(GPIO14, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(GPIO12, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(GPIO12, gpio.LOW);
elseif(_GET.pin == "ON3")then
gpio.write(GPIO13, gpio.HIGH);
elseif(_GET.pin == "OFF3")then
gpio.write(GPIO13, gpio.HIGH);
elseif(_GET.pin == "ON4")then
gpio.write(GPIO15, gpio.HIGH);
elseif(_GET.pin == "OFF4")then
gpio.write(GPIO15, gpio.HIGH);
end
print(collectgarbage("count")*1024)
collectgarbage("collect")
receive:close()
end)
end)
In the link above .lua contents exist. My problem is that it gives "init.lua:32: out of memory" error in ESPlorer.
Also i am never sure which GPIO pin is which number in lua file, if someone has a proper pinout map with numbers would really appreciate.