fix(client): default off BtMonitor unless CLAWD_ENABLE_BT (no env line needed)

This commit is contained in:
stswangzhiping
2026-03-29 08:20:08 +08:00
parent aa9561f946
commit a6e2f7ab8f
2 changed files with 23 additions and 15 deletions

View File

@@ -167,8 +167,9 @@ CLAWD_LOG_LEVEL=info
CLAWD_LOG_FILE=1
# 自定义服务器地址(留空则读 config.json
# CLAWD_SERVER=wss://claw.cutos.ai/ws
# 关闭 BtMonitor不执行 bluetoothctl。需要蓝牙状态灯时请注释掉下一行
CLAWD_DISABLE_BT=1
# BtMonitorbluetoothctl默认在程序内关闭,无需在此写 CLAWD_DISABLE_BT
# 若产品需要蓝牙指示灯,取消下一行注释:
# CLAWD_ENABLE_BT=1
# OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
# 多网口/特殊板型可固定 LAN 灯监控的以太网口(默认由 clawd 自动锁定首次 carrier 口)

View File

@@ -30,12 +30,17 @@ function bluetoothAdapterPresent() {
}
}
/** 是否启动 BtMonitor会周期性执行 bluetoothctl */
/**
* 是否启动 BtMonitor会周期性执行 bluetoothctl
* 默认关闭,仅拉代码即可与「不调 bluetoothctl」一致需要蓝牙灯时设 CLAWD_ENABLE_BT=1。
* CLAWD_DISABLE_BT=1 仍可强制关闭(优先于 ENABLE
*/
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;
const dis = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase();
if (dis === '1' || dis === 'true' || dis === 'yes') return false;
const en = (process.env.CLAWD_ENABLE_BT || '').trim().toLowerCase();
if (!(en === '1' || en === 'true' || en === 'yes')) return false;
return bluetoothAdapterPresent();
}
class ClawClient {
@@ -102,19 +107,21 @@ class ClawClient {
// RJ45 链路轮询OpenVFD play与 WS 无关,进程起来即开始
led.lan.start();
// 蓝牙状态监控bluetoothctlCLAWD_DISABLE_BT=1 或无 hci 时不启动
// 蓝牙状态监控bluetoothctl默认不启用,见 btMonitorEnabled()
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 适配器)',
);
const en = (process.env.CLAWD_ENABLE_BT || '').trim().toLowerCase();
const wantEn = en === '1' || en === 'true' || en === 'yes';
const forcedDis = dis === '1' || dis === 'true' || dis === 'yes';
let msg = '已跳过蓝牙监控(默认关闭;需要时请设 CLAWD_ENABLE_BT=1';
if (forcedDis) msg = '已跳过蓝牙监控CLAWD_DISABLE_BT 已开启)';
else if (wantEn && !bluetoothAdapterPresent()) {
msg = '已跳过蓝牙监控(已设 CLAWD_ENABLE_BT 但未检测到 hci 适配器)';
}
log.info('clawd', msg);
}
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP