Merge pull request #2013 from meandthemachine/fix/duplicate-ids-for-nearby-networks

Fix: Determine start index of nearby networks more robustly to prevent from duplicate ids for known and nearby networks
This commit is contained in:
Bill Zimmerman
2025-11-26 18:05:14 +01:00
committed by GitHub

View File

@@ -22,11 +22,9 @@ class WiFiManager
{
// find currently configured networks
exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $known_return);
$index = 0;
foreach ($known_return as $line) {
if (preg_match('/network\s*=/', $line)) {
$network = array('visible' => false, 'configured' => true, 'connected' => false, 'index' => null);
++$index;
} elseif (isset($network) && $network !== null) {
if (preg_match('/^\s*}\s*$/', $line)) {
$networks[$ssid] = $network;
@@ -38,8 +36,7 @@ class WiFiManager
$ssid = trim($lineArr[1], '"');
$ssid = str_replace('P"','',$ssid);
$network['ssid'] = $ssid;
$index = $this->getNetworkIdBySSID($ssid);
$network['index'] = $index;
$network['index'] = $this->getNetworkIdBySSID($ssid);
break;
case 'psk':
$network['passkey'] = trim($lineArr[1]);
@@ -93,13 +90,16 @@ class WiFiManager
exec('sed -rn "s/ssid=(.*)\s*$/\1/p" ' . escapeshellarg(RASPI_HOSTAPD_CONFIG), $ap_ssid);
$ap_ssid = $ap_ssid[0] ?? '';
$index = 0;
// determine the next index that follows the indexes of the known networks
$index = -1;
if (!empty($networks)) {
$lastnet = end($networks);
if (isset($lastnet['index'])) {
$index = $lastnet['index'] + 1;
foreach ($networks as $network) {
if (isset($network['index']) && ($network['index'] > $index)) {
$index = $network['index'];
}
}
}
$index++;
$current = [];
$commitCurrent = function () use (&$current, &$networks, &$index, $ap_ssid) {