diff --git a/Mesures/solar_pv_energy/0_cron.lua b/Mesures/solar_pv_energy/0_cron.lua index e60c0a1..073c089 100644 --- a/Mesures/solar_pv_energy/0_cron.lua +++ b/Mesures/solar_pv_energy/0_cron.lua @@ -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) diff --git a/Mesures/solar_pv_energy/0_send_data.lua b/Mesures/solar_pv_energy/0_send_data.lua index 9a74ea5..d0b7007 100644 --- a/Mesures/solar_pv_energy/0_send_data.lua +++ b/Mesures/solar_pv_energy/0_send_data.lua @@ -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: ") diff --git a/Mesures/solar_pv_energy/boot.lua b/Mesures/solar_pv_energy/boot.lua index 931ba86..bc3a7fd 100644 --- a/Mesures/solar_pv_energy/boot.lua +++ b/Mesures/solar_pv_energy/boot.lua @@ -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() - - - diff --git a/Mesures/solar_pv_energy/boot2.lua b/Mesures/solar_pv_energy/boot2.lua new file mode 100644 index 0000000..c4c1b70 --- /dev/null +++ b/Mesures/solar_pv_energy/boot2.lua @@ -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() diff --git a/Mesures/solar_pv_energy/cat.lua b/Mesures/solar_pv_energy/cat.lua new file mode 100644 index 0000000..7c309b9 --- /dev/null +++ b/Mesures/solar_pv_energy/cat.lua @@ -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 diff --git a/Mesures/solar_pv_energy/dir.lua b/Mesures/solar_pv_energy/dir.lua new file mode 100644 index 0000000..8bf9414 --- /dev/null +++ b/Mesures/solar_pv_energy/dir.lua @@ -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() diff --git a/Mesures/solar_pv_energy/initz.lua b/Mesures/solar_pv_energy/initz.lua index ab33e85..c5aa649 100644 --- a/Mesures/solar_pv_energy/initz.lua +++ b/Mesures/solar_pv_energy/initz.lua @@ -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 + diff --git a/Mesures/solar_pv_energy/restart.lua b/Mesures/solar_pv_energy/restart.lua new file mode 100644 index 0000000..50a1ebd --- /dev/null +++ b/Mesures/solar_pv_energy/restart.lua @@ -0,0 +1,5 @@ +--Redémarre le NodeMCU + +print("\n restart.lua zf181120.002 \n") + +node.restart() diff --git a/Mesures/solar_pv_energy/start.lua b/Mesures/solar_pv_energy/start.lua new file mode 100644 index 0000000..7ad3a72 --- /dev/null +++ b/Mesures/solar_pv_energy/start.lua @@ -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") diff --git a/Mesures/solar_pv_energy/stop.lua b/Mesures/solar_pv_energy/stop.lua new file mode 100644 index 0000000..a3a5dd6 --- /dev/null +++ b/Mesures/solar_pv_energy/stop.lua @@ -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")