자동 업데이트 기능이있는 약간의 Lua 웹 서버를 테스트하고 있습니다. HTML 코드가 매초마다 웹 서버로 리디렉션됩니다. 따라서 클라이언트의 웹 브라우저는 항상 브라우저의 캐시를 사용하여 대신 서버에서 새 데이터를 가져옵니다.NodeMCU 자동 업데이트 기능이있는 초소형 웹 서버가 메모리가 부족합니다.
나는 몇 시간 후에도 하나의 클라이언트 (내 PC 또는 스마트 폰)로 연결하는 경우이 메시지와 함께 NodeMCU 보드 충돌 :
PANIC : 루아 API (에 대한 호출에서 보호되지 않은 오류 SO-WebSrv -Test.lua : 27 : 메모리 부족)
나는 비슷한이 question "메모리 부족"에 대답 마르셀 Stoer에서이 코드를 사용했다.
Marcel 's Lua 코드가 수정되었지만이 코드는 여전히 시간이 지남에 따라 모든 힙 메모리를 먹습니다.
HTML 코드의 새로 고침 빈도가 30 초 미만이면 코드가 힙 메모리를 차지합니다.
그래서 힙 메모리를 일정하게 유지하려면이 코드를 어떻게 수정해야합니까?
감사합니다.
스테판
tmr.alarm(0, 1000, 1, function()
if wifi.sta.getip() == nil then
print("trying to connect to AccessPoint...")
else
own_ip, netmask, gateway=wifi.sta.getip()
print("connected to AccessPoint:")
print("IP Info: \nIP Address of this device: ",own_ip)
print("Netmask: ",netmask)
print("Gateway Addr: ",gateway,"\n")
print("type IP-Address "..own_ip.." into your browser to display SHT-31-website")
tmr.stop(0)
end
end)
counter = 0
srv = net.createServer(net.TCP, 28800)
print("Server created... \n")
srv:listen(80, function(conn)
conn:on("receive", function(sck, request)
local message = {}
counter = counter + 1
message[#message + 1] = "<head> <meta http-equiv=refresh content=1; URL=http://"..own_ip.."> </head>"
message[#message + 1] = "<h1> ESP8266 SHT-31 Web Server Ver 003</h1>"
message[#message + 1] = "<h2>some more text blabla blub"..counter.."</h2>"
local function send(sk)
if #message > 0 then
sk:send(table.remove(message, 1))
else
sk:close()
message = nil
print("Heap Available:" .. node.heap())
end
end
sck:on("sent", send)
send(sck)
end)
end)
근본 원인을 알았습니다. 하지만 먼저 설명에서 기록을 삭제하고 현재 코드가 무엇인지 설명하고 AFAIU에 실패한 코드를 제안합니다. –