srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
connActive = 1
--show web server
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.."<!DOCTYPE HTML>"
buf = buf.."<html><head><meta http-equiv=refresh content=1></head>"
buf = buf.."<title>myAccessPoint</title>"
buf = buf.."<body><h1>myAccesPoint</h1>"
buf = buf.."<h2>"..myip.."</h2>"
buf = buf.."<p>Led ESP <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>"
buf = buf.."<p>Led RIMS <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>"
buf = buf.."<h2> Status Attuale</h2>"
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(pinOnESP, gpio.LOW)
riga = "Led ESP ON"
elseif(_GET.pin == "OFF1")then
gpio.write(pinOnESP, gpio.HIGH)
riga = "Led ESP OFF"
elseif(_GET.pin == "ON2")then
gpio.write(pinOnRims, gpio.HIGH)
riga1 = "Led RIMS ON"
elseif(_GET.pin == "OFF2")then
gpio.write(pinOnRims, gpio.LOW)
riga1 = "Led RIMS OFF"
end
buf = buf..riga
buf = buf.."<h2> </h2>"
buf = buf..riga1
buf = buf.."<h2> </h2>"
buf = buf..string.format("Counter: %d", counter)
buf = buf.."</body></html>"
local function send(sck)
if #buf > 0 then
sck:send(buf)
buf = ""
else
sck:close()
collectgarbage();
--print("Heap2:" .. node.heap())
end
end
client:on("sent", send)
send(client)
end)
collectgarbage();
--print("Heap0:"..node.heap())
end)
The HTML page is refresh every 1 sec but after 50 time the sw crash with the msg "out of memory". The heap start from 30000 and decrease to 5000 before the crash. The function use local variable. Can help me ?
Thanks