X11 monitor wifi connection


Please note that this blog has been moved.

Now it has its own domain: mynixworld.info🙂

If you want to read the latest version of this article (recommended) please click here and I open the page for you.

If you are working on laptop then maybe you are using the wireless device for network communication. If you are using wireless device for network communication then maybe you are using the net-wireless/wpa_supplicant to set up your preferred network connection.

A simple WPA-PSK (aka WPA-Personal) configuration looks like this (you might use a different set up, this is just a plain example):

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
network={
priority=1
group=CCMP TKIP
ssid="<your SSID here>"
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
wpa_ptk_rekey=600
proto=WPA
psk="<your Pre-Shared-Key here>"
}

More information on wpa_supplicant you cand find here : http://hostap.epitest.fi/wpa_supplicant/.

Well, having a wpa_supplicant.conf in order and the wpa_supplicant daemon started this means that your wireless connection should be fully functional. BUT there exists just a problem: sometimes you lose the wireless signal or the AP link and no one is telling you nothing about that. So you need a kind of application that monitors your wireless interface and notify you about the network status. This can be achieved by using the net-misc/networkmanager GUI which take care of this.

For the most of the users NetworkManager should be just find, for me it isn’t. Why? because I do not need another application which will consume another 10MB of RAM (or even more) and consume also CPU more than I need it. So I came up with a simple solution that will help me achieve the following targets:

  • consume less memory than NetworkManager for network interface monitoring/notification
  • consume less CPU cycles than NetworkManager
  • simple to install, simple to administrate, simple to configurate, simple to add improvment

My solution is to have a simple bash script (eg: monitor_wifi) which should start at X session start up and will check every 5 seconds (can be customized) your wireless network status. When the status is changing then a balloon notification will be shown. Simple and effective.

The script will looks like:

#!/bin/bash

WPA_CLI=/usr/bin/wpa_cli
WIFI_IF=$($WPA_CLI interface | awk 'END {print}')
WIFI_SSID=$($WPA_CLI list_networks|awk 'END {print $2}')

EXPIRE_NORMAL=5000
EXPIRE_CRITICAL=3000
CHK_INTERVAL=5

LAST_STATUS=""

while :; do
WPA_STATUS=$($WPA_CLI status)
CONNECTED=$( echo "$WPA_STATUS"|grep -i "wpa_state=COMPLETED")
if [ ${#CONNECTED} -eq 0 ];then
if [ "$LAST_STATUS" != "OFF" ];then
notify-send -u critical -t ${EXPIRE_NORMAL} -c network -i /usr/share/icons/Tango/48x48/status/network-offline.png    "$WIFI_IF disconnected" "Connection problem for $WIFI_SSID !"
fi
LAST_STATUS="OFF"
else
if [ ${#LAST_STATUS} -eq 0 ];then
notify-send -u normal -t ${EXPIRE_NORMAL} -c network -i /usr/share/icons/Tango/48x48/status/dialog-information.png "WIFI Monitor started" "WIFI monitor for interface $WIFI_IF started..."
else
if [ "$LAST_STATUS" != "ON" ];then
notify-send -u normal -t ${EXPIRE_CRITICAL} -c network -i /usr/share/icons/Tango/48x48/status/connect_creating.png "$WIFI_IF connected" "$WIFI_SSID connected successfuly :$WPA_STATUS"
fi
fi
LAST_STATUS="ON"
fi
sleep $CHK_INTERVAL
done
notify-send -u normal -t ${EXPIRE_NORMAL} -c network -i /usr/share/icons/Tango/48x48/status/software-update-urgent.png "WIFI monitor stopped" "WIFI monitor for $WIFI_IF interface stopped..."
exit 0

Start monitor_wifi as daemon at session start-up

In Xfce you can set up a Application Autostart (which are supposed to start at session start up):

  • Settings -> Session and Startup -> Application Autostart tab
  • define a new application autostart as bellow:
    • name: monitor_wifi (in fact it doesn’t matter how you will name it)
    • command: monitor_wifi

So, the daemon will start when your X session starts and then will check the connection status change every 5 seconds. When status changes from connected to disconnected (or vice-versa) a balloon notification like the one bellow will be shown:

monitor_wifi

Later, when the connection is re-established, another balloon notification (with many other details) will be shown, just to keep you informed about everything.

This solutions fits my needs, it is easy to set up and to customize for your particular needs.

Important : the icons I have used in this script comes from my Xfce Tango icon theme. If you are using anything else then maybe they don’t exists on your system. In that situation you can point the icon locations to whatever icons you prefer.

About Eugen Mihailescu

Always looking to learn more about *nix world, about the fundamental concepts of arithmetic, algebra and geometry. I am also passionate about programming, database and systems administration.
This entry was posted in linux, X11 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s