Corrigé le port de la LED sur le SonOff et refactorisé encore une fois la procédure de boot avec le WIFI_init. Le mode AP est maintenant au tout début de la phase de boot, afin de pouvoir voir l'adresse IP avant que boot2 ne plante
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf191221.1509 \n")
|
||||
print("\n boot.lua zf200101.1235 \n")
|
||||
|
||||
function boot()
|
||||
gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil
|
||||
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_init.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
boot()
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot2.lua zf191228.2303 \n")
|
||||
print("\n boot2.lua zf200101.1240 \n")
|
||||
|
||||
function boot2()
|
||||
print("boot2 starting...")
|
||||
second_chance=nil initz=nil boot=nil zLED=nil
|
||||
boot2_tmr=nil secrets_wifi=nil wifi_init=nil
|
||||
cli_ssid=nil cli_pwd=nil
|
||||
boot2_tmr1=nil wifi_init1=nil wifi_info=nil boot2_go=nil
|
||||
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
collectgarbage()
|
||||
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
boot2_tmr3=tmr.create()
|
||||
boot2_tmr3:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) boot2_tmr3=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
--f= "0_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -32,7 +19,7 @@ function boot2()
|
||||
verbose = true
|
||||
|
||||
boot2_tmr2=tmr.create()
|
||||
boot2_tmr2:alarm(3*1000, tmr.ALARM_SINGLE, function()
|
||||
boot2_tmr2:alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de boot2 !")
|
||||
boot2=nil boot2_tmr2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
-- le script repair.lua pendant xx secondes avant de continuer
|
||||
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
|
||||
|
||||
print("\n init.lua zf191221.1509 \n")
|
||||
print("\n init.lua zf200101.1244 \n")
|
||||
|
||||
function initz()
|
||||
zswitch=3 --switch flash
|
||||
zswitch=3 --switch flash ou SonOff
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
@@ -20,9 +20,11 @@ function initz()
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
zLED=4 gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(5*1000, tmr.ALARM_SINGLE, function()
|
||||
initalarme:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf191222.2356 \n")
|
||||
print("\n wifi_init.lua zf200101.1244 \n")
|
||||
-- charge les secrets pour le wifi
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
|
||||
wifi.setmode(wifi.STATION,true)
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true}
|
||||
wifi.sta.autoconnect(1)
|
||||
wifi.sta.connect()
|
||||
wifi.sta.autoconnect(1) wifi.sta.connect()
|
||||
|
||||
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
if node_id == nil then node_id = "generic" end
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
|
||||
wifi_init2=tmr.create()
|
||||
wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) wifi_init2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
i=1
|
||||
wifi_init1=tmr.create()
|
||||
wifi_init1:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
@@ -18,7 +32,7 @@ function wifi_init()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
i=i+1
|
||||
if i > 10 then
|
||||
if i > 15 then
|
||||
i=nil wifi_init1:unregister()
|
||||
print("booum!")
|
||||
enduser_setup.start(function()
|
||||
@@ -34,3 +48,15 @@ function wifi_init()
|
||||
end
|
||||
|
||||
wifi_init()
|
||||
|
||||
--[[
|
||||
zLED=7
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
|
||||
zSWITCH=3
|
||||
gpio.mode(zSWITCH, gpio.INPUT)
|
||||
print(gpio.read(zSWITCH))
|
||||
|
||||
]]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf191221.1509 \n")
|
||||
print("\n boot.lua zf200101.1235 \n")
|
||||
|
||||
function boot()
|
||||
gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil
|
||||
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_init.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
boot()
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot2.lua zf191228.2303 \n")
|
||||
print("\n boot2.lua zf200101.1240 \n")
|
||||
|
||||
function boot2()
|
||||
print("boot2 starting...")
|
||||
second_chance=nil initz=nil boot=nil zLED=nil
|
||||
boot2_tmr=nil secrets_wifi=nil wifi_init=nil
|
||||
cli_ssid=nil cli_pwd=nil
|
||||
boot2_tmr1=nil wifi_init1=nil wifi_info=nil boot2_go=nil
|
||||
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
collectgarbage()
|
||||
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
boot2_tmr3=tmr.create()
|
||||
boot2_tmr3:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) boot2_tmr3=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
--f= "0_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -32,7 +19,7 @@ function boot2()
|
||||
verbose = true
|
||||
|
||||
boot2_tmr2=tmr.create()
|
||||
boot2_tmr2:alarm(3*1000, tmr.ALARM_SINGLE, function()
|
||||
boot2_tmr2:alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de boot2 !")
|
||||
boot2=nil boot2_tmr2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
-- le script repair.lua pendant xx secondes avant de continuer
|
||||
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
|
||||
|
||||
print("\n init.lua zf191221.1509 \n")
|
||||
print("\n init.lua zf200101.1223 \n")
|
||||
|
||||
function initz()
|
||||
zswitch=3 --switch flash
|
||||
zswitch=3 --switch flash ou SonOff
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
@@ -20,9 +20,11 @@ function initz()
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
zLED=4 gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
--zLED=4 -- NodeMCU
|
||||
zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(5*1000, tmr.ALARM_SINGLE, function()
|
||||
initalarme:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf191222.2356 \n")
|
||||
print("\n wifi_init.lua zf200101.1236 \n")
|
||||
-- charge les secrets pour le wifi
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
|
||||
wifi.setmode(wifi.STATION,true)
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true}
|
||||
wifi.sta.autoconnect(1)
|
||||
wifi.sta.connect()
|
||||
wifi.sta.autoconnect(1) wifi.sta.connect()
|
||||
|
||||
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
if node_id == nil then node_id = "generic" end
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
|
||||
wifi_init2=tmr.create()
|
||||
wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) wifi_init2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
--zLED=4 -- NodeMCU
|
||||
zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
i=1
|
||||
wifi_init1=tmr.create()
|
||||
wifi_init1:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
@@ -18,7 +32,7 @@ function wifi_init()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
i=i+1
|
||||
if i > 10 then
|
||||
if i > 15 then
|
||||
i=nil wifi_init1:unregister()
|
||||
print("booum!")
|
||||
enduser_setup.start(function()
|
||||
@@ -34,3 +48,15 @@ function wifi_init()
|
||||
end
|
||||
|
||||
wifi_init()
|
||||
|
||||
--[[
|
||||
zLED=7
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
|
||||
zSWITCH=3
|
||||
gpio.mode(zSWITCH, gpio.INPUT)
|
||||
print(gpio.read(zSWITCH))
|
||||
|
||||
]]
|
||||
|
||||
Reference in New Issue
Block a user