Skip to content
allenpomeroyPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

78 Commits

Folders and files

Repository files navigation

GardenPi

This repository contains all the hardware and software components for my garden automation system that is based on Raspberry Pi 4 running Debian 12 Bookworm. It uses the built-in Raspberry Pi GPIO ports, a I2C based PiController HAT for additional MCP GPIO sensor ports and LEDs, ADC channels and a separate PCB for a I2C based PowerController with 5 valve and 2 pump relays.

The overall system drives a Weather Station (feeds WeeWx software), various moisture, temperature, humidity sensors, and irrigation control system with 5 valves and 2 pumps. Three status LEDs on the external enclosure (System, Sensors, Irrigation) give an indication of operations. Web pages give Dashboard, Irrigation Control, Schedule, detailed Configuration pages.

GardenPi Dashboard

Hardware

Hardware:

  • Raspberry Pi 4 running Debian 12 Bookworm Linux
  • Native GPIO lines on the Raspberry Pi
    • Rain, Wind, power Hz sensors
  • Native I2C hardware (Bus 1) and software (Bus 3) busses
    • Si7021 Temp+Humidity sensors internal to the enclosure and external
  • PiControllerV7.1.1 expansion PCB
    • MCP23017 for 16 additional GPIO lines accessed via I2C
    • MCP3008 Analog Digital Converter accessed via native GPIO SPI interface
      • Daylight level 3V3
      • Wind Direction 3V3
      • 3x Soil moisture 3V3
      • Water pressure 5V
      • PowerController 5V monitor
      • Auxillary 5V input
  • PowerControllerV2.4.2
    • MCP23017 for control of
      • 5 24VAC relays
      • 2 12VDC pump relays
      • 60Hz 120 VAC frequency measurement
      • 3 additional GPIO input lines

