31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from threading import Event
|
|
from loguru import logger
|
|
from AbstractMqttHandler import AbstractMqttPublisher
|
|
|
|
def mqttPeriodPublisherStart(config, processImage):
|
|
mqttPeriodPublisherThread = MqttPeriodPublisher(config, processImage)
|
|
mqttPeriodPublisherThread.start()
|
|
|
|
|
|
class MqttPeriodPublisher(AbstractMqttPublisher):
|
|
def __init__(self, config, processImage):
|
|
super().__init__(config, processImage)
|
|
|
|
def localLoop(self):
|
|
while not self.killBill:
|
|
with self.processImage:
|
|
if not self.processImage.isInitialized():
|
|
continue
|
|
analogInputs = self.processImage.getAnalogsInputs()
|
|
|
|
for analogInputItem in enumerate(analogInputs):
|
|
logger.debug("Analog input {} is {}"
|
|
.format(analogInputItem[0],
|
|
analogInputItem[1]))
|
|
|
|
self.client.publish("{}/{}".format(self.config["analogInputPeriodicTopicPrefix"], str(analogInputItem[0])),
|
|
str(analogInputItem[1]))
|
|
|
|
self.killEvent.wait(timeout=float(self.config["analogInputPublishPeriod"]))
|
|
|