Skip to content
btuanPublic

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

162 Commits

Folders and files

Repository files navigation

rcflower

The RC Flower application consists of three pieces that run in an embedded Linux environment:

  • python/ — detect.py reads a USB webcam, runs a YOLOv8n NCNN model from python/yolov8n_ncnn_model, and reports person detections. See python/README.md.
  • backend/ — a Bun server that ingests those detections (POST /api/detections), persists state transitions + watering events to SQLite, and pushes live updates to the frontend over SSE. See backend/README.md.
  • frontend/ — the UI (React), compiled by Vite, served by the backend.

In principle, this software can be run on any single-board computer. It was originally developed for the Raspberry Pi 4B (the reference environment) and also supports the Arduino Uno Q, though not every feature works there yet. See docs/hardware/ for the supported devices.

One server, one port: http://localhost:3000

This trips people up, so to be explicit: the app is the Bun server on port 3000. Dev or prod, that is the only URL you open.

Bun (backend/) Vite (frontend/)
What it is The app server: /api/*, SSE, SQLite, serves the frontend The frontend compiler: TSX, Tailwind, React Compiler, hot reload
Dev (bun run dev) Listens on :3000. Proxies everything that isn't /api to Vite Spawned by Bun as an internal child on 127.0.0.1:5173. Loopback only, prints no banner. Don't open it -- it has no /api routes
Prod (bun run start) Listens on :3000. Serves frontend/dist Not running. vite build ran once (bun run build:frontend) and exited

Why both? Bun is the runtime; Vite is the toolchain that turns TSX/Tailwind into a browser bundle and hot-reloads it while you edit. Bun could bundle, but not with Tailwind v4 + the React Compiler + Fast Refresh out of the box, and in prod Vite isn't a process at all -- so there's little to gain from ripping it out. The rule of thumb: if you're typing 5173, something is wrong.

cd backend && bun install
bun run dev        # dev: :3000 (Vite child for hot reload; invisible)
bun run build:frontend && bun run start   # prod: :3000 only, no Vite

bun commands run from backend/ because Bun loads backend/.env from the cwd. The one Vite-only thing you'll touch is frontend/.env's ALLOWED_HOSTS when developing through a tunnel/proxy hostname.

Running as services (systemd)

Both python/detect.py and the backend run as systemd units so they start on boot and restart on failure. Unit files live in this repo at deploy/systemd/*.service.in (not /etc/systemd/system/ directly) so changes go through git like everything else. They're templates: install-systemd.sh fills in the current user, repo path, and Bun/uv locations (override with BUN= / UV=), so it works on any machine and user account.

Install / update

./deploy/install-systemd.sh

This is the deploy step. It builds the frontend (frontend/dist), copies the unit files into /etc/systemd/system/, reloads systemd, and (re)starts both services. Safe to re-run any time -- after git pull, or after editing a template in deploy/systemd/. Needs sudo. Pass --no-build to skip the frontend build (e.g. only a unit file changed).

Services

Unit What it runs Notes
rcflower-backend.service bun run start in backend/ Prod mode: API + prebuilt frontend/dist on :3000. No Vite process on the device. Frontend changes need a rebuild -- re-run install-systemd.sh.
rcflower-detect.service uv run --no-dev python -u detect.py --config detect-config.prod.yaml in python/ Person-only detection (headless). POSTs to the backend are best-effort, so this doesn't hard-depend on the backend being up.

Inspecting logs

stdout/stderr go straight to the journal (no more log files under /tmp):

journalctl -u rcflower-backend -f       # follow live
journalctl -u rcflower-detect -f
journalctl -u rcflower-detect -n 100 --no-pager   # last 100 lines, no pager
journalctl -u rcflower-backend --since "10 min ago"

Both logs are timestamped in UTC ISO 8601 (2026-09-04T16:07:35.758Z) in the log message itself; journalctl also shows its own local-time prefix per line.

Restart / stop / status

sudo systemctl restart rcflower-backend rcflower-detect
sudo systemctl stop rcflower-backend rcflower-detect
sudo systemctl start rcflower-backend rcflower-detect
sudo systemctl status rcflower-backend rcflower-detect   # state + last few log lines

Boot behavior

Both are enabled (WantedBy=multi-user.target), so they start automatically on boot, and Restart=on-failure (capped at 5 restarts / 60s) brings them back if they crash. If detect.py can't open the camera at startup it logs an ERROR line and exits 1, so systemd retries; after 5 failures in 60s the unit stays failed until you plug the camera in and run sudo systemctl reset-failed rcflower-detect && sudo systemctl restart rcflower-detect. Check journalctl -u rcflower-detect for the reason.

To stop a service from starting on boot without touching the unit file:

sudo systemctl disable rcflower-backend   # or rcflower-detect

Camera device

detect.py opens camera.source: 0 (/dev/video0) by default. If detection isn't seeing anything, check the device is actually there and which index it landed at -- USB enumeration order can shift after a reboot or if other USB devices are plugged in:

lsusb                        # confirm the webcam shows up
ls -la /dev/video*

If the index changes, set camera.source in python/detect-config.prod.yaml (e.g. camera: / source: 1) and sudo systemctl restart rcflower-detect.

Licensing

This software is licensed as follows:

  • Code and documentation are licensed under the MIT License
  • Audiovisual material (including visual assets and animations) is licensed under Creative Commons Attribution-ShareAlike 4.0

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages