Wireless: faster initial loading of wireless page

This commit is contained in:
bergware
2025-02-14 02:40:41 +01:00
parent c1b6fd1b64
commit 6ad120e037
3 changed files with 24 additions and 9 deletions

View File

@@ -64,8 +64,8 @@ function enable_wifi(state) {
$('input[name="#arg[1]"]').val(state);
}
function update_wifi() {
$.post('/webGui/include/Wireless.php',{cmd:'list'},function(text) {
function update_wifi(load) {
$.post('/webGui/include/Wireless.php',{cmd:'list',load:load},function(text) {
if (text.length > 0) {
var wifi = JSON.parse(text);
$('#connected').html(wifi.active);
@@ -73,7 +73,7 @@ function update_wifi() {
$('#other_networks').html(wifi.other);
}
});
timers.wifi = setTimeout(update_wifi,10000);
timers.wifi = setTimeout(update_wifi,5000);
}
function manage_wifi(ssid,task) {
@@ -146,7 +146,7 @@ function showSecurity(val) {
<?if (_var($wlan0,'WIFI')=='yes'):?>
$(function() {
$('#wifi').show();
update_wifi();
update_wifi(1);
});
<?endif;?>
</script>

View File

@@ -74,14 +74,27 @@ function saveAttr() {
switch ($cmd) {
case 'list':
$load = $_POST['load'] ?? false;
$title = _('Connect to WiFi network');
$port = array_key_first($wifi);
$carrier = "/sys/class/net/$port/carrier";
$wlan = scanWifi($port);
$echo = [];
$index = 0;
if ($load && count(array_keys($wifi)) > 1) {
foreach ($wifi as $network => $block) {
if ($network == $port) continue;
$wlan[$index]['bss'] = $block['ATTR1'];
$wlan[$index]['signal'] = $block['ATTR2'];
$wlan[$index]['security'] = $block['ATTR3'] ?? $block['SECURITY'];
$wlan[$index]['ssid'] = $network;
$index++;
}
$index = 0;
} else {
$wlan = scanWifi($port);
}
if (count(array_column($wlan,'ssid'))) {
$up = file_exists($carrier) && file_get_contents($carrier)==1;
$up = is_readable($carrier) && file_get_contents($carrier)==1;
$alive = $up ? exec("iw ".escapeshellarg($port)." link 2>/dev/null | grep -Pom1 'SSID: \K.+'") : '';
$state = $up ? _('Connected') : _('Disconnected');
$color = $up ? 'blue' : 'red';

View File

@@ -53,10 +53,12 @@ while (true) {
$locale_init = _var($display,'locale');
update_translation($locale_init);
}
if (file_exists($ini) && file_exists($wlan0)) {
if (is_readable($ini) && is_readable($wlan0)) {
$wifi = parse_ini_file($ini);
$up = file_get_contents($wlan0)==1;
$echo['color'] = $up ? 'blue-text' : 'red-text';
$echo['title'] = $up ? _('WiFi connected') : _('WiFi disconnected');
$alive = $up ? exec("iw wlan0 link 2>/dev/null | grep -Pom1 'SSID: \K.+'") : '';
$echo['color'] = $alive==$wifi['SSID'] ? 'blue-text' : 'red-text';
$echo['title'] = $alive==$wifi['SSID'] ? _('WiFi connected') : _('WiFi disconnected');
} else {
$echo['color'] = 'grey-text';
$echo['title'] = _('No active WiFi');