Skip to content

Commit b3b4d90

Browse files
committed
network - shmetwork
1 parent f019591 commit b3b4d90

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

scripts/hotspot.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CreateWifiClient()
5151
sleep 20 #give time for connection to be completed to router
5252
}
5353

54-
IsWifiConnected()
54+
IsWifiDisconnected()
5555
{
5656
wpa_cli -i ${WLAN_INTERFACE} status | grep 'ip_address' >/dev/null 2>&1
5757
return $?
@@ -67,29 +67,29 @@ SSID_REPLY=`iw dev "$wifidev" scan ap-force | egrep "^BSS|SSID:"`
6767
for SSID in ${SSID_LIST}
6868
do
6969
SSID_CLEAN=$(echo ${SSID} | tr -d '\r')
70-
if [[ -z `echo ${SSID_REPLY} | grep ${SSID_CLEAN}` ]]
70+
echo ${SSID_REPLY} | grep ${SSID_CLEAN} > /dev/null 2>&1
71+
if [[ $? ]]
7172
then
72-
return 1
73+
return 0
7374
fi
7475
done
75-
return 0
76+
return 1
7677
}
7778

7879
WLAN_INTERFACE=wlan0
7980
iw dev ${WLAN_INTERFACE} set power_save off
8081
ACTIVE_MODE=
81-
8282
while true;
8383
do
84-
if [[ ${ACTIVE_MODE} -eq "ap" ]]; then
84+
if [[ ${ACTIVE_MODE} == "ap" ]]; then
8585
echo "Running in access point mode, next check in 300 seconds"
8686
sleep 300
8787
if [[ areKnownNetworksNearBy ]]; then
8888
systemctl stop omnipy.service
8989
KillHotSpot
9090
echo "Hotspot Deactivated, Bringing Wifi Up"
9191
CreateWifiClient
92-
if [[ ! IsWifiConnected ]]; then
92+
if [[ IsWifiDisconnected ]]; then
9393
echo "Failed to connect to wifi, going back into hotspot mode"
9494
CreateHotSpot
9595
ACTIVE_MODE="ap"
@@ -98,14 +98,14 @@ do
9898
fi
9999
systemctl start omnipy.service
100100
fi
101-
elif [[ ${ACTIVE_MODE} -eq "client" ]]; then
101+
elif [[ ${ACTIVE_MODE} == "client" ]]; then
102102
echo "Running in wi-fi client mode, next check in 60 seconds"
103103
sleep 60
104-
if [[ ! IsWifiConnected ]]; then
104+
if [[ IsWifiDisconnected ]]; then
105105
systemctl stop omnipy.service
106106
echo "Wi-fi disconnected, retrying"
107107
CreateWifiClient
108-
if [[ ! IsWifiConnected ]]; then
108+
if [[ IsWifiDisconnected ]]; then
109109
echo "No wi-fi connection, creating hot-spot"
110110
CreateHotSpot
111111
ACTIVE_MODE="ap"
@@ -116,15 +116,16 @@ do
116116
fi
117117
else
118118
echo "Checking current network state"
119-
if [[ ! IsWifiConnected ]]; then
119+
if [[ IsWifiDisconnected ]]; then
120120
echo "Wi-fi not connected, scanning"
121121
if [[ areKnownNetworksNearBy ]]; then
122122
echo "Found known networks, will try to connect"
123+
KillHotSpot
123124
CreateWifiClient
124125
fi
125126
fi
126127

127-
if [[ ! IsWifiConnected ]]; then
128+
if [[ IsWifiDisconnected ]]; then
128129
echo "No wi-fi connection, creating hotspot"
129130
CreateHotSpot
130131
ACTIVE_MODE="ap"

0 commit comments

Comments
 (0)