From 5bb7c7fa305a03d0b22f2c5e8bc8950965bedcea Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 29 Jun 2019 13:43:52 +0100 Subject: [PATCH] Publish heartbeats every 20 seconds Rather than 60. Move to using tmr, rather than cron. As per https://github.com/cmukgb/ctfws-timer-iot/issues/7 --- init3.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/init3.lua b/init3.lua index 35a0930..3c6805b 100644 --- a/init3.lua +++ b/init3.lua @@ -45,12 +45,10 @@ local function mqtt_reconn() OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf") end -local mqtt_beat_cronentry -local function mqtt_beat() - mqtt_beat_cronentry = cron.schedule("* * * * *", function(e) +local mqtt_beat_tmr = tmr.create() +mqtt_beat_tmr:register(20000, tmr.ALARM_AUTO, function(t) mqc:publish(mqttBootTopic,string.format("beat %d %s",rtctime.get(),myBSSID),1,1) end) -end local function ctfws_lcd_draw_all() ctfws_lcd:reset() @@ -137,12 +135,12 @@ end nwfnet.onnet["init"] = function(e,c) dprint("NET", e) if e == "mqttdscn" and c == mqc then - if mqtt_beat_cronentry then mqtt_beat_cronentry:unschedule() mqtt_beat_cronentry = nil end + mqtt_beat_tmr:stop() if not mqtt_reconn_cronentry then mqtt_reconn() end ctfws_lcd:drawFlagsMessage("MQTT Disconnected") elseif e == "mqttconn" and c == mqc then if mqtt_reconn_cronentry then mqtt_reconn_cronentry:unschedule() mqtt_reconn_cronentry = nil end - if not mqtt_beat_cronentry then mqtt_beat() end + mqtt_beat_tmr:start() mqc:publish(mqttBootTopic,"alive",1,1) mqc:subscribe({ ["ctfws/game/config"] = 2, -- 2.50.1