Browse Source

Fix WiFi connection stability - pause BLE scanner and preserve eth0

1. Pause BLE scanner during WiFi connection (AIC8800 combo chip issue)
   - Temporarily stop BLE before connecting WiFi
   - Auto-restart BLE after WiFi connects
   - Prevents WiFi 4WAY_HANDSHAKE timeout

2. Don't kill eth0 when stopping daemon (maintain SSH access)
   - Only stop udhcpc process
   - Keep IP address assigned

3. Improved wpa_supplicant config
   - Explicit key_mgmt, proto, pairwise, group settings
   - Better WPA2-PSK compatibility

Result: WiFi connects in 6 seconds (was 60-90s timeout before)
root 1 month ago
parent
commit
dcfd127843
1 changed files with 22 additions and 2 deletions
  1. 22 2
      cmd/beacon-daemon/network_manager.go

+ 22 - 2
cmd/beacon-daemon/network_manager.go

@@ -96,10 +96,16 @@ func (nm *NetworkManager) Stop() {
 	log.Println("[netmgr] Stopping network manager...")
 	close(nm.stopChan)
 
-	// Clean up all interfaces
-	nm.stopEth0()
+	// Clean up WiFi interfaces only (leave eth0 running for SSH access)
 	nm.stopWLAN0Client()
 	nm.stopAP()
+
+	// Note: eth0 is NOT stopped to maintain SSH connectivity
+	// Only stop eth0 DHCP process, but keep the IP address
+	if nm.eth0DhcpPid > 0 {
+		syscall.Kill(nm.eth0DhcpPid, syscall.SIGTERM)
+	}
+	exec.Command("killall", "-q", "udhcpc").Run()
 }
 
 // monitorLoop is the main network management loop
@@ -343,6 +349,20 @@ func (nm *NetworkManager) connectWLAN0Client() error {
 		nm.scanners.StopWiFi()
 	}
 
+	// Temporarily stop BLE scanner during WiFi connection (AIC8800 combo chip issue)
+	bleWasRunning := nm.scanners.IsBLERunning()
+	if bleWasRunning {
+		log.Println("[netmgr] Temporarily stopping BLE scanner for WiFi connection")
+		nm.scanners.StopBLE()
+		defer func() {
+			if bleWasRunning && nm.cfg.BLE.Enabled {
+				log.Println("[netmgr] Restarting BLE scanner")
+				nm.scanners.StartBLE(nm.cfg.ZMQAddrBLE)
+			}
+		}()
+		time.Sleep(500 * time.Millisecond)
+	}
+
 	// Use wifi-connect.sh script
 	scriptPath := "/opt/mybeacon/bin/wifi-connect.sh"
 	cmd := exec.Command(scriptPath, nm.cfg.WiFi.SSID, nm.cfg.WiFi.PSK)