mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 03:09:58 +00:00
BUNCH OF TRASH
This commit is contained in:
BIN
__pycache__/models.cpython-312.pyc
Normal file
BIN
__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/server.cpython-312.pyc
Normal file
BIN
__pycache__/server.cpython-312.pyc
Normal file
Binary file not shown.
BIN
application/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
application/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
image.jpg
BIN
image.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 33 KiB |
BIN
image0.jpg
BIN
image0.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
BIN
image1.jpg
BIN
image1.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
BIN
image2.jpg
BIN
image2.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
BIN
migrations/__pycache__/env.cpython-312.pyc
Normal file
BIN
migrations/__pycache__/env.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
migrations/versions/__pycache__/dcedd32468e2_.cpython-312.pyc
Normal file
BIN
migrations/versions/__pycache__/dcedd32468e2_.cpython-312.pyc
Normal file
Binary file not shown.
@@ -1,8 +1,8 @@
|
|||||||
"""empty message
|
"""empty message
|
||||||
|
|
||||||
Revision ID: ac8b1871be3d
|
Revision ID: dcedd32468e2
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2025-04-22 22:32:26.012696
|
Create Date: 2025-04-23 09:48:54.655874
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = 'ac8b1871be3d'
|
revision = 'dcedd32468e2'
|
||||||
down_revision = None
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
port = 2222
|
port = 2222
|
||||||
server = "192.168.137.1"
|
server = "192.168.137.1"
|
||||||
data_path = "upload"
|
data_path = "api"
|
||||||
ssid = "STEF"
|
ssid = "stef"
|
||||||
password = "TEST123123"
|
password = "test123123"
|
||||||
|
|||||||
@@ -1,44 +1,38 @@
|
|||||||
import urequests as requests
|
import urequests
|
||||||
import config
|
import config
|
||||||
from connection import connection
|
from connection import connection
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import random
|
||||||
|
|
||||||
# Path to the image
|
wait_pin = Pin(13, Pin.OUT)
|
||||||
image_path = "car2.jpg"
|
good_pin = Pin(15, Pin.OUT)
|
||||||
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():
|
while connection.isconnected():
|
||||||
# Send as multipart/form-data
|
good_pin.low()
|
||||||
boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
|
bad_pin.low()
|
||||||
headers = {"Content-Type": "multipart/form-data; boundary=" + boundary}
|
wait_pin.high()
|
||||||
|
if random.choice([True, False]):
|
||||||
body = (
|
response = send_image("1234.jpg")
|
||||||
(
|
else:
|
||||||
"--"
|
response = send_image("car2.jpg")
|
||||||
+ 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)
|
|
||||||
print(response)
|
print(response)
|
||||||
print(response.status_code)
|
wait_pin.low()
|
||||||
print(response.text)
|
if response["status"]:
|
||||||
if response.json()["status"]:
|
good_pin.high()
|
||||||
pin.high()
|
else:
|
||||||
sleep(0.5)
|
bad_pin.high()
|
||||||
pin.low()
|
sleep(1)
|
||||||
response.close()
|
|
||||||
sleep(2)
|
|
||||||
|
|||||||
13
server.py
13
server.py
@@ -24,21 +24,15 @@ def home():
|
|||||||
return "Hello, World!"
|
return "Hello, World!"
|
||||||
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
|
|
||||||
# API to process vehicle
|
# API to process vehicle
|
||||||
@app.route("/api", methods=["POST"])
|
@app.route("/api", methods=["POST"])
|
||||||
def data():
|
def data():
|
||||||
data = request.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)
|
f.write(data)
|
||||||
|
|
||||||
status = asyncio.run(process_image(f"image{i}.jpg"))
|
status = asyncio.run(process_image("image.jpg"))
|
||||||
|
|
||||||
i += 1
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
{
|
{
|
||||||
"message": "Image sent succesfully",
|
"message": "Image sent succesfully",
|
||||||
@@ -48,8 +42,9 @@ def data():
|
|||||||
|
|
||||||
|
|
||||||
async def process_image(file: str) -> bool:
|
async def process_image(file: str) -> bool:
|
||||||
|
print("Processing image")
|
||||||
anpr = ANPR()
|
anpr = ANPR()
|
||||||
anpr_info: ... = await anpr.detect(file) # type: ignore
|
anpr_info = await anpr.detect(file) # type: ignore
|
||||||
number_plate = anpr_info["plate_number"]
|
number_plate = anpr_info["plate_number"]
|
||||||
if number_plate:
|
if number_plate:
|
||||||
allowed = (
|
allowed = (
|
||||||
|
|||||||
Reference in New Issue
Block a user