Last active
November 5, 2017 20:22
-
-
Save gorsuch/dd67197cd56c74ab0bd16d9209ff624d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3, logging, os | |
from datetime import datetime | |
from gpiozero import MotionSensor | |
from picamera import PiCamera | |
logging.basicConfig(level=logging.INFO) | |
camera = PiCamera() | |
pir = MotionSensor(4) | |
s3 = boto3.resource('s3') | |
bucket = "gorsuch-cameras" | |
prefix = "camera-1" | |
logging.info("starting up") | |
while True: | |
pir.wait_for_motion() | |
logging.info("motion detected") | |
now = datetime.now() | |
filename = "%s.h264" % now.isoformat() | |
camera.start_recording(filename) | |
pir.wait_for_no_motion() | |
logging.info("motion stopped") | |
camera.stop_recording() | |
data = open(filename, 'rb') | |
logging.info("started uploading recording to %s/%s" % (prefix,filename)) | |
s3.Bucket(bucket).put_object(Key="%s/%s" % (prefix,filename), Body=data) | |
logging.info("finished uploading recording to s3") | |
os.remove(filename) | |
logging.info("removed %s" % filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment