Improve snapshot payload debugging and handling
- Added a check for payload length and print debugging information. - Print part of the payload to help diagnose issues with image data.
This commit is contained in:
@@ -29,13 +29,11 @@ initial_snapshot_processed = False
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
print("Connected successfully to MQTT broker")
|
||||
client.subscribe(MQTT_SNAPSHOT_TOPIC)
|
||||
client.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1)
|
||||
print(f"Subscribed to topic: {MQTT_SNAPSHOT_TOPIC}")
|
||||
publish_discovery_configurations()
|
||||
# Publish initial rating of 0
|
||||
publish_rating(0)
|
||||
# Request the retained snapshot to process the initial image
|
||||
client.publish(MQTT_SNAPSHOT_TOPIC, "", qos=1)
|
||||
else:
|
||||
print(f"Failed to connect, return code {rc}")
|
||||
|
||||
@@ -59,6 +57,11 @@ def on_message(client, userdata, msg):
|
||||
global initial_snapshot_processed
|
||||
if msg.topic == MQTT_SNAPSHOT_TOPIC:
|
||||
print("Snapshot received")
|
||||
if len(msg.payload) == 0:
|
||||
print("Received an empty payload, skipping processing.")
|
||||
else:
|
||||
print(f"Payload length: {len(msg.payload)} bytes")
|
||||
print(f"Payload (first 100 bytes): {msg.payload[:100]}...")
|
||||
process_snapshot(msg.payload)
|
||||
initial_snapshot_processed = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user