Appearance
Hardware and RS485
The controller is a Raspberry Pi on a Sequent Systems board, with an LCD and physical buttons on the enclosure. Services reach the board over I²C through the cfc Python library, and RS485 devices over the Pi's UARTs.
The board
| I/O | Count | MQTT names | Service |
|---|---|---|---|
| High voltage relays | 8 | hv_relay1 to hv_relay8 | publisher-hv-relay, subscriber-hv-relay |
| Low voltage relays | 4 | lv_relay1 to lv_relay4 | publisher-lv-relay, subscriber-lv-relay |
| Valves | 8 | valve1 to valve8 | publisher-valves, subscriber-valves |
| Thermistors | 4 | thermistor1 to thermistor4 | publisher-thermistor |
| Flow sensors | 2 | flow_sensor1, flow_sensor2 | publisher-flow-sensor |
| Pressure sensor | 1 | pressure | publisher-pressure-sensor |
| RS485 ports | 5 | pump1 to pump5, rs485_1 to rs485_5 | subscriber-rs485, publisher-pump, publisher-rs485 |
| LCD and buttons | 1 | controlfreak-display |
The board libraries are vendored in rpi-controller/sequent-systems-firmware/, cfcrpi for the board and smlcd for the display, and installed into the mqtt-builder base image. They are snapshots of controlfreakpool/cfc-rpi. Change them upstream first and copy them back, or the two drift apart.
The cfc command line tool from cfc-rpi reads and drives the board directly, which helps when a service is suspected:
bash
cfc -hThe board needs I²C and UARTs 2 to 5 enabled in /boot/firmware/config.txt. flash-controller-init.sh sets them on a fresh Raspberry Pi OS install.
Emulation
With USE_EMULATOR=1, services load sequentulator in place of cfc, and the display driver loads smulator. The emulators keep register state in memory mapped files in /tmp, so the services and the emulator UIs share it. RS485 ports become the pseudo terminals /tmp/pump1 to /tmp/pump5.
With RS485_EMULATOR=1 only RS485 is faked. The real board and relays stay in use, and each RS485 port answers from an emulated unit. Emulated units exist for the Fairland heat pump, the Hayward MaxFlo VS and the Moov Clearsalt, and every other driver gets a generic fake.
See Local development.
RS485
Ports
| Port | TTY |
|---|---|
| Slot 1 | /dev/ttyAMA0 |
| Slot 2 | /dev/ttyAMA3 |
| Slot 3 | /dev/ttyAMA4 |
| Slot 4 | /dev/ttyAMA5 |
| Slot 5 | /dev/ttyAMA2 |
Which physical port is wired to which slot depends on the board revision. Boards 1.0 to 2.0 use slots in order, 1, 2, 3, 4, 5. Boards 4.0 and later use 1, 3, 4, 2, 5. There was no 3.0. The revision is read from the board firmware, which always tracks the board revision. The logic is in shared-lib/cfp_shared/rs485/ports.py.
One owner
subscriber-rs485 is the only process that opens the RS485 ports. It runs one worker per port. Each worker finds the device configured on its port, loads the driver for it, applies commands, and polls telemetry into the API.
publisher-pump and publisher-rs485 never touch the bus. They read the state the worker recorded and publish it on controller/pump<n>/status and controller/rs485_<n>/status.
The pump topics and the rs485_<n> topics are both backed by the same four port rows. Pumps kept their original topics, and other RS485 devices use the rs485_<n> topics.
Polling
Every port is polled every RS485_POLL_SECONDS, 15 by default. Each driver sets a floor, and the effective interval is whichever is larger. Pump drivers also set a keepalive, resending the last command on that interval, since a pump expects to keep hearing it.
Drivers
Drivers live in shared-lib/cfp_shared/rs485/drivers/ and are registered in registry.py by slug.
| Slug | Device | Protocol | Baud | Default address |
|---|---|---|---|---|
hayward_maxflo_vs | Hayward MaxFlo VS pump | Framed | 1200 | |
laswim | Laswim pump | Framed | 9600 | |
aquastar | Aquastar pump | Modbus RTU | 9600 | 1 |
blue_torrent | Blue Torrent IGV pump | Modbus RTU | 9600 | 1 |
madimack | Madimack pump, Fairland | Modbus RTU | 9600 | 160 |
fairland_heat_pump | Fairland heat pump | Modbus RTU | 9600 | 1 |
moov_clearsalt | Moov Clearsalt salt cell | Modbus RTU | 9600 | 8 |
A driver without an address speaks a framed protocol, and one with an address speaks Modbus RTU. transport.py opens the right transport from that.
A device's driver comes from its connection type's driver column, or for a pump, from its pump model's model.
Each driver declares a DriverSpec: slug, baud rate, default address, poll floor, supported modes, telemetry keys, setpoint units, speed range and keepalive. It implements open, close, apply for commands, and read_telemetry.
Pump policy
cfp_shared/rs485/policy.py holds the decisions a pump needs beyond the driver: the default mode, clamping speed to the device's limits, holding a minimum speed while a heater cools down, priming, and moving valves for pool, spa and spillover. Heat pumps and salt cells run their own control and do not go through it.
Salt cells
A salt cell needs water flowing. While the cell is on, subscriber-rs485 starts its associated pump if the pump is stopped, at the cell's default startup speed, and never changes a pump that is already running. When the cell turns off, it sends the pump a single off, and only if the cell started it. Schedules, tethers and spa mode are free to keep the pump running.
Moov Clearsalt
The vendor register sheet in claude-docs/ is the Aquark Mr. Crystal protocol v1.04. It does not match the unit in the field. Confirmed on a real unit at address 8, 9600 baud:
- Holding registers
0x0004pool volume,0x000Aacid dose and0x000Dsalt type answer illegal data address. - Mode 3, manual, on
0x0000answers illegal data value. Off,0, and auto,4, work. - Production,
0x000B, is writable in auto and takes effect. - Boost,
0x0012, turns on and off. - Input registers
0x000Dto0x0010hold software version, machine type and machine config. The driver reads them into telemetry to identify the model.
Adding an RS485 driver
- Add a driver class in
shared-lib/cfp_shared/rs485/drivers/with itsDriverSpec, and register it inregistry.py. - Point a connection type at its slug with the
drivercolumn, or for a pump, add a pump model whosemodelis the slug. Do both in the seed data indatabase-api/app/main.pyand in a migration. - Add unit tests in
tests/cfp_shared/, following the existingtest_rs485_*files. - Optionally add an emulated unit to
EMULATED_UNITSinemulator.py, so the driver can be exercised withRS485_EMULATOR=1. - Prove it on hardware with
debug-scripts/rs485-bench/, which runs inside the shipped image against the shipped driver.
Because the drivers are in shared-lib, a new driver needs mqtt-builder rebuilt. See Local development.