add option to disable analog event publishing

This commit is contained in:
Wolfgang Hottgenroth 2021-08-25 11:58:35 +02:00
parent fc78dc7f4d
commit 78f001fd70
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 17 additions and 11 deletions

View File

@ -9,3 +9,4 @@ digitalInputTopicPrefix = dt1/di
analogInputEventTopicPrefix = dt1/ai/event
analogInputPeriodicTopicPrefix = dt1/ai/periodic
analogInputPublishPeriod = 10.0
disableAnalogInputEventPublishing = true

View File

@ -30,12 +30,14 @@ Configuration is done using a configuration file
analogInputEventTopicPrefix = dt1/ai/event
analogInputPeriodicTopicPrefix = dt1/ai/periodic
analogInputPublishPeriod = 10.0
disableAnalogInputEventPublishing = true
### Operation details
While the input and discrete input registers are scanned with the configured scanrate, an action on a coil according to a received message is issued immediately. At the same time the all input registers are scanned.
Using a configuration option it is possible to disable the publishing of analog change event - if only periodic information (like for a thermometer or so) is required.
The MQTT messages related to change events of input or discrete input registers are marked as //retained//.

View File

@ -12,6 +12,7 @@ def mqttEventPublisherStart(config, processImage):
class MqttEventPublisher(AbstractMqttPublisher):
def __init__(self, config, processImage):
super().__init__(config, processImage)
self.disableAnalogInputEventPublishing = self.config["disableAnalogInputEventPublishing"].lower() in [ "true", "on" ]
def localLoop(self):
while True:
@ -19,7 +20,8 @@ class MqttEventPublisher(AbstractMqttPublisher):
self.processImage.wait()
discreteInputChangeset = self.processImage.getChangedDiscreteInputs()
analogInputChangeset = self.processImage.getChangedAnalogsInputs()
if not self.disableAnalogInputEventPublishing:
analogInputChangeset = self.processImage.getChangedAnalogsInputs()
for discreteInputChangeItem in discreteInputChangeset:
logger.debug("Discrete input {} changed from {} to {}"
@ -30,14 +32,15 @@ class MqttEventPublisher(AbstractMqttPublisher):
str(discreteInputChangeItem[1][0]),
retain=True)
for analogInputChangeItem in analogInputChangeset:
logger.debug("Analog input {} changed from {} to {}"
.format(analogInputChangeItem[0],
analogInputChangeItem[1][1],
analogInputChangeItem[1][0]))
if not self.disableAnalogInputEventPublishing:
for analogInputChangeItem in analogInputChangeset:
logger.debug("Analog input {} changed from {} to {}"
.format(analogInputChangeItem[0],
analogInputChangeItem[1][1],
analogInputChangeItem[1][0]))
self.client.publish("{}/{}".format(self.config["analogInputEventTopicPrefix"], str(analogInputChangeItem[0])),
str(analogInputChangeItem[1][0]),
retain=True)
self.client.publish("{}/{}".format(self.config["analogInputEventTopicPrefix"], str(analogInputChangeItem[0])),
str(analogInputChangeItem[1][0]),
retain=True)