input working
This commit is contained in:
32
src/MqttPeriodPublisher.py
Normal file
32
src/MqttPeriodPublisher.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import paho.mqtt.client as mqtt
|
||||
import threading
|
||||
from loguru import logger
|
||||
from AbstractMqttHandler import AbstractMqttPublisher
|
||||
from time import sleep
|
||||
|
||||
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 True:
|
||||
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]))
|
||||
|
||||
sleep(self.config["analogInputPublishPeriod"])
|
||||
|
||||
Reference in New Issue
Block a user