uptime in status message
This commit is contained in:
@ -3,7 +3,7 @@ from loguru import logger
|
|||||||
from MqttBase import AbstractMqttPublisher
|
from MqttBase import AbstractMqttPublisher
|
||||||
from queue import Empty
|
from queue import Empty
|
||||||
import json
|
import json
|
||||||
|
import datetime
|
||||||
|
|
||||||
LOOP_SLICE = 0.1 # seconds
|
LOOP_SLICE = 0.1 # seconds
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ class MqttPublish(AbstractMqttPublisher):
|
|||||||
|
|
||||||
def localLoop(self):
|
def localLoop(self):
|
||||||
cnt = 0
|
cnt = 0
|
||||||
|
startTime = datetime.datetime.now()
|
||||||
while not self.killBill:
|
while not self.killBill:
|
||||||
try:
|
try:
|
||||||
dataObject = self.queue.get(timeout=LOOP_SLICE)
|
dataObject = self.queue.get(timeout=LOOP_SLICE)
|
||||||
@ -29,7 +30,9 @@ class MqttPublish(AbstractMqttPublisher):
|
|||||||
cnt += 1
|
cnt += 1
|
||||||
logger.debug("mqtt message sent: {} -> {}".format(topic, payload))
|
logger.debug("mqtt message sent: {} -> {}".format(topic, payload))
|
||||||
if cnt % 100 == 1:
|
if cnt % 100 == 1:
|
||||||
payload = { "count": cnt }
|
currentTime = datetime.datetime.now()
|
||||||
|
uptime = int((currentTime - startTime).total_seconds())
|
||||||
|
payload = { "count": cnt, "uptime": uptime }
|
||||||
self.client.publish(self.statusTopic, json.dumps(payload), retain=True)
|
self.client.publish(self.statusTopic, json.dumps(payload), retain=True)
|
||||||
except Empty:
|
except Empty:
|
||||||
if self.killBill:
|
if self.killBill:
|
||||||
|
Reference in New Issue
Block a user