Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최지우
2020-11-19 23:02:29 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e04a43a5aa91ec2242a7431f61503dfb432adaa6
e04a43a5
1 parent
aa9a731a
aws settings lock off
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
9 deletions
api/models.py
api/videorecord.py
api/views.py
src/settings.py
videorecord.py
api/models.py
View file @
e04a43a
...
...
@@ -32,4 +32,4 @@ class Record(models.Model) :
class
AddDevice
(
models
.
Model
)
:
id
=
models
.
IntegerField
(
primary_key
=
True
)
add
=
models
.
BooleanField
(
default
=
False
)
\ No newline at end of file
state
=
models
.
BooleanField
(
default
=
False
)
\ No newline at end of file
...
...
api/videorecord.py
View file @
e04a43a
...
...
@@ -10,12 +10,12 @@ django.setup()
from
django.core
import
serializers
from
api.models
import
Video
,
Record
from
api.serializers
import
VideoSerializer
,
RecordSerializer
'''
from
boto3.session
import
Session
from
src.settings
import
AWS_REGION
,
S3_ACCESS_URL
,
S3_ACCESS_KEY_ID
,
S3_SECRET_ACCESS_KEY
,
S3_STORAGE_BUCKET_NAME
import
RPi.GPIO
as
GPIO
from
picamera
import
PiCamera
'''
def
record
()
:
path
=
'/home/pi/recorded'
# save path
...
...
@@ -61,7 +61,6 @@ def record() :
vid_time
=
time
.
strftime
(
"
%
M:
%
S"
,
time
.
gmtime
(
time
.
time
()
-
start_time
))
# s3 upload
'''
s3
=
boto3
.
client
(
's3'
,
region_name
=
'ap-northeast-2'
)
s3
.
upload_file
(
Filename
=
vid_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
)
s3
.
upload_file
(
Filename
=
thumbnail_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'_thumb'
)
...
...
@@ -73,7 +72,6 @@ def record() :
uploadVideo
[
'thumb'
]
=
S3_ACCESS_URL
+
vid_name
+
'_thumb'
serializer
=
VideoSerializer
(
data
=
uploadVideo
)
serializer
.
save
()
'''
print
(
vid_path
,
"upload success"
)
os
.
remove
(
vid_path
)
else
:
...
...
api/views.py
View file @
e04a43a
...
...
@@ -17,12 +17,11 @@ from rest_framework.request import Request
from
rest_framework.response
import
Response
from
rest_framework.authtoken.models
import
Token
"""
from
boto3.session
import
Session
from
src.settings
import
AWS_REGION
from
src.settings
import
S3_ACCESS_URL
from
src.settings
import
S3_ACCESS_KEY_ID
,
S3_SECRET_ACCESS_KEY
,
S3_STORAGE_BUCKET_NAME
"""
import
time
from
datetime
import
datetime
,
timedelta
import
json
...
...
src/settings.py
View file @
e04a43a
...
...
@@ -124,7 +124,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL
=
'/static/'
"""
AWS_REGION
=
'ap-northeast-2'
AWS_SETTINGS
=
os
.
path
.
join
(
BASE_DIR
,
'.aws_key.json'
)
awskey
=
json
.
loads
(
open
(
AWS_SETTINGS
)
.
read
())
...
...
@@ -133,4 +133,3 @@ S3_ACCESS_KEY_ID = awskey['aws']['access_key_id']
S3_SECRET_ACCESS_KEY
=
awskey
[
'aws'
][
'secret_access_key'
]
S3_STORAGE_BUCKET_NAME
=
awskey
[
'aws'
][
's3_bucket_name'
]
S3_ACCESS_URL
=
awskey
[
'aws'
][
's3_access_url'
]
"""
\ No newline at end of file
...
...
videorecord.py
0 → 100644
View file @
e04a43a
import
os
import
boto3
import
botocore
import
time
import
datetime
import
django
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'src.settings'
)
django
.
setup
()
from
django.core
import
serializers
from
api.models
import
Video
,
Record
from
api.serializers
import
VideoSerializer
,
RecordSerializer
'''
from boto3.session import Session
from src.settings import AWS_REGION, S3_ACCESS_URL, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCKET_NAME
import RPi.GPIO as GPIO
from picamera import PiCamera
'''
def
record
()
:
path
=
'/home/pi/recorded'
# save path
target
=
Record
.
objects
.
get
(
id
=
1
)
serializer
=
RecordSerializer
(
target
,
many
=
False
)
state
=
serializer
.
data
[
'recording'
]
#'''
# rpi setting
GPIO
.
setmode
(
GPIO
.
BCM
)
pir_pin
=
7
GPIO
.
setup
(
pir_pin
,
GPIO
.
IN
)
camera
=
PiCamera
()
#'''
try
:
while
state
:
target
=
Record
.
objects
.
get
(
id
=
1
)
serializer
=
RecordSerializer
(
target
,
many
=
False
)
state
=
serializer
.
data
[
'recording'
]
if
GPIO
.
input
(
pir_pin
):
# motion detected
# take a video
camera
.
resolution
=
[
320
,
240
]
camera
.
start_preview
()
now
=
datetime
.
datetime
.
now
()
start_time
=
time
.
time
()
vid_name
=
now
.
strftime
(
'
%
Y
%
m
%
d-
%
H
%
M
%
S'
)
vid_path
=
path
+
'/'
+
vid_name
+
'.h264'
thumbnail_path
=
path
+
'/'
+
vid_name
+
'.jpg'
camera
.
start_recording
(
output
=
vid_path
)
time
.
sleep
(
1
)
camera
.
capture
(
thumbnail_path
)
while
GPIO
.
input
(
pir_pin
)
:
print
(
"recoring.."
)
time
.
sleep
(
2
)
camera
.
stop_recording
()
camera
.
stop_preview
()
vid_time
=
time
.
strftime
(
"
%
M:
%
S"
,
time
.
gmtime
(
time
.
time
()
-
start_time
))
# s3 upload
'''
s3 = boto3.client('s3', region_name = 'ap-northeast-2')
s3.upload_file(Filename = vid_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name)
s3.upload_file(Filename = thumbnail_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name + '_thumb')
uploadVideo = {}
uploadVideo['vid_name'] = vid_name
uploadVideo['created'] = now
uploadVideo['vid_time'] = vid_time
uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb'
serializer = VideoSerializer(data = uploadVideo)
serializer.save()
'''
print
(
vid_path
,
"upload success"
)
os
.
remove
(
vid_path
)
else
:
camera
.
stop_preview
()
except
KeyboardInterrupt
:
print
(
"quit"
)
GPIO
.
cleanup
()
if
__name__
==
'__main__'
:
record
()
Please
register
or
login
to post a comment