You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB

5 years ago
import requests
from gpiozero import Button, LED
from picamera import PiCamera
from time import sleep, strftime
url = 'http://192.168.1.108:3000/upload-photo'
camera = PiCamera()
camera.resolution = (2560, 1920)
greenLed = LED(16)
greenLed.on()
redLed = LED(20)
redLed.off()
button = Button(21)
buttonLastState = False
def errorBlink():
greenLed.off()
redLed.on()
sleep(1)
redLed.off()
sleep(1)
redLed.on()
sleep(1)
redLed.off()
sleep(1)
greenLed.on()
def successBlink():
greenLed.on()
redLed.off()
sleep(1)
greenLed.off()
sleep(1)
greenLed.on()
sleep(1)
greenLed.off()
sleep(1)
greenLed.on()
def takePhotoAndUpload():
time = strftime("%H-%M-%S")
filename = f"{time}.jpg"
camera.capture(filename)
files = {'photo': open(filename, 'rb')}
try :
r = requests.post(url, files=files, timeout=30)
print(r.status_code)
if (r.status_code == 200):
errorSuccess()
else:
errorBlink()
except:
errorBlink()
while True:
if(buttonLastState != button.is_pressed):
if button.is_pressed:
buttonLastState = True
takePhotoAndUpload()
else:
buttonLastState = False