Hacking an ESP8266 Based Smart Switch
06/03/2023
Some time ago a neighbor gave me a few WiFi Smart Sockets because
he was frustrated with them and couldn't use them on his 5G WiFi network.
Since I had both 2.5GHz and 5G networks running at my house I gladly accepted them.
After trying to use them to run a couple of lights around the house I began to understand my neighbor’s frustration.
Whenever the power failed, even momentarily, the devices would
try to connect with the app on the phone (I guess to get the correct time of day and such)
But if my phone had automatically connected to my 5G network it couldn’t do that
and the app just pushed a failure notification to the phone.
Then I had to switch networks, and re-program the devices.
So they sat around on my desk for a long time until I decided to open one up and see what’s inside.
I immediately recognized the little board inside as an ESP8266 board.
Since all the I/O signals were plainly marked I added a 6 pin connector with the signals required to re-program it.
(GND, 3.3v, Reset, GPIO-0, TXD, RXD )
Although the software I used to flash firmware to other ESP8266 devices seemed to
communicate with this device successfully, the simple “blink” program I tried to run on
it simply would not go. It took a couple of days switching settings to eventually find the one
combination that would work.
(changing the makefile to use DIO mode instead of QIO mode to program the flash memory did the trick)
Once that was successful, I was on my way adding code to make this device a customized
Smart Socket. I don’t think I’ve improved the usefulness of this device but now the program
was mine to do whatever I wanted to with.
Instead of the closed Tuya app the original firmware used, I now communicate to the device
with a simple Telnet (TCP) terminal app. (I’m using Juice SSH but most any terminal will do)
Developmet was going along great and I was slowly adding bits of code & functionality to this device
when suddenly the WiFi stopped working (no code error messaged, just no network to connect to)
If I rolled back the code to a very early version the WiFi started to work again.
So I started all over, re-adding my bits of code till it happened again.
On the 3rd re-build of the code I finally found the bit of code that was breaking the WiFi.
The NONOS SDK has a function called system_get_vdd33() that would read the supply voltage.
I had hoped to use this to detect when the power was going down and attempt to write the
Time of Day to flash memory. I hoped that, in the case of a momentary power “blip” I could
restart and re-load the time losing only a second or two.
To do this I needed to call this function every millisecond and the WiFi system apparently
would have none of that… In my new design, the WiFi is OFF during routine operation so
I was able to still use this feature.
I’m using the same eclipse environment to build code for this device as I previously used to
program the ESP8266-12F module
The new code creates a Soft Access Point (like a router) and runs a Telnet (TCP) server
on that access point when in configuration mode.
Using a terminal menu system I’m able to set the Time of Day and setup the On/OFF
schedule of events (up to 5 events) as well as controlling the current ON/OFF state of whatever is plugged into it.
Once everything is set up I turn the WiFi off and simply monitor the time and respond to
scheduled events.
I’m attaching download links for the project code. Keep in mind that this is
an eclipse project using the ESP8266 NONOS SDK NOT Arduino code.
Description of download links:
uart_menu_ap_ss5.zip Smart Socket eclipse project