Wednesday, November 11, 2015

Automatic Wifi Connection on Openwrt (MR3020)


1. Set MR3020 as Client and Master AP from luci menu,
     - As client of  APMaster1 and as APMaster -- save configuration with nama apmaster1, put in /etc/config folder.. and so on.

2. Create file /etc/init.d/wireless_auto

#!/bin/sh
#As client APMaster1
iwinfo wlan0 scan | grep "APMaster1" &> /dev/null
if [ $? == 0 ]; then
cp /etc/config/apmaster1 /etc/config/wireless
wifibssid=$(iwinfo wlan0 scan|grep "APMaster1" -B 1|head -n 1|awk '{print $NF'})
uci set wireless.@wifi-iface[0].bssid="$wifibssid"
uci commit wireless
        /etc/init.d/network reload ;

#As client APMaster2
elif [ $? == 1 ]; then
iwinfo wlan0 scan | grep "APMaster2" &> /dev/null
if [ $? == 0 ]; then
cp /etc/config/apmaster2/etc/config/wireless
wifibssid=$(iwinfo wlan0 scan|grep "APMaster2" -B 1|head -n 1|awk '{print $NF'})
        uci set wireless.@wifi-iface[0].bssid="$wifibssid"
        uci commit wireless
        /etc/init.d/network reload ;
#As APMaster
elif [ $? == 1 ]; then
cp /etc/config/APMaster /etc/config/wireless
fi
fi



2. Reboot.


No comments: