Adding bash script to connect a wlan interface to a wifi network
usage : ./setupKit.sh wlan1 reach my_secret_wpa_key first parameter is the wifi interface second is the SSID prefix, I use reach for "reachxx:xx" last is the WPA KEY to connect to network
This commit is contained in:
parent
4489f22ac0
commit
2421071da6
|
@ -0,0 +1,73 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Try to setup Kit !
|
||||||
|
#
|
||||||
|
|
||||||
|
function scanWifi() {
|
||||||
|
local iface=${1}
|
||||||
|
iwinfo ${iface} scan
|
||||||
|
return ${?}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWifiCell()
|
||||||
|
{
|
||||||
|
local iface=${1}
|
||||||
|
local ssidPrefix=${2}
|
||||||
|
res=$(scanWifi ${iface} | grep -B 1 "ESSID: \"${ssidPrefix}")
|
||||||
|
if [[ "${res}" == "Scanning not possible" ]] || [[ "${res}" == "" ]]
|
||||||
|
then
|
||||||
|
for try in $(seq 0 10)
|
||||||
|
do
|
||||||
|
sleep 5
|
||||||
|
res=$(scanWifi ${iface} | grep -B 1 "ESSID: \"${ssidPrefix}")
|
||||||
|
if [[ "${res}" == "Scanning not possible" ]] || [[ "${res}" == "" ]]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
echo ${res}
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "Error scanning wifi networks !"
|
||||||
|
return 2
|
||||||
|
else
|
||||||
|
echo ${res}
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectWifi() {
|
||||||
|
local iface=${1}
|
||||||
|
local ssidPrefix=${2}
|
||||||
|
local wpa=${3}
|
||||||
|
|
||||||
|
local cell=$(getWifiCell ${iface} ${ssidPrefix})
|
||||||
|
if [[ $? -ne 0 ]]
|
||||||
|
then
|
||||||
|
echo "Error on wifi scan !"
|
||||||
|
exit 12
|
||||||
|
fi
|
||||||
|
local ssid=$(echo ${cell} | awk '{print $7}' | sed -e 's/"//g')
|
||||||
|
local cellMAC=$(echo ${cell} | awk '{print $5}' | sed -e 's/"//g"')
|
||||||
|
|
||||||
|
set -x
|
||||||
|
uci delete wireless.@wifi-iface[1]
|
||||||
|
uci add wireless wifi-iface
|
||||||
|
uci set wireless.@wifi-iface[1].network="EmlidReach"
|
||||||
|
uci set wireless.@wifi-iface[1].ssid="${ssid}"
|
||||||
|
uci set wireless.@wifi-iface[1].encryption="psk2"
|
||||||
|
uci set wireless.@wifi-iface[1].device="radio1"
|
||||||
|
uci set wireless.@wifi-iface[1].mode="sta"
|
||||||
|
uci set wireless.@wifi-iface[1].bssid="${cellMAC}"
|
||||||
|
uci set wireless.@wifi-iface[1].key="${wpa}"
|
||||||
|
uci commit
|
||||||
|
reload_config
|
||||||
|
sleep 20
|
||||||
|
set +x
|
||||||
|
udhcpc -i ${iface}
|
||||||
|
}
|
||||||
|
|
||||||
|
# interface SSID_PREFIX Network_KEY
|
||||||
|
connectWifi "$1" "$2" "$3"
|
||||||
|
|
|
@ -4,7 +4,7 @@ function scanWifi()
|
||||||
{
|
{
|
||||||
local ifcace=$1
|
local ifcace=$1
|
||||||
iwconfig ${iface} scan
|
iwconfig ${iface} scan
|
||||||
}
|
|
||||||
|
|
||||||
function connectBoard()
|
function connectBoard()
|
||||||
{
|
{
|
||||||
|
|
Reference in New Issue