Introduction: ESP8266 Automatic Router Restart
I'm a lazy person, and as a lazy person I'd rather sit on the sofa typing code for a while to create this, than have to occasionally go and fix the internet. If you're a lazy person like me, or you just want to get playing with your ESP module, you're in the right place!
Don't undertake this instructable unless you're comfortable working with potentially lethal voltages. I will not be responsible for your death!
For this instructable, I'll be using the following:
- NodeMCU development board (can be found here on Amazon or much cheaper in bulk on AliExpress)
- Relay board (here)
- Power supply (here)
- Dupont cable or some other wires
- Small breadboard
- Extension lead with cable (this and below were bought from my local hardware store)
- Screw terminal
- Plastic food tub
- Electrical tape
Step 1: Cut Your Cable
You'll want to cut your extension cable at a suitable point, I'd recommend leaving a couple of feet at each end at a minimum so you can locate things properly.
Strip about 1 1/2" from the cable and reveal the 3 smaller cables. We're going to switch the live cable and connect the earth and neutral back together via the terminal block. As the live cable will have to be a bit longer than the others, cut about 1/2" from the neutral and earth cables.
Finally, strip all of the connections about 1/4" (maybe slightly less) so that you have enough of the conductor to work with without bare copper being left all over the place.
If you've not done this for both sides of the extension cord, repeat now for the other side.
Step 2: Connect Earth and Neutral
Take your terminal block and cut off two sections. Unscrew and insert the earth conductor into one channel and the neutral into the other. Screw tight and visually inspect the connection to make sure you've not caught the plastic or left a lot of the conductor out of the clamp.
Repeat for the other half of the cable, remembering you want to connect earth to earth and neutral to neutral.
Step 3: Connect Live Connections to the Relay Board
We're just mocking things up now to make sure everything fits correctly into the food tub. Connect the live wires to one side of the relay board. I've connected the incoming mains wire to the common pole of relay #2, and the outgoing live wire to the normally open connection (that means by default the circuits aren't connected).
Step 4: Connect the Relay Board to Your ESP Module
The relay board has some nice and easy connections: VCC, In1, In2, GND. Connect GND to one of the GND terminals on the ESP board and connect VCC to the VIN connection (this is 5V compared to 3.3V of the ESP, but the relay won't trigger with this low voltage). Connect In1 and In2 to D0 and D1 on the ESP board.
The relay board is triggered by pulling the inputs to GND, so no need to worry about level protection.
Now on to the software!
Step 5: Test the Program
Download the attached program into your ESP module. I use ESPlorer for this job. Make sure to change the settings to match your wireless network and pin configuration.
DON'T PLUG IT IN. Just test the relay board works, and the relay board triggers when you pull your ADSL line. For safety's sake don't connect the board to your PC, or have anything accessible by little fingers when there's power going to the modules.
Step 6: Finish It Up
Unfortunately I don't have a picture for this step, because I am useless.
Once you're happy everything is working, drill two large holes on either side of your plastic case, for the mains cable. Drill a smaller hole on one of the other edges to allow the USB power to come through. (If you're so inclined and have a larger box, wire an internal socket into the box and use this to power the module).
Disconnect the cables and feed them through. Reconnect them and check to make sure everything is as it should be with no copper wires splayed out or touching anything they shouldn't, and nothing pulling apart. Use some electrical tape to cover anything base or exposed.
Feed the power cable through for USB power and then seal the box. Don't open it or connect to a PC unless the incoming mains power is disconnected. If you have little ones who like to poke around I'd recommend instead a locking/screw close case.
We have a be nice policy.
Please be positive and constructive.