6 Commits

Author SHA1 Message Date
6d8c5c25db publish cache
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:34:52 +01:00
ca08059e13 add car feedback 6
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:26:52 +01:00
6796bdd905 add car feedback 5
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:24:12 +01:00
6c208e32bf add car feedback 4
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:22:49 +01:00
d2ee8a80c2 add car feedback 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:20:13 +01:00
5e0127b571 add car feedback 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:17:25 +01:00
3 changed files with 12 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
global:
scan_interval: 1
log_level: INFO
log_level: DEBUG
mqtt:
broker: emqx01-anonymous-cluster-internal.broker.svc.cluster.local
@@ -237,7 +237,7 @@ output:
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 7
registers:
- address: 0x0001
- address: 0x0010
attribute: output
name: State
unit: "-"

View File

@@ -52,7 +52,7 @@ class FromDevices(AbstractMqttPublisher):
payload['cnt'] = cnt
payloadStr = json.dumps(payload) if not device.raw_output else str(payload['output'])
self.client.publish(device.publish_topic, payloadStr)
self.publish_with_cache(device.publish_topic, payloadStr)
logger.debug(f"mqtt message sent: {device.publish_topic} -> {payloadStr}")
except Exception as e:
logger.error(f"Caught exception: {str(e)}")

View File

@@ -25,6 +25,8 @@ class AbstractMqttPublisher(threading.Thread):
logger.info(f"mqtt client id: {client_id}")
self.client = mqtt.Client(client_id=client_id, userdata=self)
self.cache = {}
# consider this flag in the localLoop
self.killBill = False
self.killEvent = threading.Event()
@@ -62,3 +64,10 @@ class AbstractMqttPublisher(threading.Thread):
def onMessage(self, topic, payload):
logger.warning("mqtt unexpected message received: {} -> {}".format(topic, str(payload)))
def publish_with_cache(self, topic, payload):
if topic in self.cache and self.cache[topic] == payload:
logger.debug(f"mqtt message unchanged, not publishing: {topic} -> {payload}")
return
self.cache[topic] = payload
self.client.publish(topic, payload)