Files
picUploadApi/demo/README.md

3.4 KiB

Raspberry Pi Webcam Capture Demo

Automated picture capture and upload for Raspberry Pi 3 with a USB webcam (Logitech 1080p).

Quick Setup (5 minutes)

1. Install Required Packages

sudo apt update && sudo apt install -y fswebcam curl

2. Configure the Script

# Copy the config template
cp picupper.conf.example picupper.conf

# Edit with your settings
nano picupper.conf

Update picupper.conf with your API key and camera settings.

3. Install & Enable

# Make scripts executable
chmod +x capture-upload.sh install.sh

# Run installer (sets up cron job)
./install.sh

That's it! Your Pi will now capture and upload one picture per minute.


Files Included

File Purpose
capture-upload.sh Main script - captures photo and uploads
picupper.conf.example Configuration template
install.sh Installer script (sets up cron)
uninstall.sh Removes cron job

Configuration Options

Edit picupper.conf:

# PicUpper server URL
API_URL="https://dev.seedheads.de/picUploadApi/upload"

# Your API key (from server admin)
API_KEY="your-api-key-here"

# Camera identifier (unique name for this Pi)
CAMERA_ID="rpi-webcam-1"

# Resolution (1920x1080 for full HD)
RESOLUTION="1920x1080"

# Video device (usually /dev/video0)
VIDEO_DEVICE="/dev/video0"

Manual Testing

# Test capture only (saves to /tmp)
./capture-upload.sh --test

# Run full capture and upload once
./capture-upload.sh

Troubleshooting

Check if webcam is detected

ls /dev/video*
v4l2-ctl --list-devices

Test capture manually

fswebcam -d /dev/video0 -r 1920x1080 --no-banner test.jpg

Check logs

# View recent capture logs
tail -f ~/picUploadApi/demo/picupper.log

Common Issues

Problem Solution
"No video device" Replug USB webcam, check dmesg
"Permission denied" Add user to video group: sudo usermod -aG video $USER
"Upload failed" Check API key and network connection

Changing Capture Frequency

Default is 1 picture per minute. To change:

# Edit cron job
crontab -e

Examples:

  • Every 5 minutes: */5 * * * * ~/picUploadApi/demo/capture-upload.sh
  • Every 30 seconds: Use systemd timer instead of cron

SD Card Preservation

Reduce SD card writes to extend its lifetime:

# Disable swap
sudo swapoff -a
# Comment out swap line in /etc/fstab
sudo nano /etc/fstab

# Disable automatic apt updates
sudo systemctl disable apt-daily.timer apt-daily-upgrade.timer

Option 2: Full Read-Only Mode

sudo raspi-config
# Navigate to: Performance Options → Overlay File System → Enable

⚠️ Before enabling read-only mode, change log location to tmpfs:

# Edit picupper.conf
LOG_FILE="/tmp/picupper.log"

Auto-Reboot (Stability)

For long-running deployments, schedule automatic reboots:

sudo crontab -e

Add (reboots at 00:00, 06:00, 12:00, 18:00):

0 */6 * * * /sbin/reboot

Hardware Requirements

  • Raspberry Pi 3 (any model)
  • USB webcam (Logitech C920/C922/C270 recommended)
  • SD card with Raspberry Pi OS
  • Network connection (WiFi or Ethernet)

Network Notes

The script retries failed uploads and logs all attempts. If your Pi loses network, captures continue and uploads resume when connectivity returns.