External hardware controllers — phos-hw v1
PHOS implements the phos-hw v1 external-controller boundary. The official
companion ESP32 firmware is available at
phosairobot/phos-esp32, providing
ENS160 + AHT21 telemetry and WS2812B semantic LED control over USB/serial JSONL.
A hardware boundary independent of the agent
A compatible controller lets an agent use physical context without learning its
board, sensor bus, pins, or firmware. PHOS accepts supported observations through
phos-hw v1, adds availability and semantic interpretation, and exposes the
result through MCP. In the other direction, PHOS resolves permitted LED intent
before firmware executes it.
phos-hw v1 is the hardware communication protocol; MCP is the agent-facing
protocol. They serve different boundaries. The Raspberry Pi runs PHOS and owns
semantics. The external controller acquires sensors and drives its supported
outputs. It does not replace the Pi runtime.
flowchart TD
sensors[Physical sensors] --> controller[Optional compatible microcontroller]
controller -->|phos-hw v1 observations over serial| adapter[Pi controller adapter]
adapter --> context[PHOS semantic services and context]
context --> server[PHOS MCP server]
agent[External AI agent / model] <--> host[External MCP host]
host --> client[MCP client]
server -->|MCP resource data| client
server -.->|URI-only resource cues| client
client -.->|MCP tool requests| server
server --> services[Permission-checked application services]
services -->|Semantic result| server
server -->|Tool result| client
services --> intent[Runtime LED arbitration]
intent -->|phos-hw v1 set_led_animation| controller
controller --> leds[Physical LED output]
classDef phos fill:#0F4C5C,stroke:#49E7FF,color:#fff
classDef aiAgent fill:#5B21B6,stroke:#C4B5FD,color:#fff
classDef protocol fill:#312E81,stroke:#818CF8,color:#fff
classDef hardware fill:#334155,stroke:#94A3B8,color:#fff
class sensors,controller,leds hardware
class adapter,context,server,services,intent phos
class agent aiAgent
class host,client protocol
style controller stroke-dasharray: 5 4
ESP32 is the official reference firmware implementation. The protocol is not ESP32-specific: a developer could implement it on Arduino, RP2040, or STM32 hardware with a suitable serial transport and firmware. These are potential ports, not supported board integrations. A port must implement the actual frame, capability, freshness, and command contracts below; protocol extensibility does not make arbitrary sensors automatically available through MCP.
Flash the companion firmware
- Open phos-esp32 and follow its current build and flashing instructions for your ESP32 board.
- Configure the firmware's sensor wiring and WS2812B data pin/count for the attached hardware, then build and upload as described there. Keep ENS160 and AHT21 on the ESP32 I2C bus and the LED ring on the ESP32 output.
- Connect the flashed ESP32 to the Pi with a USB data cable. Configure
hardware_controller.enabled,hardware_controller.serial.device, andhardware_controller.serial.baud_ratein PHOS to match the connection. - Confirm capability discovery, fresh sensor telemetry, and semantic LED output. Use the installation checks for the PHOS side of the connection.
Responsibilities
The Raspberry Pi owns high-level semantics, state, arbitration, and application services. The controller owns supported physical execution and sensor acquisition. It does not decide robot behavior or expose a second Web/API/MCP control plane.
This separation keeps hardware modular, isolates physical execution, supports reconnection after transport failure, and lets a controller implementation be replaced or extended without moving PHOS semantics into firmware.
Connection and lifecycle
Enable hardware_controller with the configured serial transport, device, and
baud rate. PHOS performs capability discovery, sends heartbeats, reconnects
after transport failure using the configured delay, and exposes bounded
connection status/recent diagnostics in Web Admin. Controller transport failure
does not give Web clients direct serial access.
hardware_controller.serial.dtr and .rts default to false. PHOS configures
these values before opening pySerial so ESP32 USB-UART auto-reset circuitry is
not unintentionally driven by the host's default asserted control lines. Boards
with a documented different requirement may opt in through the same Hardware
Controller configuration; changing either setting reconnects the controller and
may briefly interrupt sensor readings and controller-backed LED output. Verify
the selected levels on the target controller board.
Protocol
WS2812B ring connection
The WS2812B addressable RGB LED ring connects to and is driven by the ESP32
controller. The Raspberry Pi sends resolved phos-hw v1 semantic
set_led_animation commands over USB/serial; firmware owns the data pin,
pixel count, channel ordering, and animation timing.
Enable hardware_controller.enabled in config/phos.yaml and configure
hardware_controller.serial.device and hardware_controller.serial.baud_rate
for the attached ESP32. PHOS emits LED commands only when that serial session
is connected and advertises LED support: a nonzero led_count, a nonzero
led.count, or "led" in the payload's capabilities list.
Keep the separate legacy led_ring.enabled setting false. Its pin/count
settings do not configure ESP32 firmware. On disconnect, controller output
becomes unavailable; after a new LED capability report, PHOS reapplies the
resolved intent. See the installation steps
and electrical guidance.
Message envelope
Messages are framed JSON objects with protocol: "phos-hw", version: 1, a
type, optional correlation fields, and an object payload. Capability reports
describe controller-supported features. Controller sensor_update and
motion_update messages feed the same semantic snapshots used by local sensor
providers; semantic LED commands are resolved by PHOS before the controller
executes timing/physical mapping.
See Architecture: external controller protocol for exact message contracts, validation, bounds, failure handling, and LED arbitration. See Development for configuration and Web Admin behavior.
Verified v1 commands and messages
phos-hw v1 uses UTF-8 JSON Lines: one bounded JSON object per newline. Every
message has protocol: "phos-hw", version: 1, type, and object payload;
id, reply_to, and timestamp_ms are optional correlation fields. PHOS
starts a reader before capability discovery, retries discovery until a
capabilities report arrives, sends ping as its heartbeat, and reconnects after a
transport failure using the configured delay. A controller heartbeat updates
the recorded heartbeat status. On disconnect, PHOS retains bounded diagnostics
but disables active controller LED output.
Malformed lines remain rejected. Their bounded diagnostics identify whether UTF-8 or JSON parsing failed, the frame length, a short hexadecimal prefix, and the connection generation; complete untrusted frames are not retained. Valid later lines received in the same serial read continue through normal protocol validation. ESP32 boot/debug output must not share the protocol UART, and every firmware protocol write must emit one complete UTF-8 JSON object followed by a newline.
For every enabled controller-provided environmental sensor, firmware must also
send a valid sensor_update periodically when its value is unchanged. PHOS
uses each accepted sensor-family update as freshness evidence and marks the
family stale after its configured stale_after_seconds; a heartbeat or IMU
frame cannot refresh environmental data. Use a refresh interval comfortably
below that timeout (at most half the timeout is recommended; 15 seconds or
less for the standard 30-second setting). This preserves truthful detection of
a stopped sensor while allowing a stable temperature or pressure value to stay
available.
Targeted malformed-frame diagnostics
PHOS normally keeps controller debug logging disabled. To enable bounded serial
diagnostics only (without changing global logging.level), create a temporary
user-service override on the Pi:
mkdir -p ~/.config/systemd/user/phos.service.d
printf '[Service]\nEnvironment=PHOS_CONTROLLER_DEBUG=1\n' > ~/.config/systemd/user/phos.service.d/controller-debug.conf
systemctl --user daemon-reload
systemctl --user restart phos.service
journalctl --user -u phos.service -f --no-pager
Look for PHOS CONTROLLER: rejected frame diagnostics entries. They contain
only parse category, frame length, a 24-byte hexadecimal prefix, and connection
generation. To restore ordinary logging:
rm ~/.config/systemd/user/phos.service.d/controller-debug.conf
systemctl --user daemon-reload
systemctl --user restart phos.service
High-rate orientation telemetry remains off when PHOS_CONTROLLER_DEBUG=1.
For a separate, temporary IMU investigation only, add
Environment=PHOS_CONTROLLER_IMU_DEBUG=1 to the same override, reload systemd
and restart; remove that line again afterward.
The protocol recognizes the following vocabulary. “Recognized” is not the same
as “currently emitted by PHOS”: the current serial adapter transmits only
request_capabilities, ping, and resolved set_led_animation.
| Protocol name | Direction | Purpose / data | Response or unavailable behavior |
|---|---|---|---|
request_capabilities |
Pi → controller | Starts (and resynchronizes) discovery; empty payload may carry an id. |
Controller supplies capabilities for every request and resumes/reaffirms telemetry for the current host session. PHOS retries until a capabilities report arrives, even if stale telemetry or heartbeats are already arriving. |
capabilities |
controller → Pi | Controller-defined feature metadata, including optional sensor/LED support. | Activates session capabilities; LEDs require advertised support. |
ping |
Pi → controller | PHOS heartbeat; empty payload. | Peer activity keeps the session healthy; v1 requires no separate pong. |
heartbeat |
controller → Pi | Controller liveness cue. | Updates PHOS's recorded heartbeat time. |
sensor_update |
controller → Pi | Semantic sensor/value/unit or supported push event. | Valid updates enter existing semantic services; invalid updates are rejected safely. |
sensor_status |
controller → Pi | Additive ENS160 status: sensor: "ens160", validity integer 0–3, and compensation_active boolean. |
Sent on change and at the bounded air-quality refresh cadence. Codes are normal, warm-up, startup, and invalid respectively; old controllers may omit it. |
motion_update |
controller → Pi | Semantic motion state and intensity. |
Exact validated values update the IMU service. |
orientation_update |
controller → Pi | Finite x, y, z acceleration and angular-velocity vectors. |
Exact validated vectors update IMU telemetry. |
set_led_animation |
Pi → controller | PHOS-resolved LED animation semantics. | Sent only for an active LED-capable session; otherwise unavailable. |
hello, controller_status, warning, error, ack |
controller → Pi | Recognized lifecycle/diagnostic/acknowledgement vocabulary. | Recorded as bounded diagnostics; no PHOS semantic mapping currently. |
configure_sensor_reporting, stop_led_animation, set_led_brightness, clear_led |
Pi → controller | Reserved recognized command vocabulary. | Not transmitted by the current PHOS adapter. |
Unknown message types, unsupported versions, malformed JSON, and invalid validated payloads receive bounded protocol errors. Unknown top-level fields are ignored; arbitrary controller data never reaches PHOS services.
Verified JSON Lines examples
Each complete object below is followed by a newline on the wire.
{"protocol":"phos-hw","version":1,"type":"request_capabilities","id":"phos-1-cap-1","payload":{}}
{"protocol":"phos-hw","version":1,"type":"sensor_update","payload":{"sensor":"temperature","value":24.8,"unit":"c"}}
{"protocol":"phos-hw","version":1,"type":"set_led_animation","payload":{"animation":"breathe","color":"#42a5ff","brightness":0.5,"period_ms":1200}}
Sensor and motion observations
Controller-backed observations enter the same semantic services as local providers. BME280/BMP280 can provide temperature and pressure; only BME280 supplies humidity. ENS160 reports eCO2 (an estimated CO2 equivalent, not direct CO2), TVOC in ppb and AQI-UBA on its 1–5 scale; AHT21 supplies controller-provenance temperature and humidity used for ENS160 compensation. MPU6050 telemetry is represented by semantic motion updates and/or acceleration and angular-velocity vectors. Physical hardware, wiring, and firmware support vary by installation.
The accepted semantic sensor values are temperature in c, pressure in hpa,
humidity in %, eCO2 in ppm, TVOC in ppb, and the push event
{"sensor":"push","event":"pressed"}. Motion states are stationary,
moving, directional tilt, shake, or impact, with low, medium, or
high intensity. PHOS owns the meaning of those observations after they cross
the protocol boundary.
Operational status
The PHOS controller protocol, reconnect lifecycle, capability discovery, and controller-backed sensor/LED integration are implemented and automatically tested. Use the official companion firmware and follow the wiring and protocol setup instructions.
Troubleshooting connection and LED availability
| Symptom | Check | Supported action and expected result |
|---|---|---|
| Controller is not connected or has no active device | In Connectivity → Hardware Controller, compare State, Configured device, Active device, Protocol, Last heartbeat and Capabilities. | Refresh the available ports and confirm the saved serial device/baud rate and the USB data connection. The PHOS status should show an active controller session and a valid protocol after a compatible controller reports in. Follow the companion firmware's own instructions for its build/flash issues; firmware behavior was not independently audited here. |
| No valid protocol or capabilities are reported | Inspect Recent messages in the controller status panel and check whether capabilities have been reported for the current connection. | Correct the configured connection or use a compatible phos-hw v1 controller. Do not infer sensor or LED capability from a serial connection alone. |
| Controller-backed readings are absent or stale | Check the corresponding Sensors status and the controller's reported capabilities/Recent messages. | Confirm the required sensor is supported and the controller is reporting its data. PHOS keeps missing or stale readings unavailable; this does not establish a sensor failure cause without hardware inspection. |
| LED output is unavailable | Check connection status, the active LED capability, and LED Output status. | The controller must be connected and advertise LED capability before PHOS sends resolved semantic LED commands. The status panel distinguishes unavailable output from a requested animation; PHOS does not expose a raw pin/animation command. |
These checks use existing Web Admin state and bounded in-memory diagnostics; they do not independently verify the companion firmware, wiring, electrical assembly or physical LED response. See the protocol contract and hardware evidence.