mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 03:09:58 +00:00
No empty logs and fixes some errors
This commit is contained in:
@@ -15,19 +15,23 @@ 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
|
||||
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)
|
||||
headers = {"Content-Type": "image/jpeg"}
|
||||
addr = socket.getaddrinfo(config.server,config.port)[0][-1]
|
||||
addr = socket.getaddrinfo(config.server, config.port)[0][-1]
|
||||
|
||||
|
||||
def send_image(image_file_path):
|
||||
cam.capture_jpg()
|
||||
with open(image_file_path, 'wb') as f:
|
||||
with open(image_file_path, "wb") as f:
|
||||
f.write(b"")
|
||||
cam.save_JPG(image_file_path)
|
||||
with open(image_file_path, 'rb') as f:
|
||||
with open(image_file_path, "rb") as f:
|
||||
s = socket.socket()
|
||||
s.connect(addr)
|
||||
# Send HTTP headers
|
||||
@@ -36,9 +40,9 @@ def send_image(image_file_path):
|
||||
s.send(b"Transfer-Encoding: chunked\r\n")
|
||||
s.send(b"Content-Type: application/octet-stream\r\n")
|
||||
s.send(b"\r\n")
|
||||
|
||||
|
||||
chunk_size = 512
|
||||
|
||||
|
||||
while True:
|
||||
chunk = f.read(chunk_size)
|
||||
if not chunk:
|
||||
@@ -54,16 +58,17 @@ def send_image(image_file_path):
|
||||
# Final chunk to end the stream
|
||||
s.send(b"0\r\n\r\n")
|
||||
s.close()
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
while connection.isconnected():
|
||||
good_pin.low()
|
||||
bad_pin.low()
|
||||
wait_pin.high()
|
||||
#if random.choice([True, False]):
|
||||
# if random.choice([True, False]):
|
||||
# response = send_image("1234.jpg")
|
||||
#else:
|
||||
# else:
|
||||
# response = send_image("car2.jpg")
|
||||
response = send_image("image.jpg")
|
||||
print(response)
|
||||
@@ -73,4 +78,4 @@ while connection.isconnected():
|
||||
good_pin.high()
|
||||
else:
|
||||
bad_pin.high()
|
||||
sleep(5)
|
||||
sleep(5)
|
||||
|
||||
Reference in New Issue
Block a user