fix: turn off LEDs on service start, suppress Err0 before first WS success

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-19 23:27:42 +08:00
parent 9b4287db1d
commit 8f158eeeb2
2 changed files with 8 additions and 4 deletions

View File

@@ -187,6 +187,7 @@ Wants=network-online.target
[Service] [Service]
Type=simple Type=simple
EnvironmentFile=$ENV_FILE 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 ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js
WorkingDirectory=$INSTALL_DIR WorkingDirectory=$INSTALL_DIR

View File

@@ -41,6 +41,8 @@ class ClawClient {
// WS 连续失败计数open 时清零) // WS 连续失败计数open 时清零)
this._wsFailCount = 0; this._wsFailCount = 0;
// 是否曾经成功连接过(首次成功前不显示 Err0/AP
this._hasEverConnected = false;
// systemd watchdog // systemd watchdog
this._sdTimer = null; this._sdTimer = null;
@@ -125,7 +127,7 @@ class ClawClient {
_connect() { _connect() {
if (this._stopped) return; 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} ...`); log.info('clawd', `正在连接 ${this._cfg.server} ...`);
const ws = new WebSocket(this._cfg.server, { const ws = new WebSocket(this._cfg.server, {
handshakeTimeout: 10_000, handshakeTimeout: 10_000,
@@ -136,6 +138,7 @@ class ClawClient {
log.info('clawd', 'WebSocket 已连接'); log.info('clawd', 'WebSocket 已连接');
this._backoff = 1_000; this._backoff = 1_000;
this._wsFailCount = 0; // 连接成功,重置失败计数 this._wsFailCount = 0; // 连接成功,重置失败计数
this._hasEverConnected = true; // 标记已成功连接过
this._sendConnect(); this._sendConnect();
this._startPing(); this._startPing();
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime // 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
@@ -159,7 +162,7 @@ class ClawClient {
if (!this._stopped) { if (!this._stopped) {
this._wsFailCount++; this._wsFailCount++;
log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount}${this._backoff / 1000}s 后重连...`); log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount}${this._backoff / 1000}s 后重连...`);
if (this._wsFailCount >= 3) { if (this._hasEverConnected && this._wsFailCount >= 3) {
if (hasInternet()) { if (hasInternet()) {
led.display.showErr0(); // 有网但 VPS 不可达 led.display.showErr0(); // 有网但 VPS 不可达
} else { } else {