michaelarnauts / cec-mqtt-bridge

A HDMI-CEC to MQTT bridge for connecting HDMI-CEC-devices to your Home Automation system.
145 stars 48 forks source link

Wait for mqtt on startup #41

Closed clockbrain closed 2 months ago

clockbrain commented 10 months ago

Launching cec-mqtt-bridge on boot has problems if mqtt hasn't already started. This change puts the bridge into a loop on startup until mqtt is available. The change also ignores incoming mqtt messages unless the cec_class has been configured.

Also reduce the log level of cec refresh.

Note that running cec-mqtt-bridge as a service means mqtt can be configured as a prerequisite service which I do but this wait for mqtt on startup change adds that little bit extra protection. For reference here is my bridge.service file:

`Unit] Description=CEC MQTT bridge After=network-online.target mosquitto.service

[Service] ExecStart=/opt/cec-mqtt-bridge/bridge.sh Restart=always User=xxxxxxx Group=xxxxxxx SyslogIdentifier=cec-mqtt-bridge

[Install] WantedBy=multi-user.target`

tikismoke commented 6 months ago

what about if mosquito is not running on the same machine?

clockbrain commented 6 months ago

what about if mosquito is not running on the same machine?

Fair point. So leave that entry out of the bridge.service.

Doesn't impact the PR though which waits in a loop for a connection to the broker via mqtt_client.connect()