Better handling of payloads

This commit is contained in:
2024-10-20 16:26:50 +11:00
parent 05c9b1f713
commit fe25895b38
+23 -13
View File
@@ -56,23 +56,33 @@ def on_message(client, userdata, msg):
process_snapshot(msg.payload) process_snapshot(msg.payload)
def process_latest_snapshot(): def process_latest_snapshot():
# Placeholder for processing the latest snapshot (if available)
print("Attempting to process the latest snapshot...") print("Attempting to process the latest snapshot...")
# Assuming we have a way to get the latest snapshot payload # Simulate fetching the latest snapshot payload (replace with actual logic if available)
# For now, this is just a debug statement latest_snapshot_payload = os.getenv('LATEST_SNAPSHOT_PAYLOAD', None)
if latest_snapshot_payload:
process_snapshot(latest_snapshot_payload.encode('utf-8'))
else:
print("No latest snapshot available to process.")
def process_snapshot(payload): def process_snapshot(payload):
print("Processing snapshot...") if not payload:
image_data = base64.b64decode(payload) print("Empty payload received, skipping processing.")
nparr = np.frombuffer(image_data, np.uint8) return
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if image is not None: print("Processing snapshot...")
rating = calculate_dayglo_rating(image) try:
print("Dayglo Rating calculated:", rating) image_data = base64.b64decode(payload)
publish_rating(rating) nparr = np.frombuffer(image_data, np.uint8)
else: image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
print("Invalid image received")
if image is not None:
rating = calculate_dayglo_rating(image)
print("Dayglo Rating calculated:", rating)
publish_rating(rating)
else:
print("Invalid image received")
except Exception as e:
print(f"Error processing snapshot: {e}")
def calculate_dayglo_rating(image): def calculate_dayglo_rating(image):
print("Calculating dayglo rating...") print("Calculating dayglo rating...")