diff options
author | Aki <please@ignore.pl> | 2024-01-22 23:15:41 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-01-22 23:18:08 +0100 |
commit | 9fde8f71deb29d3c7bcefd08f678365f5eaf9eee (patch) | |
tree | f5269841fd294265d786a650f16f1eaa21edad2d /wakeup.lua | |
parent | 0ff40d99e0d9db70311a78011ad52e603beec0ab (diff) | |
download | nodemcu-wakeup-master.zip nodemcu-wakeup-master.tar.gz nodemcu-wakeup-master.tar.bz2 |
Timeout vs counter still hate themselves. When assigned five packets,
it sends four, when assigned five ticks it waits five (for now). Or
the other way around... I can't count today anymore.
Diffstat (limited to 'wakeup.lua')
-rw-r--r-- | wakeup.lua | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -50,7 +50,7 @@ function start_timeout (ticks, after) local self = new_counter(ticks) return function (wakeup) if not self:up() then - wakeup = after + wakeup.step = after end end end @@ -103,12 +103,11 @@ function start_sendout (times) print("Waking up", wakeup.mac, wakeup.addr) self.udp:send(wakeup.port, wakeup.addr, wakeup.data) else + print("Done") + timer:interval(10000) self.udp:close() gpio.write(4, gpio.HIGH) - wifi.setmode(wifi.NULLMODE, false) - timer:interval(61000) - self.step = self.soft_failure - print("Done") + wakeup.step = start_timeout(6, wakeup.check_time) end end end @@ -149,9 +148,11 @@ end function wakeup:check_time (timer) local left = upcoming(self.when, now()) if left == 0 then + timer:interval(500) gpio.write(4, gpio.LOW) self.step = start_sendout(5) elseif left > 5 then + timer:interval(1000) print(string.format("Need to wait total %d minutes", left)) left = left - 5 if left > 50 then @@ -161,14 +162,16 @@ function wakeup:check_time (timer) self.step = start_timeout(3, self.sleep) print(string.format("Going to sleep %d minutes", left)) else + timer:interval(30000) print(string.format("Wake-up in %d minutes", left)) - timer:interval(15000) end end -function wakeup:sleep () - rtctime.dsleep(self.left * 6e7, 1) +function wakeup:sleep (timer) + wifi.setmode(wifi.NULLMODE, false) + timer:unregister() + rtctime.dsleep(self.left * 60e6, 1) end |