I have a Wemos D1 mini that's connected to a pc with usb, I want to be able to sleep the pc and wake it up programmatically.

Is there a way to do this? Like sending a simulated sleep keyboard button press?

Maybe I can send a wake up on lan command from the Wemos since they both are connected to the same router, but I'm still more interested in sending a sleep command.

I found this but it's old and it looks like they don't really have a way to do it.

  • When I wanted to remotely sleep my laptop through WiFi I resorted to installing an application on the PC that listened on a socket. You can't do WoL on WiFi since it relies on an active network connection, which you can't do with a WiFi adaptor. Only Ethernet, and then only on cards that support it.
    – Majenko
    Oct 19, 2017 at 9:30
  • What application did you use? Also, the PC is connected through ethernet to the same router the Wemos is connected to, so it should be possible to send WOL to the address of the pc no? @Majenko
    – shinzou
    Oct 19, 2017 at 9:37
  • In that case WoL may be doable, yes. Sleep, though, is an altogether different ballgame. I forget the application I used. It was a free one I found through google.
    – Majenko
    Oct 19, 2017 at 9:41
  • I'm voting to close this question as off-topic because it is about PC's and their operating systems, not about Arduino. When a viable solution for the PC is identified, implementing it with an Arduino might become a valid question, but not before. Oct 19, 2017 at 14:55
  • 1
    easy way to sleep it is to create a command to press the sleep button w/ autohotkey, then fire that command from a program that can both run apps and read the serial port, like python or nodejs. to wake it up, you need a fake keyboard, which the esp can't do...
    – dandavis
    Oct 19, 2017 at 21:43

2 Answers 2


The hardware interface would be the easiest like others were saying. Here is a project someone else shared that does that.


The wake-on-lan part is easy and here is some code for that.


I'm also interested in sending some kind of RPC call to a system (linux/windows/mac) via wifi to initiate a shutdown. If I find a solution I will post it here.

UPDATE: I found a Sleep-On-Lan project that should work. You can use the same code above for the ESP8266 but just reverse the MAC Address of the system you want to shutdown.


You will need to run this as a service on the system you intend to put to sleep. There is a windows and linux version. They didn't mention mac but I bet it will compile and run on a mac too. :)

I hope this helps. I will probably use this myself in the future.

  • Could you please add a summary of the key points from each of the links (in case the links go dead).
    – sa_leinad
    Jan 13, 2018 at 4:33


If this is a Windows PC and you can write a WIN32 C++ program then you can look at the WH_KEYBOARD_LL() function and use that to inject the "sleep key", but I'm not sure the "sleep key" isn't an OEM key which might make things difficult.

You could also look at sending a remote command (shutdown) over the network, but you'd have some hefty protocols to implement. Unless you had a service on your PC that listened to the serial connection and waited for the device to send a sleep command to it over that and converted it into a system call. The same will work with a Linux Daemon.

Wake Up

You can get Windows (don't know about Linux) to let a USB device wake it up, but I don't know if you could get a Arduino/ESP to send the correct signals.

Like The great Majenko says WoLAN is an option, but difficult to achieve.

My preferred option would be to splice a wire into the power button of the PC in parallel (so you can still use the button) and control that with a relay. That should give you a Wifi enabled power switch, but you need to check how the switch works and mimic it properly. I would try it with an old, almost dead, worthless PC first if I was you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.