fix(client): honor CLAWD_DISABLE_BT and skip BtMonitor without hci
This commit is contained in:
@@ -167,7 +167,7 @@ CLAWD_LOG_LEVEL=info
|
|||||||
CLAWD_LOG_FILE=1
|
CLAWD_LOG_FILE=1
|
||||||
# 自定义服务器地址(留空则读 config.json)
|
# 自定义服务器地址(留空则读 config.json)
|
||||||
# CLAWD_SERVER=wss://claw.cutos.ai/ws
|
# CLAWD_SERVER=wss://claw.cutos.ai/ws
|
||||||
# 无蓝牙机型(如部分 RK3528):强制不写 bluetoothctl
|
# 不跑 bluetoothctl / BtMonitor(有蓝牙但不想用也可设 1)
|
||||||
# CLAWD_DISABLE_BT=1
|
# CLAWD_DISABLE_BT=1
|
||||||
# OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd)
|
# OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd)
|
||||||
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
|
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const PING_INTERVAL_MS = 15_000;
|
|||||||
const HEARTBEAT_INTERVAL_MS = 10_000; // 心跳间隔:10 秒,用于快速感知网络状态
|
const HEARTBEAT_INTERVAL_MS = 10_000; // 心跳间隔:10 秒,用于快速感知网络状态
|
||||||
const METRICS_EVERY_N = 3; // 每 N 次心跳采集一次指标(= 30 秒)
|
const METRICS_EVERY_N = 3; // 每 N 次心跳采集一次指标(= 30 秒)
|
||||||
|
|
||||||
/** CLAWD_DISABLE_BT=1 或系统无 hci* 时不启动 bluetoothctl 轮询(如 RK3528 无蓝牙) */
|
/** 内核是否暴露蓝牙适配器(hci*) */
|
||||||
function bluetoothAdapterPresent() {
|
function bluetoothAdapterPresent() {
|
||||||
try {
|
try {
|
||||||
return fs.readdirSync('/sys/class/bluetooth').some((n) => n.startsWith('hci'));
|
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 {
|
class ClawClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._cfg = config.load();
|
this._cfg = config.load();
|
||||||
@@ -94,9 +102,20 @@ class ClawClient {
|
|||||||
// RJ45 链路轮询(OpenVFD play),与 WS 无关,进程起来即开始
|
// RJ45 链路轮询(OpenVFD play),与 WS 无关,进程起来即开始
|
||||||
led.lan.start();
|
led.lan.start();
|
||||||
|
|
||||||
// 启动蓝牙状态监控(独立于网络,立即开始)
|
// 蓝牙状态监控(bluetoothctl);CLAWD_DISABLE_BT=1 或无 hci 时不启动
|
||||||
this._btMonitor = new BtMonitor();
|
if (btMonitorEnabled()) {
|
||||||
this._btMonitor.start();
|
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)
|
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP)
|
||||||
this._provisionMgr = new ProvisionManager(this._cfg.claw_id);
|
this._provisionMgr = new ProvisionManager(this._cfg.claw_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user