- A generic ESP8266 RESTful software library framework bREST is developed.
- A DIY version smart WIFI power plug is created as a prototype.
- A cheaper ready-made Sonoff S20 is modified to run a customized firmware built from bREST.
An open communication protocol smart power plug
To make the experience fit your profile, pick a username and tell us what interests you.
Adobe Portable Document Format - 3.32 MB - 06/15/2018 at 12:15
After two years, I released an update of the Sonoff S20 firmware. Since 2018, I have owned 5 Sonoff S20 to control my home servers and 3D printers at home.
The new improvement are the following:
You can download my new firmware with an instruction in my bREST example repository. See link here.
Placing orders in Bangood is a good test on your patience. I ordered a box of fuse two weeks earlier than Sonoff S20. Sonoff arrived this week from Thailand. But I still haven't got my fuse.
Sonoff S20 is a cheap smart power plug. It comes with an ESP8266, a relay and a AC-DC transformer for ESP8266. It costs only $10, which is far cheaper than the cost of my prototype. It seems that it also comes with a mechanical relay since I can hear the click sound when turn on/off. For 15 min use, I can feel warm on the bottom of Sonoff even it only supply power to a low watts fan.
In any case, let me explain how to flash bREST to Sonoff in case you want to save money.
First, open the hood. You saw 4 holes: VCC, TX, RX and GROUND. These are serial ports for flashing ESP8266.
I got several packs of solderless male pins from Adafruit. I never got a chance to use it. I thought this is a good use case here. So I used a hammer and a piece of acrylic board to push them into the board. As you can see, it doesn't work. The pins are bended. I have to cut the two female wires and solder them into the holes.
After some trial and errors, I figure out the following:
1. The enable pin is 12 in Sonoff S20. That pin controls the relay. The relay is Normally Open (NO).
2. TX holes and RX holes are incorrectly labeled in the PCB. So TX (RX) should connect to TXD (RXD) in USB-to-Serial board.
3. Connect VCC to 3.3v and Ground to Ground in USB-to-Serial board.
I have a 3D printer made in China running days and nights at home without monitor. I doubt if it has a proper fire hazard protection. So I decided to add some intelligence to override its power supply.
Two features I want:
1. Shutdown the power supply when shit happens. The signal may come from external smoke detector sent by Raspberry Pi.
2. Turn on/off the power supply by Octoprint server running in Raspberry Pi.
I looked around all smart power plugs in the market. They all use proprietary communication protocol and some even pass through my firewall at home. I hate to leave my door open. Call me a security paranoid. But it is never a good idea to leave any possibilities to let any hackers mess around the appliances at home.
So I decided to build one from ground up. All parts I used here are also made in China. I admit there is a logical fallacy -- using made in China components to prevent fire hazard of the appliance also made in China.
The wiring is extremely easy. It doesn't worth my efforts to draw it in fritzing. If you don't know how to wire them, you should NOT try it on your own.
I uploaded ESP8266 specs doc. Go figure it out by yourself.
Note that I used a mechanical relay, instead of solid state relay. You can hear a click sound when you open/close. Depending on your load ( I probably will make the relay closed for a very long time ), solid state relay may need an additional heat sink to control heat build up. I don't want to add it into this small junction box. So I choose the mechanical one.
In addition, I'm waiting for the fuse and the fuse holder from China. So I don't show them here. But you should add one in case power surge.
There is a popular RESTful framework in Arduino called aREST. But several things in aREST are foobar ( fuck up beyond recognition ). So I rewrote it from scratch. If you wonder why, read the README in my bREST framework.
All source code is the 2nd sample in my bREST framework. It also includes a simple Python script for you to test.
Just go to https://github.com/rickyzhang82/bREST
The cost of the DIY home depot power plug is above $35. I found a ready-made Sonoff S20 costs less than $12 online. You can check out my project log regarding to the wiring.
The new firmware for Sonoff S20:
Become a member to follow this project and never miss any updates