From b25bc58a3b127df1b5b718e8b4726b569fb4d7c5 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Sun, 29 Mar 2026 08:16:13 +0800 Subject: [PATCH] fix(client): honor CLAWD_DISABLE_BT and skip BtMonitor without hci --- install.sh | 2 +- lib/client.js | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 96ecb1e..8d2ab08 100644 --- a/install.sh +++ b/install.sh @@ -167,7 +167,7 @@ CLAWD_LOG_LEVEL=info CLAWD_LOG_FILE=1 # 自定义服务器地址(留空则读 config.json) # CLAWD_SERVER=wss://claw.cutos.ai/ws -# 无蓝牙机型(如部分 RK3528):强制不写 bluetoothctl +# 不跑 bluetoothctl / BtMonitor(有蓝牙但不想用也可设 1) # CLAWD_DISABLE_BT=1 # OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd) # CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd diff --git a/lib/client.js b/lib/client.js index 7422f27..f330533 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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(); + // 蓝牙状态监控(bluetoothctl);CLAWD_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);