From 8f158eeeb2f25cb151c8b4a1162e970c971b8229 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Thu, 19 Mar 2026 23:27:42 +0800 Subject: [PATCH] fix: turn off LEDs on service start, suppress Err0 before first WS success Made-with: Cursor --- install.sh | 1 + lib/client.js | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 5d0daa3..052ec44 100644 --- a/install.sh +++ b/install.sh @@ -187,6 +187,7 @@ Wants=network-online.target [Service] Type=simple EnvironmentFile=$ENV_FILE +ExecStartPre=/bin/sh -c 'echo 1 > /sys/devices/platform/openvfd/attr/b1 2>/dev/null; echo 1 > /sys/devices/platform/openvfd/attr/b2 2>/dev/null; true' ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js WorkingDirectory=$INSTALL_DIR diff --git a/lib/client.js b/lib/client.js index 1159ab6..4170bea 100644 --- a/lib/client.js +++ b/lib/client.js @@ -41,6 +41,8 @@ class ClawClient { // WS 连续失败计数(open 时清零) this._wsFailCount = 0; + // 是否曾经成功连接过(首次成功前不显示 Err0/AP) + this._hasEverConnected = false; // systemd watchdog this._sdTimer = null; @@ -125,7 +127,7 @@ class ClawClient { _connect() { if (this._stopped) return; - if (this._wsFailCount < 3) led.display.showConn(); + if (!this._hasEverConnected || this._wsFailCount < 3) led.display.showConn(); log.info('clawd', `正在连接 ${this._cfg.server} ...`); const ws = new WebSocket(this._cfg.server, { handshakeTimeout: 10_000, @@ -135,7 +137,8 @@ class ClawClient { ws.on('open', () => { log.info('clawd', 'WebSocket 已连接'); this._backoff = 1_000; - this._wsFailCount = 0; // 连接成功,重置失败计数 + this._wsFailCount = 0; // 连接成功,重置失败计数 + this._hasEverConnected = true; // 标记已成功连接过 this._sendConnect(); this._startPing(); // 显示由 _onConnected 根据 status 设置,不在此处提前 showTime @@ -159,11 +162,11 @@ class ClawClient { if (!this._stopped) { this._wsFailCount++; log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount},${this._backoff / 1000}s 后重连...`); - if (this._wsFailCount >= 3) { + if (this._hasEverConnected && this._wsFailCount >= 3) { if (hasInternet()) { led.display.showErr0(); // 有网但 VPS 不可达 } else { - led.display.showAP(); // 无网,AP 模式 + led.display.showAP(); // 无网,AP 模式 } } setTimeout(() => this._connect(), this._backoff);