NodeMCU wifi在运行数小时后断开连接

我刚开始使用带有Lua的NodeMCU。首先,我正在尝试使用NodeMCU作为UDP服务器制作一个简单的wifi控制继电器。问题是,在运行几个小时后,我无法连接到板子。我尝试使用ping命令ping板子,但无响应。如果我重新启动板子,它会再次工作。有什么想法吗?谢谢。

这是我的Lua脚本:

pin_relay = 1
port = 1310
state = 0
gpio.mode(pin_relay, gpio.OUTPUT)
gpio.write(pin_relay, gpio.HIGH)

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID", "password")
wifi.sta.connect()
wifi.sta.setip({ip="192.168.1.200",netmask="255.255.255.0",gateway="192.168.1.1"})
print("ESP8266 mode is: " .. wifi.getmode())
print("The module MAC address is: " .. wifi.ap.getmac())
print("Config done, IP is "..wifi.sta.getip())

srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
   if pl=="switch" then
    if state == 0 then
        gpio.write(pin_relay,gpio.LOW)
        state = 1
    elseif state == 1 then
        gpio.write(pin_relay,gpio.HIGH)
        state = 0
    end
   end
end)
srv:listen(port)
点赞
用户2252164
用户2252164

原文:

It turns out that my wireless router is the problem.. when i tried a different router, it runs no problem until now. Been running for 3 days now :)

翻译:

原来我的无线路由器有问题...当我换了一个不同的路由器后,它一直运行得非常顺畅,直到现在为止已经运行了3天 :)
2017-01-14 04:09:26