RUT240: Enable access point only when online

Is it possible to configure the RUT240 router to enable its wifi access point only when the router is actually connected to internet? (and disable the wifi access point when internet connection is down).
Thanks.

Hello,

This is possible, but you will need a script for that. There was a similar question on the old forum here with a script. You can use the solution provided there.

Kind Regards,

Thank you, I will try this.
To create the script in /etc/mwan3.user, I need to connect through ssh, right?

A return is missing in the script just after line 9. You will need to access the device via ssh or CLI.

:+1: thanks!

The script does not seem to work for me.

First, here is more details on my current setup:
Internet is provided through 3 different interfaces (with failover configured if the following order):

  1. a wan interface
  2. a wifi client interface (_hl_tracker)
  3. a 4g mobile interface

Then I have the default RUT240_58AA wifi access point.

So when internet is down on all the above 3 failover interfaces, I want to only stop this RUT240_58AA wifi access point (not all wifi interfaces as I need to keep the above _hl_tracker wifi client interface up and running).

So with my current setup, I’ll need to update the script slightly but anyway, I have some issue since ubus cannot find my RUT240_58AA wifi access point interface:

root@RUT240:~# ubus list network.interface.*
network.interface._hl_tracker
network.interface.lan
network.interface.loopback
network.interface.mob1s1a1
network.interface.mob1s1a1_4
network.interface.wan
network.interface.wan6

I think my RUT240_58AA wifi access point interface is named wlan0-1 as I can see it in the wifi status command below:

{
	"radio0": {
		"up": true,
		"pending": false,
		"autostart": true,
		"disabled": false,
		"retry_setup_failed": false,
		"config": {
			"channel": "auto",
			"hwmode": "11g",
			"path": "platform/ahb/18100000.wmac",
			"htmode": "HT20",
			"country": "US"
		},
		"interfaces": [
			{
				"section": "default_radio0",
				"ifname": "wlan0-1",
				"config": {
					"mode": "ap",
					"ssid": "RUT240_58AA",
					"wifi_id": "wifi0",
					"encryption": "psk2",
					"key": "XXXXXXXX",
					"skip_inactivity_poll": false,
					"hidden": false,
					"disassoc_low_ack": true,
					"short_preamble": true,
					"isolate": false,
					"network": [
						"lan"
					],
					"mode": "ap",
					"isolate": false
				},
				"vlans": [
					
				],
				"stations": [
					
				]
			},
			{
				"section": "@wifi-iface[1]",
				"ifname": "wlan0",
				"config": {
					"key": "XXXXXXXX",
					"ssid": "hl-tracker",
					"encryption": "psk",
					"mode": "sta",
					"bssid": "DC:EF:09:FF:D2:30",
					"skip_inactivity_poll": false,
					"disassoc_low_ack": false,
					"short_preamble": false,
					"wifi_id": "wifi1",
					"mode": "sta",
					"network": [
						"_hl_tracker"
					]
				},
				"vlans": [
					
				],
				"stations": [
					
				]
			}
		]
	}
}

But I’m not able to stop it through ubus:

root@RUT240:~# ubus call network.interface.wlan0-1 down
Command failed: Not found

I also tried to stop it with the wifi command, but again it does not work:

root@RUT240:~# wifi down wlan0-1
Command failed: Not found
wlan0-1(): Interface type not supported

Any idea?

Check the name of the available wifi interfces using the ifconfig command, are you sure they are effectively present ?

Yes I’m sure they are actually present, I can connect to the RUT240_58AA wifi access point.

I can see the wlan0-1 interface in my ifconfig output:

root@RUT240:~# ifconfig 
br-lan    Link encap:Ethernet  HWaddr 20:97:27:13:58:A8  
          inet addr:192.168.9.1  Bcast:192.168.9.255  Mask:255.255.255.0
          inet6 addr: fd1c:be3c:2fcd::1/60 Scope:Global
          inet6 addr: fe80::2297:27ff:fe13:58a8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:105159 errors:0 dropped:0 overruns:0 frame:0
          TX packets:115467 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:17639003 (16.8 MiB)  TX bytes:69525839 (66.3 MiB)

eth0      Link encap:Ethernet  HWaddr 20:97:27:13:58:A8  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:73590 errors:0 dropped:0 overruns:0 frame:0
          TX packets:100902 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13447100 (12.8 MiB)  TX bytes:63809762 (60.8 MiB)
          Interrupt:5 

eth1      Link encap:Ethernet  HWaddr 20:97:27:13:58:A9  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:4 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:317 errors:0 dropped:0 overruns:0 frame:0
          TX packets:317 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:35364 (34.5 KiB)  TX bytes:35364 (34.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 20:97:27:13:58:AA  
          inet addr:192.168.1.228  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2297:27ff:fe13:58aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:142082 errors:0 dropped:0 overruns:0 frame:0
          TX packets:63281 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:81350740 (77.5 MiB)  TX bytes:16870778 (16.0 MiB)

wlan0-1   Link encap:Ethernet  HWaddr 22:97:27:13:58:AA  
          inet6 addr: fe80::2097:27ff:fe13:58aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:32486 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38876 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5873907 (5.6 MiB)  TX bytes:8953635 (8.5 MiB)

wwan0     Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.14.38.13  P-t-P:10.14.38.13  Mask:255.255.255.255
          inet6 addr: fe80::d5be:ea49:a96f:114c/64 Scope:Link
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:1717 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1396 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:380168 (371.2 KiB)  TX bytes:447312 (436.8 KiB)

From the wifi status result it appears that there is no separate wlan0-1 interface because both wlan0 and wlan0-1 are on the same radio channel.
Manipulating wlan0 with the ubus commands should be possible however.
If you want to change wlan0-1 use ifconfig wlan0-1 down and ifconfig wlan0-1 up instead.

Thank you @flebourse, this is now working fine.

For the record, here is my /etc/mwan3.user script:

mobstatus=$(ubus call network.interface.mob1s1a1 status | jq .up)
wanstatus=$(ubus call network.interface.wan status | jq .up)
wlanstatus=$(ubus call network.interface._hl_tracker status | jq .up)

[ "$ACTION" == "ifdown" ] || [ "$ACTION" == "disconnected" ] && {
	[ "$INTERFACE" == "wan" ] || [ "$INTERFACE" == "wwan0" ] || [ "$INTERFACE" == "_hl_tracker" ] && {
		[ "$mobstatus" == "false" ] && [ "$wanstatus" == "false" ] && [ "$wlanstatus" == "false" ] && {
			# internet is down: shutdown wifi access point
			ifconfig wlan0-1 down
			return
		}
		# at least one is up restart wifi
		ifconfig wlan0-1 up
	}
}

[ "$ACTION" == "ifup" ] || [ "$ACTION" == "connected" ] && {
	[ "$INTERFACE" == "wan" ] || [ "$INTERFACE" == "wwan0" ] || [ "$INTERFACE" == "_hl_tracker" ] && {
		# one is up restart wifi
		ifconfig wlan0-1 up
	}
}

Glad it works for you.

This topic was automatically closed after 15 days. New replies are no longer allowed.