Skip to content

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/OCountMQTT namesService
High voltage relays8hv_relay1 to hv_relay8publisher-hv-relay, subscriber-hv-relay
Low voltage relays4lv_relay1 to lv_relay4publisher-lv-relay, subscriber-lv-relay
Valves8valve1 to valve8publisher-valves, subscriber-valves
Thermistors4thermistor1 to thermistor4publisher-thermistor
Flow sensors2flow_sensor1, flow_sensor2publisher-flow-sensor
Pressure sensor1pressurepublisher-pressure-sensor
RS485 ports5pump1 to pump5, rs485_1 to rs485_5subscriber-rs485, publisher-pump, publisher-rs485
LCD and buttons1controlfreak-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 -h

The 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 ​

PortTTY
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.

SlugDeviceProtocolBaudDefault address
hayward_maxflo_vsHayward MaxFlo VS pumpFramed1200
laswimLaswim pumpFramed9600
aquastarAquastar pumpModbus RTU96001
blue_torrentBlue Torrent IGV pumpModbus RTU96001
madimackMadimack pump, FairlandModbus RTU9600160
fairland_heat_pumpFairland heat pumpModbus RTU96001
moov_clearsaltMoov Clearsalt salt cellModbus RTU96008

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 0x0004 pool volume, 0x000A acid dose and 0x000D salt type answer illegal data address.
  • Mode 3, manual, on 0x0000 answers 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 0x000D to 0x0010 hold software version, machine type and machine config. The driver reads them into telemetry to identify the model.

Adding an RS485 driver ​

  1. Add a driver class in shared-lib/cfp_shared/rs485/drivers/ with its DriverSpec, and register it in registry.py.
  2. Point a connection type at its slug with the driver column, or for a pump, add a pump model whose model is the slug. Do both in the seed data in database-api/app/main.py and in a migration.
  3. Add unit tests in tests/cfp_shared/, following the existing test_rs485_* files.
  4. Optionally add an emulated unit to EMULATED_UNITS in emulator.py, so the driver can be exercised with RS485_EMULATOR=1.
  5. 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.