feat(led): showErr(code) + WS fail>=3 shows ERRa or AP on VFD
Made-with: Cursor
This commit is contained in:
@@ -39,6 +39,9 @@ class ClawClient {
|
|||||||
this._pingTimer = null;
|
this._pingTimer = null;
|
||||||
this._awaitingPong = false;
|
this._awaitingPong = false;
|
||||||
|
|
||||||
|
// WS 连续失败计数(open 时清零)
|
||||||
|
this._wsFailCount = 0;
|
||||||
|
|
||||||
// systemd watchdog
|
// systemd watchdog
|
||||||
this._sdTimer = null;
|
this._sdTimer = null;
|
||||||
|
|
||||||
@@ -131,6 +134,7 @@ class ClawClient {
|
|||||||
ws.on('open', () => {
|
ws.on('open', () => {
|
||||||
log.info('clawd', 'WebSocket 已连接');
|
log.info('clawd', 'WebSocket 已连接');
|
||||||
this._backoff = 1_000;
|
this._backoff = 1_000;
|
||||||
|
this._wsFailCount = 0; // 连接成功,重置失败计数
|
||||||
this._sendConnect();
|
this._sendConnect();
|
||||||
this._startPing();
|
this._startPing();
|
||||||
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
|
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
|
||||||
@@ -152,7 +156,15 @@ class ClawClient {
|
|||||||
this._clearHeartbeat();
|
this._clearHeartbeat();
|
||||||
this._clearPing();
|
this._clearPing();
|
||||||
if (!this._stopped) {
|
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);
|
setTimeout(() => this._connect(), this._backoff);
|
||||||
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
|
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
|
||||||
}
|
}
|
||||||
|
|||||||
12
lib/led.js
12
lib/led.js
@@ -108,6 +108,18 @@ class Display {
|
|||||||
log.info('display', '显示屏 → AP');
|
log.info('display', '显示屏 → AP');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络错误 → 显示错误码(ERR + 单字母代码)
|
||||||
|
* code='a' → ERRa(网络正常但 VPS 不可达)
|
||||||
|
* code='b' → ERRb(预留)
|
||||||
|
*/
|
||||||
|
showErr(code = 'a') {
|
||||||
|
this._stopBlink();
|
||||||
|
const s = ('ERR' + code).slice(0, 4);
|
||||||
|
this._write('#m3' + s);
|
||||||
|
log.info('display', `显示屏 → ${s}`);
|
||||||
|
}
|
||||||
|
|
||||||
/** 网络已连接 → 显示时间 */
|
/** 网络已连接 → 显示时间 */
|
||||||
showTime() {
|
showTime() {
|
||||||
this._stopBlink();
|
this._stopBlink();
|
||||||
|
|||||||
Reference in New Issue
Block a user