diff --git a/__pycache__/models.cpython-312.pyc b/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..9d39389 Binary files /dev/null and b/__pycache__/models.cpython-312.pyc differ diff --git a/__pycache__/server.cpython-312.pyc b/__pycache__/server.cpython-312.pyc new file mode 100644 index 0000000..07a4acd Binary files /dev/null and b/__pycache__/server.cpython-312.pyc differ diff --git a/application/__pycache__/__init__.cpython-312.pyc b/application/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..5f9b41b Binary files /dev/null and b/application/__pycache__/__init__.cpython-312.pyc differ diff --git a/image.jpg b/image.jpg index 0e3f4a9..80f57d6 100644 Binary files a/image.jpg and b/image.jpg differ diff --git a/image0.jpg b/image0.jpg deleted file mode 100644 index e80034c..0000000 Binary files a/image0.jpg and /dev/null differ diff --git a/image1.jpg b/image1.jpg deleted file mode 100644 index e80034c..0000000 Binary files a/image1.jpg and /dev/null differ diff --git a/image2.jpg b/image2.jpg deleted file mode 100644 index 0e3f4a9..0000000 Binary files a/image2.jpg and /dev/null differ diff --git a/instance/data.sqlite b/instance/data.sqlite index 39d42f7..e8ddcf0 100644 Binary files a/instance/data.sqlite and b/instance/data.sqlite differ diff --git a/migrations/__pycache__/env.cpython-312.pyc b/migrations/__pycache__/env.cpython-312.pyc new file mode 100644 index 0000000..fb56cec Binary files /dev/null and b/migrations/__pycache__/env.cpython-312.pyc differ diff --git a/migrations/__pycache__/env.cpython-313.pyc b/migrations/__pycache__/env.cpython-313.pyc deleted file mode 100644 index 8c50a3e..0000000 Binary files a/migrations/__pycache__/env.cpython-313.pyc and /dev/null differ diff --git a/migrations/versions/__pycache__/ac8b1871be3d_.cpython-313.pyc b/migrations/versions/__pycache__/ac8b1871be3d_.cpython-313.pyc deleted file mode 100644 index eed28ac..0000000 Binary files a/migrations/versions/__pycache__/ac8b1871be3d_.cpython-313.pyc and /dev/null differ diff --git a/migrations/versions/__pycache__/dcedd32468e2_.cpython-312.pyc b/migrations/versions/__pycache__/dcedd32468e2_.cpython-312.pyc new file mode 100644 index 0000000..23db219 Binary files /dev/null and b/migrations/versions/__pycache__/dcedd32468e2_.cpython-312.pyc differ diff --git a/migrations/versions/ac8b1871be3d_.py b/migrations/versions/dcedd32468e2_.py similarity index 91% rename from migrations/versions/ac8b1871be3d_.py rename to migrations/versions/dcedd32468e2_.py index e762caa..82ab5ac 100644 --- a/migrations/versions/ac8b1871be3d_.py +++ b/migrations/versions/dcedd32468e2_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: ac8b1871be3d +Revision ID: dcedd32468e2 Revises: -Create Date: 2025-04-22 22:32:26.012696 +Create Date: 2025-04-23 09:48:54.655874 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'ac8b1871be3d' +revision = 'dcedd32468e2' down_revision = None branch_labels = None depends_on = None diff --git a/pico_files/config.py b/pico_files/config.py index fca380f..e3e99d1 100644 --- a/pico_files/config.py +++ b/pico_files/config.py @@ -1,5 +1,5 @@ port = 2222 server = "192.168.137.1" -data_path = "upload" -ssid = "STEF" -password = "TEST123123" +data_path = "api" +ssid = "stef" +password = "test123123" diff --git a/pico_files/main.py b/pico_files/main.py index 6cb78b1..e7a0369 100644 --- a/pico_files/main.py +++ b/pico_files/main.py @@ -1,44 +1,38 @@ -import urequests as requests +import urequests import config from connection import connection from machine import Pin from time import sleep +import random -# Path to the image -image_path = "car2.jpg" -pin = Pin(15, Pin.OUT) +wait_pin = Pin(13, Pin.OUT) +good_pin = Pin(15, Pin.OUT) +bad_pin = Pin(14, Pin.OUT) + +# Send the POST request with the raw image data as the body +url = f"http://{config.server}:{config.port}/{config.data_path}" + + +def send_image(image_file_path): + with open(image_file_path, "rb") as f: + image_data = f.read() + headers = {"Content-Type": "image/jpeg"} + response = urequests.post(url, headers=headers, data=image_data) + return response.json() -# Prepare the image for sending (open as binary) -with open(image_path, "rb") as image_file: - img_data = image_file.read() while connection.isconnected(): - # Send as multipart/form-data - boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW" - headers = {"Content-Type": "multipart/form-data; boundary=" + boundary} - - body = ( - ( - "--" - + boundary - + "\r\n" - + 'Content-Disposition: form-data; name="image"; filename="image.jpg"\r\n' - + "Content-Type: image/jpeg\r\n\r\n" - ).encode("utf-8") - + img_data - + ("\r\n--" + boundary + "--\r\n").encode("utf-8") - ) - - # Send the POST request with the raw image data as the body - url = f"http://{config.server}:{config.port}/{config.data_path}" - print(url) - response = requests.post(url, headers=headers, data=body) + good_pin.low() + bad_pin.low() + wait_pin.high() + if random.choice([True, False]): + response = send_image("1234.jpg") + else: + response = send_image("car2.jpg") print(response) - print(response.status_code) - print(response.text) - if response.json()["status"]: - pin.high() - sleep(0.5) - pin.low() - response.close() - sleep(2) + wait_pin.low() + if response["status"]: + good_pin.high() + else: + bad_pin.high() + sleep(1) diff --git a/server.py b/server.py index f730bf0..3372366 100644 --- a/server.py +++ b/server.py @@ -24,21 +24,15 @@ def home(): return "Hello, World!" -i = 0 - - # API to process vehicle @app.route("/api", methods=["POST"]) def data(): data = request.data - global i - with open(f"image{i}.jpg", "wb") as f: + with open("image.jpg", "wb") as f: f.write(data) - status = asyncio.run(process_image(f"image{i}.jpg")) - - i += 1 + status = asyncio.run(process_image("image.jpg")) return jsonify( { "message": "Image sent succesfully", @@ -48,8 +42,9 @@ def data(): async def process_image(file: str) -> bool: + print("Processing image") anpr = ANPR() - anpr_info: ... = await anpr.detect(file) # type: ignore + anpr_info = await anpr.detect(file) # type: ignore number_plate = anpr_info["plate_number"] if number_plate: allowed = (