您好 ESP8266/Lua 用户和社区!
我编写了一个(非常)简单的 Web 服务器,它根据请求从文件系统发送文件。
当然有 ara myny 图片,它们传输速度很慢。例如,50KBytes 的 jpg 文件将在 3-4 秒内发送,我认为这太慢了。
经过研究,我发现在 WIFI 网络上发送 1460 字节的数据需要大约 200 毫秒(!)。从调用
到调用发送确认函数
的时间。
我选择 1460 是因为它接近以太网数据包大小的最大长度(+ IP 开销)。发送数据的代码和我的测量点如下:
--func
tion sends file content to web
function web_sendfile(localSocket, filename)
local bytes_send = 0
local t1 = 0
local t2 = 0
-- 回调函数确认数据发送
local function web_sendfile_cnf(loc_socket)
-->> 以微秒为单位获取第二个测试时间戳并打印测试差异
t2 = tmr .now()
print( t2 - t1 ) -- 超过 200 000 微秒 ???
- 文件已存在?
if nil==file.open(filename,"r") then
loc_socket:close()
return
end
-- 转到文件中的下一个位置读取
file.seek("set",bytes_send)
-- 读取部分数据并关闭文件
local fd = file.read(1460)
file.close()
if nil~=fd then
--增加发送字节数和发送数据
bytes_send=bytes_send+string.len(fd)
loc_socket:send(fd)
else
-- 没有东西要发送,关闭套接字
loc_socket:close()
end
-- 释放内存
fd=nil
collectgarbage( );
end-- 回调函数
-->> 以微秒为单位获取第一个测试时间戳
t1 = tmr.now()
-- 发送 http header
localSocket:send(cont_type, web_sendfile_cnf)
end
它不依赖于连接模式(客户端或接入点) ),那个时间总是在 200ms 左右。
我希望这个社区包括经验丰富的用户,他们可以帮助我找到解决这个问题的方法。