Refactorisé totalement la partie boot afin d'avoir une seconde chance en cas de plantée par remote
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
-- Petit script pour faire office de crontab pour les
|
||||
--mesures
|
||||
print("\n 0_cron.lua zf190916.2318 \n")
|
||||
print("\n 0_cron.lua zf190917.0033 \n")
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(5*1000, tmr.ALARM_AUTO, function()
|
||||
send_data()
|
||||
end)
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
xfois =2
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
|
||||
blink_LED ()
|
||||
send_data()
|
||||
end)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Petit script pour envoyer les valeurs sur un serveur WEB (InfluxDB)
|
||||
-- via un http GET
|
||||
print("\n 0_send_data.lua zf190916.2254 \n")
|
||||
print("\n 0_send_data.lua zf190917.0030 \n")
|
||||
|
||||
function send_data()
|
||||
print("send_data: ")
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf190916.1523 \n")
|
||||
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
boottimer1=tmr.create()
|
||||
boottimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
end)
|
||||
end
|
||||
print("\n boot.lua zf190916.2359 \n")
|
||||
|
||||
-- charge ses propres secrets
|
||||
f= "secrets_energy.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -23,14 +13,3 @@ f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
f= "telnet_srv2.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
|
||||
|
||||
f= "0_get_data.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=nil
|
||||
--heartbeat=nil
|
||||
heartbeat()
|
||||
|
||||
|
||||
|
||||
|
||||
22
Mesures/solar_pv_energy/boot2.lua
Normal file
22
Mesures/solar_pv_energy/boot2.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot2.lua zf190917.0030 \n")
|
||||
|
||||
second_chance=nil
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
boottimer1=tmr.create()
|
||||
boottimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
end)
|
||||
end
|
||||
|
||||
f= "0_get_data.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=nil
|
||||
heartbeat=nil
|
||||
--heartbeat()
|
||||
17
Mesures/solar_pv_energy/cat.lua
Normal file
17
Mesures/solar_pv_energy/cat.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf180826.1109 \n")
|
||||
|
||||
function cat(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
zfilei = file.open(zfile, "r")
|
||||
i=1
|
||||
zline=file.readline()
|
||||
repeat
|
||||
print(i..": "..string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
until zline== nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
15
Mesures/solar_pv_energy/dir.lua
Normal file
15
Mesures/solar_pv_energy/dir.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- fonction dir() pour afficher les fichiers dans la flash
|
||||
print("\n dir.lua zf180826.1019 \n")
|
||||
|
||||
function dir()
|
||||
print("\n-------------------------------")
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
|
||||
end
|
||||
print("-------------------------------")
|
||||
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
|
||||
end
|
||||
|
||||
dir()
|
||||
@@ -3,15 +3,16 @@
|
||||
-- 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 zf190621.1612 \n")
|
||||
print("\n init.lua zf190917.0001 \n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
-- gpio.trig(zswitch, "none")
|
||||
initalarme:unregister()
|
||||
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)
|
||||
@@ -20,10 +21,17 @@ function second_chance()
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
-- tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function()
|
||||
initalarme:alarm(4*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()
|
||||
@@ -39,15 +47,17 @@ elseif reset_reason == 4 then
|
||||
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
|
||||
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
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
-- f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
|
||||
|
||||
|
||||
5
Mesures/solar_pv_energy/restart.lua
Normal file
5
Mesures/solar_pv_energy/restart.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
--Redémarre le NodeMCU
|
||||
|
||||
print("\n restart.lua zf181120.002 \n")
|
||||
|
||||
node.restart()
|
||||
6
Mesures/solar_pv_energy/start.lua
Normal file
6
Mesures/solar_pv_energy/start.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- Scripts pour renommer boot2z.lua quand cela marche
|
||||
|
||||
print("\n start.lua zf190917.0017\n")
|
||||
|
||||
--file.remove("boot2.lua")
|
||||
file.rename("boot2z.lua","boot2.lua")
|
||||
6
Mesures/solar_pv_energy/stop.lua
Normal file
6
Mesures/solar_pv_energy/stop.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- Scripts pour renommer boot2.lua quand cela plante
|
||||
|
||||
print("\n stop.lua zf190917.0017\n")
|
||||
|
||||
--file.remove("boot2z.lua")
|
||||
file.rename("boot2.lua","boot2z.lua")
|
||||
Reference in New Issue
Block a user