Browse Source

wifi retries

Bob Mottram 8 years ago
parent
commit
cbabae84b2
1 changed files with 34 additions and 3 deletions
  1. 34
    3
      src/freedombone-wifi

+ 34
- 3
src/freedombone-wifi View File

47
 NETWORKS_INTERACTIVE=
47
 NETWORKS_INTERACTIVE=
48
 WIFI_DISABLE=
48
 WIFI_DISABLE=
49
 WAIT_SEC=
49
 WAIT_SEC=
50
+WIFI_MAX_RETRIES=5
50
 
51
 
51
 IFACE=
52
 IFACE=
52
 IFACE_SECONDARY=
53
 IFACE_SECONDARY=
69
     echo $'     --networks [filename]         File containing wifi networks'
70
     echo $'     --networks [filename]         File containing wifi networks'
70
     echo $'     --createnetworks [filename]   Create file containing wifi networks'
71
     echo $'     --createnetworks [filename]   Create file containing wifi networks'
71
     echo $'     --disable [yes/no]            Disable wifi'
72
     echo $'     --disable [yes/no]            Disable wifi'
73
+    echo $'     --retries [number]            Maximum number of retries'
72
     echo ''
74
     echo ''
73
     exit 0
75
     exit 0
74
 }
76
 }
99
             shift
101
             shift
100
             WIFI_SSID=${1}
102
             WIFI_SSID=${1}
101
             ;;
103
             ;;
104
+        --retries)
105
+            shift
106
+            WIFI_MAX_RETRIES=${1}
107
+            ;;
102
         -p|--pass|--passphrase)
108
         -p|--pass|--passphrase)
103
             shift
109
             shift
104
             WIFI_PASSPHRASE=${1}
110
             WIFI_PASSPHRASE=${1}
160
 fi
166
 fi
161
 
167
 
162
 if [ -f ${WIFI_NETWORKS_FILE} ]; then
168
 if [ -f ${WIFI_NETWORKS_FILE} ]; then
163
-    networks_from_file
164
-    wpa_cli status
165
-    exit 0
169
+    wifi_established=
170
+    wifi_retry_ctr=0
171
+    while [ ! $wifi_established ]; do
172
+        if [ ${wifi_retry_ctr} -gt 0 ]; then
173
+            wpa_action ${WIFI_INTERFACE} stop
174
+            wpa_cli -i ${WIFI_INTERFACE} terminate
175
+        fi
176
+        networks_from_file
177
+        # allow some time for a connection to be established
178
+        sleep 5
179
+        # has it worked?
180
+        if [[ $(wifi_is_running) != "0" ]]; then
181
+            wifi_established=1
182
+            break
183
+        fi
184
+        # has the limit of retries been reached?
185
+        wifi_retry_ctr=$((wifi_retry_ctr+1))
186
+        if [ ${wifi_retry_ctr} -ge ${WIFI_MAX_RETRIES} ]; then
187
+            break
188
+        fi
189
+    done
190
+    if [ $wifi_established ]; then
191
+        wpa_cli status
192
+        exit 0
193
+    else
194
+        echo $'Wifi could not be started'
195
+        exit 4
196
+    fi
166
 fi
197
 fi
167
 
198
 
168
 if [ ! ${WIFI_SSID} ]; then
199
 if [ ! ${WIFI_SSID} ]; then