MQTT Client and Remote Switch

Project

Develop an MQTT client that can remotely operate the signals generated by a PC’s power and reset signal to remotely wake, power reset, and switch on a computer over the internet. This personal project came about when trying to find a way to remotely access my desktop computer while traveling, without having to leave the computer on indefinitely.

While sending “magic packets” to wake the computer is a solution, it would not provide the reliability, feedback, and versatility of an MQTT device. Further, an MQTT device can still operate the computer even if the computer is disconnected from the internet or completely turned off.

Solution

An ESP8266F board running a C++ variant code (Arduino) was used. To access the board remotely, it was configured as an MQTT client, and using a simple MQTT broker, I can send waiting commands to the client even if the board was not connected to the internet and later reconnected.

The board had to be resilient during any sort of power loss and remember any existing commands or instructions given to it. It also had to access its own onboard memory to remember certain operational configurations, including what NPT time zone it was configured to to timestamp messages. All of this had to be coded into the schema of how the board operated.

This also included developing an electronics breakout board, which supported optoisolators to directly connect to and trigger the computer power and reset switch signals as well as receive feedback signals of the computer’s power status. This allowed the board to record and report if the computer is OFF, ON, or Sleeping.

Results

Using over 2300 lines of code, the board works very well, resuming operation during power resets and allowing full remote operation. While the board and computer were left in the SF Bay Area, the operation and awakening of the computer have been tested as far away as Japan! This includes updating the time zone the board operates in (it goes to sleep during the ‘night’) to JST successfully. 

To get time, the board connects to NPT servers, to carry accurate time information, allowing it to timestamp any messages. This also allows the board to ‘deep sleep’ during times of planned non-operation and then return to an operation state thereafter.

Some of the other notable features of the board include recording the last known status of the computer and how long it has been in that state, ‘sleeping’ for planned durations well past the board’s maximum allowed deep sleep (due to the RTC memory limits), and staying ‘caffeinated’ during times of planned sporadic need so that the board remains on.