def on_message(client, userdata, msg): if msg.topic not in [MQTT_TOPIC, MQTT_TOPIC2]: return if msg.topic == MQTT_TOPIC: image = byte_array_to_pil_image(msg.payload) image = image.convert("RGB") viewer.image(image, width=VIEWER_WIDTH) elif msg.topic == MQTT_TOPIC2: image = byte_array_to_pil_image(msg.payload) image = image.convert("RGB") viewer2.image(image, width=VIEWER_WIDTH)
def on_message(client, userdata, msg): now = get_now_string() print("message on " + str(msg.topic) + f" at {now}") try: image = byte_array_to_pil_image(msg.payload) image = image.convert("RGB") save_file_path = CAPTURES_DIRECTORY + f"capture_{now}.jpg" image.save(save_file_path) # Additional code to save thumbnail to db db_conn = sqlite_connect(DB) cursor = db_conn.cursor() db_insert_blob = """ INSERT INTO {table_name} (name, data) VALUES (?, ?) """.format(table_name=DB_TABLE) image.thumbnail(size=THUMBNAIL_SIZE) binary_data = pil_image_to_byte_array(image) data_tuple = (save_file_path, binary_data) # Execute the query cursor.execute(db_insert_blob, data_tuple) db_conn.commit() print(f"Saved {save_file_path} and inserted to db") cursor.close() except Exception as exc: print(exc)
def on_message(client, userdata, msg): now = get_now_string() print("message on " + str(msg.topic) + f" at {now}") try: image = byte_array_to_pil_image(msg.payload) # PIL image image = image.rotate(ROTATE_ANGLE) # Apply rotation byte_array = pil_image_to_byte_array(image) client.publish(MQTT_PUBLISH_TOPIC, byte_array, qos=MQTT_QOS) print(f"published processed frame on topic: {MQTT_PUBLISH_TOPIC} at {now}") except Exception as exc: print(exc)
def on_message(client, userdata, msg): now = get_now_string() print("message on " + str(msg.topic) + f" at {now}") try: image = byte_array_to_pil_image(msg.payload) image = image.convert("RGB") save_file_path = CAPTURES_DIRECTORY + f"capture_{now}.jpg" image.save(save_file_path) print(f"Saved {save_file_path}") except Exception as exc: print(exc)