logo elektroda
logo elektroda
X
logo elektroda

Disassembling Tuya-Based UK Smart Plug and Installing OpenBeken Firmware [LN882H] [FL-M118-V1.2]

divadiow 1503 5
ADVERTISEMENT
  • Here I'll take a look inside a generic Tuya-based UK smart plug with energy metering. The Tuya firmware on the main chip will be replaced with OpenBeken.

    This plug can be bought from Ali Express
    Tuya smart plug with energy monitoring available on AliExpress.

    Packaging and product externals:
    Close-up of a UK smart plug with electrical pins and specification label. Smart plug with three prongs and an instruction manual. Open box containing a Tuya smart plug, with the plug inside. Smart plug packaging with manufacturer details. Photo of Tuya smart plug packaging with a barcode.Smart device user manual. A smart plug user manual lies on the carpet, instructions are written in English.

    To open, I trapped the plug in a vice below the joining lip/edge knowing that that's where the two main case pieces would be glued. With some decent, but not extreme, clamping the glue can be heard to give way and crack apart. A thin spudger helps it along. Rotate unit so different points are put under pressure until the glue is cracked in more places than not and the unit can be pulled apart by hand. My device was not glued well so this sample was relatively easy compared to some.
    Close-up of a white UK smart plug with a three-pin connector and visible CE and RoHS certifications. Tuya smart plug in a vise with a tool for opening the casing. Image of a three-pin electrical plug placed in a vise, partially opened with a tool.

    Now that we're inside:
    Interior of a smart plug with electronic components on a circuit board. Interior of a smart plug showing the circuit board and components. Close-up of the interior of an electronic module labeled CB2S with Lightning LN882HKI chip. Interior of a smart plug with visible electronic components Close-up of the interior of a Tuya smart plug showing the module and components. View of the interior of a smart plug with electrical components on the PCB. Interior of a smart plug with electronic components on a circuit board. Close-up of a circuit board inside a smart plug with energy metering. Close-up of the interior of a smart plug with the FL-S138-V2.0 board.

    Some identified main components of interest:
    Belling BL0937 energy metering chip
    FL-M118-V1.1 Lightning Semi Conductor LN882HKI module
    ZK32F 005-HLT 16A@250VAC Shenzhen Zhongke Zhilian Electronics Co.,Ltd. relay
    Main PCB marked as FL-S138-V2.0
    AMS1117-3.3v linear voltage regulator

    The FL-M118-V1.1 module is what we need access to. We need to get to certain contacts on the module to be able to take a backup of the Tuya factory firmware and flash OpenBeken (OpenLN882H).

    Unfortunately RX, TX, 3.3v and GND module contacts are at the rear underside facing the centre of the plug - inaccessible without de-soldering the main PCB from the power prongs.
    Close-up view of the CB2S module mounted on a PCB inside a smart plug.
    To de-solder I added some flux to the solder points and then melted some 63/37 pb solder into the mix to reduce the melting point of the solder used by the factory
    Close-up of the main circuit board of a smart plug with highlighted solder points.
    This process was laborious because the whole power prong draws heat away from the solder point quickly, meaning it has to heat up a lot to get to melting point. Solder wick was used to soak up most of the solder but some stubborn bits remained - keeping the unit fixed in place. Switching sides slowly inching each upwards when melted was the solution.

    With the main PCB free the FL-M118-V1.1 can be de-soldered also using wick/pb/flux.
    Bottom of the smart plug's printed circuit board.

    The "CB2S" label is...interesting. "CB2S" is of course usually reserved for Beken BK7231N modules . This LN882H is a drop-in pad-compatible replacement for CB2S, so maybe that's the link trying to be made. I've labelled all pads for clarity:

    CB2S module board with LN882HKI chip View of the FL-M118-V1.1 module with labeled pins.

    RX/TX/VCC/GND and A9 (needs to be grounded for the flashing boot mode) all soldered ready:
    Electronic module with connected wires on a blue surface.

    Connect to USB-TTL UART adaptor as:
    USB-TTL RX -> Module TX
    USB-TTL TX -> Module RX
    External 3.3V PSU (XL4015 in my case) -> Module 3.3V
    USB-TTL GND + Module GND + A9 + PSU GND (all common ground)

    Insert USB adaptor then power on PSU. Using the attached flashdumper.py script in the attached zip the following was run to start the backup
    Code: Text
    Log in, to see the code


    After approximately 40 minutes the backup is complete - two files are output <filename>.bin and <filename>_otp.bin
    the main backup file should be exactly 2,097,152 bytes.

    Power off, unplug USB, replug USB and power on PSU so OpenLN can be flashed. Using the steps outlined in here we can flash the latest LN882H UART flash file.

    Without A9 grounded the next power-up of the module should lead to an AP broadcast that can be connected to in the browser on 192.168.4.1 after joining to AP. From there OpenBeken can be joined to your wifi through the Config-> Configure Wi-Fi & Web menu. After reboot check you can browse to the DHCP-assigned IP of your device.

    Wi-Fi network icon OpenLN882H_C2B0B167 on available networks list.

    OpenLN882H user interface on a computer screen.

    With the module back in the empty slot on the main PCB, stabilised with a bit of blu-tac, the module can be soldered back. Plenty of flux and small solder blobs, especially with the ground pad which tends to be wider and requires a little more contact to heat up. I have had to de-solder the whole module again in the past before because the ground blob has splurged into neighbouring pads and I couldn't clear it with wick. I always check there isn't continuity between contacts when soldering is complete.

    The result after clearing up flux residue with IPA:
    Close-up of a smart plug's printed circuit board with visible solder contacts.

    After clearing any remaining solder from the main PCB holes, the unit can be soldered back together in position
    View of the interior of a smart plug with FL-S138-V2.0 circuit.

    What remains now is to configure the BL0937, LED, button and relay roles within OpenBeken so the plug is fully operational, exactly like or close to factory behaviour.

    Through the use of the GPIO doctor, multimeter continuity tracing and a process of elimination (GPIO options are limited to just a few on this module), the following has been determined and tested to work;

    Code: Text
    Log in, to see the code


    which makes the whole template, which can be imported through the web application the following:

    Code: JSON
    Log in, to see the code


    BL0937 metering can be calibrated as per this post: https://www.elektroda.com/rtvforum/topic4030107.html#20920434

    What remains:
    Epoxy resin glue plug casing back together
    Setup MQTT/Home Assistant https://youtu.be/pkcspey25V4?si=hPcIBAFMfHqR22sa
    Ensure PowerSave 1 is set in startup command or autoexec.bat:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md



    Notes since initial draft

    I note that the main PCB Marking starts FL- (FL-S138-V2.0) as does the marking on the module (FL-M118-V1.1). The name on one of the stickers on the box is for a Shenzhen Farylink Technology Co.,Ltd. It would be reasonable to assume FL = Farylink, also the store on Ali Express it was bought from. I don't think it would be a stretch to assume similarly-named modules like the FL-M61 V2, FL_M99_V1/2/3 are all Farylink.

    Electronic module with an integrated circuit and soldered components FL-M61 V2 module with visible IR620S1 chipset.

    How to flash FL_M99_V1/FL_M99_V2/FL_M99_V3/CB2S WiFi module - BK7231N Tuya Home Assistant guide
    https://fcc.report/company/Shenzhen-Farylink-Technology-Co-L-T-D



    UART boot log B9 is not routed out to a pad on the module so I had to use my sewing needle probe to capture the log, which is:

    Code: Text
    Log in, to see the code




    The factory firmware backup is file Tuya_3.5.4_Farylink-UK_Plug_(Smart-Plug-schemaID-g2xobg)_cptnnkbvpdxkkcvy_FL-M118-V1.1_1.0.0.bin at https://github.com/openshwprojects/FlashDumps/tree/main/IoT/LN882H




    Tuya app paired device pics

    Tuya app screen displaying smart plug energy usage information. Schedule screen in Tuya app with the option to add a new schedule. Screenshot of the Tuya app showing energy monitoring. Screenshot of Tuya app settings for a smart plug.

    Cool? Ranking DIY
    About Author
    divadiow
    Level 34  
    Offline 
    divadiow wrote 2829 posts with rating 490, helped 255 times. Live in city Bristol. Been with us since 2023 year.
  • ADVERTISEMENT
  • #2 21437194
    p.kaczmarek2
    Moderator Smart Home
    This is the first time I see CB2S module with non-Beken chip. So far I've only seen like 3 types of CB2S:
    - original CB2S (the most common one)
    - CB2S with BK7231M (different Beken keys, now supported by OBK)
    - CB2S with incorrect silk screen (wrong VDD, GND, UART placements)
    And your CB2S is now the fourth kind, interesting. This may certainly confuse beginners.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21437215
    divadiow
    Level 34  
    maybe it's their way of marking it as a CB2S replacement for interchangeable use internally within their product dev team? Dunno.

    What's also confusing, and I forgot to mention in the notes, is that the boot log looks like it contains all the pin assignments. eg:

    Code: Text
    Log in, to see the code

    but they don't line up with the correct GPIO# or IC pin# so 🤷🏼‍♂
  • ADVERTISEMENT
  • #4 21437502
    p.kaczmarek2
    Moderator Smart Home
    Do they match with the pin indexes as if it were a true BK7231N module? I mean, is the P23 on BK7231N CB2S location the same as bt1_pin here?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21437530
    divadiow
    Level 34  
    good question! that would make sense.
    ...
    it started to look like that was the answer, until..

    Comparison table with columns related to Boot Log, FL-M118-V1.1, OBK, and Boot Log Match to CB2S.
  • #6 21437564
    p.kaczmarek2
    Moderator Smart Home
    but wait, LN882H has pins in port + index format:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/hal/ln882h/hal_pins_ln882h.c
    Code: C / C++
    Log in, to see the code

    and OBK mapping (indexes) is our own idea, maybe Tuya has there a different table order
    Helpful post? Buy me a coffee.
ADVERTISEMENT