From 962e53215cd9680043861020b208c6edb83c9630 Mon Sep 17 00:00:00 2001 From: Solium <53835578+daschmidt1994@users.noreply.github.com> Date: Fri, 22 May 2026 20:50:27 +0200 Subject: [PATCH 1/3] update mqtt.py --- scripts/mqtt/mqtt.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/mqtt/mqtt.py b/scripts/mqtt/mqtt.py index ccff0a75..ed604865 100644 --- a/scripts/mqtt/mqtt.py +++ b/scripts/mqtt/mqtt.py @@ -827,10 +827,10 @@ def get_screenshot(): return img_base64 except Exception as e: print("Exception: ", e) - return null + return None -def on_message(client, flags, msg): +def on_message(client, userdata, msg): #print("Topic: " + msg.topic) #print("Message: " + str(msg.payload.decode("utf-8"))) if msg.topic == mqtt_topic + '/' + mqtt_clientId + '/reboot/set' and str(msg.payload.decode("utf-8")) == "reboot": @@ -845,11 +845,11 @@ def on_message(client, flags, msg): os.system("/usr/bin/pactl set-sink-volume @DEFAULT_SINK@ " + msg.payload.decode("utf-8") + "%") if msg.topic == mqtt_topic + '/' + mqtt_clientId + '/pause/set' and str(msg.payload.decode("utf-8")) == "pause": print("Button: pause") - url = 'http://' + jsonconfig['mupibox']['host'] + ':5005/pause' + url = 'http://127.0.0.1:5005/pause' requests.get(url) if msg.topic == mqtt_topic + '/' + mqtt_clientId + '/play/set' and str(msg.payload.decode("utf-8")) == "play": print("Button: play") - url = 'http://' + jsonconfig['mupibox']['host'] + ':5005/play' + url = 'http://127.0.0.1:5005/play' requests.get(url) if msg.topic == mqtt_topic + '/' + mqtt_clientId + '/take_screenshot/set' and str(msg.payload.decode("utf-8")) == "take_screenshot": screenshot = get_screenshot() @@ -867,7 +867,7 @@ def check_server_availability(host, port, retry_interval): time.sleep(retry_interval) def handle_shutdown(signum, frame): - print(f"Signal {signum} received. Service will be stopped...") + print(f"Exception in main loop: {e}. Service will be stopped...") client.loop_stop() client.publish(mqtt_topic + '/' + mqtt_clientId + '/state', "offline", qos=0) exit(0) @@ -998,4 +998,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() From 9bae5299ce6aa792dda3bb175dbf7fc84a325930 Mon Sep 17 00:00:00 2001 From: Solium <53835578+daschmidt1994@users.noreply.github.com> Date: Sat, 23 May 2026 09:54:36 +0200 Subject: [PATCH 2/3] update mqtt.py --- scripts/mqtt/mqtt.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/mqtt/mqtt.py b/scripts/mqtt/mqtt.py index ed604865..253ebf6b 100644 --- a/scripts/mqtt/mqtt.py +++ b/scripts/mqtt/mqtt.py @@ -718,6 +718,12 @@ def on_disconnect(client, userdata, rc): client.publish(mqtt_topic + '/' + mqtt_clientId + '/state', "offline", qos=0) client.publish(mqtt_topic + '/' + mqtt_clientId + '/power', "off", qos=0) client.publish(mqtt_topic + '/' + mqtt_clientId + '/reboot', "off", qos=0) + if rc != 0: + print("Unexpected disconnect, trying to reconnect...") + try: + client.reconnect() + except Exception as e: + print("Reconnect failed: ", e) def playback_info(): From 62e09b3a45bb70b7c7a1d5e211cad6e10d91a486 Mon Sep 17 00:00:00 2001 From: Solium <53835578+daschmidt1994@users.noreply.github.com> Date: Sat, 23 May 2026 10:24:14 +0200 Subject: [PATCH 3/3] update mqtt.py --- scripts/mqtt/mqtt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/mqtt/mqtt.py b/scripts/mqtt/mqtt.py index 253ebf6b..cf6783df 100644 --- a/scripts/mqtt/mqtt.py +++ b/scripts/mqtt/mqtt.py @@ -714,14 +714,16 @@ def on_connect(client, userdata, flags, rc): # Callback function for when the client is disconnected from the broker def on_disconnect(client, userdata, rc): print("Disconnected from MQTT broker with result code: " + str(rc)) - # Send "off" message to device topic on disconnect client.publish(mqtt_topic + '/' + mqtt_clientId + '/state', "offline", qos=0) client.publish(mqtt_topic + '/' + mqtt_clientId + '/power', "off", qos=0) client.publish(mqtt_topic + '/' + mqtt_clientId + '/reboot', "off", qos=0) if rc != 0: print("Unexpected disconnect, trying to reconnect...") + import time + time.sleep(5) try: client.reconnect() + print("Reconnect successful!") except Exception as e: print("Reconnect failed: ", e)