Skip to content

controller_settings: honor VE_DIRECT_PORT env var, prefer env over saved JSON - #77

Merged
Federico Alves (urucoder) merged 1 commit into
mainfrom
fix-controller-settings-ve-direct-env
Aug 10, 2026
Merged

controller_settings: honor VE_DIRECT_PORT env var, prefer env over saved JSON#77
Federico Alves (urucoder) merged 1 commit into
mainfrom
fix-controller-settings-ve-direct-env

Conversation

@Clamps251

Copy link
Copy Markdown
Collaborator

controller_settings.py's DEFAULTS dict hardcodes PORT: /dev/ttyUSB0. On any SPARROW Pi 5 build without a Victron VE.Direct cable — i.e. essentially every fresh field Pi we've been building — that hardcoded path is actually the XBee's FTDI adapter, not a Victron. controller_settings.py opens it thinking it's a Victron, tries to speak VE.Direct to a device that's speaking XBee API frames, and while it does that it races xbee_master_collect.py for every incoming byte. Both processes lose ~90% of their reads. Watching either process's log, this manifests as the XBee master silently missing most incoming SG?/RD frames from Robin nodes, with no error and no obvious clue as to why — the container appears "sort of" alive but throughput is broken.

Fix

Two related changes, both in sparrow/controller_settings.py:

  1. DEFAULTS["PORT"] now reads from the VE_DIRECT_PORT env var, falling back to /dev/ttyUSB0 only when the env var isn't set. Fresh installs pick up whatever the setup script writes into sparrow.env.
  2. load_config() now forces the env var to win over the saved JSON — an existing deployment with a stale controller_settings.json (already written with /dev/ttyUSB0) no longer gets locked into the wrong port. On restart it re-reads the env var.

Downstream effect on the field Pi we validated this on today: when no Victron cable is present, VE_DIRECT_PORT points at a Victron by-id path that doesn't exist. controller_settings.py tries to open it, serial.Serial raises FileNotFoundError, the existing retry loop catches it and continues without ever touching the XBee's FTDI. xbee_master_collect.py gets exclusive access to the FTDI and receives every frame cleanly.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates sparrow/controller_settings.py to avoid hardcoding a VE.Direct serial device path that can accidentally point at the XBee FTDI adapter on Pi 5 deployments, causing serial read contention and major frame loss. It makes the VE.Direct port selection deployment-driven via VE_DIRECT_PORT, and ensures the runtime always honors that environment value even if a stale JSON config exists.

Changes:

  • Set DEFAULTS["PORT"] from VE_DIRECT_PORT (fallback to /dev/ttyUSB0 only if unset).
  • Update load_config() so VE_DIRECT_PORT always overrides the saved JSON port value.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@urucoder
Federico Alves (urucoder) merged commit c8cac2c into main Aug 10, 2026
5 checks passed
@Clamps251
Carl Chalmers (Clamps251) deleted the fix-controller-settings-ve-direct-env branch August 10, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants