首页 文章

几个小时后NodeMCU wifi断开连接

提问于
浏览
0

我刚开始使用NodeaU和Lua . 首先,我尝试使用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)

1 回答

  • 0

    事实证明我的无线路由器是问题..当我尝试不同的路由器时,它直到现在都没有问题 . 已经运行了3天:)

相关问题