fix: turn off LEDs on service start, suppress Err0 before first WS success
Made-with: Cursor
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -136,6 +138,7 @@ class ClawClient {
|
||||
log.info('clawd', 'WebSocket 已连接');
|
||||
this._backoff = 1_000;
|
||||
this._wsFailCount = 0; // 连接成功,重置失败计数
|
||||
this._hasEverConnected = true; // 标记已成功连接过
|
||||
this._sendConnect();
|
||||
this._startPing();
|
||||
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
|
||||
@@ -159,7 +162,7 @@ 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 {
|
||||
|
||||
Reference in New Issue
Block a user