diff --git a/DeepSleep/Pet_tracker_2/0_dsleep2.lua b/DeepSleep/Pet_tracker_2/0_dsleep2.lua new file mode 100644 index 0000000..3532bdf --- /dev/null +++ b/DeepSleep/Pet_tracker_2/0_dsleep2.lua @@ -0,0 +1,96 @@ +-- Teste le deep sleep ! +-- s'endore pendant xx secondes après xx secondes + +-- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k ! + +print("\n dsleep.lua zf200722.1546 \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) + return (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(2*1000, tmr.ALARM_SINGLE, function () + print("Il est "..ztime().." et je vais dormir...") + tmr.delay(100*1000) + -- node.dsleep(4*1000*1000) + -- print(node.bootreason()) + rtcmem.write32(10, 43690) --flag pour détecter le réveil dsleep au moment du boot + -- 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()) + + +]] + +-- on se réveil, vérifie si on peut avoir du réseau autrement on va redormir +function dsleep_wake_up() + print("Coucou, je suis réveillé... et il est "..ztime()) + +end + + + +-- function dsleep_off() +-- print("timer dsleep off...") +-- ztmr_SLEEP:unregister() +-- end + +-- function watch_wifi_on() +-- dsleep_on() +-- ztmr_watch_wifi_on = tmr.create() +-- ztmr_watch_wifi_on:alarm(1*1000, tmr.ALARM_AUTO , function() +-- if wifi.sta.getip() == nil then +-- -- print("Unconnected... (on)") +-- else +-- ztmr_watch_wifi_on:stop() +-- print("Connected... (on)") +-- -- f= "wifi_info.lua" if file.exists(f) then dofile(f) end +-- watch_wifi_off() +-- end +-- end) +-- end + +-- function watch_wifi_off() +-- dsleep_off() +-- ztmr_watch_wifi_on:unregister() +-- ztmr_watch_wifi_off = tmr.create() +-- ztmr_watch_wifi_off:alarm(1*1000, tmr.ALARM_AUTO , function() +-- if wifi.sta.getip() == nil then +-- ztmr_watch_wifi_off:stop() +-- print("Unconnected... (off)") +-- watch_wifi_on() +-- ztmr_watch_wifi_off:unregister() +-- else +-- -- print("Connected... (off)") +-- xfois = 2 +-- blink_LED () +-- end +-- end) +-- end + +-- watch_wifi_on() + +dsleep_wake_up() diff --git a/DeepSleep/Pet_tracker_2/_zlocal_cmd.txt b/DeepSleep/Pet_tracker_2/_zlocal_cmd.txt index 47aae1a..362205f 100644 --- a/DeepSleep/Pet_tracker_2/_zlocal_cmd.txt +++ b/DeepSleep/Pet_tracker_2/_zlocal_cmd.txt @@ -1,4 +1,22 @@ -zf200621.2337 +zf200722.1537 + + +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()) + + + + srv_rt:on("connection", nil) diff --git a/DeepSleep/Pet_tracker_2/a.lua b/DeepSleep/Pet_tracker_2/a.lua index 2e94a02..7d44bbc 100644 --- a/DeepSleep/Pet_tracker_2/a.lua +++ b/DeepSleep/Pet_tracker_2/a.lua @@ -1,6 +1,6 @@ -- Scripts pour tester l'écoute des AP WIFI -print("\n a.lua zf181211.0016 \n") +print("\n a.lua zf200722.1544 \n") --f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end --f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end @@ -12,7 +12,7 @@ print("\n a.lua zf181211.0016 \n") -- print AP list in new format function a() - ztime() + print(ztime()) function listap(t) print("") for k,v in pairs(t) do @@ -23,7 +23,11 @@ function a() wifi.sta.getap(1, listap) end ---a() +--[[ +a() +]] + + --[[ -- Print AP list that is easier to read diff --git a/DeepSleep/Pet_tracker_2/boot.lua b/DeepSleep/Pet_tracker_2/boot.lua index 18e3ac2..d8afafb 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 zf200722.1132 \n") + print("\n boot.lua zf200722.1536 \n") print("On lance le boot...") collectgarbage() print(node.heap()) local f @@ -16,6 +16,9 @@ function boot() f = "set_time.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 + 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()) diff --git a/DeepSleep/Pet_tracker_2/initz.lua b/DeepSleep/Pet_tracker_2/initz.lua index e64e860..f226f9b 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 zf200722.1142 \n") +print("\n init.lua zf200722.1526 \n") verbose = true @@ -63,7 +63,7 @@ function initz() print("external reset") if rtcmem.read32(10) == 43690 then print("dsleep wake up") - f = "0_dsleep.lua" if file.exists(f) then dofile(f) end + f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end else second_chance() end diff --git a/DeepSleep/Pet_tracker_2/0_dsleep.lua b/DeepSleep/Pet_tracker_2/oldies/0_dsleep.lua similarity index 100% rename from DeepSleep/Pet_tracker_2/0_dsleep.lua rename to DeepSleep/Pet_tracker_2/oldies/0_dsleep.lua