summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--run.lua2
-rw-r--r--wakeup.lua19
2 files changed, 12 insertions, 9 deletions
diff --git a/run.lua b/run.lua
index e5a7627..60d1e07 100644
--- a/run.lua
+++ b/run.lua
@@ -2,7 +2,7 @@ local wakeup = require("wakeup")
return function ()
tmr.create():alarm(
- 500,
+ 1000,
tmr.ALARM_AUTO,
function (timer)
wakeup:step(timer)
diff --git a/wakeup.lua b/wakeup.lua
index ec8b78a..73fc25e 100644
--- a/wakeup.lua
+++ b/wakeup.lua
@@ -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