Remotely turning on my desktop
When I'm away from my desktop, I rely on Chrome Remote Desktop or Moonlight (in conjunction with ZeroTier) to remotely access it.
However, my desktop need to be powered on in order for the above methods to work. Rather than keeping my desktop powered on 24/7, I need a way to remotely turn on my desktop whenever I want to connect to it.
- Wake-on-LAN packets are one way to turn your computer on remotely. I tried setting this up, but I ran into network constraints that prevented this method from working.
- Additionally, the PC still needs the network card to be on in order to listen for the magic packet.
- The motherboard of the PC has two pins that, when shorted, will toggle the PC on or off. If we can hook something up to short these pins, then we can turn on/off the computer.
I got my inspiration from this video, which used an ESP connected to Adafruit IO (using the MQTT protocol) and wired to a relay in order remotely toggle the PC power pins. I more or less followed this concept.
Small Aside: What is MQTT and how does it work?
In short, MQTT is a lightweight communication protocol for sending data between machines, designed for use cases that have limited network bandwidth or hardware resources.
Typically, MQTT uses TCP as its transport protocol. Think of MQTT as an organized group of drivers, and TCP as the cars the drivers use to do what they need to do.
In simple terms, MQTT allows for this:
- I send data sent to an external server (called the MQTT broker)
- External server sends that data to the connected clients (the subscribed MQTT clients)
- Client receives data
- The client and I did not have to be on the same network to communicate!
With slightly more jargon:
- I publish data to the MQTT broker on a certain feed
- The "feed" is nothing more than a name that differentiates groups of clients
- MQTT broker sends data to clients that are subscribed to that feed
- Clients receive data from the broker
I used an ESP32, Adafruit IO, and a 5V relay module.
I developed with PlatformIO, and my code can be found here. This is the gist of it:
- Connect to the WiFi network
- Subscribe to the Adafruit IO MQTT feed
- If we receive a certain value on the feed, activate the relay
- Reconnect to the WiFi network if we get disconnected
- Reconnect to the MQTT feed if we get disconnected
- For monitoring's sake, publish a value to a seperate feed upon reconnect
It's simple, and it gets the job done. With this code, I've managed to keep the ESP-32 connected and running for over a week without any uptime issues.
I put it all together on a breadboard, and it got the job done. This worked well, but it was a little unsightly.
A few weeks later, I caved and went ahead and put together an enclosure for it.
- I'm quite proud of how it turned out.
- It's a fully finished project :)
- I learned about and got to use MQTT.