Gigamo Wifi Widget

A simple wifi widget using "/sys/class/net".

Widget creation: wifiwidget = widget({type = "textbox", name = "wifiwidget", align = "right" })

The function: function wifiInfo(adapter) spacer = " " local f = io.open("/sys/class/net/"..adapter.."/wireless/link") local wifiStrength = f:read if wifiStrength == "0" then wifiStrength = "Network Down" else wifiStrength = "Wifi:"..spacer..wifiStrength.."%" end wifiwidget.text = spacer..wifiStrength..spacer f:close end

Then, call the function in a hook, like this:

awful.hooks.timer.register(5, function     wifiInfo("wlan0")  end)

Change the 5 to the time you want, or wlan0 to whichever adapter you use.

Newer Kernel Versions
In newer kernel versions it seems that /sys/class/net/wlan0/wireless/link doesn't exist anymore. Here's an alternate version based on /proc/net/wireless.

Create widget as in example above: wifiwidget = widget({type = "textbox", name = "wifiwidget", align = "right" })

Altered wifiInfo-function:

function wifiInfo spacer = " " local wifiStrength = execute_command("awk 'NR==3 {print \$3 \"%\"}''' /proc/net/wireless | sed 's/\\\.//g'") wifiwidget.text = "Wifi:"..spacer..wifiStrength..spacer end

And the awful update hook as mentioned before: awful.hooks.timer.register(5, function     wifiInfo  end)

Newer Kernel Versions and Awesome 3.5
This version is based on the above, but has some edits. There is possibly one configuration option, which is in. awk 'NR==3 {printf \"%.1f%%\\n\",($3/70)*100}' /proc/net/wireless The 70 represents the maximum signal level available. This actual maximum may be different depending on your device. Run iwconfig wlan0 Where you replace wlan0 with your device (in my case this is wlp3s0, but wlan0 is much more common). In the result you should see "Link Quality=xx/yy Signal level=-zz dBm" Now yy is the maximum link quality and should replace the number 70 in the code.

-- Wifi signal wifi_signal_widget = wibox.widget.textbox("?%") -- wifi_icon = wibox.widget.imagebox function wifiInfo spacer = " " local wifiStrength = awful.util.pread("awk 'NR==3 {printf \"%.1f%%\\n\",($3/70)*100}' /proc/net/wireless") if wifiStrength == "" then -- wifi_icon:set_image(beautiful.wireless_down) wifi_signal_widget:set_text("") else -- wifi_icon:set_image(beautiful.wireless) wifi_signal_widget:set_text(spacer .. wifiStrength) end end wifiInfo wifi_timer = timer({timeout=2}) wifi_timer:connect_signal("timeout",wifiInfo) wifi_timer:start

Dont forget to add your widget to your wibox.

widget behaviour
The widgets as shown above shows the link quality as a percentage. If there is no connection, nothing is shown to indicate that the wifi is disconnected. If you have no internet connection, but still got wifi the percentage is still shown.

A stub is present for showing an image when connected and when disconnected.