Amélioré encore ma procédure de boot ;-)

This commit is contained in:
Christian Zufferey
2019-12-21 15:54:03 +01:00
parent 11ec004436
commit f4ecc8746d
5 changed files with 71 additions and 81 deletions

View File

@@ -1,13 +1,11 @@
-- Scripts à charger après le boot pour démarrer le core system
print("\n boot.lua zf191124.1920 \n")
print("\n boot.lua zf191221.1509 \n")
function boot()
--f= "led_rgb.lua" if file.exists(f) then dofile(f) end
gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
f= "wifi_init.lua" if file.exists(f) then dofile(f) end
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
--f= "web_srv2.lua" if file.exists(f) then dofile(f) end
end
boot()

View File

@@ -1,61 +1,52 @@
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot2.lua zf191220.2319 \n")
print("\n boot2.lua zf191221.1553 \n")
function boot2()
second_chance=nil initz=nil boot=nil
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
if false then
tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function()
xfois =2
blink_LED ()
end)
end
second_chance=nil initz=nil boot=nil zLED=nil
boot2_tmr=nil secrets_wifi=nil wifi_init=nil
cli_ssid=nil cli_pwd=nil ap_ssid=nil ap_pwd=nil
boot2_tmr1=nil wifi_init1=nil wifi_info=nil boot2_go=nil
boot2_tmr=tmr.create()
boot2_tmr:alarm(1*1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
xfois =2 blink_LED ()
else
boot2_tmr:unregister()
flash_led_xfois=nil blink_LED=nil ztmr_Flash_LED=nil
zTm_Off_LED=nil zTm_On_LED=nil nbfois=nil xfois=nil zLED=nil
boot2_tmr=nil secrets_wifi=nil wifi_init=nil
cli_ssid=nil cli_pwd=nil ap_ssid=nil ap_pwd=nil
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
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()
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
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
f=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()
--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
--f= "web_srv2.lua" if file.exists(f) then dofile(f) end
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
f=nil
verbose = true
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
print("BOOOOUM, y'a plus de boot2 !")
wifi_info=nil boot2=nil
print(node.heap())
collectgarbage()
print(node.heap())
end)
--tmr.create():alarm(7*1000, tmr.ALARM_SINGLE, function()
-- print("MUOOOOB !")
-- collectgarbage()
-- print(node.heap())
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
-- f=nil
--end)
end
verbose = true
boot2_tmr2=tmr.create()
boot2_tmr2:alarm(3*1000, tmr.ALARM_SINGLE, function()
print("BOOOOUM, y'a plus de boot2 !")
boot2=nil boot2_tmr2=nil
print(node.heap()) collectgarbage() print(node.heap())
--tmr.create():alarm(7*1000, tmr.ALARM_SINGLE, function()
-- print("MUOOOOB !")
-- collectgarbage()
-- print(node.heap())
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
-- f=nil
--end)
end)
end
boot2()
boot2_tmr1=tmr.create()
boot2_tmr1:alarm(1*1000, tmr.ALARM_AUTO , function()
if boot2_go then
boot2_tmr1:unregister() boot2()
end
end)
--[[

View File

@@ -1,15 +1,10 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
-- programme pour faire clignoter x fois une LED avec un rapport on/off en mS
function flash_led_xfois()
print("\n flash_led_xfois.lua zf1911124.1053 \n")
print("\n flash_led_xfois.lua zf191221.1454 \n")
--zLED=0 --NodeMCU
zLED=4 --EPS-M3
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
zTm_On_LED = 50 zTm_Off_LED = 100 nbfois = 0
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
ztmr_Flash_LED = tmr.create()
function blink_LED ()

View File

@@ -3,38 +3,34 @@
-- 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 zf191030.2015 \n")
print("\n init.lua zf191221.1509 \n")
function initz()
zswitch=3 --switch flash
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
end
gpio.trig(zswitch, "both", hvbouton)
function second_chance()
print("seconde chance...")
f= "repair.lua" if file.exists(f) then dofile(f) end
zLED=4 gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
initalarme=tmr.create()
initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function()
initalarme:alarm(5*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()
gpio.trig(zswitch)
hvbouton=nil
zswitch=nil
reset_reason=nil
f= "boot2.lua" if file.exists(f) then dofile(f) end
end)
end
_, reset_reason = node.bootreason()
print("reset_reason:",reset_reason)
if reset_reason == 0 then
@@ -42,11 +38,6 @@ function initz()
second_chance()
elseif reset_reason == 4 then
print("node.restart")
gpio.trig(zswitch)
hvbouton=nil
second_chance=nil
zswitch=nil
reset_reason=nil
f= "boot.lua" if file.exists(f) then dofile(f) end
f= "boot2.lua" if file.exists(f) then dofile(f) end
elseif reset_reason == 5 then
@@ -62,4 +53,3 @@ function initz()
end
end
initz()

View File

@@ -1,7 +1,7 @@
-- Petit script pour initaliser la couche WIFI
function wifi_init()
print("\n wifi_init.lua zf191201.2329 \n")
print("\n wifi_init.lua zf191221.1536 \n")
-- charge les secrets pour le wifi
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
@@ -12,6 +12,22 @@ function wifi_init()
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true}
wifi.sta.autoconnect(1)
wifi.sta.connect()
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
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...")
else
wifi_init1:unregister() zLED=nil
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
boot2_go = true
end
end)
end
wifi_init()