私はLuaにかなり慣れていません。以下の問題を自力で解こうとしたのですが、わかりませんでした。これが私の問題です:
NodeMCU devkit v0.9 で Web サーバーを実行しています。自分のコンピューターで Web サーバーに簡単にアクセスできますが、iPhone を介して、またはrequests
Python でモジュールを使用してサーバーにアクセスしようとするとThe network connection was lost.
、次のファームウェアを使用しているというメッセージが常に表示されます: nodemcu_float_0.9.6-dev_20150704.
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP,30)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<h1> ESP8266 Web Server</h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=led1\"><button>SWITCH LIGHTS</button></a></p>";
buf = buf.."<p>"..gpio.read(led1).."</p>";
local _on,_off = "",""
if(_GET.pin == "led1")then
if(gpio.read(led1) == 1) then
gpio.write(led1, gpio.LOW);
else
gpio.write(led1, gpio.HIGH);
end
else end
client:send(buf);
client:close();
end)
end)