ESP8266 が再起動し続けます。
これは私のinit.luaです:
cfg={}
cfg.ssid="Sensor"
cfg.auth=AUTH_OPEN
wifi.ap.config(cfg)
wifi.setmode(wifi.STATION)
wifi.sta.getap(function(t)
available_aps = ""
if t then
for k,v in pairs(t) do
ap = string.format("%-10s",k)
ap = trim(ap)
available_aps = available_aps .. "<option value='".. ap .."'>".. ap .."</option>"
end
setup_server(available_aps)
end
end)
function setup_server(aps)
wifi.setmode(wifi.SOFTAP)
srv=net.createServer(net.TCP)
srv:listen(80,function(client)
client:on("receive",function(client,request)
wifi.sta.getap(function(t)
available_aps = ""
if t then
for k,v in pairs(t) do
ap = string.format("%-10s",k)
ap = trim(ap)
available_aps = available_aps .. "<option value='".. ap .."'>".. ap .."</option>"
end
end
end)
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 = "<html><body>"
buf = buf .. "<h3>Config</h3><br>"
buf = buf .. "<form method='get' action='http://" .. wifi.ap.getip() .."'>"
buf = buf .. "Select access point: <select name='ap'>" .. available_aps .. "</select><br>"
buf = buf .. "Enter wifi password: <input type='password' name='psw'></input><br>"
buf = buf .. "Server-IP: <input name='ipTCP' value='192.168.178.1'></input><br>"
buf = buf .. "<br><button type='submit'>Save</button>"
buf = buf .. "</form></body></html>"
local _on,_off = "",""
if(_GET.pin == "ON1")then
buf = buf.."NICE";
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
end
再起動後に毎回クラッシュするのはなぜですか?
これをトラブルシューティングするにはどうすればよいですか?
Lua 5.1.4 を搭載した NodeMCU 0.9.5 ビルド 20150318 があります。
別の lua スクリプトは正常に実行されています。