Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions contrib/README
Expand Up @@ -83,6 +83,12 @@ vicious.contrib.rss
vicious.contrib.sensors 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 Usage examples
-------------- --------------
Expand Down
48 changes: 48 additions & 0 deletions 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 })
13 changes: 11 additions & 2 deletions widgets/cpufreq.lua
Expand Up @@ -29,13 +29,20 @@ local function worker(format, warg)
} }
-- Default voltage values -- Default voltage values
local voltage = { v = "N/A", mv = "N/A" } local voltage = { v = "N/A", mv = "N/A" }
local freqmhz = "N/A"
local freqghz = "N/A"




-- Get the current frequency -- Get the current frequency
local freq = tonumber(cpufreq.scaling_cur_freq) local freq = tonumber(cpufreq.scaling_cur_freq)
-- Calculate MHz and GHz -- 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 -- Get the current voltage
if cpufreq.scaling_voltages then if cpufreq.scaling_voltages then
Expand All @@ -49,6 +56,8 @@ local function worker(format, warg)
-- Represent the governor as a symbol -- Represent the governor as a symbol
governor = governor_state[governor] or governor governor = governor_state[governor] or governor


if governor == nil then governor = "N/A" end

return {freqmhz, freqghz, voltage.mv, voltage.v, governor} return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
end end
-- }}} -- }}}
Expand Down