From df5e959ff435bd360a653ccf54cd82b34b8ec9d4 Mon Sep 17 00:00:00 2001 From: Marcus Brown Date: Sun, 20 Oct 2024 17:55:05 +1100 Subject: [PATCH] Add mechanism to request a fresh snapshot upon connecting - Added a function to request a fresh snapshot from Frigate or similar system upon connecting. - Removed client disconnection to allow continued listening for snapshot messages. --- dayglo_detector/dayglo_detector.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dayglo_detector/dayglo_detector.py b/dayglo_detector/dayglo_detector.py index b51580f..bcbf78f 100644 --- a/dayglo_detector/dayglo_detector.py +++ b/dayglo_detector/dayglo_detector.py @@ -34,6 +34,8 @@ def on_connect(client, userdata, flags, rc): publish_discovery_configurations() # Publish initial rating of 0 publish_rating(0) + # Request Frigate or the source to publish a fresh snapshot + request_fresh_snapshot() else: print(f"Failed to connect, return code {rc}") @@ -53,6 +55,12 @@ def publish_rating(rating): last_rating = rating client.publish(MQTT_TOPIC_PUBLISH, json.dumps({"rating": rating})) +def request_fresh_snapshot(): + # Assuming Frigate or another system listens to this topic to generate a snapshot + SNAPSHOT_REQUEST_TOPIC = "/frigate/patiocam/request_snapshot" + print(f"Requesting fresh snapshot by publishing to topic: {SNAPSHOT_REQUEST_TOPIC}") + client.publish(SNAPSHOT_REQUEST_TOPIC, json.dumps({"request": "snapshot"}), retain=False) + def on_message(client, userdata, msg): global initial_snapshot_processed if msg.topic == MQTT_SNAPSHOT_TOPIC: @@ -64,8 +72,6 @@ def on_message(client, userdata, msg): print(f"Payload (first 100 bytes): {msg.payload[:100]}...") process_snapshot(msg.payload) initial_snapshot_processed = True - # Disconnect after receiving the retained message - client.disconnect() def process_snapshot(payload): if not payload: