Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/hal/user_comps/mqtt-publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ def create_pins(self, keys):
def update_mqtt(self):
"Run the endless loop fetching pin data and sending it to MQTT."
running = True
missing = {}
while hal.component_exists('halui') and running:
data = {}
if self.hal['enable']:
for key in self.keys:
try:
data[key] = hal.get_value(key)
except RuntimeError as e:
Comment thread
mrbubble62 marked this conversation as resolved.
# Only print warning once
if key not in missing:
print(f"warning: Missing pin {key} not sent to MQTT")
missing[key] = True
data['mqtt-publisher.period'] = self.hal['period']
if not self.dryrun:
print(f"info: Publishing MQTT message ({self.mqtt_prefix}):", json.dumps(data))
Expand All @@ -107,6 +116,7 @@ def usage():
@staticmethod
def main():
from optparse import Option, OptionParser
keys={}
options = [
Option( '--dryrun', dest='dryrun', action='store_true',
help='Dryrun, only collect HAL pin values, do not send them to MQTT.'),
Expand Down