Skip to content

Instantly share code, notes, and snippets.

@cowgp
Last active September 7, 2018 10:57
Show Gist options
  • Select an option

  • Save cowgp/0f2fe5f38872d7a6cac4fe30ad379bbb to your computer and use it in GitHub Desktop.

Select an option

Save cowgp/0f2fe5f38872d7a6cac4fe30ad379bbb to your computer and use it in GitHub Desktop.
GL-MT300N-V2 Wifi Toggle (IOT Testing)

GL-MT300N-V2 Automated Wifi Toggle for IOT Testing

Script setup

  1. Connect to your GL-MT300N router's Wifi network
  2. go to 192.168.8.1 and perform initial setup including setting a password for admin/ssh access
  3. under internet setup, add a "repeater" wifi to make the GL-MT300N bridge to a functional wifi network.
  4. ssh into router and use password setup above.
ssh root@192.168.8.1
  1. Edit a new file at setup.sh (using vi or similar)
  2. Paste in the script
  3. Save!
  4. Give the script executable permissions:
chmod +x setup.sh
  1. Run the script
./setup.sh
  1. You will be asked how many minutes you want the on/off interval to set at. Enter 10 or your preferred value
  2. Slide switch on side away from and back to your preferred setting.

Switch modes

  1. Left :: standard access point, Wifi stays on if powered on. (Center LED is off)
  2. Right :: Wifi toggles on/off at designated interval (Center LED is on)
#!/bin/sh
#--------------------------------
#prime uci so any get commands don't error
#--------------------------------
uci set wireless.@wifi-device[0].cycle=0
uci set wireless.@wifi-device[0].cycledOff=0
#--------------------------------
#write out script for switch
#--------------------------------
/bin/cat <<"EOF" > /etc/rc.button/BTN_0
#!/bin/sh
case $(uci get wireless.@wifi-device[0].cycledOff) in
0)
logger wifi already on
;;
1)
wifi
logger turned wifi on
;;
esac
if [ "${ACTION}" = "released" ]; then
logger BTN_0 is left
uci set wireless.@wifi-device[0].cycle=0
uci set wireless.@wifi-device[0].cycledOff=0
echo 0 > /sys/class/leds/gl-mt300n-v2\:lan/brightness
elif [ "${ACTION}" = "pressed" ]; then
logger BTN_0 is right
uci set wireless.@wifi-device[0].cycle=1
uci set wireless.@wifi-device[0].cycledOff=0
echo 1 > /sys/class/leds/gl-mt300n-v2\:lan/brightness
else
logger condition check failed
fi
EOF
#--------------------------------
#write out script for cron toggle
#--------------------------------
/bin/cat <<"EOF" > /sbin/wifi_toggle
#!/bin/sh
logger cron triggered
case $(uci get wireless.@wifi-device[0].cycle) in
0)
logger cron triggered but cycle wifi is off
;;
1)
case $(uci get wireless.@wifi-device[0].cycledOff) in
0)
logger wifi is on, so turning it off
wifi down
uci set wireless.@wifi-device[0].cycledOff=1
;;
1)
logger wifi is off, so turning it on
wifi
uci set wireless.@wifi-device[0].cycledOff=0
;;
esac
;;
esac
EOF
#--------------------------------
#add execute permission
#--------------------------------
chmod +x /sbin/wifi_toggle
#--------------------------------
#setup cron
#--------------------------------
echo -e "How many minutes do you want to the wifi toggle to be?"
read minutes
echo "removing existing crons"
crontab -r
echo "*/$minutes * * * * /sbin/wifi_toggle" >> mycron
#install new cron file
crontab mycron
rm mycron
crontab -l
/etc/init.d/cron restart
echo "all done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment