Skip to content

Commit 63d7f6a

Browse files
authored
Merge pull request #2449 from mrbubble62/mqtt-publisher
Update mqtt-publisher.py fixes #2431
2 parents fd03980 + cfbfb3e commit 63d7f6a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/hal/user_comps/mqtt-publisher.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,18 @@ def create_pins(self, keys):
8484
def update_mqtt(self):
8585
"Run the endless loop fetching pin data and sending it to MQTT."
8686
running = True
87+
missing = {}
8788
while hal.component_exists('halui') and running:
8889
data = {}
8990
if self.hal['enable']:
91+
for key in self.keys:
92+
try:
93+
data[key] = hal.get_value(key)
94+
except RuntimeError as e:
95+
# Only print warning once
96+
if key not in missing:
97+
print(f"warning: Missing pin {key} not sent to MQTT")
98+
missing[key] = True
9099
data['mqtt-publisher.period'] = self.hal['period']
91100
if not self.dryrun:
92101
print(f"info: Publishing MQTT message ({self.mqtt_prefix}):", json.dumps(data))
@@ -107,6 +116,7 @@ def usage():
107116
@staticmethod
108117
def main():
109118
from optparse import Option, OptionParser
119+
keys={}
110120
options = [
111121
Option( '--dryrun', dest='dryrun', action='store_true',
112122
help='Dryrun, only collect HAL pin values, do not send them to MQTT.'),

0 commit comments

Comments
 (0)