Hey guys,
I run my raspberry pi with a TP-Link Wlan-USB stick. The stick works out of the box with the pi-modded debian.
But eventhough the automatic connection to one of the saved WLAN-networks in the file /etc/wpa_supplicant/wpa_supplicant.conf works, my PI doesn't request or receive an IP-address (automatically).
I always have to login via ethernet and do a
sudo dhclient wlan0
manually.
Why?
I thought "well, whatever, no problem, I write a cronjob which runs this command every couple of minutes". But this doesn't solve the issue neither...
Please let me know what could be a better solution.
My script (not working when run as cronjob but manually it does):
#!/bin/bash
if [ `lsusb|grep WLAN|wc -l` -gt 0 ];
then
if [ `iwconfig wlan0|head -n 1|tr -s " "|cut -d" " -f2` = "unassociated" ];
then
wpa_action wlan0 stop
wpa_action wlan0 reload
ifup wlan0
#wpa_supplicant -i wlan0 -D wext -c /etc/wpa_supplicant/wpa_supplicant.conf -B
#dhclient wlan0
else
if [ `iwconfig wlan0|head -n 1|tr -s " "|cut -d" " -f2` = "IEEE" ];
then
if [ `ifconfig wlan0|grep "inet addr"|tr -s " "|tr " " ":"|cut -d: -f 4|wc -m` = 0 ];
then
dhclient wlan0
for I in 1-4; do
ping -c 1 google.com >/dev/null
done
if [ ! `ifconfig wlan0|grep "inet addr"|tr -s " "|tr " " ":"|cut -d: -f 4|wc -m` -gt 10 ] && [ ! `ifconfig wlan0|grep "inet addr"|tr -s " "|tr " " ":"|cut -d: -f 4|wc -m` -lt 16 ];
then
ifdown wlan0
fi
else
echo "`date`: WLAN0 - online `ifconfig wlan0|grep "inet addr"|tr -s " "|tr " " ":"|cut -d: -f 4`"
fi
fi
fi
fi