Hello members, I also would like to propose a change tot he wifi.sh script.
Problem: On my raspberry Pi, the IP address lease is not always obtained fast enough. After a several tries, the wifi.sh script gives up. This is probably caused by not enough performance on the Pi, or my network and/or routers is busy/slow.
Proposal: The wifi.sh script uses the -n option for the udhcpc command. I would like to introduce a option for the wifi.sh script which causes it to use the udhscpc command without the -n option. This will force the udhcpc command to indefinitely try to obtain a lease.
This might be strange and unwanted for some applications, but my Raspberry Pi is used headless with only a WiFi connection. Without the wifi connection the Raspberry is useless anyway, so "keep trying" is better then "stop trying".
I've made some changes to the script, I've introduced a -w option. The "w" stands for wait, as in "wait until lease is obtained".
This is the first version, and I've allready some tests on it. It seems to be working but I want to do more testing.
Tell me your opinion on this change, please:
--- /tmp/tcloop/wifi/usr/local/bin/wifi.sh
+++ wifi_new.sh
@@ -11,6 +11,7 @@
echo " Default select AP from menu and request IP via DHCP."
echo " -a Auto connect to first wifi.db entry via DHCP."
echo " -p Select AP from menu and prompt for IP configuration type."
+ echo " -w Wait indefinitely until lease is obtained"
echo " -? Displays this help message."
exit 0
}
@@ -25,15 +26,17 @@
DB=/home/"$TCUSER"/wifi.db
PTMP=/tmp/wpa.$$
-while getopts ap? OPTION
+while getopts apw? OPTION
do
case ${OPTION} in
a) MODE=auto ;;
p) MODE=prompt ;;
+ w) OBTAINLEASE=wait ;;
*) help ;;
esac
done
[ -n "$MODE" ] || MODE=menu
+[ -n "$OBTAINLEASE" ] || OBTAINLEASE=try
unset WIFI && CNT=0
until [ -n "$WIFI" ]
@@ -72,7 +75,7 @@
iwlist "$WIFI" scanning
[ "$?" == 0 ] && break
sleep 1
-done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v ptmp="$PTMP" '
+done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v obtainlease="$OBTAINLEASE" -v ptmp="$PTMP" '
BEGIN {
RS="\n"
FS=":"
@@ -186,13 +189,20 @@
if ($2 ~ /WPA/ ) type[i]="WPA"
}
END {
+ if ( obtainlease == "try" ) {
+ lease = "-n "
+ print("Set to try a few times to obtain a lease." )
+ } else if ( obtainlease == "wait" ) {
+ lease = ""
+ print("Set to try indefinitely until lease is obtained." )
+ }
if ( mode == "auto" ) {
print("Attempting auto connection with " autoconnect)
for (i in sid) {
gsub(" ","\\ ",sid[i])
if (autoconnect == sid[i] ) {
associate(type[i],wifi,sid[i],mypass,chan[i])
- system( "udhcpc -n -i " wifi " 2>/dev/null" )
+ system( "udhcpc " lease "-i " wifi " 2>/dev/null" )
exit
}
}
@@ -274,14 +284,14 @@
setipaddresses(wifi)
}
else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease "-i " wifi " 2>/dev/null")
if ( results == 0 )
if ( newitem == 1 )
printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
}
}
else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease " -i " wifi " 2>/dev/null")
if ( results == 0 )
if ( newitem == 1 )
printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile