我有一個非常簡單的Web服務器來切換中繼。它有時會起作用,而其他時候會建立連接,但超時。如果我重新加載頁面並重試。它會再次開始工作。有任何想法嗎?
下面是代碼:帶有ESP8266的NodeMCU工作...有時
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,data)
conn:send("HTTP/1.1 200 OK\r\n\r\n")
path = string.find(data, "chk=on")
print(path)
if path == nil then
print("off")
gpio.write(1, gpio.LOW)
end
if path ~= nil then
print("on")
gpio.write(1, gpio.HIGH)
end
conn:send("<h1>Relay Control</h1>")
conn:send("<form action='/' method='post'>")
conn:send("<input type='checkbox' value='on' name='chk'>")
conn:send("<input type='submit' value='Submit'>")
conn:send("</form>")
path = nil
data = nil
end)
conn:on("sent",function(conn) conn:close() end)
end)