Power off / shutdown

Hello dear developers,

Not to suggest you don't have something better to do, but I was wondering whether it's possible to have a 'feature' 'button' in Luci, wherein a user can simply hit 'Shutdown' and bang! just like that they're disconnected from the Internet because power to the router is cut from that action. I think this would be a great feature. For example, someone could easily log into Luci, shutdown the router and go to sleep. Or, now this is to get real nerdy, have the shutdown set to certain times, say, the user is can set that time daily, and then that time comes, the router shuts off automagically. Of course, one can then turn it on again, as one wishes. And if that's possible then it may also be possible to set a time for the router to automagically turns itself on at set times by the user.

Well, thanks for reading at any rate.

which router can cut power via software?

@jaromanda the question can be asked in the reverse; which software can cut power to a router. And I assumed Openwrt can. For example, there's a firmware used for old D-link boxes, such as the DNS-323. The software/firmware is called Alt-FAlt-F. It has s feature to shutdown these little NAS boxes.

No it can't ... software can't turn off power without some supporting hardware

In other words, the hardware needs to support "soft" power off - routers in general, are powered 24/7, so would never need such a feature

Of course, you can shutdown - but the power remains on

3 Likes

The original firmware in ER4 has shutdown capability.

But to turn on you need to reset power.

1 Like

But this question has been raised before in the forum. What these functions usually do is to run the program in a empty continuous loop so it is safe to pull power without damaging memory chip.

Most embedded devices can be shut down like that (you can just connect with ssh and send a "poweroff" command and they will turn off).
How "off" they turn, depends from the device though, some go in a low-power state and some actually turn off completely, they all lock up and stop responding.

The issue is that they have no button to turn on again. No the "reset" button or the "wifi" or any other button they have is a digital signal on a GPIO pin, it does nothing if the main CPU is in power off mode. You have to disconnect power and connect power again to turn them on.

The only devices where this works is on PC hardware and some rare devices (some NAS) where the power button is connected to physical hardware that can power on the board if it is in power off mode.

I personally think people that turn off and on their network appliances when going to sleep have nothing better to do with their time.

Most embedded devices lack an internal clock or battery so yes they know the time when they are on and can sync from a network server from the Internet, but when they are turned off they lose any idea of the passage of time.

So this is simply not possible in most devices.

Again if we are talking of PC hardware, they all have an internal clock and a coin cell battery to keep it on when the device is powered off, and also decent BIOS offer the ability to set power on timers, to wake up the system at specified hours or days of the week.

a software that can talk to dedicated hardware on the device, independent from the main CPU.
In the case of that NAS, (and of the Zyxel NAS like nsa 310 and nsa325, btw) there is a microcontroller, called generically MCU (micro controller unit) that is always on (obviously), is listening to commands from the CPU, can physically cut power to the main CPU, while also listening to power button so it can turn power on if you press it. On NAS devices it's relatively common to have at least a working power button like that so there is a microcontroller handle that. On most routers there is no such thing.
On PC hardware there are tons of things that exist and run independent of main CPU, and one of them is listening on power button. So a PC that is "turned off" still burns a few watts of power just for these auxiliary components.

On some NAS like the Zyxel I think you can also get it to work with Wake On Lan (aka the MCU is also connected to ethernet controller and will react to its signal when you send a "magic packet" to it), but it all depends on how the specific device was designed.

for example here
http://dns323.kood.org/dns-320
here it shows a script that sends commands to the onboard microcontroller to trigger a real shutdown mode.

 The shutdown script is the same as the official one except that i've added a proper shutdown for ffp : /ffp/etc/rc stop

#!/bin/sh

# /ffp/extra/shutdown/shutdown_ffp.sh

source /usr/local/modules/files/project_features

/ffp/etc/rc stop

kill_running_process
#kill -9 -1

# remove link file
rm /usr/local/upload
sync

umount_dev.sh all

umount /usr/local/config

sleep 1
# shutdown device

MODEL=$(cat "/usr/local/modules/files/model")
echo "MODEL:$MODEL"

if [ "$PROJECT_FEATURE_MCU_CHIP_WT693P" = "1" ]; then
	echo "device shutdown"
	up_send_ctl DeviceShutdown 0

elif [ "$PROJECT_FEATURE_MCU_CHIP_69P803" = "1" ]; then
	echo "send cmd to micro-p to shutdown"
	up_send_ctl DeviceShutdown 1
else
	poweroff
fi

@bobafetthotmail as always, thanks for your very comprehensive answer. I think such responses that inform and educate are much better than those that insult. Though your mention that people who want to turn off their routers at night have nothing better to do with their time. That opinion does not add any value to the technical issues you went on to address so brilliantly. Thanks a lot. Distinguishing between features of hardware, such as between routers and computers, and what is possible based on those features was great. It helps me understand why the DNS 323, which could be considered a mini-computer can have what I asked for via software, but a router cannot. Thanks!

So, to wrap this up, for devices that lack an internal MCU to do this job, imho the simplest way to roughly accomplish what you ask is to use a good old-fashioned timed power switch (mechanical or digital), that just cuts power and gives power at specified hours as set in its mechanical wheel or digital timer.

For maximum flexibility you can also go the nerdy route and use a smart power switch (which is basically a MCU that controls a power relay) with a RTC module (the same clock and battery used in PCs to keep the time), running Tasmota opensource microcontroller firmware, where you set your schedule, and the smart switch will simply turn off or on the power to the device's power brick when required.
Yes the smart switch will have to stay on 24/7, but it's a microcontroller, its power requirements are measured in milliwatts.

