Forgive me for jumping in here as a total software n00b (hardware is my specialty), but I have absolutely no idea what I'm doing with how to properly set up the desired script as well as making it run on a regular interval (i.e. every 30 seconds? every minute? I'm unsure).
Thing is, while I know how to make a bash script (or, supposedly in the case of OpenWrt, an ash script?) and I know how to use a Linux terminal and subsequently how to SSH into an OpenWrt router, I just don't know and have extreme trouble remembering and just even mentally parsing terminal commands (which is also why I heavily rely on scripts for any terminal-related stuff on my PCs). So while I've read the entire thread, I'm kind of lost as to what to do with the actual scripts that have been offered.
โโโโโโโโโโโโโโโโโ
All I want to do is, on a regular interval, to ping for a local address on my network, e.g. 192.168.254.123 and, if it's present, to turn on the wifi. If pinging times out due to being unable to find the address, then turn off wifi.
Currently the only thing I really know how to do is manually turning on or off wifi by manually running the following command, whether in an SSH session or as a scheduled task in LuCI:
wifi off:
uci set wireless.radio0.disabled='1'; uci set wireless.radio1.disabled='1'; uci commit; wifi
wifi on:
uci set wireless.radio0.disabled='0'; uci set wireless.radio1.disabled='0'; uci commit; wifi
If desired, I can provide the world's lengthiest rambles on exactly how, what, and why with regards to what I'm trying to achieve, but I think everything I've stated above is enough to explain my goal without going on lengthy tangents and such?
EDIT: I just realized that my hypothetical idea for such a script would conflict with manually turning on the wifi, i.e. if 192.168.254.123 isn't present but I manually turn on the wifi, the automated script would just turn the wifi right back off in 30 seconds to a minute.
So I guess the proper solution would be something like, 30 seconds or one minute after 192.168.254.123 is no longer present, it'll run the "turn off wifi" command only once and do nothing more until 192.168.254.123 reconnects before resuming the script? And maybe, for consistency sake, it could make sense to also run the "turn on wifi" command only once whenever 192.168.254.123 connects, but I have no idea if this would simplify the script or not.
EDIT 2: So to summarize:
- if 192.168.254.123 is ping-able then, after 30 seconds, turn on the wifi once
- 30 seconds after 192.168.254.123 is no longer ping-able, turn off the wifi once
- rinse & repeat
And an alternative, possibly better variation of this idea would actually be the following, but I'd really like to see what a script would look like for both the above and below so that I may have better understanding on how to do this on my own:
- if 192.168.254.123 is ping-able then, after 30 seconds, turn on the wifi once
- 15 minutes after 192.168.1.210 (note the different IP address) is no longer ping-able, turn off the wifi once
- wait until 192.168.254.123 (the first IP address) is no longer ping-able before continuing the script
- rinse & repeat
Also there may be situations where I'm dealing with devices that don't have a static IP address, so I'm wondering if it's alternatively possible to use a MAC address or the device's hostname?