Memory management ESP8266节点内存不足
NodeMCU信息Memory management ESP8266节点内存不足,memory-management,lua,out-of-memory,esp8266,nodemcu,Memory Management,Lua,Out Of Memory,Esp8266,Nodemcu,NodeMCU信息 > Lua 5.1.4 > SDK 2.2.1 > Memory Usage : > Total : 3260490 bytes > Used : 9287 bytes > Remain: 3251203 bytes 尝试使用大json字符串响应发送HTTP响应时出错(json\u response) 代码: 是的,如果你试图发送大量数据,那是行不通的。你需要一件一件地寄这个。显示了两种方法(您可以在此处找到更多参考资料),第一种
> Lua 5.1.4
> SDK 2.2.1
> Memory Usage :
> Total : 3260490 bytes
> Used : 9287 bytes
> Remain: 3251203 bytes
尝试使用大json字符串响应发送HTTP响应时出错(json\u response
)
代码:
是的,如果你试图发送大量数据,那是行不通的。你需要一件一件地寄这个。显示了两种方法(您可以在此处找到更多参考资料),第一种是:
srv = net.createServer(net.TCP)
function receiver(sck, data)
local response = {}
-- if you're sending back HTML over HTTP you'll want something like this instead
-- local response = {"HTTP/1.0 200 OK\r\nServer: NodeMCU on ESP8266\r\nContent-Type: text/html\r\n\r\n"}
response[#response + 1] = "lots of data"
response[#response + 1] = "even more data"
response[#response + 1] = "e.g. content read from a file"
-- sends and removes the first element from the 'response' table
local function send(localSocket)
if #response > 0 then
localSocket:send(table.remove(response, 1))
else
localSocket:close()
response = nil
end
end
-- triggers the send() function again once the first chunk of data was sent
sck:on("sent", send)
send(sck)
end
srv:listen(80, function(conn)
conn:on("receive", receiver)
end)
这里需要进一步的反馈吗?@MarcelStör我想知道是否有办法调整内存以处理一次,尽管我想现在还不可能。
-- a simple HTTP server
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"..json_response)
end)
conn:on("sent", function(sck) sck:close() end)
end)
srv = net.createServer(net.TCP)
function receiver(sck, data)
local response = {}
-- if you're sending back HTML over HTTP you'll want something like this instead
-- local response = {"HTTP/1.0 200 OK\r\nServer: NodeMCU on ESP8266\r\nContent-Type: text/html\r\n\r\n"}
response[#response + 1] = "lots of data"
response[#response + 1] = "even more data"
response[#response + 1] = "e.g. content read from a file"
-- sends and removes the first element from the 'response' table
local function send(localSocket)
if #response > 0 then
localSocket:send(table.remove(response, 1))
else
localSocket:close()
response = nil
end
end
-- triggers the send() function again once the first chunk of data was sent
sck:on("sent", send)
send(sck)
end
srv:listen(80, function(conn)
conn:on("receive", receiver)
end)