Skip to content

Conversation

@01rabbit
Copy link
Owner

@01rabbit 01rabbit commented Nov 9, 2025

PR: display: refresh EPD on WAN interface change and improve WAN detection

Summary

This PR improves runtime WAN detection and E-Paper (EPD) rendering behavior. The primary goals are:

  • Ensure the E-Paper display is cleared and fully refreshed when the active WAN interface changes (for example eth0 -> wlan1) to avoid ghosting and ensure the new interface/IP is shown immediately.
  • Improve WAN detection by preferring the kernel's default route when the runtime WAN state file is not present. Add an injectable wan_state_path for testing and overrides.
  • Clean up renderer output: remove a redundant "WAN" prefix, suppress non-actionable "[WAN] unknown" messages, and reserve a footer area to prevent text overlap.
  • Make EPaperDaemon initialization tolerant of older StatusCollector signatures (backwards-compatible fallback).

Version was bumped to 3.1.0 and CHANGELOG.md was updated. See commits 478b8ee and eee6e81 for the implementation and release bump.

Changes (high-level)

  • azazel_pi/core/display/status_collector.py

    • Accepts an optional wan_state_path argument for injection/testing.
    • If runtime WAN state is missing, attempts to query the kernel default route (e.g. ip route get) to determine the active interface.
    • Changed safe fallback preference to reduce incorrect legacy fallbacks.
  • azazel_pi/core/display/epd_daemon.py

    • Tracks last-seen active interface; when interface changes, clears the display and forces a full refresh to avoid ghosting.
    • Initialization is tolerant of older StatusCollector signatures (catches TypeError and retries without the extra param).
  • azazel_pi/core/display/renderer.py

    • Removes redundant "WAN" prefix in the network line and suppresses "[WAN] unknown" messages.
    • Reserves footer area and adjusts font sizing to avoid text overlap.

Files changed

  • azazel_pi/core/display/status_collector.py
  • azazel_pi/core/display/epd_daemon.py
  • azazel_pi/core/display/renderer.py
  • CHANGELOG.md (added 3.1.0 entry)
  • pyproject.toml (version bump to 3.1.0)

Why this is a minor bump (3.0.0 -> 3.1.0)

All changes are backward-compatible runtime improvements and feature additions (no breaking API changes). They primarily improve behavior (EPD UX and detection heuristics), so a minor version increment is appropriate.

How to test (developer / CI)

  1. Install test deps and run unit tests (recommended in a virtualenv):
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install pytest pytest-cov
pytest -v
  1. EPD emulation (quick visual smoke test):
# Save relative path from repo root and run the daemon in emulation/test mode
python3 azazel_pi/core/display/epd_daemon.py --mode test --emulate --emulate-output /tmp/epd_test.png
# Open /tmp/epd_test.png with an image viewer to inspect layout and footer
  1. Run the daemon in debug mode to see log messages and lifecycle behavior (on-device):
sudo python3 /opt/azazel/azazel_pi/core/display/epd_daemon.py --debug
# or, if testing the workspace copy directly (less privileged):
python3 ./azazel_pi/core/display/epd_daemon.py --debug
  1. To test the installed service behavior (systemd):
# If you edit the systemd drop-in to set rotation or other envs:
sudo systemctl daemon-reload
sudo systemctl restart azazel-epd.service
sudo journalctl -u azazel-epd.service -f

# Trigger a WAN interface change on the device (example):
# - unplug/plug the interface, change routing, or run the WAN manager to switch candidate
# While triggering, watch journal output for interface-change detection and EPD clear/refresh logs.

Example log excerpts (observed during development)

These excerpts are representative of the output produced during development and debugging.

TypeError observed before the runtime was updated (illustrates compat fix):

TypeError: StatusCollector.__init__() got an unexpected keyword argument 'wan_state_path'

Daemon startup and update loop messages (normal debug output):

E-Paper daemon starting...
Boot animation suppressed
Update #1: drawing status (force_full=False)
e-Paper busy
e-Paper release
Update #2: drawing status (force_full=False)
...

Interface detection/log example (route-based fallback):

resolved state path: /var/run/azazel/wan_state.json (exists: False)
kernel route probe -> dev eth0
active_interface: eth0 (ip: 192.168.40.14)
wan_state: unknown

When a WAN change is detected the daemon logs a message and forces a clear + full refresh; look for a message similar to:

WAN interface changed: wlan1 -> eth0; clearing display and forcing full refresh

Deployment notes (on-device)

  • The installed package path is /opt/azazel/azazel_pi. If you deploy the workspace copy over the installed copy, back up the existing /opt/azazel/azazel_pi first.
  • The service uses the azazel-epd.service systemd unit. Rotation and daemon options can be controlled via the systemd drop-in at /etc/systemd/system/azazel-epd.service.d/override.conf using Environment= entries, e.g.: Environment=EPD_ROTATION=180.
  • After updating files under /opt, run:
sudo systemctl daemon-reload
sudo systemctl restart azazel-epd.service
sudo journalctl -u azazel-epd.service -f

Checklist for reviewers

  • Confirm code is readable and follows project conventions.
  • Confirm there are no breaking changes to public APIs or CLI behavior.
  • Run unit tests locally or via CI.
  • Smoke-test EPD emulation (see above) for layout and footer overlap.
  • Verify that interface-switch behavior clears the display on a device.

Commits of interest

  • 478b8ee — display: refresh EPD on WAN interface change and improve WAN detection (feature implementation)
  • eee6e81 — chore(release): bump version to 3.1.0 (changelog + pyproject)

Introduce dynamic WAN selection to monitor and select the optimal WAN interface at runtime.

Changes include:
- Health check subsystem for WAN interfaces (periodic latency and reachability probes).
- Scoring algorithm to evaluate interfaces using latency, throughput and error rates.
- Failover and recovery logic to move traffic away from degraded links.
- Configuration options to tune probe intervals, thresholds, and to enable/disable selection.
- Integration with existing WAN manager/daemon and CLI.
- Unit and integration tests covering key scenarios.
- README and config schema updates with usage examples.

This improves availability and performance for multi-WAN deployments while keeping backward compatibility when the feature is disabled.
When the WAN manager starts reconfiguring interfaces it writes a transitional state ("reconfiguring") into the runtime WAN state.

Detect this transition in the E-Paper daemon and perform a best-effort display clear before rendering the next status frame. For such transitions we also force a full (non-gentle) refresh to minimise artifacts.

This reduces visual glitches when the active interface changes while keeping normal gentle/partial updates for routine refreshes.
- Clear and force full refresh when active WAN interface switches (e.g. eth0 -> wlan1)\n- Prefer kernel default route when wan_state is missing\n- Remove redundant "WAN" prefix and suppress "[WAN] unknown" messages in renderer\n- Reserve footer area to avoid text overlap and adjust fonts\n- Backwards-compatible StatusCollector init handling for older installs
…1.0\n- Add changelog entry for display/WAN improvements (commit 478b8ee)
@01rabbit 01rabbit merged commit a7a737b into main Nov 9, 2025
0 of 2 checks passed
@01rabbit 01rabbit deleted the feature/dynamic-wan-selection branch November 9, 2025 11:11
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.

2 participants