From 235c5fe8c27975876530899ec2f9505b26830c4d Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Tue, 16 Jun 2020 16:18:54 +0200 Subject: [PATCH] =?UTF-8?q?Refactoris=C3=A9=20compl=C3=A8tement=20mon=20bo?= =?UTF-8?q?ot.lua,=20le=20debug=20recording=20avec=20timestamp=20fait=20pa?= =?UTF-8?q?rtie=20maintenant=20du=20boot=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../energy/transfo_courant_clip_1p_1/boot.lua | 66 ++++++++++--------- .../{ => oldies}/0_rec_boot.lua | 24 ++----- 2 files changed, 42 insertions(+), 48 deletions(-) rename Mesures/energy/transfo_courant_clip_1p_1/{ => oldies}/0_rec_boot.lua (61%) diff --git a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua index c76eb06..7621cf5 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua @@ -1,37 +1,17 @@ -- Scripts à charger après le boot pour démarrer son projet -print("\n boot.lua zf200615.2226 \n") - --- function zztime_format(ztime) --- local tm = rtctime.epoch2cal(ztime + 2*3600) --- return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) --- end --- --- function debug_rec(zdebug) --- local sec, usec = rtctime.get() --- file.open("00_debug.txt", "a+") --- file.writeline(zztime_format(sec).."."..usec..", "..zdebug) --- file.close() --- end - - - function boot() - verbose = false + print("\n boot.lua zf200616.1613 \n") print("On lance le boot...") collectgarbage() print(node.heap()) - - f = "0_rec_boot.lua" if file.exists(f) then dofile(f) end + local f + f = "0_http_post.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()) - function http_post() local z end - -- local _, boot_reason = node.bootreason() - -- zarg_boot= "energy,memory=boot_"..yellow_id.." ram="..node.heap().."\n" - -- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason - -- http_post(influxdb_url,zarg_boot) + local _, boot_reason = node.bootreason() + zarg_boot= "energy,memory=boot_"..yellow_id.." ram="..node.heap().."\n" + zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason + http_post(influxdb_url,zarg_boot) -- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end -- print(node.heap()) collectgarbage() print(node.heap()) @@ -46,12 +26,38 @@ function boot() -- f="0_cron.lua" if file.exists(f) then dofile(f) end -- collectgarbage() print(node.heap()) - print("verbose:",verbose) print("le boot est lancé...") + verbose = false + print("verbose: ",verbose,"\nle boot est lancé...") gpio.write(zLED, gpio.HIGH) - f=nil boot=nil - collectgarbage() print(node.heap()) + boot=nil end + +function debug_rec(zdebug) + local sec, usec = rtctime.get() local tm = rtctime.epoch2cal(sec + 2*3600) + local ztm = string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]) + file.open("00_debug.txt", "a+") file.writeline(ztm.."."..usec..", "..zdebug) file.close() +end + +function rec_boot() + sntp.sync(nil, nil, nil, 1) + tmr_rec_boot1=tmr.create() + tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function() + print("beep...") + if rtctime.get() > 0 then + tmr_rec_boot1:unregister() + print("Voilà on à l'heure, on peut enregistrer la raison du boot...") + local _, zboot_reason, zboot_detail = node.bootreason() + debug_rec("boot reason: "..zboot_reason) + tmr_rec_boot1=nil rec_boot=nil + collectgarbage() print(node.heap()) + end + end) +end + +verbose=true +rec_boot() boot() +collectgarbage() print(node.heap()) --[[ diff --git a/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/oldies/0_rec_boot.lua similarity index 61% rename from Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua rename to Mesures/energy/transfo_courant_clip_1p_1/oldies/0_rec_boot.lua index 23c1c2c..c1b165e 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/oldies/0_rec_boot.lua @@ -1,22 +1,14 @@ -- Scripts qui permet d'enregistrer la raison du boot dans la flash -print("\n 0_rec_boot.lua zf200615.2229 \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) - local tm = rtctime.epoch2cal(ztime + 2*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() + print("\n 0_rec_boot.lua zf200616.1400 \n") + + local 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 @@ -25,15 +17,11 @@ function rec_boot() if verbose then print(ztime_format(rtctime.get()+3600)) end if rtctime.get() > 0 then + tmr_rec_boot1:unregister() print("Voilà on à l'heure, on peut enregistrer la raison du boot...") - tmr_rec_boot1:unregister() tmr_rec_boot1=nil - local sec, usec = rtctime.get() local _, zboot_reason, zboot_detail = node.bootreason() - file.open("00_debug.txt", "a+") - file.writeline(string.rep(".",20)) - file.writeline(ztime_format(sec).."."..usec..", boot reason: "..zboot_reason) - file.close() - ztime_format=nil rec_boot=nil + debug_rec("boot reason: "..zboot_reason) + tmr_rec_boot1=nil rec_boot=nil collectgarbage() print(node.heap()) end