fix: wait for NM auto-reconnect before starting AP on reboot
After WiFi is configured and device reboots, NetworkManager needs a few seconds to auto-connect to saved WiFi. Without waiting, AP starts immediately and occupies wlan0, preventing NM reconnect. - Add hasSavedWifiConnection() to check for saved WiFi profiles - Wait up to 20s for NM auto-connect before falling back to AP - First boot (no saved WiFi) still starts AP immediately Made-with: Cursor
This commit is contained in:
@@ -60,21 +60,25 @@ class ClawClient {
|
||||
async start() {
|
||||
log.info('clawd', `启动中... 服务器 = ${this._cfg.server}`);
|
||||
|
||||
// 后台启动 AP 配网管理器(WiFi 未连接时常驻热点)
|
||||
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP)
|
||||
this._provisionMgr = new ProvisionManager(this._cfg.claw_id);
|
||||
this._provisionMgr.start();
|
||||
|
||||
// 有网络时直接连接云端
|
||||
if (hasInternet()) {
|
||||
await this._proceedWithConnection();
|
||||
} else {
|
||||
// 等待配网完成后再连
|
||||
log.info('clawd', '等待网络就绪...');
|
||||
this._provisionMgr.once('network-ready', () => {
|
||||
// 网络就绪时连接云端
|
||||
this._provisionMgr.once('network-ready', () => {
|
||||
if (!this._ws) {
|
||||
this._proceedWithConnection().catch(e => {
|
||||
log.error('clawd', '连接启动失败:', e.message);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await this._provisionMgr.start();
|
||||
|
||||
// start() 返回后,如果已有网络,直接连
|
||||
if (hasInternet() && !this._ws) {
|
||||
await this._proceedWithConnection();
|
||||
} else if (!hasInternet()) {
|
||||
log.info('clawd', '等待网络就绪(WiFi 配网或网线接入)...');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user