From d9d92f34bac2b8e0c654693c4e211dce1a25463a Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Wed, 22 Jul 2020 11:49:42 +0200 Subject: [PATCH] =?UTF-8?q?Voil=C3=A0=20mon=20dsleep=20commence=20enfin=20?= =?UTF-8?q?=C3=A0=20fonctionner=20J'ai=20fait=20un=20sacr=C3=A9=20moment?= =?UTF-8?q?=20car=20quand=20le=20NodeMCU=20se=20r=C3=A9veille=20d'un=20dsl?= =?UTF-8?q?eep=20il=20est=20toujours=20vu=20comme=20venant=20d'un=20hard?= =?UTF-8?q?=20reset=20et=20pas=20moyen=20alors=20de=20d=C3=A9tecter=20que?= =?UTF-8?q?=20l'on=20=C3=A9tait=20en=20dsleep.=20Maintenant=20je=20sauve?= =?UTF-8?q?=20un=20flag=20dans=20la=20rtc-mem=20et=20je=20peux=20tester=20?= =?UTF-8?q?ce=20flag=20au=20moment=20du=20reset=20et=20d=C3=A9tecter=20si?= =?UTF-8?q?=20je=20sors=20du=20dsleep.=20Reste=20encore=20=C3=A0=20mieux?= =?UTF-8?q?=20faire=20la=20d=C3=A9tection=20wifi=20pour=20savoir=20si=20on?= =?UTF-8?q?=20arr=C3=AAte=20le=20dsleep=20ou=20si=20on=20le=20relance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeepSleep/Pet_tracker_2/0_dsleep.lua | 35 ++++++++++++++++++--- DeepSleep/Pet_tracker_2/boot.lua | 6 ++-- DeepSleep/Pet_tracker_2/flash_led_xfois.lua | 4 +-- DeepSleep/Pet_tracker_2/initz.lua | 9 ++++-- DeepSleep/Pet_tracker_2/set_time.lua | 8 +++-- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/DeepSleep/Pet_tracker_2/0_dsleep.lua b/DeepSleep/Pet_tracker_2/0_dsleep.lua index 0ebb97f..160c466 100644 --- a/DeepSleep/Pet_tracker_2/0_dsleep.lua +++ b/DeepSleep/Pet_tracker_2/0_dsleep.lua @@ -3,21 +3,48 @@ -- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k ! -print("\n dsleep.lua zf200722.0933 \n") +print("\n dsleep.lua zf200722.1133 \n") +zLED=4 f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) 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"])) +end + function dsleep_on() print("timer dsleep on...") ztmr_SLEEP = tmr.create() - ztmr_SLEEP:alarm(5*1000, tmr.ALARM_SINGLE, function () + ztmr_SLEEP:alarm(2*1000, tmr.ALARM_SINGLE, function () print("Je dors...") tmr.delay(100*1000) --- node.dsleep(4*1000*1000) - rtctime.dsleep(10*1000*1000,4) + -- node.dsleep(4*1000*1000) + -- print(node.bootreason()) + rtcmem.write32(10, 43690) --flag pour détecter le réveil dsleep + -- print("le flag est à "..rtcmem.read32(10)) + wifi.setmode(wifi.NULLMODE,true) + rtctime.dsleep(4*1000*1000) end) end +--[[ +dsleep_on() +print(node.bootreason()) +print("le flag est à "..rtcmem.read32(10)) + +f= "wifi_info.lua" if file.exists(f) then dofile(f) 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"])) +end + +print(ztime()) + + +]] + function dsleep_off() print("timer dsleep off...") ztmr_SLEEP:unregister() diff --git a/DeepSleep/Pet_tracker_2/boot.lua b/DeepSleep/Pet_tracker_2/boot.lua index 76b520c..18e3ac2 100644 --- a/DeepSleep/Pet_tracker_2/boot.lua +++ b/DeepSleep/Pet_tracker_2/boot.lua @@ -1,7 +1,7 @@ -- Scripts à charger après le boot pour démarrer son projet function boot() - print("\n boot.lua zf200720.2055 \n") + print("\n boot.lua zf200722.1132 \n") print("On lance le boot...") collectgarbage() print(node.heap()) local f @@ -16,8 +16,8 @@ function boot() f = "set_time.lua" if file.exists(f) then dofile(f) end print(node.heap()) collectgarbage() print(node.heap()) - f = "flash_led_xfois.lua" if file.exists(f) then dofile(f) end - print(node.heap()) collectgarbage() print(node.heap()) + -- f = "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + -- print(node.heap()) collectgarbage() print(node.heap()) -- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end -- print(node.heap()) collectgarbage() print(node.heap()) diff --git a/DeepSleep/Pet_tracker_2/flash_led_xfois.lua b/DeepSleep/Pet_tracker_2/flash_led_xfois.lua index 8bf982b..5b08aff 100644 --- a/DeepSleep/Pet_tracker_2/flash_led_xfois.lua +++ b/DeepSleep/Pet_tracker_2/flash_led_xfois.lua @@ -1,10 +1,10 @@ -- programme pour faire clignoter x fois une LED avec un rapport on/off function flash_led_xfois() - print("\n flash_led_xfois.lua zf200720.2053 \n") + print("\n flash_led_xfois.lua zf200722.1139 \n") --zLED=0 --NodeMCU - -- zLED=4 --EPS-M3 + --zLED=4 --EPS-M3 zTm_On_LED = 50 --> en ms zTm_Off_LED = 100 --> en ms nbfois = 0 diff --git a/DeepSleep/Pet_tracker_2/initz.lua b/DeepSleep/Pet_tracker_2/initz.lua index 1e30574..e64e860 100644 --- a/DeepSleep/Pet_tracker_2/initz.lua +++ b/DeepSleep/Pet_tracker_2/initz.lua @@ -3,7 +3,7 @@ -- 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 zf200612.1632 \n") +print("\n init.lua zf200722.1142 \n") verbose = true @@ -61,7 +61,12 @@ function initz() initz_end() elseif reset_reason == 6 then print("external reset") - second_chance() + if rtcmem.read32(10) == 43690 then + print("dsleep wake up") + f = "0_dsleep.lua" if file.exists(f) then dofile(f) end + else + second_chance() + end else print("autre raison") second_chance() diff --git a/DeepSleep/Pet_tracker_2/set_time.lua b/DeepSleep/Pet_tracker_2/set_time.lua index 26c3679..8adfc85 100644 --- a/DeepSleep/Pet_tracker_2/set_time.lua +++ b/DeepSleep/Pet_tracker_2/set_time.lua @@ -1,15 +1,19 @@ -- Scripts pour régler l'horloge quand on est connecté en WIFI -print("\n set_time.lua zf200720.2055 \n") +print("\n set_time.lua zf2007222.110755 \n") function set_time() sntp.sync(nil, nil, nil, 1) end function ztime() - tm = rtctime.epoch2cal(rtctime.get()+3600) + 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 set_time() +--[[ +print(ztime()) +]] +