For example this project shows how to add a RTC module to a cheap and cheerful Sonoff Basic smart power switch (that you flashed with Tasmota opensource firmware) https://makeitmore.fun/smarthome/use-tasmota-with-real-time-clock-ds3231

Yes it's assuming a bunch of things (like that you do know how to work with Tasmota to begin with), but I'm linking it more as a "food for thought" and an example that "it can be done" than a real step-by-step guide.

Oh no on the contrary, it points out how little sense it makes to turn off embedded devices that consume a few watts on idle, and contextualizes the choice of the hardware manufacturers to not even care about implementing the hardware to do so in most routers and other pure network devices (switches, wifi APs and so on).

It's important for the "full picture" I'm going for

I can see one place where a power-off button in LuCI could be useful: when you need to power-down the router (say to unplug it from power), it is always best if you can close all open files to prevent data corruption. This is a somewhat common (although not universal) issue for some devices like the Edgerouter X (while running EdgeOS) where unexpected power loss can cause issues with data integrity. That said, I think it is quite rare to experience this issue with OpenWrt on most devices.

For OpenWrt, the effect of the poweroff command is very much dependent on the hardware that is being used. Most of my devices will simply shutdown the OS and halt, but don't (more accurately: can't) do anything with the power circuitry. This will obviously shutdown all network interfaces and radios. I do have a TL-WR902AC travel router which appears to actually physically power-down pretty much everything, but without actually probing the board, I can only confirm that the LEDs and network interfaces go down (possibly also the USB-A port power and the power to the ethernet phy).

On the travel router, I would love to have a simple poweroff button in LuCI because that one is constantly being moved. But I can (and have) just mapped the WPS button using the hotplug buttons feature (hold the WPS button for x seconds and it issues the poweroff command).

As stated by others -- once the poweroff command has been issued, there is no way to turn these devices back on again without physically bouncing the incoming power... which means that a basic AC powered timer device is probably the better option for any kind of scheduled power-off/power-on events. Note that a "smart" wifi based power switch would not work unless it is connected to another network -- by bringing the router down, you also would incapacitate the wifi power switch.

Operating systrems optimized for embedded use like OpenWrt aren't writing anything to storage so you can freely pull the plug and they will be fine on reboot.

Of course if you install services where the entire point is writing to storage (for example smb filesharing, or a mysql database) then you probably want a clean poweroff button, but for a lot of OpenWrt applications and the default firmware image, there is no need to shut down cleanly.

The fact that EdgeOS (which is supposed to be an embedded device firmware) fails in these ways does not speak well about its design. Another project like VyOS is also based on Debian but is designed to run from RAM properly and does not care much about hard rebooting.

The above is not to say "we don't want a power off button in Luci", but just giving some context on where this button would be actually needed or useful and where it would just be an occasion to shoot yourself in the foot.

2 Likes

Exactly. Which is why I said that it is uncommon for there to be data corruption in OpenWrt (when used as a router without data intensive services running).

Yeah... I've never experienced this myself, but I used to be active on the UI forums and there were horror stories of the ER-X failing in spectacular fashion from power outages. I agree that if there are a bunch of open files or other data intensive tasks going on, this is bad design. But it is hard to know if the users had caused this by way of odd configuration with lots of data being written to internal storage (vs an external syslog server or similar).

Agreed. And in the case I described, I think a hardware button makes more sense anyway. I have it set, but I usually don't bother -- I just yank the power.

I have seen that to. But edgerouters are build for weather front line EMP duty so they are powered by mains with power ground and ground potential connector.
They have shielded RJ45 connectors and metal casing.

You better be sure what you are doing when connecting your ISP to this kind of router because if the internet comes through anything else than optical fiber connected to your home and you get a earth potential disturbance from a power outage (grid power outage) for example. Your router will be the connection between ISP ground and power grid ground and that will shorten life of the electronics in the router.

There is a reason home routers are in plastic, have non shielded rj45 connectors and external isolated DC power supplies.

I personally never had any issues with the ER-X when I ran it... but that said, I would fully expect that a surge (such as a lightning strike) on the coax coming into my cable modem would fry downstream components even when using UTP cabling. And I would expect that for most cable modems and consumer routers.

I suspect that the ground lug is actually there to help dissipate static electricity that can buildup on ethernet cables that are exposed to the elements, particularly in windy environments. I just tested continuity and the ground of the DC barrel jack is tied to the chassis ground, as is the shielding on the ethernet ports. But if UTP cables are used, the only place you would get a ground disturbance would be on the DC barrel jack (which should be largely irrelevant for minor electrical disturbances since the power adapters are usually double-insulated and not earth grounded). The risk, therefore, is a surge coming through the standard UTP cabling and/or via the power adapter, both of which should only be an issue for more extreme events.

There is already a shutdown button in luci-app-advanced-reboot.

8 Likes

@5p0ng3b0b after all that was said, you came and said this. But I suppose this is only on the current latest release.

No, it's been there since 19.07 (at least)

I think the reason many people (including myself) might not have ever bothered with the advanced-reboot app is that it is most commonly used for dual-boot devices. But it is nice to know that this is an option :slight_smile:

@camus - not sure if you're a bit frustrated about how long the thread went before this info became available... but we don't know when @5p0ng3b0b actually read this thread and/or remembered that this feature is available in that luci-app. But now we have the info :slight_smile:

I have used the app in wrt3200acm to change boot partition a couple of times. But to be honest I didn’t remember the shutdown button until @5p0ng3b0b said it😄

Wrt3200acm has a real on/off button on the back I always use.