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.

VideoServer.py 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.

     http://192.168.1.12:5010/startarm
     http://192.168.1.12:5010/stoparm
     http://192.168.1.12:5010/startvideo
     http://192.168.1.12:5010/stopvideo
     http://192.168.1.12:5010/timelapseon
     http://192.168.1.12:5010/timelapseoff
     http://192.168.1.12:5010/lastimage

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
http://192.168.1.12:5010/lastimage
# save from command line
curl -o http://192.168.1.12:5010/lastimage

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@192.168.1.200:securitycam

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@192.168.1.200:securitycam

Here is a gist with VideoServer.py and timelapse_app.py

Tags: raspberry, linux, flask

©2020. Robert Cudmore.