Added Pico Files

Added the files used on the raspberry pi pico to send and receive data
This commit is contained in:
2025-04-10 16:34:53 +02:00
parent 1b3efa5fa4
commit 2af034cc86
3 changed files with 85 additions and 0 deletions

44
pico_files/main.py Normal file
View File

@@ -0,0 +1,44 @@
import urequests as requests
import config
from connection import connection
from machine import Pin
from time import sleep
# Path to the image
image_path = "car2.jpg"
pin = Pin(15, Pin.OUT)
# 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)
print(response)
print(response.status_code)
print(response.text)
if response.json()["status"]:
pin.high()
sleep(0.5)
pin.low()
response.close()
sleep(2)