-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
67 additions
and
154 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
GOARGS=GOOS=linux GOARCH=arm CGO_ENABLED=0 | ||
|
||
.PHONY: build | ||
build: | ||
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -o ./root/usr/local/bin/cctv_upload ./cmd/cctv_upload | ||
|
||
.PHONY: install | ||
install: | ||
go get -u github.com/golang/dep/cmd/dep | ||
dep ensure -v | ||
@cd ./uploader \ | ||
&& $(GOARGS) go build -o ../root/usr/local/bin/uploader . |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,26 +40,15 @@ be helpful for that. | |
|
||
A USB webcam is used for this project. Any USB camera should do, I'm using a [Logitech C920 Webcam](https://www.amazon.com/gp/product/B006JH8T3S). | ||
|
||
## Golang | ||
|
||
You'll need a working Go environment on your local machine to build the code. | ||
|
||
* Go v1.11 | ||
* [dep](https://github.com/golang/dep) | ||
|
||
# Device Setup | ||
|
||
## Install dependencies | ||
|
||
|
||
``` | ||
sudo apt-get update | ||
ssh [email protected] | ||
# usb camera support | ||
sudo apt-get install fswebcam | ||
# Install motion | ||
sudo apt-get install motion | ||
# usb camera support and motion | ||
sudo apt-get update -y && sudo apt-get install -y fswebcam motion | ||
``` | ||
|
||
Test the camera with `fswebcam` | ||
|
@@ -77,8 +66,8 @@ Captured frame in 0.00 seconds. | |
--- Processing captured image... | ||
Writing JPEG image to 'image.jpg'. | ||
``` | ||
Now we know our webcam is at `/dev/video0`. If you look at `image.jpg` you'll see the picture it took. | ||
|
||
Now we know our webcam is at `/dev/video0`. If you look at `image.jpg` you'll see the picture it took. | ||
|
||
## Configure motion | ||
|
||
|
@@ -125,7 +114,7 @@ to AWS S3 and notifying a Slack channel. | |
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "cctv_upload", | ||
"Sid": "securitycamera", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:PutObject", | ||
|
@@ -144,36 +133,38 @@ to AWS S3 and notifying a Slack channel. | |
|
||
# Uploading images | ||
|
||
Edit the `on_picture_save` script with your AWS and Slack secrets: | ||
``` | ||
# ./root/usr/local/bin/on_picture_save | ||
When motion is detected a new image is created and the `on_picture_save` script is invoked. This calls the `uploader` which uploads the image to S3. Download the [latest release](https://github.com/bndw/security-camera/releases/latest) of the uploader and save it in `./root/usr/local/bin/uploader`. | ||
|
||
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/slack/webhook | ||
S3_BUCKET_NAME=my-bucket-name | ||
S3_BUCKET_REGION=us-west-2 | ||
AWS_ACCESS_KEY=xxx | ||
AWS_SECRET_KEY=xxxxx | ||
Or, build from source if you have Go 1.13 or later: | ||
``` | ||
make build | ||
``` | ||
|
||
Build the [cctv_upload](./cmd/cctv_upload) program that ties the system together. | ||
It's called by the `on_picture_save` script when a new image is created. | ||
The program uploads the image to S3 and then sends a webhook to Slack with the image url. | ||
|
||
Next, upload both programs to the pi | ||
``` | ||
make install | ||
make build | ||
scp ./root/usr/local/bin/* [email protected]:/tmp/ | ||
``` | ||
|
||
Upload both programs to the pi | ||
SSH to the pi to complete configuration | ||
``` | ||
rsync -avz root/usr/local/bin/ pi@your_ip:/tmp | ||
ssh pi@raspberrypi.local | ||
cp /tmp/cctv_upload /usr/local/bin/ | ||
cp /tmp/on_picture_save /usr/local/bin/ | ||
# Copy the scripts into the PATH | ||
sudo mv /tmp/{uploader,on_picture_save} /usr/local/bin/ | ||
``` | ||
|
||
Finally, open the motion config again and configure it to call the `on_picture_save` script everytime it creates an image. | ||
Edit `/usr/local/bin/on_picture_save` and add your AWS and Slack secrets: | ||
``` | ||
# /usr/local/bin/on_picture_save | ||
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/slack/webhook | ||
S3_BUCKET_NAME=my-bucket-name | ||
S3_BUCKET_REGION=us-west-2 | ||
AWS_ACCESS_KEY=xxx | ||
AWS_SECRET_KEY=xxxxx | ||
``` | ||
|
||
Open the motion config again and configure it to call the `on_picture_save` script everytime it creates an image. | ||
``` | ||
# /etc/motion/motion.conf | ||
on_picture_save /usr/local/bin/on_picture_save %f | ||
|
@@ -183,3 +174,5 @@ Restart motion | |
``` | ||
systemctl restart motion | ||
``` | ||
|
||
You should be good to go. Check out the motion detection settings in `/etc/motion/motion.conf` for customizing thresholds, etc. |
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/bndw/security-camera/uploader | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.30.29 | ||
github.com/google/uuid v1.1.1 | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
github.com/aws/aws-sdk-go v1.30.29 h1:NXNqBS9hjOCpDL8SyCyl38gZX3LLLunKOJc5E7vJ8P0= | ||
github.com/aws/aws-sdk-go v1.30.29/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | ||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | ||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= | ||
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= | ||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= | ||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= | ||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
File renamed without changes.
This file contains 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
File renamed without changes.