the Worthless Writeup Library @ szy.lol

Syrionator 2000

launched on 2023-02

A tiny device to restart my router at a distance, because going downstairs requires effort.


Networking is hard. This applies not only to personal relationships, but also to digital networks - sometimes the difficulty of talking to more than two people/devices at a time is just too much and you need to take a break. Here digital devices have a bit of an advantage - they can nap at any time, for just a short while, and wake up completely refreshed. The methods used can also be quite brutal, and they don’t mind. While temporarily stopping one’s heart is not a great way to go to sleep, temporarily disconnecting power from a router works just right.

I threw together a device to do just that, remotely, without having to bother to go downstairs. Meet Syrionator 2000.

Named after my ISP, who provided the router, the device hosts a user interface over HTTP over WiFi, which lets me cut power to the router for 5 seconds with a single click.

Hardware

The device is quite simple. It’s based on the ESP-01 module, with an ESP8266 MCU. The module controls a random 5V relay I found in my stuff, through a couple of transistors. The relay, when energized, cuts power to the router by disconnecting the hot wire. Everything is powered by an old smartphone charger I took apart, with a random LDO to provide 3.3V for the MCU. Everything is housed by a neat plastic electric box from a home improvement store. These make really good project boxes, and are very easily available! I also created the label you can see on the outside, containing the device name and UI URL, with a typewriter.

Yes, the relay is right next to the antenna, this is somehow yet to cause issues.

The circuit design I made up on the fly, and only made this schematic after the project was built, for documentation. The circuit is basic enough for this to be viable - it consists of trivial power routing involving a power brick and an LDO, a relay (with a flyback diode) switching mains voltage, a basic rig for booting the ESP (the correct set of pullup resistors), and a few transistors to drive the relay.

The design of the relay driver is indeed quite quirky, and this is due to a combination of my odd requirements and my stupidity. I wanted this design to be fail-safe. Usually, in power routing systems, “fail-safe” means that the circuit will fail open, and not provide power if it’s not certain it’s safe. However, in this case, the “safe” state is that I get my needed fix of worldwide imported octets - which requires the device to fail closed. Having to go downstairs to fix the Syrionator would go against the idea of not having to go downstairs! Part of this is achieved by using the normally closed (NC) contact of the relay to carry power. It’s the side which is connected when the relay is not energized, and is as such “the default”. However, a similar approach is needed when driving the relay. The relay will switch when current is passed through its coil. It requires much more current than the MCU can provide, and at a different voltage, so some driver circuit is needed.

The simplest transistor circuit that could accomplish this is a NPN pulling one of the contacts to ground, while the other is connected to supply 5V. However, this has an issue. Such a design would be active-high, as in it would switch the relay when the driver received a logic high (in this case, over 0.7V) voltage. This is an issue, as the ESP-01 is a tiny board, and only has a few available pins, and most of them have additional functions. I ended up using the GPIO2. That pin is held high at boot, which means had the microcontroller crash, it would bring down the network. As such, I had to make this pin active low - high voltage meaning “keep stuff working”, and low voltage used to signal “please turn on the coil”. I could then use a PNP transistor to switch the high side, but this has a different problem - the voltages used by the MCU and relay are different. The simplest way to do this is to use that high-side switched relay as an inverter, and the use it to control an active high low-side switching NPN transistor, but because I was ad-libbing the circuit I ended up with one more PNP transistor high-side switching the relay based on the doubly inverted signal from the two earlier transistors, which ended up essentially acting like a voltage level shifter. This is a huge failure in terms of cost optimization, but a decent success in making shit up as I go and having it work. Please enjoy the attached GIF of a simulation made in Paul Falstad’s CircuitJS of this part of the design working.

Software

The software took the most time, and also the least time, depending if you count time elapsed or time spent working. The firmware of the MCU receives HTTP requests, and either displays a trivial HTML page of a button or switches a pin for 5 seconds, depending on the request’s content. It also uses MDNS to announce a friendly name. The entire thing is written in C in for the ESP8266 RTOS SDK, which helpfully contains HTTP and MDNS stacks, which makes my 400 lines of code near entirely glue. As such I’m not posting it.

The software is quite minimal, and could definitely use improvement - stuff like cancellation of scheduled restarts, authentication, announcing incoming restarts over the network - but I haven’t gotten around to it, and I find it unlikely that I will, as it all works good enough as is.

A variant of this circuit was built for my friend, with software that integrated with Siri via HomeKit instead of crap HTML, and the relay staircase wired to a physical switch, to use as a smart light switch. However, that ended up scrapped as there were signal issues due to wireless networking being located in the wall and next to arcing switches, and likely Apple’s protocols requiring better connectivity than my crap UI.