luci-mod-network: improve wifi scan status reporting
authorJo-Philipp Wich <jo@mein.io>
Fri, 19 Jul 2019 15:59:05 +0000 (17:59 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 19 Jul 2019 15:59:05 +0000 (17:59 +0200)
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>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/wifi_join.js
modules/luci-mod-network/luasrc/controller/admin/network.lua

index d5bd7b0a6d8fcea10c5f4beadfdc0fb350fdcdf4..af926ab4a2c32964308f2a91353b688562570975 100644 (file)
@@ -113,6 +113,7 @@ function scan() {
                var count = 0;
 
                poll = L.poll(3, L.url('admin/network/wireless_scan_results', dev), null, function(s, results) {
+
                        if (Array.isArray(results)) {
                                var bss = [];
 
@@ -143,9 +144,13 @@ 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) {
                                count = 0;
                                L.post(L.url('admin/network/wireless_scan_trigger', dev, 1), null, function() {});
index fac8d95a2052fe4f923643b7a0628055f0e068af..b20607e2e9a9ed31ca832ce61b458611a26d8bbc 100644 (file)
@@ -311,7 +311,7 @@ local function _wifi_get_scan_results(cache_key)
                return results.values[cache_key]
        end
 
-       return { }
+       return nil
 end
 
 function wifi_scan_trigger(radio, update)
@@ -343,10 +343,13 @@ function wifi_scan_trigger(radio, update)
                end
 
                if update then
-                       for _, bss in ipairs(_wifi_get_scan_results(cache_key)) do
-                               if not bssids[bss.bssid] then
-                                       bss.stale = true
-                                       data[#data + 1] = bss
+                       local cached = _wifi_get_scan_results(cache_key)
+                       if cached then
+                               for _, bss in ipairs(cached) do
+                                       if not bssids[bss.bssid] then
+                                               bss.stale = true
+                                               data[#data + 1] = bss
+                                       end
                                end
                        end
                end
@@ -361,7 +364,7 @@ end
 function wifi_scan_results(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.write_json(results)
        else