Essbante / raspi_webcam

Simple camera app to run on o a raspberry pi
Apache License 2.0
1 stars 0 forks source link

raspi_webcam

Simple camera app to run on o a raspberry pi

requirements

sudo apt-get update
sudo apt-get install python3-opencv
pip3 install flask
pip3 install python-dotenv

.env file

cd <path>/raspi_webcam
nano .env

Add this lines to the file:

# Server port
PORT=5000
# Camera ID
DEV_VIDEO=0
# Resolution width (Possible values: 1280, 640. may be different depending on the device)
WIDTH=1280
# Resolution height (Possible values: 720, 480. may be different depending on the device)
HEIGHT=720
# Frames per second (Possible values: 25, 10. may be different depending on the device)
FPS=25
# Fingerprint for authentication 
FINGERPRINT=
# Token for authentication
TOKEN=
# URL to post the snapshot
SNAPSHOT_POST_URL=https://webcam.connect.prusa3d.com/c/snapshot
# Delay between snapshots in seconds
SNAPSHOT_DELAY=10
# Path to store the snapshot
SNAPSHOT_PATH=/tmp/snapshot.jpg
# PRUSA LINK IP (Printer local IP)
PRUSA_LINK_IP=
# PRUSA LINK API key (Printer token)
PRUSA_LINK_API_KEY=

Service setup

Create a service config file:

sudo nano /etc/systemd/system/raspi_webcam.service

Add this to the file

[Unit]
Description=raspi_webcam     
After=multi-user.target

[Service]
ExecStart=/usr/bin/python3 <path>/app.py
Restart=on-failure
RestartSec=10
User=<user>

[Install]
WantedBy=multi-user.target

Replace <path> with the full path to your app.py file and <user> with the raspi user. Then run the commands below:

sudo systemctl daemon-reload
sudo systemctl enable raspi_webcam.service
sudo systemctl start raspi_webcam.service

Usefull commands:

stop service

sudo systemctl stop raspi_webcam.service

restart service

sudo systemctl restart raspi_webcam.service

service status

sudo systemctl status raspi_webcam.service

service logs

journalctl -u raspi_webcam.service -n 50

List video devices

v4l2-ctl --list-devices

List video device supported formats

v4l2-ctl --device=/dev/video0 --list-formats-ext

List video device supported resolutions

v4l2-ctl --device=/dev/video0 --list-framesizes=MJPG