Lingan SWA1 Plug in Wi-Fi Socket with MQTT (ESP8266)

Lingan SWA1

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:

// Supported hardware modules
enum module_t {
SONOFF_BASIC,
SONOFF_RF,
SONOFF_SV,
SONOFF_TH,
SONOFF_DUAL,
SONOFF_POW,
SONOFF_4CH,
S20,
SLAMPHER,
SONOFF_TOUCH,
SONOFF_LED,
CH1,
CH4,
MOTOR,
ELECTRODRAGON,
EXS_RELAY,
WION,
WEMOS,
SONOFF_DEV,
H801,
SONOFF_SC,
LINGAN_SWA1,
MAXMODULE };

and then at the end of the file under the module setting for Sonoff SC” add a new section as below before the final };

,
 { "Lingan SWA1",    // Lingan SWA1
   0,                // GPIO00 Button
   GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
   0,                // GPIO02
   GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
   GPIO_LED1_INV,    // GPIO04 Blue Led (0 = On, 1 = Off)
   GPIO_REL1,        // GPIO05 Red Led and Relay (0 = Off, 1 = On)
   0,
   0,0,0,0,0,0,
   GPIO_KEY1,        // GPIO13 Button
   0, 0, 0, 0
}

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.

 

 

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

  1. 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

  2. Hi Keith,
    i had the same problem, but got it to work! Newer Lingan SWA1 uses the ESP8285 CHIP!

    I use the Arduino IDE to flash ESPEasy (https://www.letscontrolit.com/wiki/index.php/ESPEasy)
    So i just have to change ESP8266 to ESP8285.
    Maybe this solve your problem too

    The bootloader uses 74880 baud, if you see “csum err” the upper procedure my help 😉
    .Flash uses DOUT

    Regards,
    Stephan

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.