Robert Cudmore    archive    tags    search    software

Camera with a REST interface

I’ve written a few versions of this. In previous versions I would control everything from a Python prompt, or a complex flask app, or use DIO to trigger video.

In this version I am trying to keep it simple and starting/stopping video and timelapse images with a REST api.

To test this out, I will have a motion sensor on another Pi send a REST command to start video when it senses motion. is using a circular stream such that when recording is started, it also saves ‘pre-triggered’ video before recording was started. It can also capture timelapse images while it is recording video. The Raspberry camera is very nice for these two features. I’ve written VideoServer as a class inheriting from threading.Thread so it can run daemonized as a background thread, otherwise it will block other code.

To Do: I still need to expose ‘bufferSeconds’ and ‘stillinterval’ to the REST API.

Get the last timelapse image in a browser or with curl

# display in browser
# save from command line
curl -o

rsync the images and video to a remote host

Now I want to get the videos/images off the machine with the camera. There are more options than I can count but here are three:

I will use rsynch to push the images to a remote server. Follow this for a really thorough explanation.

# assuming you have a folder 'securitycam' on remote host
rsync -avz /home/pi/video/20151206/ -e ssh cudmore@

Make sure you can login to remote server without entering a password

add this

Run rsynch command every 10 minutes with crontab

crontab -e
*/10 * * * * /usr/bin/rsync -avz /home/pi/video/20151206/ -e ssh cudmore@

Here is a gist with and

Tags: raspberry, linux, flask

©2018. Robert Cudmore.