Showing
1 changed file
with
11 additions
and
8 deletions
... | @@ -3,11 +3,11 @@ import os | ... | @@ -3,11 +3,11 @@ import os |
3 | #import botocore | 3 | #import botocore |
4 | import time | 4 | import time |
5 | import datetime | 5 | import datetime |
6 | -#from django.core import serializers | ||
7 | 6 | ||
8 | -#from api.models import Video, Record | ||
9 | -#from api.serializers import VideoSerializer, RecordSerializer | ||
10 | ''' | 7 | ''' |
8 | +from django.core import serializers | ||
9 | +from api.models import Video, Record | ||
10 | +from api.serializers import VideoSerializer, RecordSerializer | ||
11 | from boto3.session import Session | 11 | from boto3.session import Session |
12 | from src.settings import AWS_REGION, S3_ACCESS_URL, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCKET_NAME | 12 | from src.settings import AWS_REGION, S3_ACCESS_URL, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCKET_NAME |
13 | ''' | 13 | ''' |
... | @@ -19,6 +19,7 @@ def record() : | ... | @@ -19,6 +19,7 @@ def record() : |
19 | path = '/home/pi/recorded' # save path | 19 | path = '/home/pi/recorded' # save path |
20 | state = True | 20 | state = True |
21 | #''' | 21 | #''' |
22 | + # rpi setting | ||
22 | GPIO.setmode(GPIO.BCM) | 23 | GPIO.setmode(GPIO.BCM) |
23 | PIR_PIN = 7 | 24 | PIR_PIN = 7 |
24 | GPIO.setup(PIR_PIN, GPIO.IN) | 25 | GPIO.setup(PIR_PIN, GPIO.IN) |
... | @@ -27,18 +28,20 @@ def record() : | ... | @@ -27,18 +28,20 @@ def record() : |
27 | 28 | ||
28 | try: | 29 | try: |
29 | while state : | 30 | while state : |
30 | - #target = Record.objects.get(id = 1) | 31 | + ''' |
31 | - #serializer = RecordSerializer(target, many = False) | 32 | + target = Record.objects.get(id = 1) |
32 | - #state = serializer.data['recording'] | 33 | + serializer = RecordSerializer(target, many = False) |
34 | + state = serializer.data['recording'] | ||
35 | + ''' | ||
33 | if GPIO.input(PIR_PIN): # motion detected | 36 | if GPIO.input(PIR_PIN): # motion detected |
34 | # take a video | 37 | # take a video |
35 | - camera.resolution = [320,240] | 38 | + camera.resolution = [320, 240] |
36 | camera.start_preview() | 39 | camera.start_preview() |
37 | now = datetime.datetime.now() | 40 | now = datetime.datetime.now() |
38 | vid_name = now.strftime('%Y%m%d-%H%M%S') | 41 | vid_name = now.strftime('%Y%m%d-%H%M%S') |
39 | vid_path = path + '/' + vid_name + '.h264' | 42 | vid_path = path + '/' + vid_name + '.h264' |
40 | thumbnail_path = path + '/' + vid_name + '.jpg' | 43 | thumbnail_path = path + '/' + vid_name + '.jpg' |
41 | - camera.start_recording(output = vid_path) | 44 | + camera.start_recording(output=vid_path) |
42 | time.sleep(1) | 45 | time.sleep(1) |
43 | camera.capture(thumbnail_path) | 46 | camera.capture(thumbnail_path) |
44 | time.sleep(5) | 47 | time.sleep(5) | ... | ... |
-
Please register or login to post a comment