Syrionator 2000 - router restarter
#13927
what do you do when you get tired of going downstairs to reset your router? that's right, you put an unreasonable amount of effort into building a BS machine to restart it for you!

https://i.szymszl.xyz/h797.jpg

this is Syrionator (named after my ISP). it plugs in between power and the appliance you want to molest. it hosts a simple UI over WiFi letting you turn it off for 5 seconds when you want with a single click.

https://i.szymszl.xyz/2swc.png

hardware



on the technical side it's ran by the ESP8266 MCU, here through the ESP-01 module. the module controls a random chinese 5V relay, driven by a couple of transistors. the relay simply switches the hot wire. the 5V power is provided by an old phone charger i took apart. the 3.3v is obtained with a random LDO i had around. the entire thing is (badly) soldered together and put in a plastic box i got in a home improvement store. a schematic follows; i did not design a pcb nor plan the perfboard arrangement. hell i only made the schematic for this thread lol

https://i.szymszl.xyz/nzwm.jpg

https://i.szymszl.xyz/xyf4.png

the circuit is mostly rather basic - there is the 5V power brick, the LDO providing 3.3V, the module with its companion boootpin resistors, and a relay with a snubber diode switching the live wire to the output socket. however, there is one weird part - the relay coil driver using arbitrarily three transistors. this might appear odd, but it's a result of my odd design choices. i will get further into this because i think it's pretty interesting

BJT intermission



let's discuss my odd requirements for the circuit. first of all, i am putting the router connection on the NC (normally closed) relay contact. this is in a way the "default" connection of a relay, it's how it's connected if you don't power it. it only disconnects if you power the relay. this is so if my electronics breaks then the router has a chance of working despite that, kind of a fail-safe. the second requirement is that the circuit be active-low, as in be enabled by a low voltage level. this is because pin 2 on an ESP8266 is a bootpin and needs to be pulled high on boot. this essentially makes the high state default, since it needs to be that way for the chip to work at all. it would be possible for the chip to just always put out a low voltage and make do with an active-high circuit, but this would make it so when the chip is not working (because it's fucked or because it's only starting up) it would turn on the relay, turning off the router. as such, i want an active-low circuit, so a not(-yet) working chip leaves the router alone. a third issue is that my relay runs on 5V, since this is what i had around.


https://i.szymszl.xyz/z19h.gif
the obvious way to drive a relay is to use an NPN transistor to connect one of its leads to ground. providing current through the base will cause the transistor to conduct and let current flow through the relay, closing it. this would work here, but it has a caveat - it's active high. this means the circuit enables itself on high voltage.

https://i.szymszl.xyz/xh3p.gif
this is the slightly less so but still obvious way to drive a relay. in this case the NPN has been replaced with a PNP, and to match it now switches between a relay lead to 5V. this is also a working circuit, it would even be active low, but it has a problem in this context - the logic signal is not 5V, it's 3.3V - so the transistor stays on even when it should be on. had the signal been 5V, or the relay 3.3V, this would work.

https://i.szymszl.xyz/vmzc.gif
this is a correct solution to my problem, but i had somehow missed it when i was building this machine. this uses two transistors to do its job - a PNP powered by 3.3V is used to source current for the NPN to drive the relay. still no idea why i didnt think of it

https://i.szymszl.xyz/5jmb.gif
what i ended up coming up with. it uses two NPNs and a PNP. the first PNP is used basically as an inverter. when enabled (with a low signal) it sources current, creating a high level at the base of the second transistor. the second tranny, a NPN, when enabled starts sinking current which enables the last PNP, which then lets current flow through the relay. overcomplicated? perhaps, but it worked.

shoutouts to circuitjs for being a cool circuit simulator and looking good in gifs

software



the software is what took me the most (in procrastionation) and the least (in actual work done). it's rather.. lacking right now, all it does is turn off a pin for 5 seconds when it receives the right HTTP request. i plan to add automatic reboots at a chosen time of day, and maybe even warnings when it's about to come down, but so far this is all far away in When I Get Around To It-land.

the entire thing is written (obviously) in C, for the ESP8266 RTOS SDK. it luckily provides a HTTP server and MDNS, so it's pretty much all glue code and as such rather short, coming in under 400 lines. if there's interest, i might clean it up and post it for people to Enjoy

https://i.szymszl.xyz/pmww.png
in the meantime, here's the HTML+JS that it runs on. i promise you, the js is indented in the C source (because i wrote in inline out of laze)

you could get much more out of the same circuit, just changing the software. i built another one of these (actually with trivial changes for failsafes) for a friend, just that instead of running a shitty HTTP UI it integrates with Homekit and works as a Siri-enabled light switch. you can get it to do much more if you want to (and i plan to do so myself)

 



idk what else to say, build your own it's fun
#13930
you should perhaps put a power indicator LED between the LDO and the ESP or make the ESP control it so you know the status of it.

edit: nvm didn't realize you already used up all the GPIO on the ESP-01 lol. between the LDO and the ESP would be the obvious choice then
https://cockdickball.in/media/button.gif
#13931
i don't think there's much of a need for a status indicator, you can tell the state by just looking at the router lol

also, i havent used up all the GPIOs, i have only used one (out of four). while yes it's annoying that every pin of the 01 is in some way special (0 and 2 are bootpins, and 1 and 3 are boot log UART), you can use them with a bit of care. for example, an LED is barely business critical and can afford a bit of instability during boot, so it could be reasonably placed on every single one of these pins. in fact, i thought of making a physical "reboot" button, and it could easily connect to either 0 or 3 as long as i dont press it during boot (and 3 might work anyway? havent tried)
#13932
ah, i didn't know that. haven't used this specific board before. i kinda assumed that the RX and TX were specifically reserved for that purpose only
https://cockdickball.in/media/button.gif
#13933
they almost are, you can always abuse them though!
the ESP has a lot of odd rules about pin usage, there's only a couple pins on the entire chip which you can use with no strings attached. there's a cute table on https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/#table so you can see just how fucked it all is