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]
|
[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
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -135,7 +137,8 @@ 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._wsFailCount = 0; // 连接成功,重置失败计数
|
||||||
|
this._hasEverConnected = true; // 标记已成功连接过
|
||||||
this._sendConnect();
|
this._sendConnect();
|
||||||
this._startPing();
|
this._startPing();
|
||||||
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
|
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
|
||||||
@@ -159,11 +162,11 @@ 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 {
|
||||||
led.display.showAP(); // 无网,AP 模式
|
led.display.showAP(); // 无网,AP 模式
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => this._connect(), this._backoff);
|
setTimeout(() => this._connect(), this._backoff);
|
||||||
|
|||||||
Reference in New Issue
Block a user