WLAN receiving DHCP-IP Address doesn't work

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

If its not working in cron, that is because your interactive session has environment variables set cron doesnt... fix that and it will run in cron...

1 Like

Hey VBE thanks for your quick answer.
That might be a good hint...but, I don't see any. Do you think the Path for all the commands (dhclient, ifconfig, iwconfig, ...) I run has to be set?
I didn't see any errors in the message or syslog log.

Usually it only knows /usr/bin:/bin ... ( for the PATH that is...)
So setting the PATH so it finds all your commands might be enough...
You dont have any other VAR in your .profile or so that could be used by any of your commands?

Ok thanks a lot.
I need to check that in detail at home. I might just replace every command (not those in /sbin/) with the full path to see if that helps..