NodeMCU のドキュメントと、以前は複数のデータ ストリームの送信を許可していた SDK の変更 (キューに入れられた net.socket:send のように動作する) に関するいくつかの解決済みの問題を読んでいます。
ここ ( #730 ) やあちら ( #993 ) 、さらにはここ ( #999 ) で大きな議論が起こったようです。ただし、ページを表示するために複数の html ファイル (head.html
および など)を読み取れる Web サーバー コードの説得力のある例は見つかりませんでした。body.html
これは、私が適応しようとしたTerryEの例ですが、成功しませんでした:
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on ("receive", function(sck, req)
local response = {}
local f = file.open("head.html","r")
if f ~= nil then
response[#response+1] = file.read()
file.close()
end
local f = file.open("body.html","r")
if f ~= nil then
response[#response+1] = file.read()
file.close()
end
local function sender (sck)
if #response>0 then sck:send(table.remove(response,1))
else sck:close()
end
end
sck:on("sent", sender)
sender(sck)
end )
end )
ESP8266 に接続すると、何も読み込まれず、lua ターミナルからエラーが発生しません。
参考までに、以下head.html
が含まれます。
<html>
<head>
</head>
そしてbody.html
含まれています:
<body>
<h1>Hello World</h1>
</body>
</html>
私は NodeMCU に非常に慣れていません。寛大にしてください。