From 3f7179869fbbef1ff94b4855a06c0a739c2b6568 Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Tue, 7 Dec 2010 11:13:39 +0000 Subject: [PATCH] modules/freifunk: Wifi status was not showing on brcm47xx. --- .../luasrc/view/freifunk/public_status.htm | 167 ++++++++---------- 1 file changed, 73 insertions(+), 94 deletions(-) diff --git a/modules/freifunk/luasrc/view/freifunk/public_status.htm b/modules/freifunk/luasrc/view/freifunk/public_status.htm index 8948d5e9d..688a8ee99 100644 --- a/modules/freifunk/luasrc/view/freifunk/public_status.htm +++ b/modules/freifunk/luasrc/view/freifunk/public_status.htm @@ -1,11 +1,12 @@ <% -local sys = require "luci.sys" -local twa = require "luci.tools.webadmin" +require "luci.sys" +require "luci.tools.webadmin" + -- System -local system, model, memtotal, memcached, membuffers, memfree = sys.sysinfo() -local uptime = twa.date_format(tonumber(sys.uptime())) -local_time = os.date("%c") -local load1, load5, load15 = sys.loadavg() + +local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo() +local uptime = luci.sys.uptime() +local load1, load5, load15 = luci.sys.loadavg() local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15) local memory = string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", tonumber(memtotal) / 1024, @@ -16,18 +17,24 @@ local memory = string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", 100 * memfree / memtotal, tostring(translate("free")) ) - --- wireless -local ntm = require "luci.model.network".init() -local devices = ntm:get_wifidevs() -local netlist = { } -local netdevs = { } -local dev -local has_iwinfo = pcall(require, "iwinfo") +local_time = os.date("%c") +local uptime = luci.tools.webadmin.date_format(tonumber(uptime)) + +-- Wireless +local uci = require "luci.model.uci".cursor() +ifaces = {} +uci:foreach("wireless", "wifi-iface", function(s) + if s.network then + table.insert(ifaces, s.network) + if (uci:get("network", s.network, "ifname")) then + has_ifaces = true + end + end +end) -- Routes -local defroutev4 = sys.net.defaultroute() -local defroutev6 = sys.net.defaultroute6 () +local defroutev4 = luci.sys.net.defaultroute() +local defroutev6 = luci.sys.net.defaultroute6 () %> <%+header%> @@ -44,18 +51,9 @@ local defroutev6 = sys.net.defaultroute6 () -<% if devices[1] then %> - +<% if has_ifaces == true then %>

<%:Wireless Overview%>

- - <% if not has_iwinfo then %> -
- <%:Package libiwinfo required!%>
- <%_The libiwinfo package is not installed. You must install this component for working wireless configuration!%> -
- <% end %> -
@@ -65,68 +63,54 @@ local defroutev6 = sys.net.defaultroute6 () - - - + - <% - for _, dev in ipairs(devices) do - local net - for _, net in ipairs(dev:get_wifinets()) do - netlist[#netlist+1] = net:ifname() - netdevs[net:ifname()] = dev:name() - - if net.iwdata.ifname then - local signal = net.iwinfo.signal or "N/A" - local noise = net.iwinfo.noise or "N/A" - local q = net.iwinfo.quality or "0" - local qmax = net.iwinfo.quality_max or "100" - local qperc = q / qmax * 100 - - if qperc == 0 then - icon = "signal-none.png" - elseif qperc < 26 then - icon = "signal-0-25.png" - elseif qperc < 51 then - icon = "signal-25-50.png" - elseif qperc < 76 then - icon = "signal-50-75.png" - elseif qperc < 100 then - icon = "signal-75-100.png" - else - icon = "signal-0.png" - end - - signal_string = "Signal Quality" - local ssid = net.iwinfo.ssid or "N/A" - local bssid = net.iwinfo.bssid or "N/A" - local chan = net.iwinfo.channel or "N/A" - local mode = net.iwinfo.mode or "N/A" - local txpwr = net.iwinfo.txpower or "N/A" - if txpwr ~= "N/A" then - txpwr = txpwr.." dbm" - end - local bitrate = net.iwinfo.bitrate or "N/A" - if bitrate ~= "N/A" then - bitrate = ( bitrate / 1000 ).."Mb/s" - end - local interface = net.iwdata.ifname or "N/A" - %> - + + <% for k,v in pairs(ifaces) do + local iface = uci:get("network", v, "ifname") + if iface then + iwinf = luci.sys.wifi.getiwinfo(iface) + local signal = iwinf.signal + local noise = iwinf.noise + local q = iwinf.quality + local qmax = iwinf.quality_max + local qperc = q / qmax * 100 + + if qperc == 0 then + icon = "signal-none.png" + elseif qperc < 26 then + icon = "signal-0-25.png" + elseif qperc < 51 then + icon = "signal-25-50.png" + elseif qperc < 76 then + icon = "signal-50-75.png" + elseif qperc < 100 then + icon = "signal-75-100.png" + else + icon = "signal-0.png" + end + + signal_string = "Signal Quality" + + local ssid = iwinf.ssid + local bssid = iwinf.bssid + local chan = iwinf.channel + local mode = iwinf.mode + local txpwr = iwinf.txpower.." dbm" + local bitrate = (iwinf.bitrate / 1000).."Mb/s" + %> + - - - + - <% end - end - end %> -
<%:SSID%> <%:BSSID%> <%:Channel%><%:Mode%><%:TX%>-<%:Power%><%:Interface%><%:Mode%><%:TX%>-<%:Power%>
<%=signal_string%> <%=bitrate%> <%=ssid%> <%=bssid%> <%=chan%><%=mode%><%=txpwr%><%=interface%><%=mode%><%=txpwr%>
+ <% end %> + <% end %> +
@@ -135,44 +119,39 @@ local defroutev6 = sys.net.defaultroute6 ()

<%:Default routes%>

-
- - -<% if not defroutev4 and not defroutev6 then %> - <%:No default routes known.%> -<%else%> +
+
+ <% if not defroutev4 and not defroutev6 then %> + <%:No defaultroutes known.%> + <%else%> - <% if defroutev4 then %> - - - <% end - if defroutev6 then %> - + <% end %> + <% if defroutev6 then %> - <% end %> -
<%:Network%> <%:Interface%> <%:Gateway%> <%:Metric%>
<%=defroutev4.dest:string()%> <%=defroutev4.device%> <%=defroutev4.gateway:string()%> <%=defroutev4.metric%>
<%=defroutev6.dest:string()%> <%=defroutev6.device%> <%=defroutev6.nexthop:string()%> <%=defroutev6.metric%>
+ <% end %> <%+footer%> + -- 2.25.1