Voilà mon dsleep commence enfin à fonctionner

J'ai fait un sacré moment car quand le NodeMCU se réveille d'un dsleep il est toujours vu comme venant d'un hard reset et pas moyen alors de détecter que l'on était en dsleep.
Maintenant je sauve un flag dans la rtc-mem et je peux tester ce flag au moment du reset et détecter si je sors du dsleep.
Reste encore à mieux faire la détection wifi pour savoir si on arrête le dsleep ou si on le relance
This commit is contained in:
Christian Zufferey
2020-07-22 11:49:42 +02:00
parent cb98b94bc3
commit d9d92f34ba
5 changed files with 49 additions and 13 deletions

View File

@@ -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()

View File

@@ -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())

View File

@@ -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

View File

@@ -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()

View File

@@ -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())
]]