Skip to content

Loading…

And wifi tool using 'wpa_cli', i.e 'wpa_supplicant' #8

Closed
wants to merge 4 commits into from

2 participants

@jinleileiking

plz only check the commit:

6d1e46b jinleileiking wpa_cli tool added

@Mic92
Owner

The code looks well so far. But could you explain me the advantage over vicious.widgets.wifi?

@jinleileiking

@Mic92 Some users donot use wireless-tools for wlan, such as me.
I only use wpa_supplicant tool to setup my wlan.

@jinleileiking

For convinence, I will recommit a pull

@jinleileiking jinleileiking reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 65 additions and 2 deletions.
  1. +6 −0 contrib/README
  2. +48 −0 contrib/wpa.lua
  3. +11 −2 widgets/cpufreq.lua
View
6 contrib/README
@@ -83,6 +83,12 @@ vicious.contrib.rss
vicious.contrib.sensors
-
+vicious.contrib.wpa
+ - the 'wpa_cli' cmd should be at '/usr/bin/wpa_cli'
+ - Using the wpa_supplicant tool to show your wifi status
+ - takes the interface as an argument, i.e "wlan0" or "wlan1"
+ - $1 returns the ssid your wireless lan is connecting
+ - $2 returns the quality of your wireless lan
Usage examples
--------------
View
48 contrib/wpa.lua
@@ -0,0 +1,48 @@
+---------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2012, jinleileiking. <jinleileiking@gmail.com>
+---------------------------------------------------
+
+-- {{{ Grab environment
+local tonumber = tonumber
+local math = { ceil = math.ceil }
+local setmetatable = setmetatable
+local helpers = require("vicious.helpers")
+local io = {
+ open = io.open,
+ popen = io.popen
+}
+local string = {
+ find = string.find,
+ match = string.match
+}
+-- }}}
+
+
+-- Wifi: provides wireless information for a requested interface
+module("vicious.contrib.wpa")
+
+
+-- {{{ Wireless widget type
+local function worker(format, warg)
+ if not warg then return end
+
+ local wpa_cmd = "/usr/bin/wpa_cli -i" .. warg .. " status 2>&1"
+ local f = io.popen(wpa_cmd)
+ local output = f:read("*all")
+ f:close()
+
+ bssid = string.match(output, 'bssid=([%d:]+)')
+ ssid = string.match(output, 'ssid=([%a]+)')
+
+ local wpa_cmd = "/usr/bin/wpa_cli -i" .. warg .. " bss " .. bssid .. " 2>&1"
+ local f = io.popen(wpa_cmd)
+ local output = f:read("*all")
+
+ qual = string.match(output, 'qual=([%d]+)')
+
+ return {ssid, qual}
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })
View
13 widgets/cpufreq.lua
@@ -29,13 +29,20 @@ local function worker(format, warg)
}
-- Default voltage values
local voltage = { v = "N/A", mv = "N/A" }
+ local freqmhz = "N/A"
+ local freqghz = "N/A"
-- Get the current frequency
local freq = tonumber(cpufreq.scaling_cur_freq)
-- Calculate MHz and GHz
- local freqmhz = freq / 1000
- local freqghz = freqmhz / 1000
+
+ if freq then
+ freqmhz = freq / 1000
+ freqghz = freqmhz / 1000
+ end
+
+
-- Get the current voltage
if cpufreq.scaling_voltages then
@@ -49,6 +56,8 @@ local function worker(format, warg)
-- Represent the governor as a symbol
governor = governor_state[governor] or governor
+ if governor == nil then governor = "N/A" end
+
return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
end
-- }}}
Something went wrong with that request. Please try again.