From abcfe3e18bf9d9a4f859a44e584669a31828a567 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sat, 15 Aug 2020 14:26:57 +0200 Subject: [PATCH] Nouveau set_time, qui sauvegarde toutes les minutes l'heure dans la FLASH --- DeepSleep/Pet_tracker_3/_zlocal_cmd.txt | 4 ++- DeepSleep/Pet_tracker_3/boot.lua | 4 +-- DeepSleep/Pet_tracker_3/set_time2.lua | 33 ++++++++++++++++++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/DeepSleep/Pet_tracker_3/_zlocal_cmd.txt b/DeepSleep/Pet_tracker_3/_zlocal_cmd.txt index 4049e85..5447d91 100644 --- a/DeepSleep/Pet_tracker_3/_zlocal_cmd.txt +++ b/DeepSleep/Pet_tracker_3/_zlocal_cmd.txt @@ -1,6 +1,8 @@ -zf200814.1936 +zf200815.1404 print(ztime()) +print("rtctime: "..rtctime.get()) + dsleep_on() f = "0_wifi_scan.lua" if file.exists(f) then dofile(f) end diff --git a/DeepSleep/Pet_tracker_3/boot.lua b/DeepSleep/Pet_tracker_3/boot.lua index 99e5c7c..77ce385 100644 --- a/DeepSleep/Pet_tracker_3/boot.lua +++ b/DeepSleep/Pet_tracker_3/boot.lua @@ -1,7 +1,7 @@ -- Scripts à charger après le boot pour démarrer son projet function boot() - print("\n boot.lua zf200722.1944 \n") + print("\n boot.lua zf200815.1358 \n") print("On lance le boot...") collectgarbage() print(node.heap()) local f @@ -13,7 +13,7 @@ function boot() -- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason -- http_post(influxdb_url,zarg_boot) - f = "set_time.lua" if file.exists(f) then dofile(f) end + f = "set_time2.lua" if file.exists(f) then dofile(f) end print(node.heap()) collectgarbage() print(node.heap()) f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end diff --git a/DeepSleep/Pet_tracker_3/set_time2.lua b/DeepSleep/Pet_tracker_3/set_time2.lua index 9fef185..cabed49 100644 --- a/DeepSleep/Pet_tracker_3/set_time2.lua +++ b/DeepSleep/Pet_tracker_3/set_time2.lua @@ -1,19 +1,34 @@ -- Scripts pour régler l'horloge quand on est connecté en WIFI +-- et la sauve dans un fichier pour si jamais on n'a pas d'Internet +-- au power boot +-- https://www.unixtimestamp.com/index.php -print("\n set_time2.lua zf200815.1255 \n") +print("\n set_time2.lua zf200815.1426 \n") function set_time() sntp.sync(nil, nil, nil, 1) end -function ztime() - tm = rtctime.epoch2cal(rtctime.get()+2*3600) - print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) +-- function ztime() +-- tm = rtctime.epoch2cal(rtctime.get()+2*3600) +-- print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) +-- end + +function zget_time() + zrtc_time = rtctime.get() + if zrtc_time > 0 then + ztmr_set_time:alarm(60*1000, tmr.ALARM_SINGLE , zget_time) + print("j'ai trouvé l'heure: "..zrtc_time) + file.putcontents("_ztime_", zrtc_time) + -- print(file.getcontents("_ztime_")) + else + ztmr_set_time:alarm(1*1000, tmr.ALARM_SINGLE , zget_time) + print("je cherche l'heure: "..zrtc_time) + end + end +ztmr_set_time = tmr.create() +ztmr_set_time:alarm(1*1000, tmr.ALARM_SINGLE , zget_time) + set_time() - ---[[ -print(ztime()) -]] -