mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
Can take a single photo, haven't tested regular workflow
This commit is contained in:
@@ -4,35 +4,42 @@ from connection import connection
|
||||
from machine import Pin
|
||||
from time import sleep
|
||||
import random
|
||||
from machine import Pin, SPI, reset
|
||||
from camera import *
|
||||
|
||||
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}"
|
||||
url = f'http://{config.server}:{config.port}/{config.data_path}'
|
||||
|
||||
spi = SPI(0,sck=Pin(18), miso=Pin(16), mosi=Pin(19), baudrate=8000000) # Pins for the Raspberry Pi Pico
|
||||
cs = Pin(17, Pin.OUT)
|
||||
cam = Camera(spi, cs, debug_text_enabled=True)
|
||||
cam.capture_jpg()
|
||||
cam.save_JPG(filemanager.new_jpg_filename('image'))
|
||||
|
||||
def send_image(image_file_path):
|
||||
with open(image_file_path, "rb") as f:
|
||||
image_data = f.read()
|
||||
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()
|
||||
|
||||
|
||||
while connection.isconnected():
|
||||
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")
|
||||
#if random.choice([True, False]):
|
||||
# response = send_image("1234.jpg")
|
||||
#else:
|
||||
# response = send_image("car2.jpg")
|
||||
response = send_image("image.jpg")
|
||||
print(response)
|
||||
wait_pin.low()
|
||||
if response["status"]:
|
||||
good_pin.high()
|
||||
else:
|
||||
bad_pin.high()
|
||||
sleep(1)
|
||||
sleep(1)
|
||||
Reference in New Issue
Block a user