Friday, March 15, 2019

"Have you tried turning it off and on again?" "Yes, my robot did"

Ok, so it's not quite a robot, but it is automated...

Yesterday while I was at work, there was a power failure at home that lasted longer than my UPS could handle. My server shut down, and when it came back up after the power was restored, it couldn't get online. The problem that I discovered after I got home was that the cable modem had stopped responding to DHCP requests, pings, or anything. The solution to this was simple - unplug it and plug it back in.

But what if something like this happens when I'm out of town? I need some way of resetting it without being physically present. I realized I already had the components to hack together a solution - I had a relay module from an Arduino kit, an Arduino already up and running controlling my air conditioner via an IR LED, and jumper wire. I even had a script monitoring the internet connection already running on the server, but all it could do at that point is force the server to re-request DHCP. All I needed to do was cut the low-voltage wire for the power adapter, connect the cut ends to the Common Normally Closed terminal of the relay, then wire it to my Arduino. That proved a bit challenging, because the Arduino has to be in a spot where its LEDs have line-of-sight to my air conditioner, but I don't want to put the modem right there. I had to chain together several individual jumper wires to get it to reach, and I may re-visit that design in the future.

So then it's just a matter of writing the software. I modified my existing Arduino sketch to pull a GPIO high most of the time, but when it receives a command over USB serial, pulls it low for 5 seconds. The relay module has a P-channel MOSFET controlling the relay, so it is active-low. When the relay activates, it disconnects the Normally Closed circuit and the modem reboots. I set up my monitoring software so that if it can't ping the modem for a period of 90 seconds, it resets. While the modem is connecting, it hands out a local IP address of 192.168.100.11, so I can still ping it and grab the status. It also resets the whole thing if it boots up, but doesn't come online within 4 minutes.

It's not the most hacky solution I've come up with so far, but it's close.

No comments: