I recently had a similar problem for my Linux-based desktop, but found that it didn't support wake on LAN. So instead I wired an ESP8266 to the ATX power pins on the motherboard (via an opto-isolator, in parallel with the actual switch so both could be used). Code on the esp8266, which connects to a network server, can then "depress" the power line for a configurable number of milliseconds.
Apart from working on my PC, this is also quite nice as it gives you a way to force-power-off remotely if necessary.
I wanted to wake my laptop via wifi. There's no way to do it using WoL with the laptop's wifi card.
For some reason the laptop's wifi card won't be powered during sleep or never responds to WoL packets, but the USB port is powered during sleep.
I got an ESP32-S3 which has built-in USB. I cobbled together the examples from the ESP-IDF framework. Using one wifi example I got the ESP32 to detect WoL packets sent to it, and the other example was the USB HID example that acts like a mouse and moves the cursor around.
So now I can send a WoL request to the ESP32, and it will then "move the mouse" and wake the laptop. It worked like a charm and only took me about 2 evenings to put together.
On my desktop, wake on LAN stopped working after a BIOS update, so I set it to "power on after power fail" (when the power comes back) and plugged it into a WiFi switchable power socket on which I installed the Tasmota firmware.
Power outages and therefore undesired activation are extremely rare where I live. Probably less than one in five years.
My first computer had an unintended 'power on after power fail' mode, resulting from a short-circuited power button! I don't believe modern motherboards would do that; they must be listening for their power button's state transition when it is depressed rather than simply checking whether it is closed.
I converted an old system to a server, and the WOL was super unreliable (poor mobo support, crappy network, ??). Wound up getting a PiKVM setup for $100 + RPi5 (Geekworm KVM-A8 Kit "PCIe" Version) which works pretty well, if perhaps overkill. The "official" PiKVM hardware is a bit more expensive (~$300 but also has a fancy steel case and HDMI passthrough)
There's a BliKVM "card" which also looks interesting and I'd probably use if I did it again because I was trying to fit the card above the GPU and it took some modding.
One solution that I use and like because it is reliable, is to change the BIOS to "Power On" after a power failure and use a smart plug to turn on the computer.
So turning the smart plug on my phone on would start the computer. I use it for my backup server with a JBOD that is only turned on when I need it. You can also schedule on/off time on the app. And if you want to programmatically turn it on/off you can setup Home Assistant with the plug.
This is a really good solution for the problem, imo. How do you power off without cutting electricity completely? Or do you power off computer then the socket?
> Now, you might be wondering to yourself “Max, you said you weren’t running as root. How are you binding to port 80?” Well, sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/busybox. But you could also run on an unprivileged port like 8080.
As you're launching from systemd anyway, I'd try something like `AmbientCapabilities=CAP_NET_BIND_SERVICE` in the unit file (caveat: untested). Then it's scoped to that unit, where it's (1) needed and (2) clear why it's needed. Instead of the busybox executable that (1) likely is used in a bunch of places where that's unneeded and (2) may get reinstalled by the package manager without this perm, quietly breaking your setup.
systemd also supports binding the port for you, but afaict from a quick skim, Busybox httpd doesn't support accepting the socket from systemd, so that wouldn't be as easy a change.
I wrote a pure bash shell version for use on my IPv6-only networks. I initially wanted to make pure POSIX sh but the ease of being able to use ${param,,} and more importantly /dev/udp/$IP/$PORT makes bash more suitable for the use-case.
#!/usr/bin/env bash
config_sys="${config_sys:-/etc/wol}"
config_user="${config_user:=$HOME/.config/wol}"
PORT="${PORT:-9999}"
cat <<EOF
WoL Wake-On-LAN Magic Packet transmitter
Copyright 2023 Tj <hacker@iam.tj>
Licensed on the terms of the GNU General Public Licence version 3.
EOF
ls() {
shopt -s nullglob
for f in $@; do
printf "%s\n" "${f##*/}"
done
}
if [ -z "$1" ]; then
cat <<-EOF
Please specify the hostname. Currently defined:
System ($config_sys/): $(ls "$config_sys/*" 2>/dev/null)
User ($config_user/): $(ls "$config_user/*" 2>/dev/null)
Config files should be named for the target host
Content is shell variable definitions
Required: IP= and MAC=
Optional: PORT= (default is ${PORT})
E.g:
MAC="60:45:cb:9f:42:fb"
IP="fddc:7e00:e001:ee80::2"
EOF
exit 1
fi
for conf in "$config_sys" "$config_user"; do
if [[ -r "$conf/$1" ]]; then
. "$conf/$1"
# don't break; allow user override
fi
done
if [[ -z "$IP" ]] || [[ -z "$MAC" ]]; then
>&2 printf "Error: required configuration missing IP='%s' MAC='%s'\n" "$IP" "$MAC"
exit 2
fi
target="/dev/udp/$IP/$PORT"
hex2char() # $1 = 2 hex digits
{
case "${#1},${1,,}" in
(2,*[!0-9a-f]*) return 2 ;;
(2,*) printf '%b' "\x$1" ;;
(*) return 1 ;;
esac
}
make_payload() # $1 = Ethernet MAC address with ":" separators
{
IFS=":" read -r -a mac < <(echo "$1")
for h in "${mac[@]}"; do
magic="$magic$(hex2char "$h")"
done
payload=""
ff="$(hex2char "ff")"
for ((i=0; i < 6; i++)); do
payload="${payload}${ff}"
done
for ((i=0; i < 16; i++)); do
payload="${payload}${magic}"
done
}
printf "Sending magic packet to %s (%s port %s [MAC %s])\n" "$1" "$IP" "$PORT" "$MAC"
make_payload "$MAC"
printf "%s" "$payload" > "$target" || printf "error: failed to send (error %s)\n" "$?"
> I added the Pi to my Tailscale network (no, this is not an ad; just happy), which was pretty painless.
I had a quick look at Tailscale and it seems to be a VPN network that you get to manage? So it's still a VPN just with convenience functions to make adding devices easy is that about right? Where does the DNS for this exist, is it on Tailscale's own servers. There must be some purpose to having to login. Does Tailscale also hold some connection open to figure out which devices are on or not.
In a way this reminds me of AWS SSM Agent. I think it's talking to some central Amazon servers and I don't need to open a port on an EC2.
Tailscale runs its own local DNS resolver on your computer at 100.100.100.100, if you have enabled that in settings. Your DNS queries don't go to any Tailscale servers. By default, the client simply forwards all queries to the system DNS resolver, providing some added conveniences like automatic DNS over HTTPS upgrade when available. Also, you don't really have to use Tailscale for DNS if you're comfortable reaching your devices using their 100.x.y.z IP address. See https://tailscale.com/kb/1081/magicdns for more details.
And yes, Tailscale keeps a connection open to its servers to allow other devices to reach you when you're behind a firewall and direct connections can't be established.
Tailscale is a mesh overlay network that uses Wireguard under the hood. Traffic moves peer to peer as much as possible. DNS happens locally (the special 100.100.100.100 address actually points at the tailscale daemon running on each machine, which already holds the name -> address mapping that MagicDNS needs to work).
You login to Tailscale from each device in order for the central Tailscale control plane to authenticate the device and for it to distribute that device's public Wireguard key out to the rest of the mesh.
I haven't personally used this, but many folks on HN also like that there's an open-source, self-hosted implementation of the control server. https://github.com/juanfont/headscale
This seems a use case where the smallest the better since the small system only has to close a contact according to a condition on the local network. This could also be done with a very small uC with Ethernet (example: Arduino and others + w5100 or compatible Ethernet chip; I'm not a fan of WiFi in these contexts). There is also a SSL library that can be used to run a minimal secure web server to host the magic button that would trigger the switch on through the gpio.
Or it could employ some sort of port knocking on the uC+Eth board so that it wakes up the main system only when the right sequence is used. The advantage of using a uC, lower power draw aside, is that micro SD cards (and their sockets) are less reliable than internal flash.
Did something similar when I was behind CGNAT and had no IPv6 or port forwarding. Instead of a pi, I cheaped out even more and used an old android phone. Wrote a little Rust program that listened on a ntfy[1] channel, cross-compiled with cargo-ndk[2] and ran it in termux (which had the wol tool, a perl script that sends magic packet). The web UI simply pinged the channel (and showed the pong).
This is my setup, without the GUI. I join the Tailscale network on my laptop, ssh into my pihole (slash homelab misc) pi, and run ‘wol’. I also have the PC set to boot in the early hours (in BIOS) in case I’m away for a long time and accidentally pick ‘shut down’ instead of ‘sleep’ at some point.
I used a similar setup to reboot my home server remotely, with gpio pins instead of wakeonlan.
I eventually replaced it with an aliexpress tuya pcie power switch. I just wish I'd gotten the zigbee version. Homeassistant with local tuya wifi devices is quite janky.
Have you ever actually tried that? I have. It's possible with some router, but IIRC I had to install some custom config file from some random site. Definitely wasn't easy. I think with most routers it isn't possible at all.
If you're imagining you just forward the port to your computers IP address... no that doesn't work. Because while your computer is asleep it doesn't have an IP address. What you need to do is configure the router to forward broadcast packets to the local subnet. Something like that anyway, I can't remember the exact details.
What I've done (and again, this is routers where you have access, though maybe some somewhere have wakeonlan capabilities) is make it so that if you port knock right, the router itself sends a wakeonlan packet for you.
Maybe some have the feature if you're forwarding a port, it will send a wakeonlan packet if it detects traffic on that port.
Sorry, I don't want to be rude. If you are happy with your setup that is really all that matters. I was just seriously puzzled that's all. If someone has an OpenWrt router instead of something off the shelf, I would assume that they have it exactly for the tinkering and setting up port forwarding should be a piece of cake. Though I don't have a OpenWrt device myself so maybe this is just me being naive. On my MikroTik router this is pretty easy once you know how to do it :)
Security-wise I prefer the port forwarding because there is no third party involved and less complexity in general, but sure, you can find pros and cons here and there.
I've tried. But the Linux environment is pretty limited and Luci has stumped me more than once over the years. It's also slightly riskier: if I bork the router, it may take me (a significant amount of) time to get my network back up and running.
Are there places in the world where people have to actually care about the power consumption of their computer so much that this is a thing? Any examples?
Because it costs money to run and I’m not made of money? It might be cherish, but money I don’t have to spend is even better. It’s also better for the environment(!!) and I like my working space to be as quiet as possible.
It takes 20 seconds to boot and it warms up my room if on. So why would I keep it on all the time. I turn it on when I use it and turn it off when I don't.
From a hardware perspective, it seems to be high temperature for a long time (>70C, >55C if it's passively cooled) and thermal cycling are the two mechanisms that cause hardware to fail. Neither of these are true for a computer left on when idling.
Where I am from, 1 W 24/7/365 is approximately one dollar per year (~10 cents per kWh). I have a Mac Mini M1, now, but I used to have an Intel MacBook Pro and before that, a 300W workstation.
The MacBook Pro took about 30 watts idling, so about two dollars a month. I probably lose more than that on exchange rate fluctuations.
The 300W workstation took about 300 watts idling, so about 20 dollars a month. This is rightfully significant, and due to this concern, that computer was replaced. However, if I did not have the option, 20 dollars a month is a perfectly reasonable price to pay considering the hundreds of tabs, programs, daemons, and other misc things that I always had going on. I treated the computer as an extension of my mind that doesn't sleep, and I would pay $20 gladly for this feature.
Now I have a Mac Mini M1. I haven't measured the wall power but "powermetrics" says the CPU, which is the only actual part in the computer, taking 600 mW (0.6W) idling. Absolutely no reason to shut this down ever. Why would I even consider that.
Unless you have a GPU, and a relatively modern system, most desktop PCs (dell, etc) probably take about 15-20W to run. A GPU adds about 20-30W of idle drain. Depending on what you do with your computer, the question is simple: Would I pay $1/W/24/7/365 per year to keep all my stuff open? If it's too high, can you reduce the idle power consumption?
I know this is probably extremely surprising for you, but some people do the little things which help the environment even if it causes them mild inconvenience.
Many people with homelabs - or a NAS with a ton of disks - don't use it all that often and it can cost quite a bit in electricity over the course of a month.
Or maybe they live in an apartment and prefer quiet over the noise of fans and disks.
Some people live in places with rolling blackouts and the UPS doesn't last long enough, so easier to shutdown cleanly and power off the UPS so you're not constantly cycling the battery for no good reason.
It depends on what the computer is doing. My home server runs 24/7 and idles around 80W. I have a backup server at my parents house that uses about the same amount of power but it only needs to be one once a week for an hour while I run my backup. Why would I have it wasting power doing nothing the other 99% of the time? So I have a Raspberry Pi that sets up a reverse SSH tunnel to my house which idles under 2W. I use that to send the Wake On LAN packet to the server.
also, more time on might mean more disk wear and greater chance of hardware failure. (there is probably some sort of heat shock, so leaving things on might be good too)
It's not just power consumption - fire safety can be a factor. Although spontaneous combustion of a computer by itself is vanishingly unlikely, it only takes some loose piece of fabric or paper to waft its way across the fan and you have a genuine combustion risk. That is better-protected against now that most chips have built-in thermal cutoff measures, but a lot of machines still get warmer than I would like them to be.
Your comment is shockingly out of touch, are you Elon Musk? Check out Mr. Billionaire over here, with money to throw away on idle computers.
I live in California. Electricity is not free, or even cheap.
I have 4 computers. 1 out in the garage that's my "off-site" backup system, complete with LTO tape drive. It's also got an 8 drive RAID10 array. I don't need it running 24/7. I need it on when I have a backup job for it to do, and off when I don't need it on.
I have a workstation that I only use when I'm developing personal code. I don't need it running 24/7. It also has 8 spinning disks, video card, and a massive CPU. It consumes about 300W of power, so that adds up.
My laptop is off when I'm not using it, but even that I wake remotely from time to time when I'm out in the garage and need a file from it.
I have 1 server that runs 24/7 and handles Plex, security cameras, and 6 virtual machines. It's a workhorse, but it's got a 65W CPU in it and barely uses the video card.
My electric bill is $600/month in the summer months, mostly due to AC but I don't need to make it any worse by running 4 computers continuously when I don't need to.
My computer uses about 150W idle. The only people who leave that running 24/7 are those that a) enjoy ruining things for others, b) hate money, or c) are too stupid to realise how much power they're wasting.
Apart from working on my PC, this is also quite nice as it gives you a way to force-power-off remotely if necessary.