Feature/wifi setup improvements (#187)

* fix: Handle permission errors when removing plugin directories

- Added _safe_remove_directory() method to handle permission errors gracefully
- Fixes permissions on __pycache__ directories before removal
- Updates uninstall_plugin() and install methods to use safe removal
- Resolves [Errno 13] Permission denied errors during plugin install/uninstall

* feat(wifi): Add grace period for AP mode and improve setup documentation

- Add 90-second grace period (3 checks at 30s intervals) before enabling AP mode
- Change AP to open network (no password) for easier initial setup
- Add verification script for WiFi setup
- Update documentation with grace period details and open network info
- Improve WiFi monitor daemon logging and error handling

* feat(wifi): Add Trixie compatibility and dynamic interface discovery

- Add dynamic WiFi interface discovery instead of hardcoded wlan0
  - Supports traditional (wlan0), predictable (wlp2s0), and USB naming
  - Falls back gracefully if detection fails

- Add Raspberry Pi OS Trixie (Debian 13) detection and compatibility
  - Detect Netplan configuration and connection file locations
  - Disable PMF (Protected Management Frames) on Trixie for better
    client compatibility with certain WiFi adapters

- Improve nmcli hotspot setup for Trixie
  - Add explicit IP configuration (192.168.4.1/24)
  - Add channel configuration to hotspot creation
  - Handle Trixie's default 10.42.0.1 IP override

- Add dnsmasq conflict detection
  - Warn if Pi-hole or other DNS services are using dnsmasq
  - Create backup before overwriting config

- Improve error handling
  - Replace bare except clauses with specific exceptions
  - All subprocess calls now have explicit timeouts

- Document sudoers requirements in module docstring
  - List all required NOPASSWD entries for ledpi user

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor(wifi): Use NM_CONNECTIONS_PATHS constant in _detect_trixie

Replace hardcoded Path instances with references to the
NM_CONNECTIONS_PATHS constant for consistency.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(verify): Use ETH_CONNECTED and AP_ACTIVE in summary output

Add connectivity summary section that displays Ethernet and AP mode
status using the previously unused ETH_CONNECTED and AP_ACTIVE flags.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Chuck <chuck@example.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-01-19 16:43:02 -05:00
committed by GitHub
parent 2381ead03f
commit 1833e30c1d
5 changed files with 771 additions and 121 deletions

View File

@@ -51,10 +51,9 @@ You should see output indicating the service is active and running.
### Accessing the WiFi Setup Interface
1. **If WiFi is NOT connected**: The Raspberry Pi will automatically create an access point
- Connect to the WiFi network: **LEDMatrix-Setup**
- Password: **ledmatrix123** (default)
- Open a web browser and navigate to: `http://192.168.4.1:5000`
1. **If WiFi is NOT connected**: The Raspberry Pi will automatically create an access point (after a 90-second grace period)
- Connect to the WiFi network: **LEDMatrix-Setup** (open network, no password required)
- Open a web browser and navigate to: `http://192.168.4.1:5000` or `http://192.168.4.1` (captive portal may redirect)
- Or use the IP address shown in the web interface
2. **If WiFi IS connected**: Access the web interface normally
@@ -92,7 +91,7 @@ The WiFi monitor daemon (`wifi_monitor_daemon.py`) runs as a background service
3. Automatically disables AP mode when WiFi or Ethernet connection is established
4. Logs all state changes for troubleshooting
**Note**: By default, `auto_enable_ap_mode` is `true`, meaning AP mode will automatically activate when both WiFi and Ethernet are disconnected. This ensures you can always configure the device even when it has no network connection.
**Note**: By default, `auto_enable_ap_mode` is `true`, meaning AP mode will automatically activate when both WiFi and Ethernet are disconnected. However, there's a 90-second grace period (3 consecutive checks at 30-second intervals) to prevent AP mode from enabling on transient network hiccups. This ensures you can always configure the device even when it has no network connection.
### WiFi Manager Module
@@ -125,13 +124,14 @@ WiFi settings are stored in `config/wifi_config.json`:
**Configuration Options:**
- `ap_ssid`: SSID for the access point (default: "LEDMatrix-Setup")
- `ap_password`: Password for the access point (default: "ledmatrix123")
- `ap_channel`: WiFi channel for AP mode (default: 7)
- `auto_enable_ap_mode`: Automatically enable AP mode when WiFi/Ethernet disconnect (default: `true`)
- When `true`: AP mode automatically enables when both WiFi and Ethernet are disconnected
- When `true`: AP mode automatically enables after a 90-second grace period when both WiFi and Ethernet are disconnected
- When `false`: AP mode must be manually enabled through the web interface
- `saved_networks`: List of saved WiFi network credentials
**Note**: The access point is configured as an open network (no password required) for ease of initial setup. This allows any device to connect without credentials.
### Access Point Configuration
The AP mode uses `hostapd` and `dnsmasq` for access point functionality:
@@ -141,6 +141,31 @@ The AP mode uses `hostapd` and `dnsmasq` for access point functionality:
- **Gateway**: 192.168.4.1
- **Channel**: 7 (configurable)
## Verification
### Running the WiFi Verification Script
Use the comprehensive verification script to check your WiFi setup:
```bash
cd /home/ledpi/LEDMatrix
./scripts/verify_wifi_setup.sh
```
This script checks:
- Required packages are installed
- WiFi monitor service is running
- Configuration files are valid
- WiFi permissions are configured
- WiFi interface is available
- WiFi radio status
- Current connection status
- AP mode status
- WiFi Manager module availability
- Web interface API accessibility
The script provides a summary with passed/warning/failed checks to help diagnose issues.
## Troubleshooting
### WiFi Monitor Service Not Starting
@@ -254,12 +279,12 @@ sudo systemctl restart ledmatrix-wifi-monitor
## Security Considerations
- **Default AP Password**: The default AP password is "ledmatrix123". Consider changing this in `config/wifi_config.json` for production use
- **Open AP Network**: The access point is configured as an open network (no password) for ease of initial setup. This allows any device within range to connect to the setup network. Consider your deployment environment when using this feature.
- **WiFi Credentials**: Saved WiFi credentials are stored in `config/wifi_config.json`. Ensure proper file permissions:
```bash
sudo chmod 600 config/wifi_config.json
```
- **Network Access**: When in AP mode, anyone within range can connect to the setup network. Use strong passwords for production deployments
- **Network Access**: When in AP mode, anyone within range can connect to the setup network. This is by design to allow easy initial configuration. For production deployments in secure environments, consider using the web interface when connected to WiFi instead.
## API Endpoints
@@ -291,11 +316,13 @@ The system supports multiple scanning methods:
AP mode configuration:
- Uses `hostapd` for WiFi access point functionality
- Uses `dnsmasq` for DHCP and DNS services
- Uses `hostapd` (preferred) or `nmcli hotspot` (fallback) for WiFi access point functionality
- Uses `dnsmasq` for DHCP and DNS services (hostapd mode only)
- Configures wlan0 interface in AP mode
- Provides DHCP range: 192.168.4.2-20
- Gateway IP: 192.168.4.1
- **Open network**: No password required (configures as open network for easy setup)
- Captive portal: DNS redirection for automatic browser redirects (hostapd mode only)
## Development