ADR-013:在消费级设备上的功能级感知(选项 3)¶
状态¶
已接受 — 已实现(36/36 个单元测试通过,参见 archive/v1/src/sensing/ 和 archive/v1/tests/unit/test_sensing.py)
日期¶
2026-02-28
背景¶
并非所有人都能部署定制硬件¶
ADR-012 指定了一个提供真实 CSI 数据的 ESP32 CSI 网状网络。然而,它需要: - 购买 ESP32 开发板 - 刷写自定义固件 - 安装 ESP-IDF 工具链 - 物理部署节点
对于许多用户——尤其是正在评估 WiFi-DensePose 或在受管环境中部署的用户——修改硬件并非可行选项。我们需要一条能够基于现有、未修改的消费级 WiFi 设备工作的感知路径。
消费级硬件可暴露的指标¶
标准 WiFi 驱动和工具无需自定义固件即可暴露多项指标:
| 信号 | 来源 | 可用性 | 采样率 |
|---|---|---|---|
| RSSI(接收信号强度) | iwconfig、iw、NetworkManager |
通用 | 1-10 Hz |
| 噪声底 | iw dev wlan0 survey dump |
大多数 Linux 驱动 | ~1 Hz |
| 链路质量 | /proc/net/wireless |
Linux | 1-10 Hz |
| MCS 索引 / PHY 速率 | iw dev wlan0 link |
大多数驱动 | 每数据包 |
| TX/RX 字节 | /sys/class/net/wlan0/statistics/ |
通用 | 连续 |
| 重试计数 | iw dev wlan0 station dump |
大多数驱动 | ~1 Hz |
| 信标间隔计时 | iw dev wlan0 scan dump |
通用 | 每次扫描 |
| 信道利用率 | iw dev wlan0 survey dump |
大多数驱动 | ~1 Hz |
RSSI 是主要信号。当人类在任意发射机-接收机对之间的传播路径中移动时,它会发生变化。研究证实基于 RSSI 的感知可用于: - 存在检测(单接收机,基于方差的阈值) - 无设备运动检测(RSSI 方差随运动增加) - 粗略的房间级定位(多接收机 RSSI 指纹) - 呼吸检测(专用设置,质量有限)
研究支持¶
- 基于 RSSI 的存在检测:Youssef 等人(2007)使用来自多个接收机的 RSSI 实现了无设备被动检测,准确率超过 90%。
- RSSI 呼吸检测:Abdelnasser 等人(2015)在受控环境中通过 RSSI 方差展示了呼吸检测,使用 4 个或更多接收机时准确率约为 85%。
- 无设备跟踪:使用 RSSI 指纹的多个接收机可达到房间级(3-5 米)精度。
决策¶
我们将实现一个功能级感知模块,从任何 Linux 机器上可用的标准 WiFi 指标中提取运动、存在和粗略活动信息,无需修改硬件。
架构¶
┌──────────────────────────────────────────────────────────────────────┐
│ Feature-Level Sensing Pipeline │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ Data Sources (any Linux WiFi device): │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌──────────────┐ │
│ │ RSSI │ │ Noise │ │ Link │ │ Packet Stats │ │
│ │ Stream │ │ Floor │ │ Quality │ │ (TX/RX/Retry)│ │
│ └────┬────┘ └────┬────┘ └────┬────┘ └──────┬───────┘ │
│ │ │ │ │ │
│ └───────────┴───────────┴──────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Feature Extraction Engine │ │
│ │ │ │
│ │ 1. Rolling statistics (mean, var, skew, kurt) │ │
│ │ 2. Spectral features (FFT of RSSI time series) │ │
│ │ 3. Change-point detection (CUSUM, PELT) │ │
│ │ 4. Cross-receiver correlation │ │
│ │ 5. Packet timing jitter analysis │ │
│ └────────────────────────┬───────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Classification / Decision │ │
│ │ │ │
│ │ • Presence: RSSI variance > threshold │ │
│ │ • Motion class: spectral peak frequency │ │
│ │ • Occupancy change: change-point event │ │
│ │ • Confidence: cross-receiver agreement │ │
│ └────────────────────────┬───────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Output: Presence/Motion Events │ │
│ │ │ │
│ │ { "timestamp": "...", │ │
│ │ "presence": true, │ │
│ │ "motion_level": "active", │ │
│ │ "confidence": 0.87, │ │
│ │ "receivers_agreeing": 3, │ │
│ │ "rssi_variance": 4.2 } │ │
│ └────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────┘
特征提取规范¶
class RssiFeatureExtractor:
"""Extract sensing features from RSSI and link statistics.
No custom hardware required. Works with any WiFi interface
that exposes standard Linux wireless statistics.
"""
def __init__(self, config: FeatureSensingConfig):
self.window_size = config.window_size # 30 seconds
self.sampling_rate = config.sampling_rate # 10 Hz
self.rssi_buffer = deque(maxlen=self.window_size * self.sampling_rate)
self.noise_buffer = deque(maxlen=self.window_size * self.sampling_rate)
def extract_features(self) -> FeatureVector:
rssi_array = np.array(self.rssi_buffer)
return FeatureVector(
# Time-domain statistics
rssi_mean=np.mean(rssi_array),
rssi_variance=np.var(rssi_array),
rssi_skewness=scipy.stats.skew(rssi_array),
rssi_kurtosis=scipy.stats.kurtosis(rssi_array),
rssi_range=np.ptp(rssi_array),
rssi_iqr=np.subtract(*np.percentile(rssi_array, [75, 25])),
# Spectral features (FFT of RSSI time series)
spectral_energy=self._spectral_energy(rssi_array),
dominant_frequency=self._dominant_freq(rssi_array),
breathing_band_power=self._band_power(rssi_array, 0.1, 0.5), # Hz
motion_band_power=self._band_power(rssi_array, 0.5, 3.0), # Hz
# Change-point features
num_change_points=self._cusum_changes(rssi_array),
max_step_magnitude=self._max_step(rssi_array),
# Noise floor features (environment stability)
noise_mean=np.mean(np.array(self.noise_buffer)),
snr_estimate=np.mean(rssi_array) - np.mean(np.array(self.noise_buffer)),
)
def _spectral_energy(self, rssi: np.ndarray) -> float:
"""Total spectral energy excluding DC component."""
spectrum = np.abs(scipy.fft.rfft(rssi - np.mean(rssi)))
return float(np.sum(spectrum[1:] ** 2))
def _dominant_freq(self, rssi: np.ndarray) -> float:
"""Dominant frequency in RSSI time series."""
spectrum = np.abs(scipy.fft.rfft(rssi - np.mean(rssi)))
freqs = scipy.fft.rfftfreq(len(rssi), d=1.0/self.sampling_rate)
return float(freqs[np.argmax(spectrum[1:]) + 1])
def _band_power(self, rssi: np.ndarray, low_hz: float, high_hz: float) -> float:
"""Power in a specific frequency band."""
spectrum = np.abs(scipy.fft.rfft(rssi - np.mean(rssi))) ** 2
freqs = scipy.fft.rfftfreq(len(rssi), d=1.0/self.sampling_rate)
mask = (freqs >= low_hz) & (freqs <= high_hz)
return float(np.sum(spectrum[mask]))
def _cusum_changes(self, rssi: np.ndarray) -> int:
"""Count change points using CUSUM algorithm."""
mean = np.mean(rssi)
cusum_pos = np.zeros_like(rssi)
cusum_neg = np.zeros_like(rssi)
threshold = 3.0 * np.std(rssi)
changes = 0
for i in range(1, len(rssi)):
cusum_pos[i] = max(0, cusum_pos[i-1] + rssi[i] - mean - 0.5)
cusum_neg[i] = max(0, cusum_neg[i-1] - rssi[i] + mean - 0.5)
if cusum_pos[i] > threshold or cusum_neg[i] > threshold:
changes += 1
cusum_pos[i] = 0
cusum_neg[i] = 0
return changes
数据采集(无需 root)¶
class LinuxWifiCollector:
"""Collect WiFi statistics from standard Linux interfaces.
No root required for most operations.
No custom drivers or firmware.
Works with NetworkManager, wpa_supplicant, or raw iw.
"""
def __init__(self, interface: str = "wlan0"):
self.interface = interface
def get_rssi(self) -> float:
"""Get current RSSI from connected AP."""
# Method 1: /proc/net/wireless (no root)
with open("/proc/net/wireless") as f:
for line in f:
if self.interface in line:
parts = line.split()
return float(parts[3].rstrip('.'))
# Method 2: iw (no root for own station)
result = subprocess.run(
["iw", "dev", self.interface, "link"],
capture_output=True, text=True
)
for line in result.stdout.split('\n'):
if 'signal:' in line:
return float(line.split(':')[1].strip().split()[0])
raise SensingError(f"Cannot read RSSI from {self.interface}")
def get_noise_floor(self) -> float:
"""Get noise floor estimate."""
result = subprocess.run(
["iw", "dev", self.interface, "survey", "dump"],
capture_output=True, text=True
)
for line in result.stdout.split('\n'):
if 'noise:' in line:
return float(line.split(':')[1].strip().split()[0])
return -95.0 # Default noise floor estimate
def get_link_stats(self) -> dict:
"""Get link quality statistics."""
result = subprocess.run(
["iw", "dev", self.interface, "station", "dump"],
capture_output=True, text=True
)
stats = {}
for line in result.stdout.split('\n'):
if 'tx bytes:' in line:
stats['tx_bytes'] = int(line.split(':')[1].strip())
elif 'rx bytes:' in line:
stats['rx_bytes'] = int(line.split(':')[1].strip())
elif 'tx retries:' in line:
stats['tx_retries'] = int(line.split(':')[1].strip())
elif 'signal:' in line:
stats['signal'] = float(line.split(':')[1].strip().split()[0])
return stats
分类规则¶
class PresenceClassifier:
"""Rule-based presence and motion classifier.
Uses simple, interpretable rules rather than ML to ensure
transparency and debuggability.
"""
def __init__(self, config: ClassifierConfig):
self.variance_threshold = config.variance_threshold # 2.0 dBm²
self.motion_threshold = config.motion_threshold # 5.0 dBm²
self.spectral_threshold = config.spectral_threshold # 10.0
self.confidence_min_receivers = config.min_receivers # 2
def classify(self, features: FeatureVector,
multi_receiver: list[FeatureVector] = None) -> SensingResult:
# Presence: RSSI variance exceeds empty-room baseline
presence = features.rssi_variance > self.variance_threshold
# Motion level
if features.rssi_variance > self.motion_threshold:
motion = MotionLevel.ACTIVE
elif features.rssi_variance > self.variance_threshold:
motion = MotionLevel.PRESENT_STILL
else:
motion = MotionLevel.ABSENT
# Confidence from spectral energy and receiver agreement
spectral_conf = min(1.0, features.spectral_energy / self.spectral_threshold)
if multi_receiver:
agreeing = sum(1 for f in multi_receiver
if (f.rssi_variance > self.variance_threshold) == presence)
receiver_conf = agreeing / len(multi_receiver)
else:
receiver_conf = 0.5 # Single receiver = lower confidence
confidence = 0.6 * spectral_conf + 0.4 * receiver_conf
return SensingResult(
presence=presence,
motion_level=motion,
confidence=confidence,
dominant_frequency=features.dominant_frequency,
breathing_band_power=features.breathing_band_power,
)
能力矩阵(诚实评估)¶
| 能力 | 单接收器 | 3 个接收器 | 6 个接收器 | 准确率 |
|---|---|---|---|---|
| 二元存在检测 | 是 | 是 | 是 | 90-95% |
| 粗略运动(静止/移动) | 是 | 是 | 是 | 85-90% |
| 房间级定位 | 否 | 勉强 | 是 | 70-80% |
| 人数统计 | 否 | 勉强 | 勉强 | 50-70% |
| 活动类别(行走/坐/站) | 勉强 | 勉强 | 是 | 60-75% |
| 呼吸检测 | 否 | 勉强 | 勉强 | 40-60% |
| 心跳 | 否 | 否 | 否 | 不适用 |
| 身体姿态 | 否 | 否 | 否 | 不适用 |
结论:基于普通设备的特征级感知能很好地完成存在检测和运动检测。它不能做姿态估计、心跳或可靠的呼吸检测。任何相反的说法都是不诚实的。
决策矩阵:选项 2(ESP32)与选项 3(消费级设备)¶
| 因素 | ESP32 CSI(ADR-012) | 消费级(ADR-013) |
|---|---|---|
| 核心能力 | 呼吸 + 运动 | 存在 + 粗略运动 |
| 硬件成本 | $54(3 节点套件) | $0(现有设备) |
| 设置时间 | 2-4 小时 | 15 分钟 |
| 技术门槛 | 中等(刷写固件) | 低(pip install) |
| 数据质量 | 真实 CSI(幅度 + 相位) | 仅 RSSI |
| 多人 | 勉强 | 差 |
| 姿态估计 | 勉强 | 否 |
| 可复现性 | 高(受控硬件) | 中(因硬件而异) |
| 公开可信度 | 高(真实 CSI 产物) | 中(RSSI 是“显然的”) |
消费级感知证明包¶
archive/v1/data/proof/commodity/
├── rssi_capture_30sec.json # 30 seconds of RSSI from 3 receivers
├── rssi_capture_meta.json # Hardware: Intel AX200, Router: TP-Link AX1800
├── scenario.txt # "Person walks through room at t=10s, sits at t=20s"
├── expected_features.json # Feature extraction output
├── expected_classification.json # Classification output
├── expected_features.sha256 # Verification hash
└── verify_commodity.py # One-command verification
与 WiFi-DensePose 流水线集成¶
商品级感知模块输出与 CSI 流水线相同的 SensingResult 类型,从而支持优雅降级:
class SensingBackend(Protocol):
"""Common interface for all sensing backends."""
def get_features(self) -> FeatureVector: ...
def get_capabilities(self) -> set[Capability]: ...
class CsiBackend(SensingBackend):
"""Full CSI pipeline (ESP32 or research NIC)."""
def get_capabilities(self):
return {Capability.PRESENCE, Capability.MOTION, Capability.RESPIRATION,
Capability.LOCATION, Capability.POSE}
class CommodityBackend(SensingBackend):
"""RSSI-only commodity hardware."""
def get_capabilities(self):
return {Capability.PRESENCE, Capability.MOTION}
影响¶
积极方面¶
- 零成本入门:可配合现有 WiFi 硬件使用
- 15 分钟部署:
pip install wifi-densepose && wdp sense --interface wlan0 - 广泛采用:任何 Linux 笔记本电脑、Pi 或手机都可以参与
- 诚实的能力报告:
get_capabilities()准确告知用户哪些功能可用 - 与 ESP32 互补:用户可从商品级硬件起步,再升级到 ESP32 以获得更多能力
- 无模拟数据:来自真实硬件的真实 RSSI,确定性流水线
消极方面¶
- 能力有限:无姿态估计、无心率、呼吸检测效果有限
- 硬件差异:不同芯片组的 RSSI 校准存在差异
- 环境敏感性:商品级 RSSI 比 CSI 更容易受干扰影响
- 并非“姿态估计”演示:该模块确实无法实现项目名称所暗示的功能
- 可信度上限较低:RSSI 感知已广为人知,不如 CSI 令人印象深刻
实现状态¶
完整的商品级感知流水线已实现在 archive/v1/src/sensing/ 中:
| 模块 | 文件 | 描述 |
|---|---|---|
| RSSI 采集器 | rssi_collector.py |
LinuxWifiCollector(实时硬件)+ SimulatedCollector(确定性测试),带环形缓冲区 |
| 特征提取器 | feature_extractor.py |
RssiFeatureExtractor,带 Hann 窗 FFT、频带功率(呼吸 0.1-0.5 Hz、运动 0.5-3 Hz)、CUSUM 变点检测 |
| 分类器 | classifier.py |
PresenceClassifier,具有 ABSENT/PRESENT_STILL/ACTIVE 级别,置信度评分 |
| 后端 | backend.py |
CommodityBackend 将采集器 → 提取器 → 分类器连接起来,报告 PRESENCE + MOTION 能力 |
测试覆盖:archive/v1/tests/unit/test_sensing.py 中有 36 个测试——全部通过:
- TestRingBuffer (4), TestSimulatedCollector (5), TestFeatureExtractor (8), TestCusum (4), TestPresenceClassifier (7), TestCommodityBackend (6), TestBandPower (2)
依赖项:numpy、scipy(用于 FFT 和频谱分析)
注意:LinuxWifiCollector 需要一个已连接的 Linux WiFi 接口(/proc/net/wireless 或 iw)。在 Windows 上或接口未连接时,请使用 SimulatedCollector 进行开发和测试。
参考资料¶
- Youssef 等人 - 无设备被动定位中的挑战
- 无设备 WiFi 感知综述
- 基于 RSSI 的呼吸检测
- Linux 无线工具
- ADR-011:Python 真实性证明与模拟数据消除
- ADR-012:ESP32 CSI 传感器网格
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView