Turn a Cheap WiFi Plug Into an OpenHAB ESP8266 Switchable Plug

by instrbles37568 in Circuits > Arduino

14532 Views, 73 Favorites, 0 Comments

Turn a Cheap WiFi Plug Into an OpenHAB ESP8266 Switchable Plug

wrkchc.jpeg
IMG_20160925_171540.jpg

These things out of the box are cheap and insecure. These plugs use no encryption and connects to servers openly over the web. To make things worse, each device is usually authenticated and identified using a standard serial or MAC address. Basically, any user should be able to use anyone else's switch with a little guess work.

Next: Thank you!

  • Thank you to The Great Geekery for doing the research and discovering the pinout
  • Thank you to the writers of ESP Easy and their work for a solid DIY IOT using ESP8266

Parts:

WARNING!

High voltage may cause severe personal injury or death disconnect all power supplies before opening the electrical enclosure or servicing.

Wire It Up

IMG_20160925_163454.jpg
1.png
2.png

Solder the esp, on the plug, to the header as shown in the pictures. I bridged the ground to an extra pin on the header so that I could isolate the GPIO 0. You will need to ground the GPIO 0 in order to program the esp chip. Remove the ground in order to test and read the serial log using Putty or similar.

Change the Firmware the Plug With ESP Easy

IMG_20160925_170436.jpg
Capture01.PNG
Capture02.PNG
Capture03.PNG
IMG_20160925_172355.jpg
IMG_20160925_173404.jpg

Download ESP Easy (Current version is 120 at the time of this Instructable)

ESP Easy firmware Mainpage for ESP Easy is here in case link is broken.

Unzip the contents. I recommenced using c:\Esp8266

Edit the flash.cmd file to direct the script to your current directory. (line 7 in code below)

@echo off
set /p comport= Comport (example 3, 4, ..) : set /p fsize= Flash Size (example 512, 1024, 4096) : set /p build= Build (example 71, 72, ..) : echo Using com port: %comport% echo Using bin file: ESPEasy_R%build%_%fsize%.bin C:\Esp8266\esptool.exe -vv -cd nodemcu -cb 115200 -cp COM%comport% -ca 0x00000 -cf ESPEasy_R%build%_%fsize%.bin pause

Plug the USB serial adapter into your newly wired header. Make that the VCC and GRN match. Once pluged your PC will assign the adapter a port. Make note of this port for the flashing procedure. Port 5 in my case.

Double click the Flash.cmd file to start the flashing procedure. Type in:

  • your port number (5 in my case)
  • Flash Size: 512
  • Build: 120 (as of the date of this post)

If all goes well, the serial adapter and ESP will start to blink as the firmware is being flashed to the ESP.

That's it, ESP Easy is on this plug now. Button it up and plug it into the wall to setup. I ended up removing the push button to make room for the header. I think that I'll wire it up much tighter on the next one.

Setup ESP Easy and OpenHab

Capture.PNG

Follow the Easy Setup Wizard instructions to get your ESP connected to your network.

I've included a shot of my setup that goes with my previous tutorials.

RECOMMENDATION! Change the "WPA AP Mode Key" to a complex password. If you don't and your ESP looses connectivity to your network, it will create the default network and open up to anyone within range. I pull my random passwords from GRC's Ultra High Security Password Generator.

Here is my OpenHAB code:

Sitemap (I placed this switch into a "Quick Access" Group)

Frame label="Most Used" {<br>        Group    item=Quick_Access label="Quick Access" icon="quick_access"
        Group    item=Masters    label="Master Switches"    icon="MasterSwitch"    
        Group    item=Weather label="Weather" icon="weather"        
        Group    item=Test label="Test" icon="TestIcon"
    }

Item

Switch	WrkChc_Portable_Plug01	"Play Room Laser Light"	(All,Quick_Access)        {mqtt=">[mymosquitto:/WrkChc01/gpio/15:command:ON:1],>[mymosquitto:/WrkChc01/gpio/15:command:OFF:0]"}<br>

As you can see the ESP Name matched the mymosquitto protocol and we are using GPIO 15 for the relay.

Enjoy a secure switch!