# FillDrainPump (Server footprint)

Schedule sync and request logging for the FillDrainPump ESP32 firmware. Served by the combined Server app on port 5000.

Firmware project: `/workplace/Workspace/Software/FillDrainPump`

## Endpoints

| Path | Method | Description |
|------|--------|-------------|
| `/filldrain/` | GET | Schedule editor, device commands, and check-in log |
| `/filldrain/settings` | POST | Save settings/reboot or queue reboot only |
| `/filldrain/sync` | GET, POST | ESP32 schedule sync (plain text) |

OTA firmware updates use separate projects in the shared OTA blueprint:

| Hardware version | OTA endpoint |
|------------------|--------------|
| Full | `/ota/project/filldrainpump/update` |
| Light | `/ota/project/filldrainpump-light/update` |

Keeping separate slugs prevents installing a build that expects the Full
display, sensors, and controls on Light hardware.

## Files (this directory)

| File | Purpose |
|------|---------|
| `schedule.txt` | Pump schedule (3 lines: on1, on2, duration seconds) |
| `commands.json` | Pending reboot command for Full and Light hardware |
| `filldrain.log` | Request log (created at runtime) |

Paths are configured in `config.py`:

- `FILLDRAIN_SCHEDULE_FILE` → `filldrain/schedule.txt`
- `FILLDRAIN_COMMAND_FILE` → `filldrain/commands.json`
- `FILLDRAIN_LOG_FILE` → `filldrain/filldrain.log`

## Schedule file: `schedule.txt`

Three lines:

- Line 1: first on-time (e.g. `08:00`)
- Line 2: second on-time (e.g. `19:00`), or `disabled` to use only one start
- Line 3: duration in seconds (e.g. `40`)

If the file is missing or invalid, defaults 08:00, 19:00, 40 seconds are used.
Use `disabled` on line 2 for a single daily start.

## Dashboard

Open `/filldrain/` to edit both start times and run duration. Schedule
parameters are shared by Full and Light. Uncheck **Enable second start** to
run only once per day.

- **Save parameters and reboot devices** writes the schedule and queues reboot
  for both hardware variants.
- **Reboot devices** queues reboot for both without changing the schedule.

Each device receives its reboot command on its next five-minute check-in. The
bottom of the page displays the latest 250 log entries.

## Sync request

ESP32 sends query parameters:

- `epoch` – device Unix time
- `time` – device time string (ISO-like)
- `on1`, `on2` – current on-times on device
- `duration` – current duration (seconds)
- `variant` – `full` or `light`
- `firmware_version` – current firmware version
- `pump` – current relay state
- `ambient_temp_f`, `humidity_pct`, `nutrient_temp_f` / `ds18b20_f` – Full sensor readings (DS18B20 is nutrient probe °F)

Response: plain text, 4 lines – on1, on2, duration seconds, and command
(`none` or `reboot`).

## Log file: `filldrain.log`

Each sync request is appended with timestamp, client IP, and request data.
