3 Commits

Author SHA1 Message Date
311d4cf555 add car feedback
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:15:03 +01:00
ad043b5921 add raw output 3
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2025-12-05 15:00:22 +01:00
7c90962de1 add raw output 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 14:58:46 +01:00
2 changed files with 25 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
global:
scan_interval: 1
log_level: DEBUG
log_level: INFO
mqtt:
broker: emqx01-anonymous-cluster-internal.broker.svc.cluster.local
@@ -123,10 +123,11 @@ output:
- name: pv_control
publish_topic: IoT/PV/Control/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 1
registers:
- address: 0x0001
attribute: state
attribute: output
name: State
unit: "-"
register_type: holding
@@ -136,10 +137,11 @@ output:
enabled: true
publish_topic: IoT/Car/Control/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 5
registers:
- address: 0x0001
attribute: state
attribute: output
name: State
unit: "-"
register_type: holding
@@ -228,3 +230,17 @@ output:
register_type: input
data_type: float32
adaptor: floatAdaptor
- name: car_feedback
enabled: true
publish_topic: IoT/Car/Feedback/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 7
registers:
- address: 0x0001
attribute: output
name: State
unit: "-"
register_type: holding
data_type: int32
adaptor: onOffAdaptor

View File

@@ -9,7 +9,7 @@ def floatAdaptor(i):
return float(f"{i:0.2f}") if i else 0.0
def onOffAdaptor(i):
return bool(i)
return 'on' if bool(i) else 'off'
@@ -49,12 +49,13 @@ class FromDevices(AbstractMqttPublisher):
payload[registers.attribute] = value
payload['status'] = "Ok"
payload['cnt'] = cnt
payloadStr = json.dumps(payload) if not device.raw_output else str(payload['output'])
self.client.publish(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)}")
payload['cnt'] = cnt
payloadStr = json.dumps(payload) if not device.raw_output else str(payload)
self.client.publish(device.publish_topic, payloadStr)
logger.debug(f"mqtt message sent: {device.publish_topic} -> {payloadStr}")
self.killEvent.wait(timeout=float(self.config.global_.scan_interval))