Esempio n. 1
0
def main():
    client = get_mqtt_client()
    client.on_message = on_message
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    client.subscribe(MQTT_TOPIC)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_forever()
Esempio n. 2
0
def main():
    """ """
    client = get_mqtt_client()
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_start()

    for frame in AsyncVideoStream(src=VIDEO_SOURCE):
        client.publish(
            MQTT_TOPIC_CAMERA,
            pil_image_to_byte_array(
                Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))),
            qos=MQTT_QOS,
        )
        print(f"published frame on topic: {MQTT_TOPIC_CAMERA} at {now_repr()}")
        time.sleep(1 / FPS)
Esempio n. 3
0
def main():
    client = get_mqtt_client()
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_start()

    # Open camera
    camera = VideoStream(src=VIDEO_SOURCE, framerate=FPS).start()
    time.sleep(2)  # Webcam light should come on if using one

    while True:
        frame = camera.read()
        np_array_RGB = opencv2matplotlib(frame)  # Convert to RGB

        image = Image.fromarray(np_array_RGB)
        byte_array = pil_image_to_byte_array(image)
        client.publish(MQTT_TOPIC_CAMERA, byte_array, qos=MQTT_QOS)
        now = get_now_string()
        print(f"published frame on topic: {MQTT_TOPIC_CAMERA} at {now}")
        time.sleep(1 / FPS)