NodeMCU 服务器没有响应
NodeMCU Server not responding
使用 NodeMCU 作为 wifi 接入点。接入点正在工作,我可以连接到它,当我访问 192.168.4.1 时,print(payload)
我的请求被打印到控制台,所以一切正常,但 iOS 上的 Safari 抱怨服务器已停止回应。
function initialConnection()
wifi.setmode(wifi.SOFTAP)
-- Setup as Access Point
print(wifi.ap.config({
ssid = "SSIDNAME",
pwd = "SSIDPASSWORD",
auth = wifi.OPEN
}))
server = net.createServer(net.TCP, 30)
if server then
server:listen(80, function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMCU!!! </h1>")
end)
end)
end
-- statusLed:flashBlue( 100 )
end
这是打印到控制台的请求
GET /?gddf HTTP/1.1
Host: 192.168.4.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1
Accept-Language: en-us
DNT: 1
Cache-Control: max-age=0
测试一下:
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)end)
使用 NodeMCU 作为 wifi 接入点。接入点正在工作,我可以连接到它,当我访问 192.168.4.1 时,print(payload)
我的请求被打印到控制台,所以一切正常,但 iOS 上的 Safari 抱怨服务器已停止回应。
function initialConnection()
wifi.setmode(wifi.SOFTAP)
-- Setup as Access Point
print(wifi.ap.config({
ssid = "SSIDNAME",
pwd = "SSIDPASSWORD",
auth = wifi.OPEN
}))
server = net.createServer(net.TCP, 30)
if server then
server:listen(80, function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMCU!!! </h1>")
end)
end)
end
-- statusLed:flashBlue( 100 )
end
这是打印到控制台的请求
GET /?gddf HTTP/1.1
Host: 192.168.4.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1
Accept-Language: en-us
DNT: 1
Cache-Control: max-age=0
测试一下:
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)end)