Skip to content

Instantly share code, notes, and snippets.

@petedoyle
Last active June 21, 2018 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petedoyle/9c56be06dc662d569e39db9b8d2bdd5f to your computer and use it in GitHub Desktop.
Save petedoyle/9c56be06dc662d569e39db9b8d2bdd5f 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

Device setup (optional)

  1. Do whatever you'd normally do to set up a router- set the SSID, password, etc.

Script setup

  1. Plug in power to your device
  2. Connect your laptop or phone to the default SSID using the SSID/Password listed on the label on the back of the router.
  3. SSH to 192.168.8.1 as user root (default password is goodlife). For example, from Mac or Linux:
# ssh root@192.168.8.1
  1. Edit a new file at /sbin/wifi_toggle (using vi or similar)
  2. Paste in the script
  3. Save!
  4. Give the script executable permissions:
# chmod +x /sbin/wifi_toggle

Cron setup

  1. Click the advanced interface link in the upper right
  2. Sign in to the advanced interface as user root (default password: goodlife)
  3. Go to System > Scheduled Tasks
  4. Enter */3 * * * * /sbin/wifi_toggle and save
    Adjust this cron string to change the timing, e.g. */10 * * * * /sbin/wifi_toggle would toggle every 10 minutes.
  5. Go to System > Reboot to reboot the router
  6. Your device should reboot and start cycling wifi on/off!

Notes

  • This is based on the wifi toggle script here, but avoids manually changing the lights. The device seems to already be watching wifi state and the lights update automatically.
  • This should work on any OpenWRT/LEDE compatible router, but you may need to change the device variable in the wifi_toggle script. Here's an example of how to find it on the GL-MT300N-V2 (its wireless device name is mt7628).
# uci show | grep wifi-device
wireless.mt7628=wifi-device

Note: your device may have more than one wireless device.

  • For other devices, you may or may not need to manually update the wifi lights as shown here. The GL-MT300N-V2 doesn't seem to need it.
#!/bin/sh -x
device="mt7628"
case $(uci get wireless.$device.disabled) in
0)
wifi down $device
uci set wireless.$device.disabled=1
echo "Wifi disabled"
;;
1)
uci set wireless.$device.disabled=0
wifi up $device
echo "Wifi enabled"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment