在 ESP8266 NodeMCU 上尝试连接强制门户时接收到结构错误

我正在尝试让 ESP8266 上的强制门户工作,但我一直收到这个错误。

"PANIC: unprotected error in call to Lua API (dnsServerInit.lua:11: attempt to index global 'struct' (a nil value))"

local dns_ip = ...

local s = net.createUDPSocket();
s:on("receive", function(con, req, port, ip)
    local ix = 13
    while req:byte(ix) > 0  do
        ix = ix + 1 + req:byte(ix)
    end

    if "\0\1" == req:sub(ix + 1, ix + 2) then
        local id, nr, query, check, class = struct.unpack("c2xxc2xxxxxxc"..(ix-12).."i2c2", req)
        if id then
            con:send(port, ip, id .. "\129\128" .. nr .. "\0\1\0\0\0\0" .. query .. "\0\1" ..
                                class .. "\192\12\0\1" .. class .. "\0\0\0\218\0\4" .. dns_ip)
        end
    end
end)

s:on("sent", function(con)
    con:close()
    con:listen(53)
end)

s:listen(53)

return s
点赞
用户2858170
用户2858170

错误是由这一行引起的

local id, nr, query, check, class = struct.unpack("c2xxc2xxxxxxc"..(ix-12).."i2c2", req)

其中你索引了一个名为struct的全局变量。 该变量为nil,因此不允许对其进行索引。

您可能没有在构建NodeMCU固件时包含struct模块。

使用struct重新构建您的固件。

2019-08-20 14:16:13