Schematic and PCB for both the Pi expansion HAT and the standalone I2C irrigation power controller were designed with KiCad. PCB fabrication was done by the awesome folks at OSH Park (https://oshpark.com/) who are US based. Parts were sourced from Mouser Electronics (https://mouser.com).

PiController

PiControllerV7 1 kicad_pcb 3d2 PiControllerV7 1 pcb3d2 PiControllerV7 1 kicad_pcb 3d1

PowerController

PowerController-3d2 PowerController-3d PowerController

Software

Overview

All software for this project has been completely rewritten to one integrated project based on

  • handlers to interface with hardware for command, control and queries
  • comprehensive API which exposes endpoints that provide control and query access to hardware
  • many clients could be accessing the MCP23017's or the MCP3008 simultaneously, so there is a small number of handlers to provide exclusive access to the chips without reinitialization on each different access
  • client programs communicate to the handlers via unix sockets and implement an exclusive lock to ensure only one client of each handler is communicating with the handler at a time
  • handler / clients:
    • adc-handler.py / adc.py - read voltage of any of the ADC channels
    • irrigation-handler.py / irrigation.py - control valves and pumps, turn on/off, get status
    • led-handler.py / led.py - control LEDs
    • weather-handler.py - read wind, rain, temperature, humidity sensors
  • API endpoints api.py (default port 5000)
  • webui web HTTPS interface (default port 8787)
  • python3 virtual env in which all needed third party libraries such as the Adafruit CircuitPython
  • Uses Adafruit libraries for both MCP23017 and MCP3008 chips (installed by install process) https://docs.circuitpython.org/projects/mcp230xx/en/latest/api.html#adafruit_mcp230xx.digital_inout.DigitalInOut adafruit-circuitpython-mcp230xx
  • No native modules are used (bcryptjs instead of bcrypt, a JSON file instead of SQLite) specifically so npm install works cleanly on a Raspberry Pi without a C build toolchain.

Quickstart

Download the zip file from GitHub. Unzip then run the install steps. Open https://<host>:8787 — you'll be prompted to create the admin account on first visit.

Installation

GardenPi is implemented with python and virtual environment for handlers and clients and a plain Node.js/Express application for the web UI. The default values in /opt/gardenpi/config/garden.json will start a web UI at port 8787 and API listener at port 5000.

Deployed at /opt/gardenpi, configured entirely from web UI Configuration page. Writes configuration data into /opt/gardenpi/config/garden.json — see Configuration.

unzip GardenPi-main.zip  (will create GardenPi-main directory)
cd GardenPi-main
sudo mkdir -p /opt/gardenpi
sudo mv * /opt/gardenpi
cd ..
rmdir GardenPi-main
cd /opt/gardenpi
sudo /opt/gardenpi/scripts/fix-perms.sh
sudo /opt/gardenpi/scripts/install-gardenpi.sh
sudo /opt/gardenpi/scripts/restart-services.sh

Targets Raspberry Pi OS (bookworm or trixie). Before installing anything, install-gardenpi.sh:

  1. Turns on NTP time sync (timedatectl set-ntp true) and waits up to 90 seconds for the clock to synchronize. With the clock behind, apt rejects repository signatures ("Not live until …") and watering schedules run at the wrong times. If it doesn't sync in time, the install continues with a warning; check that the Pi can reach the internet on UDP port 123.
  2. Runs apt-get update.
  3. Installs nodejs and npm, unless both are already present (the web UI needs Node 18 or newer; trixie ships 20, bookworm 18). A Node.js installed some other way, e.g. from NodeSource, is left alone.
  4. Installs pijuice-base, the PiJuice Python module, unless the system python3 can already import pijuice. Safe shutdown and the battery charge limiter both need it (see PiJuice battery charge limiter). If apt can't install it, the install continues with a warning: the web UI then refuses to shut down, and the charge limiter isn't installed until you install the package and re-run add-services.sh.

It also installs swig and liblgpio-dev (from the Raspberry Pi archive): on newer Pythons, such as 3.13 on trixie, pip has no prebuilt lgpio package and compiles it from source.

Service account and ports come from garden.json. Every GardenPi service except the one-shot gardenpi-init (which runs as root) runs as config.application_user:config.application_group (default pi:pi). The installer applies them everywhere: the systemd units (add-services.sh writes them into User=/Group= when installing), ownership of /opt/gardenpi, the virtual environment and web UI packages, the sudo rules and the log-cleanup crontab. The account must already exist and, for hardware access, belong to the gpio, i2c and spi groups. After changing either setting, re-run sudo /opt/gardenpi/scripts/install-gardenpi.sh; a service restart alone doesn't apply it.

The web UI reads its port, webui.listen_port (default 8787), from garden.json when it starts. The API's port is set in two places that must match: handlers.api.listen_port in garden.json and --bind in gardenpi-api.service, whose command-line value is the one the API actually uses. To change it, edit both, update the web UI's API URL (webui.api_base_url) to match, reinstall the unit (add-services.sh), then restart gardenpi-api and gardenpi-webui. The Configuration page shows the API port read-only for this reason.

Optionally populate watering schedule using

node scripts/seed-schedule.js   # optional: pre-loads an example watering schedule
  • Open browser https://raspberry.local:8787
  • Create initial admin user / password
  • Set any sensor, channel, relay user names and friendly names
InitialConfig

By default the app expects a TLS certificate/key already installed at /etc/pki/tls/certs/node.pem and /etc/pki/tls/private/node.key set via Configuration > GardenPi System. Certificates are used by both API and WebUI.

If they don't exist, the installer creates a temporary one. install-gardenpi.sh runs scripts/setup-tls.sh, which checks the configured config.tls_cert_file and config.tls_key_file. If either is missing (or its directory is), it generates a temporary self-signed pair with scripts/gen-tmp-cert.sh and moves it into place, creating the directories as needed:

  • certificate 0644, private key 0640, both owned by config.application_user:config.application_group
  • a newly created private-key directory is 0750, owned by root with the application group, so only that group can enter it
  • the certificate lists localhost, the Pi's host name and its IP addresses, and is valid for 365 days

Browsers warn about a self-signed certificate until you replace it with a real one at the same paths (or point the Configuration settings at a real one). Existing certificates are never replaced or re-owned. For those, the script only checks that the application user can read both files and that they match, and warns if not. Run it again at any time: sudo /opt/gardenpi/scripts/setup-tls.sh.

The API (gardenpi-api) currently takes its certificate and key from --certfile/--keyfile in gardenpi-api.service (/etc/pki/tls/certs/node.pem, /etc/pki/tls/private/node.key), which override garden.json. If you point the two settings elsewhere, change the unit to match (or remove those two options, and bin/gunicorn.conf.py will read them from garden.json).

Permissions note (your own certificates): a key installed by other tools, such as /etc/pki/tls/private/node.key, is typically root-only readable (0600). Whatever OS user runs this app needs read access to it — either run the service as root, or grant your app user read access, e.g.:

sudo setfacl -m u:pi:r /etc/pki/tls/private/node.key

or

sudo chgrp certificates /etc/pki/tls/private/node.key

Assumes pi user has already been added to certificates group.

Navigate to Configuration tab, set a unique API bearer token in Web UI and API configuration panes. Set a unique session secret in Web UI pane. These can both be alphanumeric strings.

GardenPi Control Web UI

A modern web UI (TLS-only, port 8787) for this GardenPi irrigation system: a configurable-widget Dashboard, an Irrigation tab for direct valve/pump control, a Schedule tab to drive the in-app scheduler, and a Configuration tab. Implemented as a Gunicorn app in node.

It talks to the real GardenPi REST API (Bearer-token auth, relay-based irrigation control, LED status, ADC sensors, a weather endpoint) running on the Pi, with an in-memory simulation mode for development/demo without hardware.

UI

GardenPi Dashboard GardenPi Dashboard2 GardenPi Irrigation GardenPi Irrigation2 GardenPi Schedule GardenPi Config1 GardenPi Config2 GardenPi Config3

Testing

To test the GardenPi web UI without the live API listener, navigate to Configuration > Advanced > Web UI > Use Mock API. Set the API base URL and authentication Token for API and Web UI once you're ready to point at the real controller (see Configuration).

Functions

Features

  • Dashboard with a configurable widget grid: System Status LEDs, Valve Quick Status, Sensors, Scheduler & Controller Health. Widget visibility and (within the Sensors widget) individual sensor visibility are both toggleable and remembered per-browser.
  • Recent Activity — a curated, human-readable, reverse-chronological activity feed (newest first) spanning 2 of the dashboard's 3 widget columns, with infinite scroll back through history.
  • Irrigation tab with separate Valves and Pumps sections, live state, on/off control, and an optional "run for N minutes" safety limit — the minutes box defaults to, and is capped at, handlers.irrigation. max_valve_run_time in garden.json (so it always reflects whatever safety limit is currently configured, not a hardcoded guess) — plus an "Emergency stop" button that stops every relay at once.
  • Schedule tab — an in-app scheduler with add/edit/delete watering windows, per-valve "select all" enable/disable, a per-window Skip next checkbox (with a per-valve "skip all" header box), a Rain delay that pauses all scheduled watering for 1–30 days, next-run times, and live "RUNNING" / "SKIPPED" / "RAIN DELAY" badges.
  • Configuration tab — a full editor for the garden.json file. It is laid out to match the "GardenPi System / Web UI / Software" grouping used across all GardenPi configuration surfaces, with type-preserving edits, masked secrets, HW ID/User ID/Friendly Name label tables for ADC/LED/Irrigation/ Weather, hardware pin-map tables, and automatic backups on every save.
  • Auth — first connection prompts creation of an admin username/password; afterwards it's session-cookie based, with a configurable idle timeout.
  • No raw error pages — a central error handler guarantees the browser never sees a raw 400/500 or a GardenAPI stack trace; it always gets a short, human message, while full detail goes to the logs.
  • TLS-only, listening on port 8787.

Configuration

/opt/gardenpi/config/garden.json is a file SHARED across the whole GardenPi system (handlers, clients, API, WebUI). There are no .env files and nothing is configured via environment variables (with one narrow exception, GARDEN_CONFIG_PATH, described below). Everything is loaded and cross-referenced by server/config.js.

WARNING: Only edit the GardenPi settings via the WebUI versus direct edits of /opt/gardenpi/config/garden.json. Run /opt/gardenpi/scripts/restart-services.sh to load the changes.

Dynamic data lives in its own files, never in garden.json

Nothing dynamic — user accounts, sessions, the watering schedule, or activity history — is ever read from or written to garden.json. That file is shared system-wide configuration; embedding per-user password hashes or fast-changing runtime state in it would be both a security problem (every service that reads the shared file would see password hashes) and a data-integrity one (concurrent writes from multiple services). Instead, all of that lives under webui.data_dir (default /opt/gardenpi/data), managed exclusively by server/db.js:

/opt/gardenpi/data/
  users.json       admin account(s)
  sessions.json    active session tokens
  schedule.json    the watering schedule (edited from the Schedule tab)
  events.json      the Recent Activity feed's event history

If garden.json is missing or fails to parse, the app logs a clear error to the console and falls back to built-in defaults in mock mode rather than crashing, so a bad edit doesn't take the whole service down silently.

The one environment variable: GARDEN_CONFIG_PATH overrides where the app looks for garden.json (default /opt/gardenpi/config/garden.json) — this is a pointer to where configuration lives, not a configuration value itself, which is why it's the one thing still set outside the file (useful for local dev/testing without touching /opt/gardenpi).

The GardenAPI integration

The adapter (server/gardenApiClient.js) implements the documented GardenPi REST API v1.0.

Authentication

All endpoints except /api and /api/health require authentication with a bearer token.

Authentication token is supplied using the HTTP Authorization header:

Authorization: Bearer YOUR-API-TOKEN

Responses

Missing token

HTTP/1.1 401 Unauthorized
Content-Type: application/json
{
  "error": "No authorization token provided"
}

Invalid token

HTTP/1.1 403 Forbidden
Content-Type: application/json
{
  "error": "Invalid authorization token"
}

Endpoints

Purpose Method Path Auth
Index of every endpoint (method, path, auth, description) GET /api No
Health / handler status (live probe of every handler; 503 if any fails) GET /api/health No
ADC channel ids and user-assigned names GET /api/adc/channels Yes
Read one ADC channel GET /api/adc?channel=ID Yes
Read all ADC channels GET /api/adc?channel=all Yes
Turn a relay on/off / get status POST /api/irrigation {relay, action} Yes
Relay status (all or one) GET /api/irrigation/status[?relay=X] Yes
Turn all relays off POST /api/irrigation {relay:"all",action:"off"} Yes
LED on/off/blink POST /api/leds {led, action} Yes
LED status (all or one) GET /api/leds/status[?led=X] Yes
Latest/recent weather reading GET /api/weather?last=N Yes
Is a rain delay active? GET /api/irrigation/rain-delay Yes
Relay ids, user-assigned names, valve/pump, safety timeout GET /api/irrigation/relays Yes
Weather sensor names, /api/weather field, enabled GET /api/weather/sensors Yes

Discovering endpoints and ids

GET /api lists every endpoint the running API serves, so it is always in step with the installed version. The three name endpoints list the ids each command accepts, with the names set on the Configuration page. They read garden.json as it is on disk, so renames show up without a restart.

$ curl -sk https://gctl1:5000/api | python3 -m json.tool
$ curl -sk -H "Authorization: Bearer YOUR-API-TOKEN" https://gctl1:5000/api/adc/channels
{"channels": [{"id": "daylight", "hardware_id": "channel0", "user_id": "daylight",
  "friendly": "Daylight"}, ...], "count": 8, "success": true}

id is what to pass to /api/adc?channel= (or as relay for irrigation): the user_id when one is set, otherwise the hardware_id. Either form is accepted. /api/weather/sensors gives each sensor's field, the key it appears under in /api/weather responses.

Rain delay status

GET /api/irrigation/rain-delay reports whether the rain delay (set from the web UI's Schedule tab) is pausing scheduled watering. It is read-only; the API reads <webui.data_dir>/rain-delay.json and never changes it. Times are local, with UTC offset.

$ curl -s -H "Authorization: Bearer YOUR-API-TOKEN" https://gctl1:5000/api/irrigation/rain-delay
{"rain_delay": true, "until": "2026-10-05T13:48:00-05:00",
 "remaining_seconds": 172680, "set_at": "2026-10-03T13:48:00-05:00", "set_by": "allen"}

When no delay is active (never set, cancelled, or expired), rain_delay is false and the other fields are null / 0. It answers 503 if webui.data_dir isn't set in garden.json.

Response shapes confirmed against a real controller

  • Irrigation status (bulk and single-relay) is a flat map: {"mag": "off", "plants": "off", ...} — a single-relay query returns the same shape, just with one key (not a {relay, state} object).
  • LED status (bulk and single-LED) is wrapped in a status key: {"status": {"sysred": {"effect": "static", "state": "off"}, ...}}. Blink detection reads from effect (e.g. "active (patternblink-led2green-3)"), not from the momentary state — state genuinely toggles on/off every poll while an LED is blinking, so using it directly would make a blinking LED flicker in the UI instead of showing a steady "blinking" indicator.
  • The /api/irrigation POST response has no state field (e.g. {"action":"on","relay":"mag","safety_timeout_sec":900,"success":true}), so a command's result is never assumed from the POST response alone — the adapter immediately reads back the relay's actual status and only reports success if that confirms it. If it can't get a clear confirmation, it fails with a specific error rather than assuming the command worked (see Error handling).

Where this maps to your controller

  • Which relay is which — webui.irrigation.valves[]/.pumps[] give the friendly name/location; handlers.irrigation.relay_map is the ground truth for which customer-facing label each physical relay slot actually answers to (see Valves and pumps).
  • LEDs — derived entirely from handlers.leds.led_map (see Status LEDs).
  • Connection — webui.api_base_url and handlers.api.token.

The table of documented endpoints above is reference material, not something read from a file — the actual calls are made directly in server/gardenApiClient.js. If your controller ever changes shape, adjust extractRelayStates() / extractLedStates() there — see Diagnostics for how to see the raw responses.

Valves and pumps

Configured relays are split into two independent groups, shown as separate "Valves" and "Pumps" sections on the Irrigation tab:

  • Valves (mag, plants, nearbed, farbed, valve5 by default) — mutually exclusive when handlers.irrigation.allow_concurrent_valves is false (the default) in garden.json: only one can be on at a time. This is a hardware/handler-level setting edited on the Configuration tab, not an app-level toggle this web UI maintains its own copy of.
  • Pumps — not part of that mutual-exclusion rule; both can run at the same time as each other and alongside a valve.

Pump rules are keyed to the physical relay's hardware_id, not the customer-facing id

webui.irrigation.pumps[].id is a customer-configurable label (the user_id from the matching handlers.irrigation.relay_map entry, falling back to hardware_id if no user_id is set) — a customer can relabel which physical relay (pump1 or pump2, defined by hardware.powercontroller.pin_map) answers to which name. For example, a customer might relabel the physical pump1 relay to "outsidelights" because that's what it actually controls at their site.

Because of this, the pump-specific safety rules below are resolved against the hardware_id (server/config.js cross-references relay_map by hardware_id to find it, exposed as each valve/pump's hardwareId — an immutable, read-only field), never against the current user_id/friendly name — so relabeling a relay doesn't silently break its safety behavior:

  • The relay with hardware_id pump1 has no timeout restriction and can run any time, for any length of time — this comes from handlers.irrigation.no_timeout_relays (ground truth), not a webui guess.
  • The relay with hardware_id pump2 may only run while an irrigation valve is on. This interlock is an app-level business rule (garden.json doesn't declare it) — the app blocks turning it on otherwise ("Pump 2 can only run while an irrigation valve is on"), and automatically turns it off if the valve it was running alongside turns out to be the last one running — whether that valve was stopped manually, by the scheduler, or by a safety timeout.

This was verified directly: with pump1 relabeled to "outsidelights" in relay_map, turning on outsidelights with no valve running still succeeds (it's really the unrestricted pump1 relay), while turning on pump2 with no valve running is still correctly blocked.

The Irrigation tab's "Emergency stop" button sends {relay:"all", action:"off"}, which — per the controller's actual behavior — turns off every configured relay, pumps included. It's a full stop, not just a valve stop.

Status LEDs

The full LED list is derived entirely from handlers.leds.led_map in garden.json — there is no separate webui-owned LED list to keep in sync. Each LED's color is inferred from its id suffix (sysred → red, led2blue → blue, etc.) and its display group from the handler's internal group name (sys → System, led1 → Sensors, led2 → Irrigation).

The Dashboard shows three vertical rows — System, Sensors, Irrigation — each showing whichever color (red/green/blue) is currently lit for that group, with a status label:

Group Red Green Blue
System Error Boot Running
Sensors Error Initializing Running
Irrigation Error Initializing (solid) / Valve on (blinking) Running

Pumps are intentionally not represented in the Irrigation LED or anywhere else in the LED grouping: the physical pump1 slot can free-run with no need for an indicator, and the physical pump2 slot only ever runs while a valve is on, which the Irrigation LED already indicates.

Sensors

The Sensors widget combines two GardenAPI sources:

  • ADC channels (GET /api/adc?channel=all) — e.g. soil moisture, light, pressure voltages.
  • Weather (GET /api/weather?last=1) — temperature, humidity, wind, rain, daylight, soil-moisture-sensor voltages, etc.

All floating-point readings are rounded to at most 3 decimal places for display (long raw values like 2.697685740236551 display as 2.698).

Names come from Configuration, live. Each reading is labelled with its configured friendly name, read straight from garden.json on every refresh, so a rename shows up on the Dashboard within seconds, without restarting anything:

  • ADC readings use the channel's name from Software → ADC → Channel Labels.
  • Weather readings follow Sensor Labels to the sensor's owning table: ADC Channel Labels for source: "adc" sensors (e.g. moisture1_v → the moisture1 channel's name), Weather Input Labels for source: "weather" sensors. A reading with no configured name falls back to a built-in one ("Outside Temp", "Soil Moisture 1", …).
  • Names are shown exactly as entered.

Readings are grouped under ADC Inputs (raw channel voltages from /api/adc) and Weather Inputs (the weather handler's readings from /api/weather). The same sensor can appear in both, e.g. a soil-moisture probe's raw ADC voltage and the weather handler's reading of it.

Which readings are shown is configurable — click Configure on the Sensors widget to check/uncheck individual readings, grouped the same way. New sensors are visible by default the first time they're seen; the choice is remembered per-browser (localStorage), independent of which top-level dashboard widgets are shown. Choices are keyed on the sensor's hardware ID (ADC) or field name (weather), not its name, so renaming a sensor keeps it hidden or shown as before.

Recent Activity

The Dashboard's Recent Activity panel is a curated, human-readable, reverse-chronological feed (newest first) of the app's own meaningful actions — valve/pump on/off, schedule changes, safety-rule enforcement (e.g. Pump 2 auto-shutoff), scheduler deferrals — served page by page via GET /api/activity/current?limit=&offset= (server/routes/activity.js, backed by db.getEventsPage()). It's distinct from the full raw application log: entries read like "Magnolia turned ON (manual)" rather than a raw JSON log line, and there's no request-trace noise to filter, since this feed is built from a small set of curated event types to begin with.

It sits in the same widget grid as the other dashboard tiles, spanning 2 of the grid's 3 columns (grid-column: span 2) rather than a single tile's width.

  • Loads the most recent 20 events on first view, newest at the top.
  • Each entry's timestamp includes the date (e.g. Aug 24 01:38:59 PM), not just the time of day, since the feed can be scrolled back across multiple days of history.
  • Scroll down toward the bottom of the box to load the next older page — keeps loading further back through history as you scroll, like a typical activity/news feed (append-at-bottom; no position compensation needed since new content appears below what's already visible).
  • New events appear at the top as they happen (checked on every status poll): if you're already looking at the very top of the feed, it stays pinned there so new items are visible; if you've scrolled down into history, your view is preserved exactly (scrollHeight/scrollTop compensation), rather than being pushed around by items appearing above.
  • Uses the same synthetic, always-visible scroll indicator as elsewhere in the app (updateActivityScrollbar() in public/js/app.js) rather than relying on the browser's native scrollbar, since several platforms (macOS's default trackpad "overlay" scrollbar behavior, some Linux/Chrome configurations) hide native scrollbars until an active scroll gesture.
  • Because this panel is a genuine grid item (not appended after the grid), and its content/scroll state must survive the other widgets' periodic innerHTML rebuild, renderDashboard() detaches the same DOM node before rebuilding the grid and reinserts it afterward — explicitly saving and restoring its scroll position around that, since some browsers reset an element's scrollTop on detach/reattach even when it's the same node.

If you want the full raw request/response log instead (e.g. for troubleshooting GardenAPI integration issues), that's still available via GET /api/logs/current — see Diagnostics — it just isn't what's shown in this dashboard panel.

Scheduler

server/scheduler.js implements the watering schedule. Design notes:

  • A tick runs every 15 seconds and checks whether "now" falls inside any enabled schedule window (day-of-week + start time + duration).

  • If a window should start but another valve is already running (manual or another schedule), the start is deferred (retried every tick) rather than force-stopping the other valve — this is logged and visible in the dashboard's Recent Activity feed as a "deferred" event.

  • The scheduler only ever turns off a valve it turned on, so it never interferes with a valve you started by hand.

  • Each valve's block on the Schedule tab has a "select all" checkbox next to the Enabled column header, to enable/disable every window for that valve at once.

  • Skip next skips only the next occurrence of a window, then clears itself. Ticking the box records the start time of the run to skip (skipRunAt in schedule.json); when that window arrives the valve is not started, the box unticks, and a "Skipped" event appears in Recent Activity. The Skip next header checkbox ticks every window for that valve, which cancels that valve's watering for the coming week in one click; each box clears as its run is skipped, so the normal schedule resumes on its own. Ticking it while a window is already running skips next week's run (stop the current run from the Irrigation tab). If the Pi is off during a skipped window, the flag is cleared afterwards rather than carried to the next week. A header checkbox shows a dash when only some of the windows are ticked.

  • Rain delay (top of the Schedule tab) pauses scheduled watering for every valve: 1, 2, 3 or 7 days from now, or through the end of a chosen date (30 days at most). It's stored in data/rain-delay.json, so it survives restarts, and ends on its own. While it's on:

    • no window whose start time falls inside the delay is started, and a window the scheduler is running when the delay is set is stopped;
    • a window that began during the delay is not started part-way through when the delay ends;
    • manual runs from the Irrigation tab are not affected;
    • each suppressed window is logged once in Recent Activity, the Next run column shows the cancelled run struck through with the next real one, and the dashboard's Scheduler widget shows when the delay ends.

    "+1 day" extends an active delay; "Cancel rain delay" resumes the schedule immediately. Skip next and the rain delay work together: Next run always shows the first run that will actually happen.

Authentication and sessions

  • First connection: if no account exists yet, you're prompted to create one (username + password, bcrypt-hashed).
  • Afterwards: a signed, random session token is set as an httpOnly, secure, sameSite=strict cookie. There's no separate "remember me" state — the cookie is the session.
  • Multiple users, no roles. More accounts can be added from the Configuration tab's Users block (see below) — every account is identical in what it can do: control valves/pumps, edit the schedule, edit garden.json, and manage every other account (add/remove users, change anyone's password, including its own). There's no admin/viewer distinction and no per-account restriction. The only constraint enforced anywhere is that the last remaining account can never be removed — the app must always have at least one way to sign in.
  • Session timeout (webui.settings.session_timeout_minutes in garden.json, edited on the Configuration tab): idle timeout in minutes, or 0 = never time out.
  • What counts as "activity": any request that passes through the requireAuth middleware touches the session and resets its idle clock. This includes valve/schedule/settings changes, and the automatic status poll (GET /api/status/all) that the Dashboard and Irrigation tab call every few seconds on their own while open. In practice this means: as long as a browser tab with the app open keeps polling, the session effectively never times out from simple on-screen inactivity — the timeout mainly protects against a closed tab, backgrounded/sleeping device, or dropped connection (which stop the polling loop) rather than a person stepping away while the tab stays open. If you'd rather have the timeout reflect only explicit user actions (ignoring the background poll), that's a small, contained change in server/middleware/requireAuth.js / the status route.

Guard rails, summarized

  • Only one valve can be on at a time (toggleable in Settings) — enforced in one shared place (server/valveControl.js) used by both manual control and the scheduler, so it can't be bypassed from either path.
  • The physical pump2 slot can only run while a valve is on; the physical pump1 slot is unrestricted — both keyed to the physical relay slot, not the current customer-facing label, so relabeling a relay doesn't change its safety behavior (see Valves and pumps).
  • A manual "run for N minutes" request (or the configured app-level max-run-minutes setting, whichever is shorter) always sets a server-side safety auto-shutoff timer — capped at the hardware's own max_valve_duration_sec ceiling regardless of what the app setting says, and skipped entirely for any relay listed in handlers.irrigation.no_timeout_relays. A valve can never be left open by a dropped connection, a forgotten tab, or an app setting that's higher than the physical controller's own limit. The Irrigation tab's minutes input itself defaults to, and cannot exceed, the app-level Max run time per valve setting, refreshed whenever the Irrigation tab is opened or the setting is changed.
  • After sending an on/off command, the app reads back the relay's actual status and only reports success if that confirms it — it will not report "on" if the controller silently accepted the command but the valve never actually changed state.

Error handling and logging

  • A central error handler (server/middleware/errorHandler.js) guarantees the browser never sees a raw 400/500 or a stack trace — always a short, friendly message (e.g. "The Garden Controller is not responding right now", "invalid API token", "handler unavailable"), with the full detail logged server-side.
  • Logging: winston, rotated daily, split into logs/app-*.log (all activity — logins, valve commands, schedule changes, scheduler decisions) and logs/error-*.log (errors only).
  • Expected/handled conditions (guard-rail conflicts, unreachable hardware, bad input) are logged at warn, keeping error-level logs meaningful for genuine bugs.

Diagnostics (LOG_LEVEL=debug)

If you ever see LEDs stuck on "Unknown", or a command reporting it "couldn't confirm" the result, set server.logLevel to "debug" in /opt/gardenpi/config/garden.json and restart the service. The logs will show the exact raw JSON returned for every irrigation/LED status and command call:

  • Raw irrigation POST response
  • Raw per-relay status response after command
  • Raw bulk irrigation status response
  • Raw bulk LED status response / Raw per-LED status response

Compare those to extractRelayStates() / extractLedStates() in server/gardenApiClient.js and adjust if your controller's firmware ever returns a different shape. Set server.logLevel back to "info" once confirmed working, to keep logs quieter.

You can get the same information directly, without the app, via (substitute your actual token from garden.json's gardenApi.token):

curl -k -H "Authorization: Bearer <token>" "https://<host>:5000/api/irrigation/status?relay=mag"
curl -k -H "Authorization: Bearer <token>" "https://<host>:5000/api/leds/status?led=sysblue"
curl -k -H "Authorization: Bearer <token>" "https://<host>:5000/api/leds/status"

GardenPi Components Run As systemd Services

Unit files scripts/gardenpi-*.service are used by add-services.sh to setup each service. add-services.sh also installs scripts/pijuice-charge-limiter.service when the PiJuice Python module is present (see below).

PiJuice battery charge limiter

A LiPo battery that sits at 100% charge, especially in a warm outdoor enclosure, ages much faster than one held around half charge. Since the PiJuice is on mains power almost all the time, bin/pijuice-charge-limiter.py keeps the battery between 45% and 50%:

  • When the charge reaches 50%, it turns PiJuice charging off.
  • When the charge falls below 45%, it turns charging back on. Between the two, it leaves charging as it is, so it doesn't switch back and forth.
  • When the battery is 40°C or hotter, or 0°C or colder, it blocks charging. The block lifts once the temperature is 3°C back inside that range.
  • After a change, it waits at least 2 minutes before turning charging back on, so a noisy reading can't toggle it rapidly. Turning charging off is always immediate.

It checks every 30 seconds and logs a status line every 15 minutes. The charging setting is written to the PiJuice's RAM, not its EEPROM, so if the PiJuice itself loses power, it starts up charging normally.

It runs as the systemd service pijuice-charge-limiter, with /usr/bin/python3 (the pijuice module comes from the pijuice-base apt package, not the GardenPi virtual environment). Like the gardenpi-* services, it runs as config.application_user:config.application_group: add-services.sh writes them into the unit's User=/Group= when installing. That account needs the i2c group to reach the PiJuice; add-services.sh warns if it's missing.

install-gardenpi.sh installs pijuice-base and add-services.sh installs, enables and starts the service. If the system python3 can't import pijuice, add-services.sh skips the limiter with a message rather than install a service that would only fail and restart. To add it later:

sudo apt install pijuice-base
sudo /opt/gardenpi/scripts/add-services.sh

To change the limits, edit the ExecStart= line in scripts/pijuice-charge-limiter.service and re-run add-services.sh, which reinstalls the unit and restarts the service. The options are:

Option Default Unit file Meaning
--upper 50 50 turn charging off at or above this %
--lower 45 45 turn charging on below this %
--max-temp 45 40 block charging at or above this battery °C
--min-temp 0 0 block charging at or below this battery °C
--temp-hysteresis 3 3 °C back inside the range before the block lifts
--no-temp off off ignore battery temperature
--interval 30 30 seconds between checks
--min-switch-interval 120 120 seconds before charging may be turned back on
--summary-interval 900 900 seconds between status log lines
--non-volatile off off write the setting to the PiJuice EEPROM
--on-exit leave|enable leave leave what to do with charging when the service stops
--bus, --address 1, 0x14 1, 0x14 PiJuice I2C bus and address
--debug off off log every check

Checking on it:

systemctl status pijuice-charge-limiter
journalctl -u pijuice-charge-limiter -n 50

To turn it off and keep it off across reboots:

sudo /opt/gardenpi/scripts/add-services.sh --no-charge-limiter

Charging stays as it was last set (--on-exit leave). If it was off, turn the service on again or re-enable charging with the PiJuice tools. A later install-gardenpi.sh, or add-services.sh without the option, installs and starts it again.

pijuice-charge-limiter is not a gardenpi-* service: it isn't listed on Configuration > Services, isn't part of Restart all or restart-services.sh, and isn't in the password-less sudo rules. Control it from ssh with sudo systemctl …, which asks for the service user's password.

Config and code versions

garden.json carries two version numbers in its config stanza, both shown read-only in Configuration > GardenPi System:

  • config_version: the revision of the configuration itself. The web UI bumps its patch number (3.0.6 → 3.0.7) and sets last_changed on every save that changes something. It is also what the header badge shows. Older files name it version; the first save renames it automatically.
  • code_version: the version of the installed code base. The web UI never changes it. Update it by hand when you install new code. A save from a browser tab that was opened before your edit will not undo it: the web UI always keeps the value already in the file.

Uptime

The header shows how long the Pi has been up, left of the API badge. It switches units as uptime grows (Up 42s, Up 5h 12m, Up 45d 3h, Up 1y 45d); a year counts as 365 days. Hover over it for the full breakdown and the exact boot time. It is the uptime of the Pi itself (the host the web UI runs on), not of the web UI or API service.

Restarting services from the web UI

Configuration > Services lists every gardenpi-* service with its live status, a Restart button for each, Restart all, and Reboot system / Shut down system. There is intentionally no Stop button: if gardenpi-webui is stopped, it can only be started again from an ssh session.

  • Restart needed: every GardenPi service reads garden.json only when it starts, so a saved change takes effect when the services that use it are restarted. After each save the web UI works out which ones those are, says so in the save message (with a Restart now button), and flags them Restart needed on this card (hover for what changed). The Restart needed (n) button restarts just those, in startup order, the web UI last. A flag clears once the service has been restarted by any means: this card, ssh, or a reboot. The list is kept in <data_dir>/pending-restarts.json. Some examples:

    Change Restart
    ADC channel friendly name gardenpi-api (the Dashboard updates without it)
    ADC channel user ID gardenpi-adc, gardenpi-weather, gardenpi-api
    Relay friendly name gardenpi-api, gardenpi-webui
    Weather input friendly name nothing (only the Dashboard uses it)
    Max valve run time, concurrent valves gardenpi-irrigation, gardenpi-webui
    API access token gardenpi-api, gardenpi-webui
    Global log level every service
    WeeWx URL nothing (read live)
  • Restart all restarts every service except the one-shot gardenpi-init, in one systemd transaction, so they stop and start in the same order as restart-services.sh. The page reconnects on its own once the web UI is back.

  • Restarting gardenpi-init re-runs the PiController hardware initialisation, and systemd also restarts the LEDs, ADC, irrigation and weather handlers, because they Require= it.

  • Reboot / Shut down require typing REBOOT / SHUTDOWN, and turn off every valve and pump through the API first.

  • Shut down runs bin/pijuice-safe-shutdown.py rather than shutdown/systemctl poweroff directly. The script sets the PiJuice to wake on charge (5%) and to cut the 5V rail 60 seconds later, then halts the OS, so the Pi powers back on when external power returns. It runs as the web UI's user with the system /usr/bin/python3, which needs:

    • the pijuice Python module: sudo apt install pijuice-base (installed by install-gardenpi.sh)
    • I2C access for that user: sudo usermod -aG i2c pi (default on Raspberry Pi OS)

    Before anything is stopped, the web UI checks that the PiJuice answers. If it doesn't, the shutdown is refused rather than halting a Pi with nothing set to power it back on.

These actions need password-less sudo for a small, fixed set of commands. install-gardenpi.sh sets this up, and also lets the service user run any other command with sudo after entering its own password. To do it by hand, or after changing the service user:

sudo /opt/gardenpi/scripts/setup-sudoers.sh               # application_user, restarts + reboot/shutdown
sudo /opt/gardenpi/scripts/setup-sudoers.sh --no-power    # no reboot/shutdown
sudo /opt/gardenpi/scripts/setup-sudoers.sh --no-control  # web UI needs only (no command-line control)
sudo /opt/gardenpi/scripts/setup-sudoers.sh --no-admin    # no general sudo with password
sudo /opt/gardenpi/scripts/setup-sudoers.sh --user bob    # different service user
sudo /opt/gardenpi/scripts/setup-sudoers.sh --remove      # take the permissions away again

This writes /etc/sudoers.d/gardenpi (validated with visudo before it is installed) allowing only exact systemctl restart gardenpi-….service, single-service systemctl start|stop|restart|enable|disable [--now] gardenpi-…, systemctl reboot and shutdown -h now command lines (the last is what pijuice-safe-shutdown.py runs). The script itself is deliberately not run as root: /opt/gardenpi is owned by the service user, and a root sudo rule for a file that user can edit would amount to giving it root. Until it is in place, the Services card still shows status but its buttons are disabled with a hint to run the script.

General sudo, with a password. Unless you pass --no-admin, the file also lets the service user run any command as any user with sudo, the same as a member of the sudo group: sudo apt upgrade, sudo nano /etc/hosts, sudo systemctl restart pijuice-charge-limiter, and so on. Those ask for the service user's password. The GardenPi commands listed above still don't, as long as they are typed exactly as shown. The general rule is written before the password-less ones, because sudo uses the last rule that matches a command; sudo -l lists both. For this to be usable the account needs a password. setup-sudoers.sh warns if it doesn't have one; set it with sudo passwd pi (or your application_user). Pick a strong one: the web UI and the API run as this user, so the password is what stands between a flaw in them and root.

Controlling services from the command line (troubleshooting). The same rules let the service user start, stop, restart, enable and disable any one GardenPi service without a password, with or without the .service suffix:

sudo systemctl stop gardenpi-adc
sudo systemctl start gardenpi-adc
sudo systemctl restart gardenpi-adc
sudo systemctl disable --now gardenpi-adc     # stop it and keep it stopped
sudo systemctl enable --now gardenpi-adc      # undo: start it and start at boot again

One service per command; --now may go before or after the name.

Auto-start: stop alone doesn't keep a service down. Every GardenPi service is enabled, meaning it starts at boot, and the handlers restart on their own if they crash. systemctl stop stops a service only until something starts it again, which happens:

  • at the next reboot (or PiJuice power cycle), since it's still enabled
  • when the web UI restarts it: Restart all, Restart needed, or its own Restart button. Restarting an API or other service from the web UI does not start a stopped handler, since the services don't pull each other up (no Wants= between them)

To keep a service down, including across reboots, use sudo systemctl disable --now gardenpi-<name>: it stops the service and removes its start-at-boot link. When you're done, sudo systemctl enable --now gardenpi-<name> turns it back on. systemctl status gardenpi-<name> shows both states, e.g. Loaded: … disabled and Active: inactive (dead). The web UI's restart buttons will still start a disabled service if you use them, so avoid those while troubleshooting.

Stopping and disabling are for the command line only: the web UI deliberately has no Stop button, and a stopped gardenpi-webui has to be started again from an ssh session. sudo setup-sudoers.sh --no-control leaves these command-line rules out, granting only what the web UI needs.

Configuration Tab

The Configuration tab lets you view and edit garden.json from the UI which is the only settings store.

This is an explicit allowlist, not a full generic editor. Only the fields listed below are shown at all; anything not mapped is excluded from the UI entirely for now, expanded in future iterations as more fields are decided safe/useful to expose. Hiding a field here doesn't delete it from garden.json, it's simply not editable from the UI yet.

The layout below mirrors the same "GardenPi System / Web UI / Software / Hardware" grouping used across GardenPi's configuration surfaces.

Always visible

Group Fields
GardenPi System (config) Config Version (read-only), Code Version (read-only), Last Changed (read-only), Global Log Level (dropdown), TLS Certificate File, TLS Key File (changing these only updates garden.json; the API also needs --certfile/--keyfile edited in gardenpi-api.service, then restart gardenpi-api and gardenpi-webui), plus a Users block (add/remove accounts, change any account's password — see below; this is the one part of the GardenPi System card that isn't backed by garden.json)
Web UI (webui) Listener Port, Log Level (dropdown), API URL, API Access Token, Session Secret, Session Timeout (dropdown, webui.settings.session_timeout_minutes), Dashboard Refresh in seconds (webui.settings.poll_interval_seconds), System IP Address (read-only, not stored in garden.json: the address this controller uses to reach the host bin/check-wifi.sh pings (dest1), i.e. its operational address when it has several interfaces, with the interface the route uses, taken from ip route get, so it's right even when two interfaces share an address; falls back to the default route if that can't be determined; other addresses are listed underneath)
API (handlers.api) Listener Port (read-only; to change it, edit garden.json and gardenpi-api.service by hand, then restart gardenpi-api and gardenpi-webui), Log Level (dropdown), API Access Token, then a link to this README (/README.md)
Software → ADC (handlers.adc) Log Level (dropdown), then Channel Labels (collapsed by default): one row per handlers.adc.channel_map entry: HW ID (read-only), User ID (editable), Friendly Name (editable)
Software → LEDs (handlers.leds) Log Level (dropdown)
Software → Irrigation (handlers.irrigation) Log Level (dropdown), then Relay Labels (collapsed by default): one row per handlers.irrigation.relay_map entry: HW ID (read-only), User ID (editable), Friendly Name (editable); then Max Valve Run Time (max_valve_run_time, seconds), Allow Concurrent Valves (toggle)
Software → Weather (handlers.weather) Log Level (dropdown), then two tables, both collapsed by default: Input Labels (one row per handlers.weather.input_map entry: HW ID (read-only), User ID (editable), Friendly Name (editable); the owning table for every source: "weather" sensor's friendly name) and Sensor Labels (one row per handlers.weather.sensor_map entry: Sensor ID (read-only, the map key), HW or User ID (editable source_id), Friendly Name (read-only, edited on the owning table: ADC → Channel Labels for source: "adc" sensors, Weather → Input Labels for source: "weather" sensors), Enabled (toggle))
Software → WeeWx (weewx) Main URL

Users (GardenPi System pane)

Also on the GardenPi System card, below the config fields above, is a Users block for managing sign-in accounts. Unlike everything else on the Configuration page, this doesn't read or write garden.json at all — it's backed by its own file, users.json (in webui.data_dir, alongside sessions/schedule/activity — see Configuration above), via a dedicated /api/users endpoint (GET /, POST /, POST /:id/password, DELETE /:id), separate from /api/config.

  • No roles or permissions. Every account can do everything: control the system, edit garden.json, add or remove any account (including its own), and change any account's password (including its own) — there's no concept of an admin vs. a regular user.
  • Add a user: username (3+ characters) and a password (8+ characters, bcrypt-hashed the same way as the original setup flow) — no confirmation step server-side beyond matching the two password fields in the modal.
  • Change password: works the same for your own account or anyone else's — there's no "current password" check, since there's no privilege distinction to protect against.
  • Remove a user: blocked, both in the UI (the button is disabled with a tooltip) and by the API (DELETE /api/users/:id returns an error), if it's the last remaining account — the app must always have at least one way to sign in. Removing your own currently-signed-in account is otherwise allowed; the UI warns you first, then signs you out immediately since that session's account no longer exists. Removing any account also immediately invalidates that account's other active sessions (other signed-in browsers/tabs), not just the one that clicked Remove.

Advanced (collapsed by default, with a warning banner)

Group Fields
Web UI API TLS Reject (toggle), API Timeout (ms), Use Mock API (toggle)
Software → ADC Listener Socket (read-only, handlers.adc.socket). The ADC channel labels are in the Software pane (Software → ADC → Channel Labels).
Software → LEDs Listener Socket (read-only, handlers.leds.socket), then the LED labels table: one row per handlers.leds.led_map entry: HW ID, Group, Aliases — all read-only (LED hardware_id and labels can never be customer-edited)
Software → Irrigation Listener Socket (read-only, handlers.irrigation.socket). The relay labels are in the Software pane (Software → Irrigation → Relay Labels).
Software → Weather Listener Socket (read-only, handlers.weather.socket). The input and sensor labels are in the Software pane (Software → Weather).
Hardware → RaspberryPi GPIO Pin HW ID table: hardware_id (read-only) → pin number (editable), from hardware.raspberrypi.pin_map
Hardware → PiController HW Version (read-only), I2C Address, then three pin tables filtered from the single hardware.picontroller.pin_map by type: GPIO Pin HW ID (type: "gpio"), MCP LED Pin HW ID (type: "led"), ADC Pin HW ID (type: "adc") — hardware_id read-only, pin number editable
Hardware → PowerController HW Version (read-only), I2C Address, Relay HW ID table (hardware.powercontroller.pin_map filtered to type: "relay") — hardware_id read-only, pin number editable
Hardware → Temperature Sensors Internal I2C Address, External I2C Address (hardware.powercontroller.temperature_sensors)

Every hardware_id shown anywhere on this page — channel/relay/LED/pin identifiers — is always read-only text, matching the rule that hardware_id and LED labels can never be changed from the UI; only user_id, friendly names, pin numbers, and the settings above are editable.

The bottom of the API pane (first row of the Configuration tab) links back to this README (/README.md, served directly by server/index.js — README.md lives at the repo root, outside the public/ folder that express.static exposes, so it gets its own small route), so reference docs like the weather.csv layout below are reachable without repo access.

API Reference (between Software and Advanced)

Swagger-style documentation of every endpoint api.py exposes: method, path, auth requirement, parameters, an example response and a ready-to-paste curl command built from the configured API URL. The endpoint list is collapsed by default (Endpoints (7)). Nothing in this pane is editable, and the curl examples use a $TOKEN placeholder rather than the real configured token.

weather.csv column layout

The Advanced section's Web UI row (webui.api_tls_reject, webui.api_timeout_ms, webui.mock_api) is the only place the Configuration tab talks about the GardenAPI connection. It does not cover the separate file the Weather handler writes on its own schedule — handlers.weather. weather_file (default /opt/gardenpi/data/weather.csv) — which is consumed directly by WeeWx and any other downstream tooling, not through the API. Since that file's column layout isn't exposed anywhere in the UI itself (the Configuration tab only lets you edit the path, not its contents), it's documented here instead:

# Column Sensor ID Friendly name Source
1 Timestamp — — time.strftime("%Y-%m-%d %H:%M:%S"), local time
2 Wind Speed s_wind_speed Wind Speed handlers.weather.input_map (wind_speed)
3 Rain s_rain Rain handlers.weather.input_map (rain)
4 Daylight s_daylight Daylight ADC channel0 (handlers.adc.channel_map)
5 Pressure s_pressure Pressure ADC channel2
6 Moisture 1 s_moisture1 Mag ADC channel4
7 Moisture 2 s_moisture2 M2 ADC channel5
8 Moisture 3 s_moisture3 M3 ADC channel6
9 Wind Direction s_wind_dir WindDir ADC channel7
10 Internal Temp s_int_temp Int Temp handlers.weather.input_map (int_temp)
11 Internal Humidity s_int_humidity Int Humidity handlers.weather.input_map (int_humidity)
12 External Temp s_ext_temp Ext Temp handlers.weather.input_map (ext_temp)
13 External Humidity s_ext_humidity Ext Humidity handlers.weather.input_map (ext_humidity)

Notes:

  • No header row is ever written to the file. weather_csv_loop() in the weather handler only calls csv.writer(...).writerow(row) for data rows, on every sample cycle (default_period) — there's no matching writerow(header) call, and the file isn't pre-seeded with a header line when first created. The table above is the implied layout, fixed by the headers_sensor_ids list hardcoded in weather_csv_loop(), not by whatever order handlers.weather.sensor_map happens to be in.
  • Column order never changes based on config — it's the same 13 columns in the same order every row, regardless of which sensors are enabled.
  • Disabled sensors still get a column, just an empty one: if a sensor has no cached value (either disabled in sensor_map — e.g. s_moisture2/ s_moisture3 are disabled by default — or simply hasn't reported yet), its cell is written as an empty string, not 0 or omitted.
  • s_hz (Power Hz) is not in this file — it's written separately to its own file, handlers.weather.hz_file, as a two-column (timestamp, value) CSV by hz_csv_loop().
  • Friendly names for the ADC-sourced columns (Daylight, Pressure, Moisture 1–3, WindDir) are edited under Software → ADC → Channel Labels (the Software pane), not under Weather — see the Software → Weather row above (Sensor Labels).

Field-level behaviors

  • Comments and examples are read-only. Any key containing "comment" (comment, comment_max_valve_run_time, …) or "example" renders as plain text, never an editable input.
  • Every log_level-style field is a dropdown, not free text — including global_log_level and any field ending in log_level. The dropdown's options come from config.supported_log_levels in the loaded file itself (falling back to a built-in list if that's ever missing).
  • String "true"/"false" fields render as toggles, not text boxes (webui.mock_api, webui.api_tls_reject) — but still save back as that same lowercase string, not a real JSON boolean, matching the file's existing convention. Verified directly: toggling mock_api writes "false" (a string), not false (a boolean).
  • Secrets are masked (token/secret/password) with a Show/Hide toggle.
  • Arrays are editable in place with add/remove — used for e.g. the timeout-exempt relay list and the relay label assignments.
  • Type-preserving, same as before: a numeric-looking string stays a string, a float stays a float, on save.

Advanced warning banner

The Advanced section is collapsed by default, with a plain Advanced toggle. Expanding it shows a Warning banner first: everything inside includes items rarely changed (hardware pin numbers, socket paths, hardware versions) that are more likely to break a running handler if misconfigured. The panes above Advanced carry a softer, factual reminder (the file is shared with the other services, and changes need a service restart), since those fields are the ones considered safe to change routinely.

Safety on save

Since this is a file shared with hardware handlers that hard-exit on malformed config (see garden_config.py's require() philosophy on the handler side):

  1. A confirmation modal appears before saving.
  2. PUT /api/config/current writes a timestamped backup of the previous file first (garden.json.bak.<ISO-timestamp>, never overwritten), writes the new content to a temp file, and atomically renames it into place — a crash mid-write can never leave a handler looking at a half-written, corrupt file.
  3. The freshly-written file is read back and re-parsed as a final sanity check before the save is reported as successful.
  4. No hot-reload, anywhere. Every GardenPi service — including this web UI itself — reads garden.json once at startup and never watches it for changes. Saving updates the file on disk immediately, but nothing picks up the new values until the affected service is restarted.

Extending the allowlist

The mapping lives in three functions in public/js/app.js: renderCommonSettings(), renderAdvancedSettings(), and renderRelayFriendlyFieldsSection(). Each field is one mappedField(path, label, opts) call; add a new one to promote a field into the UI. opts.readOnly marks it non-editable; everything else infers its input type automatically (log-level dropdown, boolean-string toggle, masked secret, or plain text/number) from the field's name/current value, the same detection used throughout the rest of the editor.


Versioning

The app version lives in one place, package.json, and is read from there by server/version.js — nothing else hardcodes it. It's surfaced in three ways:

  • Every major source file (server/**/*.js, public/js/app.js, public/css/style.css, public/index.html, scripts/seed-schedule.js) has a GardenPi Control vX.Y.Z comment as its first line, so the version is visible directly in the source regardless of which file you're looking at. Bump package.json's version and update these header comments together.
  • A public (no-auth) GET /api/version endpoint, used by the UI and available for scripts/health checks.
  • A small vX.Y.Z badge at the top-right of the app header, next to "Sign out" (#app-version-badge in public/index.html, populated by loadVersionBadge() in public/js/app.js).

A small WeeWx link also sits in the header, immediately to the right of the API mode badge (#weewx-link in public/index.html), pointing at weewx.main_url from garden.json. It's populated by updateWeewxLink() in public/js/app.js (called from loadRuntimeSettings()) and stays hidden if weewx.main_url isn't set.

Project layout

Deployed layout:

/opt/gardenpi/
  config/
    garden.json           SHARED across the whole GardenPi system --
                           webui owns only the 'webui' stanza in it
  data/                   dynamic data
      users.json, sessions.json, schedule.json, events.json
  webui/                  this project
    server/
      index.js              HTTPS server, route mounting, TLS + port 8787
      config.js             loads garden.json; resolves valves/pumps/LEDs/safety
                             limits against the hardware/handlers stanzas
      version.js             reads the app version from package.json
      auth.js                first-run setup, login, session tokens
      db.js                  tiny JSON-file datastore -- the ONLY place dynamic
                             data (users/sessions/settings/schedule/events) lives
      gardenApiClient.js     adapter to the real (or mock) GardenAPI
      valveControl.js        shared guard-rail logic (valve mutual exclusion,
                             pump rules keyed to physical relay slot)
      scheduler.js           in-app watering scheduler (replaces cron + bash wrapper)
      logger.js              winston logging setup
      middleware/            auth guard + central friendly-error handler
      routes/                auth, valves, schedule, status, settings, logs, activity, config
    public/                the frontend (vanilla HTML/CSS/JS, no build step)
      favicon.svg, favicon.ico, apple-touch-icon.png,
      icon-192.png, icon-512.png, site.webmanifest    favicon set (the 🌿 leaf, matching the header)
    scripts/
      seed-schedule.js          loads an example watering schedule
      gardenpi-webui.service    systemd unit, pre-configured for this layout
    garden.example.json     shipped template showing the full shared schema
                            (config/hardware/handlers/webui stanzas)
    logs/                   created at runtime (webui.log_dir in garden.json)

Known limitations / things to verify on your hardware

  • The leds and valves arrays in garden.json reflect relay/LED names confirmed against a real controller during development, but if your controller's firmware/config differs, edit those arrays in garden.json — no other code needs to change.
  • The bulk relay/LED status parsing has a per-item fallback if the bulk call ever fails or returns an unrecognized shape (see gardenApiClient.js); this was validated against real response shapes but firmware updates could change them again — see Diagnostics if that happens.
  • Status polling (Dashboard/Irrigation tab) is short-interval HTTP polling, not a push/WebSocket mechanism — "near real-time" at whatever interval is configured in Settings (default 3s).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages