WICD sucks!


I always use a WLAN USB adapter on my Raspberry Pi since the entire household is wireless. But when the WLAN goes temporary down and comes back on the standard configuration using wpa_supplicant will not reconnect until you reboot. But how to reboot without network connection? I know …

While searching for an alternative I found WICD which is a nice utility with a really nice curses TUI. So when I setup a Pi last weekend using Raspbian “wheezy” I tried it out. I messed around for more than two hours to get the WICD working but WICD and wpa_supplicant jammed each other.

How to resolve?

Very simple plan - write a little shell script which does the job (and I love writing shell scripts because they are designed to perform a special task):

#!/bin/sh

NWN="YOUR-NETWORK-SSID"

echo " *** WLAN connector *** "
date

WLAN0_ONLINE=$(ifconfig wlan0 | grep "inet addr" | wc -l)
if [ "$WLAN0_ONLINE" -eq "1" ]; then
        echo "wlan0 is connected:"
        ifconfig wlan0 | grep "inet addr"
else
        echo "wlan0 not connected to WIFI $NWN"
        echo "Is $NWN avialable?"
        AVAIL=$(iwlist wlan0 scan | grep "$NWN" | wc -l)
        echo "Found $AVAIL WLAN networks with SSID $NWN"
        if [ "$AVAIL" -eq "1" ]; then
                echo "Trying to connect to that network"
                ifconfig wlan0 down
                sleep 1
                ifconfig wlan0 up
                iwconfig wlan0 essid "$NWN"
                service networking stop
                service networking start
                echo "Connection should be established"
        else
                echo "Nothing to do when $NWN unavailable"
        fi
fi

First of all: the script is really simple! It assumes that your WLAN device is connected on wlan0 and that /etc/network/interfaces is configured correctly e.g. using wpa_passphrase "YOUR-NETWORK-SSID" to generate the wpa-ssid and wpa-psk string. The script could be improved with no doubt but hey: it works and that is important.

To get this "daemon" working one needs a crontab entry which executes this script every once in a while:

$ crontab -e
*/1 * * * * sudo /home/pi/scripts/wland.sh >/dev/null 2>&1

Simply run it every minute and dump the output to the garbage bin. One certainly could remove all the echo statements in the script but for debugging I left them there and they don’t take up much performance.

The script basically operates according to this scheme:

And that’s it. It took me about 5 Minutes to write this script (okay, with testing and manpage research maybe 10 minutes) and it runs smoothly (until now). On the other side I messed over two hours with WICD. You can guess which method is my favorite …

Side note: WICD works without any problems on Raspbian “Jessie” after one did systemctl disable wpa_supplicant.