# SaltyBot WiFi Mesh Handoff (Issue #458)

Seamless WiFi AP roaming with automatic fallback to USB tethering.

## Features

- **Signal Monitoring**: Continuous WiFi signal strength tracking via iwconfig
- **Auto-Roaming**: Seamless handoff to stronger AP when signal < -70dBm
- **Gateway Ping**: Periodic connectivity verification to 8.8.8.8
- **USB Tethering Fallback**: Auto-activate phone USB tether if WiFi offline >30s
- **TTS Warnings**: Voice alerts for connectivity issues
- **Coverage Mapping**: Logs all signal transitions for analysis
- **wpa_supplicant Integration**: Native WiFi roaming support
- **Status Publishing**: Real-time WiFi state on `/saltybot/wifi_state`

## Setup

### 1. WiFi Configuration

Edit `/etc/wpa_supplicant/wpa_supplicant.conf`:

```
network={
  ssid="SaltyLab"
  psk="password"
  bgscan="simple:30:-70:600"
  ap_scan=1
  priority=10
}
```

### 2. Launch

```bash
ros2 launch saltybot_wifi_monitor wifi_monitor.launch.py
```

### 3. Monitor

```bash
ros2 topic echo /saltybot/wifi_state
```

## Configuration

| Parameter | Default | Description |
|-----------|---------|-------------|
| `interface` | wlan0 | WiFi interface |
| `roam_threshold_dbm` | -70 | Roaming signal threshold |
| `offline_warning_timeout` | 30.0 | Timeout before USB fallback |
| `target_ssid` | SaltyLab | Target mesh SSID |
| `fallback_tether` | true | Enable USB tethering |

## Roaming Behavior

Automatic roaming when:
1. Signal < -70dBm
2. Stronger AP available (>5dBm better)
3. wpa_supplicant performs seamless handoff
4. No ROS message disruption

## Fallback Behavior

Automatic fallback when:
1. Gateway ping fails for >30 seconds
2. TTS warning published
3. USB tethering activated
4. Auto-deactivated when WiFi restored

## Topics

| Topic | Type | Description |
|-------|------|-------------|
| `/saltybot/wifi_state` | String | Current WiFi state |
| `/saltybot/speech_text` | String | TTS warnings |
| `/saltybot/wifi_cmd` | String | Control commands |

## Coverage Log

```bash
tail -f /tmp/wifi_coverage.log
```

Output:
```
2026-03-05T09:15:23.456 | SSID:SaltyLab | Signal:-65dBm | Connected:true | Roaming:false
2026-03-05T09:15:45.789 | SSID:SaltyLab-5G | Signal:-62dBm | Connected:true | Roaming:true
```

## Issue #458 Completion

✅ WiFi signal monitoring (iwconfig/nmcli)
✅ WiFiState.msg interface
✅ Auto-roam at -70dBm
✅ Seamless wpa_supplicant handoff
✅ Gateway ping verification
✅ USB tethering fallback
✅ TTS warnings (offline >30s)
✅ Coverage logging + AP transitions
✅ Configurable parameters
✅ Manual control commands
