Raspberry Pi4 | Wi-Fi for management | How to

I have OpenWrt running on a Raspberry Pi 4.

I initially experienced a few issues with VLANs and ended up having to nuke the device and perform a fresh install. Everything is now working and I've backed up my settings.

I have configured a 5GHz Wi-Fi access point as a fail safe to ensure I can always gain access to the device. I'd rather not leave this running all the time because the RP4 is sat next to my wireless access point and might cause interference/degradation of my main Wi-Fi.

Is it possible to have the Wi-Fi come on for say 30 minutes when the device first boots and then automatically turn off? That would allow me enough time to boot the device, log in via Wi-Fi and make the necessary changes to get the device back online.

You can do this in /etc/rc.local... just something like

wifi on
sleep $((30*60))
wifi off

You might need to put those commands in their own script file and then run that script in the background... I'm not sure what happens if rc.local itself runs for 30 mins

1 Like

To use it as a single line in rc.local you must use && to separate each command, lîke this :

wifi on && sleep $((30*60)) && wifi off

But as you said’ an external script may be more accurate, and will not lock the other command, if there is, placed in rc.local

nothing wrong with wifi temp-on-boot... but consider learning / experimenting a little with how vlans work...

i'm always forgetting what ip i've assigned to stuff (managed switch) and I don't really want it to be globally accessible...

one way to handle this and provide a little 'stupid-proofing'

  1. /etc/config/network
config interface 'mng'
	option ifname 'eth0.90'
	option proto 'static'
	option ipaddr ''
	option netmask ''
  1. Set switch port that rpi-lan connects to... to accept (!ALSO! not 'JUST") (tagged VLAN90)... give the switch an ip in this management range ( i.e. )

  2. Set additional optional switch ports (not wan if possible) to also tag (or not tag = management port) VLAN90

you could then tag or not tag VLAN90 on certain switch interfaces you want management access... or route straight through ( or firewall block ) when the router is functioning correctly...

The problem was that the Raspberry Pi wasn't routing between VLANs and I wasn't able to access the router. That's now sorted, but it was a real pain getting locked out and, due to the single interface, it wasn't possible to get back in again.

with the above config... you can assign VLAN90 tagging to your laptop (and a static ip because we have not setup dhcp on the management vlan) ( or plug it into a 90-untagged~access/management port ) and still have access in most cases...

Thanks. I'll take a look at that as well.

With regards to configuring this, would the commands be:

vi /etc/config/rc.local
wifi on && sleep $((30*60)) && wifi off

With regards to configuring this, would the commands be:

vi /etc/config/rc.local
wifi on && sleep $((30*60)) && wifi off

FYI, the && separator is for waiting for successful command.
It’will only execute next command if the command before is ended with success.

these are parts of how i'm doing it... may be of use (although had to strip some stuff out so... you may need to make some effort to have it work properly)


ecmd="echo ${i} "

writewatcher() {
cat <<'EOF' > /bin/wifiwatcher.sh
ecmd="echo ${i} "

radio="$1"; WDURATION="$2"; SNAME="wifiwatcher.sh"

if [ "$(uci -q get wireless.default_$radio.disabled)" -eq 1 ] || [ "$(uci -q get wireless.$radio.disabled)" -eq 1 ]; then
	$ecmd "state is disabled"
	$ecmd "state is not disabled [exit]"; exit 0

if [ -f "/tmp/.wifiadminwatch.sh.on" ]; then
	echo "Already running: /tmp/.wifiadminwatch.sh.on" >> $LOGFILE
	$ecmd "Already running: /tmp/.wifiadminwatch.sh.on"
	exit 0
fi; touch /tmp/.wifiadminwatch.sh.on

echo "$radio enable" >> $LOGFILE

uci -q set wireless.$radio.disabled='0'
uci -q set wireless.default_$radio.disabled='0'

wifi down; sleep 2
/etc/init.d/wpad restart; sleep 2
wifi up; sleep 2

$ecmd "AdminWifiBoot [on:$WDURATION]"

while [ "${WDURATION}" -gt 0 ]; do

	if [ "$WDURATION" -eq 30 ]; then
	iw dev wlan0 station dump | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
		$ecmd "[30seconds-remain]"
	if [ "$WDURATION" -eq 60 ]; then
	iw dev wlan0 station dump | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
		$ecmd "[1minutes-remain]"
	if [ "$WDURATION" -eq 120 ]; then
	iw dev wlan0 station dump | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
		$ecmd "[2minutes-remain]"
	sleep 1; WDURATION=$((${WDURATION} - 1))
	echo $WDURATION > /tmp/.wifiadminwatch.sh.on
done; $ecmd "AdminWifiBoot [off]" #logger -t $SNAME "time-up"
rm /tmp/.wifiadminwatch.sh.on

#stop wireless here

chmod +x /bin/wifiwatcher.sh


getradioinfo() {
	if uci -q get wireless."$radio" 1>/dev/null; then
		$ecmd "######################## Checking radio: $radio"
		ssid="$(uci -q get wireless.default_${radio}.ssid)"
		key="$(uci -q get wireless.default_${radio}.key)"
		encryption="$(uci -q get wireless.default_${radio}.encryption)"
		channel=$(uci -q get wireless."$radio".channel)
		htmode=$(uci -q get wireless."$radio".htmode)
		hwmode=$(uci -q get wireless."$radio".hwmode)
		disabled=$(uci -q get wireless."$radio".disabled)
		country=$(uci -q get wireless."$radio".country)
		wifiisdisabled=$(uci -q set wireless.radio0.disabled)
		$ecmd "Checking radio: $radio [not-found]" && return 1
	return 0

for thisradio in ${allradios}; do
	if getradioinfo "$thisradio"; then
		if [ ! -z "$wifiisdisabled" ] && [ "$wifiisdisabled" -ne 1 ]; then
			$ecmd "$radio is already enabled"; continue
		elif [ "$ssid" = "OpenWrt" ]; then
			$ecmd "$radio defaultssid: $ssid [x]"

	if [ ! -z "$toggleradio" ]; then
		sh /bin/wifiwatcher.sh "$radio" "${WIFIADMINBOOTTIME:-230}" &
		$ecmd "$radio not suitable defaultssid|nopw|alreadyon"

exit 0

It might be wifi up and wifi down rather than on and off... I suggest to read the wiki or try it out manually.

Unfortunately, that didn't work.

The file 'vi /etc/config/rc.local' was completely blank before I entered the code. Am I looking at the right file? Should there be other config already in there?

I believe the path is /etc/rc.local

Thanks for providing the file path, but it still isn't working. I tested with a 1 minute delay, but the interface isn't being disabled.

#the system init finished. By default this file does nothing.
wifi on && sleep $((1*60)) && wifi off
exit 0

Usage: /sbin/wifi [config|up|down|reload|status]

The correct commands are up and down .

1 Like

Thanks for replying. Would the correct command be this?

#the system init finished. By default this file does nothing.
wifi up && sleep $((1*60)) && wifi down
exit 0

Yes, it's correct.

Perfect. I've just tested it and it shutdown the Wi-Fi after a minute.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.