RESTful API with Flask that serves images from Raspberry Pi powered by picamera.
This software is intended to run in the following environment:
- Raspberry Pi 3 Model B v1.2
- Picamera v2
The testing environment for this software is a Macbook, the built-in camera is used.
All dependencies are specified in requirements.txt. Install all python packages:
pip install -r requirements.txt
- If using
virtualenvwrapper:workon WatcherEye - Set Flask app environment variable:
export FLASK_APP=watchereye - Set Flask app development variable:
export FLASK_ENV=info - Start the Flask server:
flask run - Point your favorite browser to
localhost:5000
Note that flask in debug mode only exposes the web service locally on the host. To have the web service accessible from external IPs (i.e. using the public IP of the server), you may need to run flask with the --host=0.0.0.0 flag.
The API can be accessed via HTTP/S requests, see watchereye/api.pyfor up-to-date API endpoint documentation. Briefly:
| Method | Endpoint | Description | Return Format |
|---|---|---|---|
GET |
/api/v1/ping |
Ping API server | JSON array |
GET |
/api/v1/stats |
Usage statistics | JSON array |
GET |
/api/v1/image |
Capture and return image | image/jpeg |
GET |
/api/v1/stream |
View video stream | multipart/x-mixed-replace; image/jpeg |
Logging at the debug level (recording all incoming requests and IPs) using the default python logging facility. Logs are stored in logs/log.log and streamed to STDOUT
Using PyTest:
workon WatcherEyepython -m pytest -s -v --disable-pytest-warnings tests/
- Installing Raspbian on Raspberry Pi on Mac OS X
- Video Streaming with Flask
- Flask Video Streaming Revisited
Update requirements.txt after installing any new pip modules using:
pip freeze > requirements.txt