9 Commits

Author SHA1 Message Date
d677b33cdb recreate
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-02-26 12:19:48 +01:00
d9b1000665 publish cache retained
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:46:39 +01:00
7794fabaf3 publish cache 4
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:41:39 +01:00
6e6ff4c229 publish cache 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:39:53 +01:00
dc2175c298 publish cache 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:38:01 +01:00
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
7 changed files with 25 additions and 17 deletions

View File

@@ -47,10 +47,7 @@ steps:
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- kubectl create configmap pv-controller-config
--from-file=config.yaml=config/config.yaml
--namespace=$NAMESPACE
--dry-run=client -o yaml | kubectl apply -f -
- kubectl create configmap pv-controller-config --from-file=config.yaml=config/config.yaml --namespace=$NAMESPACE --dry-run=client -o yaml | kubectl apply -f -
deploy:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4

View File

@@ -1,5 +1,5 @@
global:
scan_interval: 1
scan_interval: 0.25
log_level: INFO
mqtt:
@@ -24,18 +24,11 @@ input:
output:
- name: pv_meter
enabled: true
scan_rate: 15
enabled: true
scan_rate: 60
publish_topic: IoT/PV/Values
slave_id: 2
registers:
- address: 0x0048
attribute: importEnergyActive
name: Import active energy
unit: kWh
register_type: input
data_type: float32
adaptor: floatAdaptor
- address: 0x004c
attribute: importEnergyReactive
name: Import reactive energy
@@ -231,7 +224,7 @@ output:
data_type: float32
adaptor: floatAdaptor
- name: car_feedback
enabled: false
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'

7
config/config.yaml-bak Normal file
View File

@@ -0,0 +1,7 @@
- address: 0x0048
attribute: importEnergyActive
name: Import active energy
unit: kWh
register_type: input
data_type: float32
adaptor: floatAdaptor

View File

@@ -9,6 +9,8 @@ metadata:
reloader.stakater.com/configmap: "pv-controller-config"
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: pv-controller

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, retain=True)

View File

@@ -51,7 +51,7 @@ class ModbusConfig(BaseModel):
class GlobalConfig(BaseModel):
"""Global settings"""
scan_interval: int
scan_interval: float
log_level: str