commit 8fe522fe9ecaa5aa1aea2841f1555043aba29be1
parent 39fecfe655a104cdee2a974abbe1c78a44ff6b06
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Feb 2021 17:04:02 +0100
parent 39fecfe655a104cdee2a974abbe1c78a44ff6b06
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Feb 2021 17:04:02 +0100
devices/lacrosseSensors: only process messurement every ~60 seconds
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/devices/lacrosseSensors.nim b/src/devices/lacrosseSensors.nim @@ -16,14 +16,19 @@ proc lacrosseHandleLoop (sock: AsyncSocket) {.async.} = if device.id != msg.id: continue + let currentTimestamp = toUnix(getTime()) + + if server.state[key].lastUpdated.isSome: + if (currentTimestamp - server.state[key].lastUpdated.get) < 50: + break + if msg.hum == 106: server.state[key].humidity = -1 else: server.state[key].humidity = msg.hum server.state[key].temperature = msg.temp.isaRound(2) server.state[key].weakBattery = bool(msg.weakBatt) - server.state[key].lastUpdated = some(toUnix(getTime())) - + server.state[key].lastUpdated = some(currentTimestamp) if server.config.serverConfig.influx.isSome: let config = server.config.serverConfig.influx.get @@ -38,14 +43,13 @@ proc lacrosseHandleLoop (sock: AsyncSocket) {.async.} = fields["temperature"] = $msg.temp.isaRound(2) - discard await config.insertDatabase(config.lacrosseDatabase.get, key, tags, fields, server.state[key].lastUpdated.get) + discard await config.insertDatabase(config.lacrosseDatabase.get, key, tags, fields, currentTimestamp) broadcastServerState() except: - let e = getCurrentException() - echo("error while updating lacrosse: ", e.msg) + echo "Error[lacrosseHandleLoop]:\n", getCurrentExceptionMsg() proc lacrosseConnectLoop () {.async.} = while true: @@ -55,8 +59,7 @@ proc lacrosseConnectLoop () {.async.} = await lacrosseHandleLoop(lacrosseSocket) except: lacrosseSocket.close() - let e = getCurrentException() - echo("error while connectiong to lacrosse relay: ", e.msg) + echo "Error[lacrosseConnectLoop]:\n", getCurrentExceptionMsg() await sleepAsync(1000) proc initLacrosseSensors* () =