+
+function wifi_status()
+ local function jsondump(x)
+ if x == nil then
+ luci.http.write("null")
+ elseif type(x) == "table" then
+ local k, v
+ if type(next(x)) == "number" then
+ luci.http.write("[ ")
+ for k, v in ipairs(x) do
+ jsondump(v)
+ if next(x, k) then
+ luci.http.write(", ")
+ end
+ end
+ luci.http.write(" ]")
+ else
+ luci.http.write("{ ")
+ for k, v in pairs(x) do
+ luci.http.write("%q: " % k)
+ jsondump(v)
+ if next(x, k) then
+ luci.http.write(", ")
+ end
+ end
+ luci.http.write(" }")
+ end
+ elseif type(x) == "number" or type(x) == "boolean" then
+ luci.http.write(tostring(x))
+ elseif type(x) == "string" then
+ luci.http.write("%q" % tostring(x))
+ end
+ end
+
+
+ local path = luci.dispatcher.context.requestpath
+ local dev = path[#path]
+ local iw = luci.sys.wifi.getiwinfo(dev)
+
+ if iw then
+ local f
+ local j = { }
+ for _, f in ipairs({
+ "channel", "frequency", "txpower", "bitrate", "signal", "noise",
+ "quality", "quality_max", "mode", "ssid", "bssid", "country",
+ "encryption", "mbssid_support", "ifname"
+ }) do
+ j[f] = iw[f]
+ end
+
+ luci.http.prepare_content("application/json")
+ jsondump(j)
+ return
+ end
+
+ luci.http.status(404, "No such device")
+end