-->
Page 1 of 1

ECO or KAB outlet hack for a Control Your Own Outlet

PostPosted: Sun Aug 21, 2016 5:48 pm
by Ecoli-557
This is an adaptation of the Sonoff code I already posted and applying here to these inexpensive wifi controlled outlets. You can buy them from Amazon, Walmart, and probably Ebay.
They are made by KAB, a Chinese company. They are ESP8266 based and are perfect to modify for your own uses. As with the Sonoff module, DO NOT FLASH WHILE PLUGGED INTO A SOCKET!
You will need to remove the 4 screws located on the back of the outlet, then the 3 screws inside on the front half which will expose the ESP8266. You will need to tack-solder 4 connections (either cut piece of resistor wire or other wire) for 3.3v, GND, RXD, TXD from your usual USB to 3.3v data interface.
The pins are noted below, note that it is not a normal ESP8266.
Pin# USE
1 GND
2 Power 3v3
3 CHIP_EN reset sw
4 XPD_DCDC / GPIO16
5 MTMS / GPIO14
6 MTD1 / GPIO12
7 MTCK / GPIO13 power sw, active LOW
8 MTD0 / GPIO15 Y to main board, D8 - Power LED
9 GPIO2 D3- wireless signal LED

10 GPIO0
11 GPIO4
12 DVDD / GPIO5
13 U0RXD
14 U0TXD
15 EXT_RSTB
16 GND
17 TOUT / No Connection?
18 GND
-------------------------------------------
Pin 1 is the top left with antenna at top
Pin 9 is lower left
Pin 10 is lower right
Pin 18 is upper right

Once all your connections are made, you will need to ground GPIO0, then press the reset switch, then remove the ground connection at GPIO0 and flash ver3.0.
when done, remove all the extra connections you made, plug it into a SWITCHED outlet strip, then turn ON the outlet strip.
Look for the familiar AP broadcast, sign in to the settings page, and change the wifi information to suit your environment.
Once you have your new IP adress into the outlet, load the following code:
Code: Select all'Outlet code (based on Sonoff code) to get the device working under Build 3.0 of ESPbasic.
'Continued thanks to Electroguard and Mike - this would have taken much longer.
'A good starting point for some Home Automation?
deviceName = read("DName")                  'Outlet device has a name such as "living room fan"
if deviceName == "" then deviceName = "Outlet"            'Filler
RelayPin = 15                        'IO pin for the relay
LedPin = 2                        'WiFi LED
LocalButton = 13                     'The 'power' button
RelayLogic = 0                        'Means relay is ACTIVE HIGH
LedLogic = 0                        'Means LED is ACTIVE HIGH

[top]
cls
io(po,2,0) 'Turn ON wifi LED so you know we have power, could be used when the outlet actually joins the wireless network
print deviceName & "  "
textbox Status
interrupt 13, [Pressed]                     'Hardware button pressed?  Branch
html "<BR>"
Button "Toggle", [Toggle]                  'Web buttons pressed?  Branch
Button "ON", [on]                     'Web buttons pressed?  Branch
Button "OFF", [off]                     'Web buttons pressed?  Branch
html "<BR>"
button "Settings", [settings]                  'Web buttons pressed?  Branch
wait


[on]                           'Get here by wanting to turn ON
if RelayLogic == 0 then io(po,RelayPin,1) else io(po,RelayPin,0)   'Turn ON the relay and power LED
goto [set.Stat.indicator]                  'Go update the status on the web screen

[off]                           'Get here by wanting to turn OFF
if RelayLogic == 0 then io(po,RelayPin,0) else io(po,RelayPin,1)   'Turn OFF the relay and power LED
goto [set.Stat.indicator]                  'Go update the status on the web screen

[Toggle]                        'Get here by wanting to toggle
if io(laststat,RelayPin) = 0 then io(po,RelayPin,1) else io(po,RelayPin,0)   'If ON, then turn OFF and vice versa
goto [set.Stat.indicator]                  'Go update the status on the web screen
end if

[Pressed]                        'Got here cuz we pressed the hardware button
if io(laststat,LocalButton) = 1 then goto [Toggle]         'Wait until the button is released for debounce
goto [top]                        'Done, so start over

[set.Stat.indicator]                     'Get here because we need to update the web status
if io(laststat,15) = 0 then Status = "OFF" else Status = "ON"      'Get the correct text on the box
wait


[settings]                        'Here because we want to change the settings
cls
html "Device name"
textbox deviceName
button "Save", [save.set]
wait

[save.set]                        'To ensure we put something in here
if deviceName == "" then
   print "device name must be specified"
   wait
else
write("DName",deviceName)                  'Write to flash
end if
goto [top]                        'Done, so start over



This code functions the same as the Sonoff code except for one thing: THE LOCAL POWER BUTTON DOES NOT WORK!
I have gone through this, it IS connected to GPIO13 (well, pretty sure) but I cannot get it to work.
Anyone who fixes this, please share.

Enjoy!

Re: ECO or KAB outlet hack for a Control Your Own Outlet

PostPosted: Mon Aug 22, 2016 11:50 am
by Ecoli-557
Wooops! The images came out in reverse...... Start at the last one and work your way UP.

Re: ECO or KAB outlet hack for a Control Your Own Outlet

PostPosted: Sun Aug 28, 2016 4:39 am
by forlotto
Interesting to note these outlets are esp based then go figure way cool stuff.

I have a couple of proposals to shorten things up a bit and possibly get your button working.

Use your button pin as an interrupt to shut off the mains power so once interrupt is triggered you will want to go to a sub routine to shut on or off the outlet.

To easily know the on or off status of your outlet you can use this on the pin that turns on and off the relay.

io(laststat,relaypin)

lets say for a moment that pin 4 ways the relay pin.

io(laststat,4) no need to do the extra code for logic level but it is good for others to see how to track variables.

There is a slight bit of confusion on how to handle things I hope I sorted them out to point you in the direction of a fully working unit.

Excellent project good find I would say you are an expert warranty voider and tinkerer.

Great work!

Re: ECO or KAB outlet hack for a Control Your Own Outlet

PostPosted: Sun Aug 28, 2016 2:16 pm
by Ecoli-557
Thanks Forlotto, but that is what I used, the button pin just doesn't seem to work and I don't know why....

Another update, I just received additional controlled outlets from Walmart (yes, Walmart) and it looks like the power circuitry is all installed, so, with appropriate software added, it will tell you how much power you have used. The power (amperage) is serial streamed to the ESP - I don't have any of that code started.

The Walmart brand is called 'WorkChoice' and the part numbers are CT-065W and RC-031W. Just do a Google search and it will pop-up, then just place an order, wait for them to arrive, and void their warranty!

If anyone gets the buttons to work, post it so we can all use it.

Regards