Hello everybody,
I've got a proposal for a change to the wifi.tcz.
Problem:
I've encountered some problems with some WiFi adapters. Running wifi.sh produced only a partial access point list, and/or wouldn't automatically connect.
I traced the problem down to the adapter not being entirely ready scanning, but it does return an empty or partial list.
The problem is that in the wifi.sh script the "iwlist "$WIFI" scanning" command is executed too soon after "ifconfig "$WIFI" up".
At the moment of scanning, the network might be up, but the wifi adapter is not entirely started up yet. This results in a partial AP list. The adapter needs a little more time to complete the scan for AP points.
The automatic connect fails because of this reason too. Most of the times, it can not find the set accespoint name in the partial AP list.
Solution:
The "solution" is to wait a little before before executing the iwlist command. This solved the problem for some adapters, but not for all.
Apparently some adapters automatically start scanning after the "ifconfig "$WIFI" up" command, to prepare for the iwlist command.
But other adapters don't do this, and start the first scan when the "iwlist "$WIFI" scanning" is executed.
So, the solution is twofold:
- add a dummy iwlist scanning command right after ifconfig up, for starting the first scan.
- move the "sleep 1" from line 85 to line 83. Now it will sleep 1 second before each iwlist scanning try. This will give the WiFi adapter some time for scanning.
The drawback is that connecting to a wifi network takes one second longer, the benefit is that it makes the wifi connection much more reliable.
I've tested it on several WiFi adapters on piCore 6.0rc1, and piCore 6.0. Also user sbp tested this solution (only the sleep mod) on piCore 6.1alpha2.
And it seems to work great.
The difference report:
--- /tmp/tcloop/wifi/usr/local/bin/wifi.sh
+++ /home/tc/wifi.sh
@@ -78,11 +78,15 @@
echo "Standby for scan of available networks..."
ifconfig "$WIFI" up 2>/dev/null
+# do a dummy ap scan to start up the wifi adapter
+iwlist "$WIFI" scanning >/dev/null
(for i in `seq 5`
do
+ # sleep 1 sec to give the wifi adapter some time to complete scanning
+ sleep 1
+ # do actual scan
iwlist "$WIFI" scanning
[ "$?" == 0 ] && break
- sleep 1
done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v obtainlease="$OBTAINLEASE" -v currenthostname=$CURRENTHOSTNAME -v ptmp="$PTMP" '
BEGIN {
RS="\n"
Greetings,
Gerrelt.