A Next.js-based frontend for a Raspberry Pi webcam system, providing a responsive UI to manage cameras (Raspberry Pi via picamera2 or CameraIDS), preview live streams, capture and store images, and monitor system metrics like CPU usage, memory, and temperature. Integrates with the webcam-backend API.
- Camera Management: Select and control Raspberry Pi or CameraIDS cameras.
- Live Preview: Stream camera feeds via WebSocket with start/stop functionality.
- Image Storage: Capture images manually or at set intervals, with access to stored images in a file explorer.
- System Monitoring: Display Raspberry Pi metrics (hostname, platform, architecture, CPU temperature, per-core CPU usage, memory, and storage).
- Responsive UI: Built with Next.js 15.1.7, shadcn/ui (New York style), Tailwind CSS, and Lucide icons.
- Hardware:
- Raspberry Pi (tested on Raspberry Pi 5) with compatible cameras (
picameraor CameraIDS).
- Raspberry Pi (tested on Raspberry Pi 5) with compatible cameras (
- Software:
- Node.js (v18 or later).
- Next.js (15.1.7).
- Systemd (for production deployment).
- Backend:
- webcam-backend running on
http://0.0.0.0:8000. - For CameraIDS, IDS Peak software must be installed (see backend README).
- webcam-backend running on
- Dependencies: Listed in
package.json.
-
Clone the Repository:
git clone https://github.com/gnaegit/webcam-frontend.git mv webcam-frontend /home/pi/webcam/webcam-frontend cd /home/pi/webcam/webcam-frontend -
Install Dependencies:
npm install
Installs
next@15.1.7,react@19.0.0,react-use-websocket,@radix-ui/*(shadcn/ui),lucide-react,tailwindcss, and other dependencies. -
Verify UI and Styling Setup:
- shadcn/ui configured with "New York" style in
components.json. - Tailwind CSS configured in
tailwind.config.tsandsrc/app/globals.css. - Path aliases:
@/components,@/lib/utils,@/ui,@/lib,@/hooks. - Lucide icons enabled for UI elements.
- shadcn/ui configured with "New York" style in
-
Configure Proxy:
next.config.jsproxies/py/:path*to the backend athttp://0.0.0.0:8000:const nextConfig = { async rewrites() { return [ { source: "/py/:path*", destination: "http://0.0.0.0:8000/:path*", }, ]; }, }; export default nextConfig;
- Update
destinationif the backend is hosted elsewhere.
-
Set Up Systemd Service (Production):
- Copy
webcam-frontend.serviceto/etc/systemd/system/:sudo cp webcam-frontend.service /etc/systemd/system/
- Verify
ExecStartuses the correctnpmpath:[Unit] Description=Webcam Next.js Frontend After=network.target [Service] User=pi WorkingDirectory=/home/pi/webcam/webcam-frontend ExecStart=/usr/bin/npm run start Restart=always Environment=PORT=3000 StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.target
- Enable the service (do not start during development):
sudo systemctl enable webcam-frontend.service
- Copy
-
Verify Setup:
- Ensure the backend is running on
http://0.0.0.0:8000. - Start the frontend service (production):
sudo systemctl start webcam-frontend.service sudo systemctl status webcam-frontend.service
- Ensure the backend is running on
-
Access the Application:
- Open
http://<raspberry-pi-ip>:3000in a browser.
- Open
-
Welcome Page (
/):- Links to Camera Page and Stats Page.
-
Camera Page (
/camera):- Select a camera (Raspberry Pi or CameraIDS).
- Start/stop live preview via WebSocket.
- Capture images manually or set storage intervals.
- Adjust CameraIDS settings (exposure, gain) if supported.
- Access stored images via "View Stored Images" (links to
/camera/images).
-
File Explorer (
/camera/images):- Browse, download, or delete stored images and folders.
- WebSocket updates refresh the file list when new images are saved.
-
Stats Page (
/stats):- Displays system metrics: hostname, platform, architecture, CPU temperature, per-core CPU usage, memory, and storage usage.
- Updates every 5 seconds.
-
Monitoring:
- Check WebSocket connection status and camera states on the Camera Page.
- View errors/warnings in the UI or browser console.
app/page.tsx: Welcome page with navigation links.app/camera/page.tsx: Camera management, live preview, and storage controls.app/camera/images/page.tsx: File explorer for stored images.app/stats/page.tsx: System metrics display.next.config.js: Configures backend proxy.components.json: shadcn/ui and Tailwind CSS configuration.package.json: Dependencies and scripts (dev,build,start).webcam-frontend.service: Systemd service for production.
-
Stop Production Services:
sudo systemctl stop webcam-frontend.service sudo systemctl stop webcam-backend.service
- Verify ports are free:
sudo lsof -i :3000 sudo lsof -i :8000
- Verify ports are free:
-
Run the Backend:
- Follow webcam-backend README:
cd ../webcam-backend source venv/bin/activate uvicorn main:app --host 0.0.0.0 --port 8000
- Follow webcam-backend README:
-
Run the Frontend:
npm run dev
- Uses Turbopack (
next dev --turbopack) for hot-reloading. - Access at
http://localhost:3000.
- Uses Turbopack (
-
Testing:
- Test camera selection, live preview, image capture/storage, and file explorer.
- Verify system stats update correctly.
- Check browser console and backend logs for errors.
-
Stop Development Servers:
- Terminate
npm run devand backend processes.
- Terminate
-
Build the Application:
npm run build
-
Start Services:
sudo systemctl start webcam-frontend.service sudo systemctl start webcam-backend.service
-
Verify:
- Check service status:
sudo systemctl status webcam-frontend.service sudo systemctl status webcam-backend.service
- Access at
http://<raspberry-pi-ip>:3000.
- Check service status:
- Service Fails to Start:
- Check logs:
journalctl -u webcam-frontend.service. - Verify
npmpath:which npm. - Ensure
/home/pi/webcam/webcam-frontendexists.
- Check logs:
- Port Conflicts:
- Check occupied ports:
sudo lsof -i :3000orsudo lsof -i :8000. - Terminate conflicting processes or change ports.
- Check occupied ports:
- Backend Unavailable:
- Confirm backend is running on
http://0.0.0.0:8000. - Check backend logs:
journalctl -u webcam-backend.service.
- Confirm backend is running on
- Camera Issues:
- Verify camera hardware and backend configuration.
- For CameraIDS, ensure IDS Peak software is installed (see backend README).
- WebSocket Issues:
- Ensure backend WebSocket endpoint (
/py/ws) is accessible. - Check browser console for connection errors.
- Ensure backend WebSocket endpoint (
Submit issues or pull requests to webcam-frontend or webcam-backend.
MIT License.