logo elektroda
logo elektroda
X
logo elektroda

[LN882H] CB2S WiFi Module in Tuya 1CH Mini Smart Switch: Behavior After Power Loss

rchristescu 132 0
ADVERTISEMENT
  • #1 21754104
    rchristescu
    Level 7  
    Here is the teardown of a Tuya smart switch.
    Purchased from Link.

    1CH Mini Smart Switch housing with terminal labels and technical specs White sensor with circular holes, placed on a blue backgroundMini Smart Switch with box and instruction manual on a green cutting mat Small Wi-Fi switch, packaging, and user manual on a green cutting mat

    Electronic module with XINCHUANGZHI relay and green screw terminalGreen PCB with a tactile switch, solder points, and labeled connection terminalsCB2S module with integrated chip and Ethernet port on blue PCBPCB close-up with LIGHTNING LN882HKI chip and 40 MHz quartz resonator

    The wifi module is CB2S, but the chip is not BK7231N, it is LN882H.
    I tested the switch with original firmware, without adding to Tuya app. Short pressing back button toggle the output. Same when connecting or disconnecting S to N. If output is ON and main power is disconnected, when connected back output goes ON. So far, as expected.
    But, if output is OFF, disconnect mains power and connect back, output goes ON for a millisecond before switching back to OFF. Strange.

    I desoldered wifi module, flash with BK7231Flasher firmware OpenLN882H_1.18.211.bin, then solder back wifi module.
    Pin A9 shall be connected to GND for the entire flashing process.

    Breadboard with jumper wires and an electronic I2C module connectedClose-up of blue PCB with colored wires soldered to labeled pins

    ADVERTISEMENT


    Original firmware:readResult...-01-13.zip Download(603.83 kB)

    The flasher was not able to extract Tuya configuration.

    Screenshot of Tuya Config Quick Viewer showing missing GPIO configuration

    So, I used GPIO Doctor - very useful tool, btw.
    Code: JSON
    Log in, to see the code


    Device works as expected, except is does not retain relay status after disconnecting from mains power.
    Actually it has a strange startup behavior.
    If I put -1 in Configure Startup, it starts ON if it was OFF and it starts OFF (after a short ON) if it was ON.
    If I put 0 it starts ON.
    If I put 1 it starts OFF (after a short ON).
    If I put "power off" in startup command, it starts ON.
    If I put "power on" in startup command, it starts OFF (after a short ON).

    But if I manually run "power on" / "power 1" or "power off" / "power 0" command, it behaves normally.


    Below is the log when starting from OFF, with -1 on Configure Startup and no startup command:
    
    Info:MAIN:Main_Init_Before_Delay
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 103 changes count.
    Error:CMD:no file early.bat err -2
    Info:GEN:PIN_SetupPins pins have been set up.
    Info:MAIN:Main_Init_Before_Delay done
    Info:MAIN:Main_Init_Delay
    Info:MAIN:Main_Init_Delay done
    Info:MAIN:Main_Init_After_Delay
    Info:MAIN:Using SSID [********]
    Info:MAIN:Using Pass [********]
    Error:HTTP:Created HTTP SV thread with (stack=2048)
    Info:MQTT:MQTT_RegisterCallback called for bT LN882H_01/ subT LN882H_01/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT obks/ subT obks/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/LN882H_01/ subT cmnd/LN882H_01/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/obks/ subT cmnd/obks/+
    Info:MQTT:MQTT_RegisterCallback called for bT LN882H_01/ subT LN882H_01/+/get
    Info:MQTT:MQTT_RegisterCallback called for bT homeassistant/ subT homeassistant/+
    Info:CMD:CMD_StartScript: started @startup at the beginning
    Info:CMD:LFS_ReadFile: failed to file autoexec.bat
    Info:CMD:CMD_StartScript: failed to get file autoexec.bat
    Info:BERRY:[berry init]
    Info:BERRY:[berry start]
    Info:BERRY:[berry end]
    Info:BERRY:[berry start]
    Info:BERRY:be_pcall fail, retcode 3
    Info:BERRY:top=3
    Info:BERRY:stack traceback:
    Info:BERRY:   
    Info:BERRY:string
    Info:BERRY::1:
    Info:BERRY: in function `
    Info:BERRY:main
    Info:BERRY:`
    Info:BERRY:stack[1] = type='function' ()
    Info:BERRY:stack[2] = type='string' (import_error)
    Info:BERRY:stack[3] = type='string' (module 'autoexec' not found)
    Info:BERRY:[berry end]
    Info:MAIN:Main_Init_After_Delay done
    Info:MQTT:Channel has changed! Publishing 1 to channel 1 
    Info:MAIN:Time 1, idle 0/s, free 82144, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 2, idle 0/s, free 82144, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 3, idle 0/s, free 82144, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 4, idle 0/s, free 82144, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 5, idle 0/s, free 82144, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Registered for wifi changes
    Info:MAIN:Connecting to SSID [********]
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Time 6, idle 0/s, free 81312, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:MAIN:Time 7, idle 0/s, free 72792, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:mqtt_userName ********
    mqtt_pass ********
    mqtt_clientID LN882H_01
    mqtt_host ********:1883
    Info:MAIN:Time 8, idle 0/s, free 78368, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to LN882H_01/+/set
    Info:MQTT:mqtt_subscribed to obks/+/set
    Info:MQTT:mqtt_subscribed to cmnd/LN882H_01/+
    Info:MQTT:mqtt_subscribed to cmnd/obks/+
    Info:MQTT:mqtt_subscribed to LN882H_01/+/get
    Info:MQTT:mqtt_subscribed to homeassistant/+
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic LN882H_01/1/get
    Info:MQTT:Publishing val LN882H_01 to LN882H_01/host retain=0
    Info:MAIN:Time 9, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val OpenLN882H 1.18.211 Nov 14 2025 13:26:27 to LN882H_01/build retain=0
    Info:MAIN:Time 10, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 00:50:c2:17:e5:d4 to LN882H_01/mac retain=0
    Info:MAIN:Time 11, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 65.16 to LN882H_01/temp retain=0
    Info:MAIN:Time 12, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val ******** to LN882H_01/ssid retain=0
    Info:MAIN:Time 13, idle 0/s, free 78336, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 0 to LN882H_01/sockets retain=0
    Info:MAIN:Time 14, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val -65 to LN882H_01/rssi retain=0
    Info:MAIN:Time 15, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 15 to LN882H_01/uptime retain=0
    Info:MAIN:Time 16, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 78456 to LN882H_01/freeheap retain=0
    Info:MAIN:Time 17, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Publishing val 192.168.0.191 to LN882H_01/ip retain=0
    Info:MAIN:Time 18, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:Channel has changed! Publishing 1 to channel 1 
    Info:MQTT:Publishing val 1 to LN882H_01/1/get retain=1
    Info:MAIN:Time 19, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic LN882H_01/1/get
    Info:MAIN:Time 20, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 21, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 22, idle 0/s, free 78456, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 0/0  
    
  • ADVERTISEMENT
ADVERTISEMENT