luci-mod-network: improve wifi scan status reporting

Attempt to properly report the scan status by treating 404 replies as
not yet completed scans and empty array replies as successful scans
that did not yield any results.

Fixes: #2874
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-07-19 17:59:05 +02:00
parent 5510bdae39
commit 8dd2df29c4
2 changed files with 15 additions and 7 deletions

View file

@ -113,6 +113,7 @@ function scan() {
var count = 0; var count = 0;
poll = L.poll(3, L.url('admin/network/wireless_scan_results', dev), null, function(s, results) { poll = L.poll(3, L.url('admin/network/wireless_scan_results', dev), null, function(s, results) {
if (Array.isArray(results)) { if (Array.isArray(results)) {
var bss = []; var bss = [];
@ -143,8 +144,12 @@ function scan() {
]); ]);
}); });
cbi_update_table(tbl, bss, E('em', { class: 'spinning' }, _('No scan results available yet...'))); cbi_update_table(tbl, bss, E('em' {}, _('No networks in range')));
} }
else {
cbi_update_table(tbl, [], E('em', { class: 'spinning' }, _('No scan results available yet...')));
}
if (count++ >= 3) { if (count++ >= 3) {
count = 0; count = 0;

View file

@ -311,7 +311,7 @@ local function _wifi_get_scan_results(cache_key)
return results.values[cache_key] return results.values[cache_key]
end end
return { } return nil
end end
function wifi_scan_trigger(radio, update) function wifi_scan_trigger(radio, update)
@ -343,10 +343,13 @@ function wifi_scan_trigger(radio, update)
end end
if update then if update then
for _, bss in ipairs(_wifi_get_scan_results(cache_key)) do local cached = _wifi_get_scan_results(cache_key)
if not bssids[bss.bssid] then if cached then
bss.stale = true for _, bss in ipairs(cached) do
data[#data + 1] = bss if not bssids[bss.bssid] then
bss.stale = true
data[#data + 1] = bss
end
end end
end end
end end
@ -361,7 +364,7 @@ end
function wifi_scan_results(radio) function wifi_scan_results(radio)
local results = radio and _wifi_get_scan_results("scan_%s" % radio) local results = radio and _wifi_get_scan_results("scan_%s" % radio)
if results and #results > 0 then if results then
luci.http.prepare_content("application/json") luci.http.prepare_content("application/json")
luci.http.write_json(results) luci.http.write_json(results)
else else