Controling WiFi from another router

Hi,

I have 2 LEDE routers. One is used for wan failover, other as AP.
I'm trying to switch off WiFi on AP when WAN1 is offline on other router and to turn on WiFi when WAN1 is online.
Can somebody help me with my "project"?

Thanks!

As a sketch to start:

The "disabled" option for a wireless radio can turn it (and all its SSIDs) on and off. It can be set with UCI commands. The wireless system can then be reloaded to make the change "effective". See, for example, /etc/rc.button/rfkill

You'll also need a way to know the other router is "up and active". ping might be sufficient, but not very robust to detecting if the other device is "really up" or "just booting or crashed". ping (or netcat, socat, ... ) could also be "push" where the router sends out pings to the other router when it's up and ready, with the other router "listening" for them.

More sophisticated approaches abound, including a non-privileged, keyed ssh access to the other router, non-privileged RPC calls, or MQTT and perhaps utilizing the "last will and testament" feature.

1 Like

Step 1: Login to router1 (the one with the internet access) via SSH. Once there, run: ssh root:password@router2. Where password is the root password for router2 and router2 is the second router's IP/name. Make sure to agree to continue and save the fingerprint when prompted. Ideally you should configure key-based authentication for ssh rather than the password-based..

Step 2: On the router with the internet access (router1), create a new file: /etc/hotplug.d/iface/90-remote-wifi-kill

#!/bin/sh
[ "$INTERFACE" == "wan" ] || exit 0

if [ "$ACTION" == "ifup" -o "$ACTION" == "ifupdate" ]; then
	logger -t remote-wifi-kill "Enabling remote wifi due to $ACTION of $INTERFACE ($DEVICE)"
	ssh root:password@router2 "{ uci -q del wireless.radio0.disabled; uci -q del wireless.radio1.disabled; uci commit wireless; /sbin/wifi; }"
else
	logger -t remote-wifi-kill "Disabling remote wifi due to $ACTION of $INTERFACE ($DEVICE)"
	ssh root:password@router2 "{ uci -q set wireless.radio0.disabled=1; uci -q set wireless.radio1.disabled=1; uci commit wireless; /sbin/wifi; }"
fi
1 Like

@stangri Thank you!

I have learned about key-based authentication and have it configured.
Everything works like charm.

1 Like