awake daemon
awaked version 0.0
Copyright(c)2022 by Hiroaki Sengokusengoku@gcd.org
awaked (pronounced "awake dee") is a Windows service (daemon) that prevents a Windows PC from going to sleep. It prevents the Windows PC from sleeping even when it is idle (no keyboard or mouse used) as long as UDP packets continue to reach a specified port. By sending UDP packets remotely, you can keep your Windows PC "awake".
awaked has the following features:
- 1. No GUI
- There are already tools that prevent Windows from going into sleep (PowerToys Awake etc.), but all of them require you to operate on your Windows PC to start the sleep avoidance feature. awaked doesn't have a GUI, and you can remotely control sleep avoidance. With Wake-on-LAN and awaked, you can "wake up" and "keep awake" your Windows PC remotely, while you keep it most of time asleep to save power. My Windows PC connected to my TV set, for example, wakes up automatically, when the TV set is on.
- 2. Simple
- Only 400 lines (C language), so it minimizes the possibility of security holes. It is so simple that it will be easy to integrate into other systems (GPL license). It only requires cl.exe (C/C++ compiler in VC++) to build, so you don't need a full set of VC++ and just install Build Tools for Visual Studio.
- 3. Windows 11 compatible
- The behavior of SetThreadExecutionState API of Windows 11 is different from that of Windows 10 (ES_SYSTEM_REQUIRED alone does not work), and some of the similar tools do not work on Windows 11. Adding ES_CONTINUOUS to the argument of SetThreadExecutionState, awaked will work stably on Windows 11 as well.
- 4. Echo Protocol (RFC 862) conformance
- Sending and receiving UDP packets conform to the ECHO protocol, so tools that use the ECHO protocol can be used as the client of awaked (for example, Net::Ping in perl).
Snapshot
Usage
- C:\>awaked.exe -v -p 55084
- When a UDP packet arrives on UDP port 55084, awaked prevents the Windows PC from going to sleep for 3 minutes from that point.
- awaked send back the content of the UDP packet (ECHO protocol).
- Before you register awaked as a Windows service, you can check your Windows Firewall settings by first running it at the command line.
- C:\>awaked.exe -p 55084 -M install waker
- Register awaked as the Windows service "awaked waker". The "waker" part can be set arbitrarily. Please "start" the service from "Computer Management" => "Services and Applications" => "Service". If "Startup Type" is set to "Automatic", awaked will run automatically when Windows starts up.
- C:\>awaked.exe -p 55084 -M remove waker
- Delete the Windows service "awaked waker".
Sample perl script to send a UDP packet:
#!/usr/bin/perl use Net::Ping; my $p = Net::Ping->new("udp"); $p->port_number(55084); for (;;) { my @ret = $p->ping("hostname", 10); sleep 60; }
Background of development
With mounting a physical disk in WSL2, I use Windows more often as a server. Of course, I have used VMware and virtual machines running on Windows as servers for a long time, but since VMware requires a lot of memory and CPU, it's hard to keep them running all the time. WSL2 is lightweitht VM, so I can keep them running all the time.
When I'm able to use Linux all the time, I wanted to log in using ssh even if I am not in front of my Windows PC, and I started to wake it up using Wake-on-LAN when it was in sleep mode.
Also, I have a Windows PC that is connected to a TV set to watch videos. I made a trick to trigger Wake-on-LAN automatically when I turn on the TV set. As I watch videos more often than TV broadcasting, so it is convenient if the PC wakes up from sleep automatically when I turn on the TV set.
The problem here is the timeout period until sleep. Normally I set it to 2 hours, but when I wake it up with Wake-on-LAN, without touching the keyboard nor mouse at all, the PC will go back to sleep only a few minutes. The timeout period set by "System" => "Power & battery" => "screen and sleep" is only counted from the last time you used the keyboard / mouse.
Concerning the Windows PC connected to my TV set, it's OK if I touch the mouse immediately after turning on the TV set, but if I don't operate the Windows PC by watching TV broadcasting for a while, the PC will go to sleep shortly. Since both of my mouse and keyboard are connected with Bluetooth, I cannot use them while the PC is sleeping, and it is troublesome that I need to press the power button to wake the PC from sleep.
So, I've been looking for a way to keep it awake after Wake-on-LAN, but I can't find the right software.
I found several programs to avoid sleep, but to avoid sleep, I had to use the mouse, that was nonsense for me.
If you touch the mouse, the timeout to sleep will be extended, so I don't feel much need to avoid sleep. What I need is a way to avoid sleep without touching.
If you don't have it, make it ! I start to write awaked.c after my breakfast on Saturday, June 18, 2022.
#10425. | ||
https://www.gcd.org/sengoku/ | Hiroaki Sengoku <sengoku@gcd.org> |
| home | up | japanese | sengoku@gcd.org