Bien refactorisé ma procédure de boot, mais cela n'est pas encore terminé
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf200106.2313 \n")
|
||||
print("\n boot.lua zf200107.1443 \n")
|
||||
|
||||
function boot()
|
||||
|
||||
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
if zswitch ~= nill then
|
||||
gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil
|
||||
end
|
||||
|
||||
@@ -3,49 +3,54 @@
|
||||
-- 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 zf200101.1301 \n")
|
||||
print("\n init.lua zf200107.1525 \n")
|
||||
|
||||
function initz()
|
||||
zswitch=3 --switch flash ou SonOff
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
initalarme:unregister() initalarme2:unregister()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
function initz_end()
|
||||
print("initz_end...")
|
||||
f= "wifi_init.lua" if file.exists(f) then dofile(f) end
|
||||
f=nil initz=nil second_chance=nil hvbouton=nil initz_end=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none") zswitch=nil
|
||||
print("hvbouton...")
|
||||
initalarme1:unregister() initalarme1=nil second_chance=nil
|
||||
gpio.write(zLED, gpio.HIGH) zLED=nil
|
||||
reset_reason="hvbouton"
|
||||
initz_end()
|
||||
end
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
--zLED=4 -- NodeMCU
|
||||
zLED=7 -- SonOff
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme1=tmr.create()
|
||||
initalarme1:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.write(zLED, gpio.HIGH) zLED=nil
|
||||
gpio.trig(zswitch, "none") zswitch=nil
|
||||
reset_reason="seconde_chance"
|
||||
initz_end()
|
||||
end)
|
||||
zswitch=3 --switch flash ou SonOff
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
end
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason:",reset_reason)
|
||||
print("reset_reason: ",reset_reason)
|
||||
if reset_reason == 0 then
|
||||
print("power on")
|
||||
second_chance()
|
||||
elseif reset_reason == 4 then
|
||||
print("node.restart")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
initz_end()
|
||||
elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
initz_end()
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf200106.2322 \n")
|
||||
print("\n wifi_init.lua zf200107.1530 \n")
|
||||
|
||||
function wifi_init_end()
|
||||
wifi_init1:unregister() zLED=nil i=nil
|
||||
@@ -9,7 +9,9 @@ function wifi_init()
|
||||
f=nil secrets_wifi=nil cli_pwd=nil cli_ssid=nil
|
||||
wifi_init1=nil wifi_init=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
boot2_go = true
|
||||
|
||||
--boot2_go = true
|
||||
|
||||
wifi_init_end=nil
|
||||
end
|
||||
|
||||
@@ -40,21 +42,16 @@ function wifi_init()
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
--zLED=4 -- NodeMCU
|
||||
zLED=7 -- SonOff
|
||||
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()
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
|
||||
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
|
||||
i=i+1
|
||||
if i > 15 then
|
||||
if i > 5 then
|
||||
print("pas de wifi :-(")
|
||||
wifi_init2:unregister() wifi_init2=nil
|
||||
wifi_init_end()
|
||||
|
||||
Reference in New Issue
Block a user