Files
Christian Zufferey a9abd91aa5 Complètement refactorisé la procédure de boot (initz.lua)
Maintenant les *secrets* sont chargés au moment de l'init.lua et
l'aiguillage du boot *dsleep* se fait en fonction de la variable
node_mode. Ainsi c'est le même iniz.lua et wifi_init.lua pour les
différents projets NodeMCU.
Reste encore à faire de pouvoir sauver deux possibilités de connexions
WIFI dans les secrets_wifi afin de pouvoir se connecter sur le
WIFI du smartphone en cas de dépannage sur le terrain
2020-08-16 14:58:54 +02:00

106 lines
3.1 KiB
Lua

--Script de bootstrap, test au moment du boot qui a été la cause de boot.
-- Si la cause est un power on ou une connexion depuis l'IDE, alors
-- 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 zf200816.1421 \n")
verbose = true
function initz()
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())
print("initz_end out...")
end
function hvbouton()
gpio.trig(zswitch, "none") zswitch=nil
print("hvbouton...")
print(tmr.now())
if tmr.now() > 5000000 then
file.putcontents("_setup_wifi_", "toto")
print("on a demandé le setup wifi !")
end
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
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
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)
if reset_reason == 0 then
print("power on")
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
second_chance()
end
elseif reset_reason == 4 then
print("node.restart")
initz_end()
elseif reset_reason == 5 then
print("dsleep wake up")
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
initz_end()
end
elseif reset_reason == 6 then
print("external reset")
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
initz_end()
end
else
print("autre raison")
second_chance()
end
end
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
initz()
--[[
zLED=7
gpio.mode(zLED, gpio.OUTPUT)
gpio.write(zLED, gpio.LOW) -- actif !
gpio.write(zLED, gpio.HIGH)
zBTN=3
gpio.mode(zBTN, gpio.INPUT)
print(gpio.read(zBTN))
zRELAY=6
gpio.mode(zRELAY, gpio.OUTPUT)
gpio.write(zRELAY, gpio.HIGH) -- actif !
gpio.write(zRELAY, gpio.LOW)
]]