This is another cheap plug in Wi-Fi mains socket that uses the ESP8266, comparable to the Sonoff S20. Cost was £8.34 + £2.34 shipping to the UK from TVC-Mall. It is also available from Banggood for a little more and is starting to show up on eBay now too.

I didn’t try the standard software/firmware combination, it’s likely to be as rubbish as they usually are and I need MQTT support so I jumped straight into flashing something more useful. This one isn’t supported as standard by my favoured firmware TASMOTA but it is easy to add it in.

Rated current is 10A, maximum power 2000W. It has an FCCID (2AJK8-SWA1) and is CE marked.

Relay and red LED are on GPIO5
Blue LED is on GPIO 4
Button is on GPIO 13

Opening the case is easy, first remove the screw in the middle of the 3 pin plug and remove the plate and you can then access the four screws, once they are removed the case just unclips.

Remove plate to access screws

The ESP8266 is on a separate board with the push button and LEDs, be careful with the 3 wires linking it to the mains board as they seem to be quite fragile and I had to resolder two of them. It’s probably easiest to unscrew the board attached to the front of the housing but there is no need to take the whole thing to bits.

You don’t need to go this far.

There are pads for a programming header but unusually the power is to the input of the AMS1117 3V3 regulator and not directly to the 3V3 input of the ESP8266. I just fed 5V into the header but you could also tap 3V3 onto the output of the regulator.

Pinout

Making it work with TASMOTA

I’ve been standardising on TASMOTA for as many of my ESP8266 devices as possible, it doesn’t support the SWA1 as standard but it only requires a couple of modifications to add it, both are in the file sonoff_template.h

First add an entry for the SWA1 under “Supported hardware modules” at the bottom, before MAXMODULE as below:

Now when you have flashed the code to the device you will have a new entry in the module config which sets the correct GPIO pins for the SWA1.

Module type in TASMOTA

Flashing

Due to the positioning of the programming header and the lack of room in the case I decided not so solder pin headers on this time and just held one in place while flashing it and fed 5V to the power input as it goes through the 3V3 regulator. Don’t forget to ground the GPIO0 connection to get into programming mode.

Header in place for flashing firmware

When using TASMOTA I always preset my Wi-Fi credentials in user_config.h and then upload with PlatformIO. After flashing, restart it and connect to the web interface and set the correct module type, MQTT settings and so on.

Usage

Controlling via MQTT is then just a matter of sending an MQTT message with a payload of “on” or “1” to the topic “cmnd/lingan-swa1/power” to turn it on and “off” or “0” to turn it off. A payload of “toggle” will toggle the output. The device will publish the status to “stat/lingan-swa1/POWER” (examples assume you set the topic in the device conifg as “lingan-swa1”). See the TASMOTA Wiki here for more MQTT features.

Related

7 thoughts on “Lingan SWA1 Plug in Wi-Fi Socket with MQTT (ESP8266)”

Hi Nathan,
Nice write up 🙂 I’ve been trying to do this for some time but I can’t even get a blink sketch running on it 🙁 The code uploads but does not appear to run, as no LEDs blink or relay clicks and there is no serial ouput. Can you think of any reason why it would not run the code?
Regards,
Keith

i have flash with Atom (PlatformIO) and the message means success. My plug connect to wlan and become a ip and i can ping it. But no website is runnning. The port 80TCP is open and i can connect with telnet but no data will be send from the plug. W10 X64 and FTDI232 USB used.
thanks for help and ideas