Reprogramming a WLAN Power Outlet

Welcome to our new blogpost! Today we will disassemble and reprogram an IoT unit that already exists on the market; a WLAN power outlet. This product can be found in Obi Markts in Germany, but there is still no specific model name for it.

The credits of this blogpost go to: https://heise.de/-4038695

Image 1: WLAN Power Outlet

Image 1: WLAN Power Outlet

This unit has an ESP8266 controller inside and it is easy to upload new firmware. This alternative firmware is called Tasmota.
On its GitHub page, it is defined as "an alternative firmware for ESP8266 based devices like iTead Sonoff with web, timers, 'Over The Air' (OTA) firmware updates and sensors support, allowing control under Serial, HTTP, MQTT and KNX, so as to be used on Smart Home Systems. Written for Arduino IDE and PlatformIO." Link: https://github.com/arendst/Sonoff-Tasmota

Warning!

Warning! This unit is directly powered with 230V.
Please take proper precautions when working with electricity, beware of the risk of injury or death. If you don't have enough experience with electrical units, We'd advise you to stop here!

Otherwise, proceed at your own risk and ensure that you have a safe working environment.

Let's start with today's shopping list:

  • 1x WLAN Power Outlet from Obi Markt
  • 1x CP2102 Serial Converter USB to UART
  • Soldering Station
  • Jumper Cables
  • USB Cable
  • Triangular Slotted Screw Driver**

You’ll also need a PlatformIO membership in order to compile the code.

** This is the screw that you’re going to deal with:

Image 2: Triangular Screw

Image 2: Triangular Screw

First, you can plug in the unit and test it as it is. If you see some lights, it should be working properly.
Unplug the unit now and start to disassemble.

After disassembling the unit, we can easily see that the MCU was placed vertically. You can also see that there is a 16A relay module in the unit. Finally, other electronic components that are responsible for voltage regulation can be observed. This unit is designed in a way that is not overly complex. It’s now time to connect it to our computer.

Image 3: Disassembling the Power Outlet

Image 3: Disassembling the Power Outlet

On the J1 PCB, you will see GND, GPIO, RXD, GND, TXD, RESET and VCC contacts. Now you need to solder some jumper cables on them and connect them as follows:

Image 4: J1 PCB on Power Outlet

Image 4: J1 PCB on Power Outlet

  • GND to GND on your USB/UART converter.
  • RXD to TXD on your USB/UART converter.
  • TXD to RXD on your USB/UART converter.
  • VCC to 3V3 on your USB/UART converter.

Image 5: Power Outlet - USB Interface Connection

Image 5: Power Outlet - USB Interface Connection

Note 1: Switch to Flash Mode by soldering GPIO0 to the GND port next to it.

The following steps will erase the ESP's flash storage and upload the new firmware.

To do this:

  • Install the esptool library:
    $ pip install esptool

  • Clone the repository of Sonoff Tasmota firmware:
    $ git clone https://github.com/arendst/Sonoff-Tasmota.git

  • Erase the firmware of ESP:
    $ esptool.py --port /dev/cu.SLAB_USBtoUART --baud 115200 erase_flash

  • Navigate to following directory under repository:
    $ cd Sonoff-Tasmota-development/sonoff

  • Edit following header file:
    $ nano /user_config.h

  • Update your WLAN credentials at line 62 and 63.

    #define STA_SSID1 "<myWIFI>"
    #define STA_PASS1 "<myPass>"
  • Compile and upload the code:
    $ pio run
    $ cd .pioenvs/sonoff/
    $ esptool.py --port /dev/cu.SLAB_USBtoUART write_flash -fs 1MB -fm dout 0x0 firmware.bin

Note 2: Switch back to Operation Mode by desoldering GPIO0 from the GND port.

Note 3: Switch to Soft-Access-Mode by touching GPIO0 jumper 4 times (<1 second) to the GND port.

Now, the local access point should be visible as "sonoff-1902". Connect to that, and you should see the following page:

Image 6: Sonoff WiFi Parameters

Image 6: Sonoff WiFi Parameters

You will see that the credentials that you already entered are here and you can click on Save.

Image 7: Sonoff Restarting
Image 7: Sonoff Restarting

Connect again to your home network and find the IP address of the power outlet. To do so, you can use any IP Scanner application. Type the IP address on your web browser and proceed:
http://192.168.2.167

Here is the user interface of the firmware:

Image 8: Tasmota Firmware User Interface

Image 8: Tasmota Firmware User Interface

Let's customise it a little bit! Navigate yourself to Configuration > Configure Module > Module Type and choose Generic.

Here are the required settings:

Image 9: GPIO Port Settings

Image 9: GPIO Port Settings

The GPIO4 will be set to LED1. GPIO5 is controlling Relay1 and the GPIO12 is LED2. The reason of selecting GPIO12 as LED2 is for using it as a GND, because LED2 does not exist. GPIO14 will be selected as Button1, so the reset button on the device can be used as relay controller. After clicking on save button, the settings will be saved and the device will restart itself.

Now you can test it by clicking Toggle on the user interface or by pressing the reset button on the device. You will hear the relay module clicking.

Conclusion

That's it! You can basically attach any other sensors like BME280 and others like this, and you can control it via your home network. There are also several possibilities like configuring MQTT server, changing a timer, giving commands by using the console and so on.

Stay tuned for more blog posts from ThingForward crew!

Eren