controller_settings: honor VE_DIRECT_PORT env var, prefer env over saved JSON - #77
Merged
Federico Alves (urucoder) merged 1 commit intoAug 10, 2026
Conversation
There was a problem hiding this comment.
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"]fromVE_DIRECT_PORT(fallback to/dev/ttyUSB0only if unset). - Update
load_config()soVE_DIRECT_PORTalways 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.
Federico Alves (urucoder)
approved these changes
Aug 10, 2026
Carl Chalmers (Clamps251)
deleted the
fix-controller-settings-ve-direct-env
branch
August 10, 2026 18:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
controller_settings.py'sDEFAULTSdict hardcodesPORT: /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.pyopens 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 racesxbee_master_collect.pyfor every incoming byte. Both processes lose ~90% of their reads. Watching either process's log, this manifests as the XBee master silently missing most incomingSG?/RDframes 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:DEFAULTS["PORT"]now reads from theVE_DIRECT_PORTenv var, falling back to/dev/ttyUSB0only when the env var isn't set. Fresh installs pick up whatever the setup script writes intosparrow.env.load_config()now forces the env var to win over the saved JSON — an existing deployment with a stalecontroller_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_PORTpoints at a Victron by-id path that doesn't exist.controller_settings.pytries to open it,serial.SerialraisesFileNotFoundError, the existing retry loop catches it and continues without ever touching the XBee's FTDI.xbee_master_collect.pygets exclusive access to the FTDI and receives every frame cleanly.