fix(client): honor CLAWD_DISABLE_BT and skip BtMonitor without hci

This commit is contained in:
stswangzhiping
2026-03-29 08:16:13 +08:00
parent e3e9580e46
commit b25bc58a3b
2 changed files with 24 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ const PING_INTERVAL_MS = 15_000;
const HEARTBEAT_INTERVAL_MS = 10_000; // 心跳间隔10 秒,用于快速感知网络状态
const METRICS_EVERY_N = 3; // 每 N 次心跳采集一次指标(= 30 秒)
/** CLAWD_DISABLE_BT=1 或系统无 hci* 时不启动 bluetoothctl 轮询(如 RK3528 无蓝牙 */
/** 内核是否暴露蓝牙适配器hci* */
function bluetoothAdapterPresent() {
try {
return fs.readdirSync('/sys/class/bluetooth').some((n) => n.startsWith('hci'));
@@ -30,6 +30,14 @@ function bluetoothAdapterPresent() {
}
}
/** 是否启动 BtMonitor会周期性执行 bluetoothctl */
function btMonitorEnabled() {
const v = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase();
if (v === '1' || v === 'true' || v === 'yes') return false;
if (!bluetoothAdapterPresent()) return false;
return true;
}
class ClawClient {
constructor() {
this._cfg = config.load();
@@ -94,9 +102,20 @@ class ClawClient {
// RJ45 链路轮询OpenVFD play与 WS 无关,进程起来即开始
led.lan.start();
// 启动蓝牙状态监控(独立于网络,立即开始)
this._btMonitor = new BtMonitor();
this._btMonitor.start();
// 蓝牙状态监控(bluetoothctlCLAWD_DISABLE_BT=1 或无 hci 时不启动
if (btMonitorEnabled()) {
this._btMonitor = new BtMonitor();
this._btMonitor.start();
} else {
const dis = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase();
const forced = dis === '1' || dis === 'true' || dis === 'yes';
log.info(
'clawd',
forced
? '已跳过蓝牙监控CLAWD_DISABLE_BT 已开启)'
: '已跳过蓝牙监控(未检测到 hci 适配器)',
);
}
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP
this._provisionMgr = new ProvisionManager(this._cfg.claw_id);