Ejemplo n.º 1
0
def main():
    client = get_mqtt_client()
    client.on_message = on_message
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    client.subscribe(SAVE_TOPIC)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_forever()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
def main():
    client = get_mqtt_client()
    # if MQTT_USER != "" and MQTT_PWD != "":
    client.username_pw_set(MQTT_USER, MQTT_PWD)
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_start()

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

    while True:
        frame = camera.read()

        font = cv2.FONT_HERSHEY_SIMPLEX
        datet = datetime.datetime.now().strftime("%d.%m.%Y, %H:%M:%S")
        frame = cv2.putText(frame, datet, (10, 20), font, 0.7, (255, 255, 255),
                            1, cv2.LINE_AA)
        # cv2.imshow('frame', frame)

        np_array_RGB = opencv2matplotlib(frame)  # Convert to RGB

        image = Image.fromarray(np_array_RGB)  #  PIL image
        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}")
Ejemplo n.º 4
0
def main():
    db_conn = sqlite_connect(DB)
    cursor = db_conn.cursor()
    cursor.execute(CREATE_TABLE_DDL.format(table_name=DB_TABLE))
    db_conn.commit()
    db_conn.close()

    client = get_mqtt_client()
    client.on_message = on_message
    client.connect(MQTT_BROKER, port=MQTT_PORT)
    client.subscribe(SAVE_TOPIC)
    time.sleep(4)  # Wait for connection setup to complete
    client.loop_forever()
Ejemplo n.º 5
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 = WebcamVideoStream(src=VIDEO_SOURCE).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)  #  PIL image
        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)