feat(led): showErr(code) + WS fail>=3 shows ERRa or AP on VFD

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-19 22:44:56 +08:00
parent e36bec8660
commit 53b9804c72
2 changed files with 25 additions and 1 deletions

View File

@@ -39,6 +39,9 @@ class ClawClient {
this._pingTimer = null;
this._awaitingPong = false;
// WS 连续失败计数open 时清零)
this._wsFailCount = 0;
// systemd watchdog
this._sdTimer = null;
@@ -131,6 +134,7 @@ class ClawClient {
ws.on('open', () => {
log.info('clawd', 'WebSocket 已连接');
this._backoff = 1_000;
this._wsFailCount = 0; // 连接成功,重置失败计数
this._sendConnect();
this._startPing();
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
@@ -152,7 +156,15 @@ class ClawClient {
this._clearHeartbeat();
this._clearPing();
if (!this._stopped) {
log.warn('clawd', `连接断开 (${code})${this._backoff / 1000}s 后重连...`);
this._wsFailCount++;
log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount}${this._backoff / 1000}s 后重连...`);
if (this._wsFailCount >= 3) {
if (hasInternet()) {
led.display.showErr('a'); // 有网但 VPS 不可达
} else {
led.display.showAP(); // 无网AP 模式
}
}
setTimeout(() => this._connect(), this._backoff);
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
}