|  | @@ -47,6 +47,7 @@ WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
 | 
	
		
			
			| 47 | 47 |  NETWORKS_INTERACTIVE=
 | 
	
		
			
			| 48 | 48 |  WIFI_DISABLE=
 | 
	
		
			
			| 49 | 49 |  WAIT_SEC=
 | 
	
		
			
			|  | 50 | +WIFI_MAX_RETRIES=5
 | 
	
		
			
			| 50 | 51 |  
 | 
	
		
			
			| 51 | 52 |  IFACE=
 | 
	
		
			
			| 52 | 53 |  IFACE_SECONDARY=
 | 
	
	
		
			
			|  | @@ -69,6 +70,7 @@ function show_help {
 | 
	
		
			
			| 69 | 70 |      echo $'     --networks [filename]         File containing wifi networks'
 | 
	
		
			
			| 70 | 71 |      echo $'     --createnetworks [filename]   Create file containing wifi networks'
 | 
	
		
			
			| 71 | 72 |      echo $'     --disable [yes/no]            Disable wifi'
 | 
	
		
			
			|  | 73 | +    echo $'     --retries [number]            Maximum number of retries'
 | 
	
		
			
			| 72 | 74 |      echo ''
 | 
	
		
			
			| 73 | 75 |      exit 0
 | 
	
		
			
			| 74 | 76 |  }
 | 
	
	
		
			
			|  | @@ -99,6 +101,10 @@ do
 | 
	
		
			
			| 99 | 101 |              shift
 | 
	
		
			
			| 100 | 102 |              WIFI_SSID=${1}
 | 
	
		
			
			| 101 | 103 |              ;;
 | 
	
		
			
			|  | 104 | +        --retries)
 | 
	
		
			
			|  | 105 | +            shift
 | 
	
		
			
			|  | 106 | +            WIFI_MAX_RETRIES=${1}
 | 
	
		
			
			|  | 107 | +            ;;
 | 
	
		
			
			| 102 | 108 |          -p|--pass|--passphrase)
 | 
	
		
			
			| 103 | 109 |              shift
 | 
	
		
			
			| 104 | 110 |              WIFI_PASSPHRASE=${1}
 | 
	
	
		
			
			|  | @@ -160,9 +166,34 @@ if [ ${WIFI_DISABLE} ]; then
 | 
	
		
			
			| 160 | 166 |  fi
 | 
	
		
			
			| 161 | 167 |  
 | 
	
		
			
			| 162 | 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 | 197 |  fi
 | 
	
		
			
			| 167 | 198 |  
 | 
	
		
			
			| 168 | 199 |  if [ ! ${WIFI_SSID} ]; then
 |