From b0b67eaa00c4f973ed3b1c7ca83285589e13c04a Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Thu, 11 Jun 2020 11:55:49 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=C3=A9,=20enfin,=20la=20possibilit=C3=A9?= =?UTF-8?q?=20d'enregistrer=20dans=20la=20FLASH=20la=20raison=20du=20boot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0_btn_flipflop.lua | 6 +-- .../transfo_courant_clip_1p_1/0_rec_boot.lua | 51 +++++++++++++++++++ .../energy/transfo_courant_clip_1p_1/boot.lua | 25 +++------ .../transfo_courant_clip_1p_1/wifi_init.lua | 4 +- 4 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua diff --git a/Mesures/energy/transfo_courant_clip_1p_1/0_btn_flipflop.lua b/Mesures/energy/transfo_courant_clip_1p_1/0_btn_flipflop.lua index b455aa9..c016469 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/0_btn_flipflop.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/0_btn_flipflop.lua @@ -2,14 +2,14 @@ -- Très intéressant la techno utilisée ici pour enlever les rebonds du micro switch -- dans la variable b se trouve l'heure à laquelle l'interruption est arrivée, il suffit juste alors de lui mettre un petit délai de 300mS -print("\n 0_btn_flipflop.lua zf200216.1457 \n") +print("\n 0_btn_flipflop.lua zf200611.1153 \n") gpio.write(zLED,1) gpio.mode(zLED,gpio.OUTPUT) gpio.mode(zBTN,gpio.INT) d=tmr.now() -function zled (a,b,c) +function z_btn_led (a,b,c) --print("a: "..a..",b: "..b..",c: "..c) if b-d > 300*1000 then if verbose then @@ -24,4 +24,4 @@ function zled (a,b,c) end end -gpio.trig(zBTN, "down", zled) +gpio.trig(zBTN, "down", z_btn_led) diff --git a/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua new file mode 100644 index 0000000..73874db --- /dev/null +++ b/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua @@ -0,0 +1,51 @@ +-- Scripts qui permet d'enregistrer la raison du boot dans la flash + +print("\n 0_rec_boot.lua zf200611.1151 \n") + +-- Problématique: +-- Afin de pouvoir enregistrer l'heure du boot dans la FLASH il faut +-- en premier récupérer l'heure sur Internet et après seulement on peut +-- faire l'enregistrement dans la FLASH + +function rec_boot() + + sntp.sync(nil, nil, nil, 1) + + function ztime_format(ztime) + tm = rtctime.epoch2cal(ztime + 3600) + return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) + end + + tmr_rec_boot1=tmr.create() + tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function() + if verbose then print("tmr_rec_boot1........................") end + if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end + + if verbose then print(rtctime.get()) end + if verbose then print(ztime_format(rtctime.get()+3600)) end + + if rtctime.get() > 0 then + print("Voilà on à l'heure, on peut enregistrer...") + tmr_rec_boot1:unregister() tmr_rec_boot1=nil + file.open("00_boot_reason.txt", "a+") + file.writeline(ztime_format(rtctime.get()+3600)) + _, zboot_reason, zboot_detail = node.bootreason() + file.writeline(zboot_reason,zboot_detail) + file.close() + zboot_detail=nil zboot_reason=nil + ztime_format=nil rec_boot=nil + end + + if verbose then print("End tmr_rec_boot1:") end + collectgarbage() + if verbose then print(node.heap()) end + end) + +end +rec_boot() + + +--[[ +verbose = true +verbose = false +]] diff --git a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua index 625107f..5e545bd 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua @@ -1,12 +1,9 @@ -- Scripts à charger après le boot pour démarrer son projet -print("\n boot.lua zf200610.2238 \n") +print("\n boot.lua zf200611.1053 \n") -- function ztime_stamp() return tmr.now()/1000000 end - - - -- sntp.sync(nil, nil, nil, 1) -- -- function ztime_format(ztime) @@ -26,24 +23,14 @@ print("\n boot.lua zf200610.2238 \n") -- znanosec= zsec*1000000000 -- print(znanosec) - - - - - - - - - - - - - function boot() verbose = true print("On lance le boot...") collectgarbage() print(node.heap()) + f = "0_rec_boot.lua" if file.exists(f) then dofile(f) end + collectgarbage() print(node.heap()) + f = "0_http_post.lua" if file.exists(f) then dofile(f) end collectgarbage() print(node.heap()) @@ -63,8 +50,8 @@ function boot() -- f="0_get_power.lua" if file.exists(f) then dofile(f) end -- collectgarbage() print(node.heap()) - f="0_cron.lua" if file.exists(f) then dofile(f) end - collectgarbage() print(node.heap()) + -- f="0_cron.lua" if file.exists(f) then dofile(f) end + -- collectgarbage() print(node.heap()) print("verbose:",verbose) print("le boot est lancé...") gpio.write(zLED, gpio.HIGH) diff --git a/Mesures/energy/transfo_courant_clip_1p_1/wifi_init.lua b/Mesures/energy/transfo_courant_clip_1p_1/wifi_init.lua index e76660a..551d5cb 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/wifi_init.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/wifi_init.lua @@ -1,7 +1,7 @@ -- Petit script pour initaliser la couche WIFI function wifi_init() - print("\n wifi_init.lua zf200610.2236 \n") + print("\n wifi_init.lua zf200611.1053 \n") f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end f= "secrets_project.lua" if file.exists(f) then dofile(f) end @@ -14,7 +14,7 @@ function wifi_init() print(node.heap()) collectgarbage() print(node.heap()) -- f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end - f="0_tst4_socat.lua" if file.exists(f) then dofile(f) end + -- f="0_tst4_socat.lua" if file.exists(f) then dofile(f) end -- f= "web_srv2.lua" if file.exists(f) then dofile(f) end print(node.heap()) collectgarbage() print(node.heap())