logo elektroda
logo elektroda
X
logo elektroda

BK7231N and CB3S: Detailed Guide on LoraTap SC400W-EU Switch Board Desoldering and Flashing

paulomac1000 6393 53

TL;DR

  • BK7231N-based LoraTap SC400W-EU curtain/blinds switch board was opened, identified, and prepared for flashing through the CB3S module.
  • Instead of desoldering the soldered board pins, the board was lifted, RX/TX were connected, power went to the outer pins, and flashing started by shorting GND to CEN.
  • Pin mapping used P6 WifiLED_n;0, P7 Btn;2, P8 LED_n;2, P9 Btn;1, P14 Rel;3, P23 Btn;3, P24 LED;3, and P26 Rel;1.
  • The flashing application could not read settings automatically, so all pins had to be found manually and entered into the configuration JSON.
  • A custom /autoexec.bat restored OPEN/CLOSE/STOP logic, with buttons auto-disabling after 60 seconds, reset lit for 1 second, and RESET toggling the buttons off.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • #31 20990453
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    hezipereg wrote:
    Quote:
    You need to create a branch. Issues are irrevelant for creating PR.

    I don't have the open branch button available.

    My Github knowledge is not good but I think that you need to first fork my repository. Then you will be able to open PRs from your fork to main repo.


    hezipereg wrote:

    Quote:
    run build in cygwin

    I tried to build using wsl. I get: ./b.sh: 1: ./build_app.sh: not found

    Please double check paths, here is how it looks on my side:
    Screenshot of a folder with various script and document files in Windows File Explorer.
    Screenshot of the apps folder in Windows with highlighted paths to location.

    Added after 2 [minutes]:

    BTW: On my side build in wsl fails, hmm:
    Screenshot of a terminal showing compilation errors of a script in Linux.
    Linux console showing compilation errors in the OpenBK7231T_App repository.
    I don't know why, we may want to investigate that. I know that it works in cygwin.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #32 20993164
    hezipereg
    Level 7  
    Posts: 19
    Any progress with figuring out why it is not working in wsl?

    I also get the following error:
    Screenshot of a compilation error in a Linux terminal.
  • ADVERTISEMENT
  • #33 20993226
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    I didnt' have time yet, I think it would be faster to just install Cygwin.

    There was also an alternative docker build system on the repository somewhere.
    Helpful post? Buy me a coffee.
  • #34 20994640
    hezipereg
    Level 7  
    Posts: 19
    OK succeeded to build on wsl.
    The problem was https://askubuntu.com/questions/133389/no-such-file-or-directory-but-the-file-exists
    Bottom line: need to install lib32z1 using
    Code: Bash
    Log in, to see the code

    Also needed to install python-is-python3:
    Code: Bash
    Log in, to see the code

    Waiting for further guidance.
    BTW, how can I perform incremental build? Running b.sh rebuilds.
  • #35 20995202
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Good job, I will post that information in a form of miniguide for compiling on WSL soon. I didn't know that.

    Regarding rebuild, I think that @btsimonh added the recursive "delete generated files" in the build script somewhere because there was some kind of issue. I am not sure.

    I do the 90% of the development on Windows port in MSVC and test things through the unit tests like:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/src/selftest
    I only upload to the physical device for the final testing.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #36 20995745
    hezipereg
    Level 7  
    Posts: 19
    If you want me to write the shutter driver, I need you to give me some guidance.
  • #37 20995747
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Sure, how can I help you futher? Just ask and I will try to help the best I can.

    Do you want to develop first in Windows, like I do, or do you want to test everything on BK7231, as some people prefer?
    Helpful post? Buy me a coffee.
  • #38 20995782
    hezipereg
    Level 7  
    Posts: 19
    I will develop on Windows.
    I need to know what are these driver function are all about:
    Code: C / C++
    Log in, to see the code
  • #39 20995798
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    hezipereg wrote:
    I will develop on Windows.

    Do you need help with compiling OBK to run on Windows (as a simulator with self tests)?

    hezipereg wrote:

    Code: C / C++
    Log in, to see the code

    This is called once when a driver starts. You can create custom commands there via CMD_RegisterCommand. The registered commands can be later called via MQTT, etc.

    hezipereg wrote:

    Code: C / C++
    Log in, to see the code


    This is called on every second. I am not sure if you need it.

    hezipereg wrote:

    Code: C / C++
    Log in, to see the code


    This is used to add custom information to HTTP page. Maybe you can use it to display the percentages, etc, how much shutters are open.


    hezipereg wrote:

    Code: C / C++
    Log in, to see the code

    This is called on quick tick, every 25ms. See QUICK_TMR_DURATION . Use this to update your timer counters and when they overflow, stop the shutter operations.

    hezipereg wrote:

    Code: C / C++
    Log in, to see the code

    This is called when a driver is stopped. This is often ignored, as we just assume user will restart the device.

    hezipereg wrote:

    Code: C / C++
    Log in, to see the code

    This is a channel change callback in case that you might need that. If you decide that you want to use some channel as as shutter percentage level, you may watch for it to change.

    For more specific information, please see our drivers directory here:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/src/driver
    Just open any driver file of interest and check out how are init/everysecond/quick tick functions used.

    Keep in mind that there are many possible approaches to implementing the shutters driver and even I don't know which is the best. You can use our SDK in many ways, just find the one that suits your needs best.
    Helpful post? Buy me a coffee.
  • #40 21101397
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    Hello you.

    Till today I had a controller working about 2 years and suddenly disconnected from the Wifi network. I can not normally add to Tuya :( so I decided if it is possible to do an Open Beken?


    Hover up down pause and light.

    Control panel with four buttons: up, pause, light, down. .
  • #41 21101398
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    What WiFi module is inside?
    Helpful post? Buy me a coffee.
  • #42 21101441
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    >>21101398 I haven't had a chance to open it yet. The question is whether it is the software that has crashed somehow? Will an OB help hmmm
  • #43 21101445
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    It is hard to assess remotely. It is also possible that a capacitor in the power supply is simply damaged. In that case the Tuya will continue to work after repair. In such a situation, the repair looks like here:
    How do I fix a smart device that chirps, squeaks and makes strange noises? .
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #44 21101451
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    Even strangely reports this device after bluetooth probably in the application. No drawing and no name :/

    App interface for adding a new Bluetooth device

    Printed circuit board with electronic components and a module labeled CBU. Electronic module with coils and connectors held in a hand. Image of a round circuit board with visible electronic components and soldering. Image of a round circuit board with visible electronic components and soldering.
  • #45 21108076
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    There is a problem because the device reports as New Device when it should be a Curtain Switch.
    I have checked the capacitors and replaced them without any change.
    I still need to change the software :) .
    Can I ask for help?
  • #46 21109623
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    You can upload OpenBeken on it, but that MCU there is on the UART pins? So it's a TuyaMCU device?
    Helpful post? Buy me a coffee.
  • #47 21109628
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    >>21109623 .
    I do not know TuyaMCU... it worked normally with tuya app.
    I have something to upload the soft so maybe check.
    Where can I generate the soft? You have already helped me in the past with the light switch flies nicely
  • #48 21109635
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Our flasher downloads the soft from the internet:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    But first check with a multimeter if the RX and TX from the WiFi module is not connected to this microcontroller by any chance?
    Helpful post? Buy me a coffee.
  • #49 21109641
    PSlowik
    Level 12  
    Posts: 80
    Rate: 2
    >>21109635 ok I'll get back to you in about 2 hours :) thanks
  • #50 21109644
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    I recommend looking through the topic on TuyaMCU, it will definitely help:
    TuyaMCU flashing, installation and configuration guide - configure dpID for Home Assistant .
    Helpful post? Buy me a coffee.
  • #51 21477597
    antonioriosarroyo
    Level 5  
    Posts: 10
    Hello, good morning. Sorry for the message, but I find the blind drivers very interesting. How's it going? I'm interested. Thank you very much.
  • #52 21484624
    antonioriosarroyo
    Level 5  
    Posts: 10
    Hello, very good, just thank @rodionzhitomirsky and @gliga69 for your code. I modified it and it works very well. Both the physical and web buttons work correctly, and the blind percentage seems great. I have it on a Loratap SC400W-EU, but don't trust the PINs; each Loratap is unique.

    I'm leaving the code here, with a comment on where to put your PINs, in case anyone is interested.

    Translated with Google, in case it's not clear.
    
    clearIO
    // ====== CONFIG ======
    // Used to hold the delay value in millis for sleeping during closing or opening loop
    // Play with your curtain and find the right value for this delay
    
    SetChannel 8 100
    
    // Delay to wait (millis) before starting to move the curtain after we close both relays
    // maybe it is not necessary, but I prefer it to be to ensure we do not have
    // both open and close relays powered simultaneously:
    SetChannel 7 500
    
    // MQTT stuff
    MqttClient lr_curtain_2
    MqttHost <YOUR_HA_MQTT_HOST>
    MqttUser <YOUR_HA_MQTT_USER>
    MqttPassword <YOUR_HA_MQTT_PASSWORD>
    
    // ====== END OF CONFIG ======
    
    // set channels 7, 8 and 9 to be private, so that we do not spend resources to publish their values:
    SetChannelPrivate 7 1
    SetChannelPrivate 8 1
    SetChannelPrivate 9 1
    
    // HIde relays from GUI
    setChannelVisible 1 0
    setChannelVisible 3 0
    
    // We start the main opening/closing loop with a delay
    // and than immediately have a calibration delay
    // so, let's decrement the calibration delay to not have them both
    // at the beginning of the loop:
    
    addChannel 7 -$CH8 0 5000
    
    PowerSave 1
    //startDriver ntp
    
    // set pins and channels
    
    // Pin 7 is connected to opening relay
    SetPinRole 7 Rel
    // we also connect it to channel 1
    SetPinChannel 7 1
    SetChannelLabel 1 "Up"
    
    // Pin 6 is connected to closing relay
    SetPinRole 6 Rel
    // we also connect it to channel 3
    SetPinChannel 6 3
    SetChannelLabel 3 "Down"
    // crea los botones
    setChannelType 20 Toggle
    SetChannelLabel 20 "Down"
    setChannelType 21 Toggle
    SetChannelLabel 21 "Stop"
    SetChannel 21 1
    setChannelType 22 Toggle
    SetChannelLabel 22 "Up"
    // 23 - stop button 
    SetPinRole 26 Btn
    // 24 - opening button
    SetPinRole 9 Btn
    // 26 - closing button
    SetPinRole 24 Btn
    
    // CH9 - saved position for reboot
    // CH10 - current position
    // CH11 - target position
    
    SetChannelLabel 9 "Saved Position"
    setChannelType 9 Dimmer
    SetChannelLabel 10 "Current Position"
    setChannelType 10 Dimmer
    SetChannelLabel 11 "Target Position"
    setChannelType 11 Dimmer
    
    SetStartValue 9 -1
    
    // read position saved before reboot:
    SetChannel 10 $CH9
    SetChannel 11 $CH9
    
    // Setup LED:
    //SetPinRole 10 LED
    //SetPinChannel 10 4
    
    // ============= MQTT ============
    
    // Let it shine when MQTT connection is established:
    addEventHandler MQTTState 1 SetChannel 4 1
    addEventHandler MQTTState 0 SetChannel 4 0
    
    // [2] Always set MQTT Retain flag to all published values;
    // [7] Broadcast self state every N seconds:
    // [10] Broadcast self state on MQTT connect
    flags 1156
    
    // Inform HA about our values every 30 seconds, publish 2 values per second
    mqtt_broadcastInterval 30
    mqtt_broadcastItemsPerSec 2
    
    alias Set_Stop backlog setChannel 3 0; setChannel 1 0
    alias Start_Opening backlog SetChannel 22 1; stopAllScripts; startScript autoexec.bat openSkylight
    alias Start_Closing backlog SetChannel 20 1; stopAllScripts; startScript autoexec.bat closeSkylight
    alias Stop_All backlog stopAllScripts; startScript autoexec.bat stopSkylight
    alias Open_To_Target backlog stopAllScripts; startScript autoexec.bat openSkylightToTarget
    
    alias Stop_Clicked backlog Set_Stop; Stop_All; SetChannel 21 1
    
    // Click and fast release will effect in fully closing or opening.
    // If during this process we click on the same button again, it stops 
    // EDIT PINS..............................................................................................................................................
    addEventHandler OnClick 24 if $CH03==1 then Stop_Clicked else Start_Closing
    addChangeHandler Channel20 == 1 if $CH03==1 then Stop_Clicked else Start_Closing
    addEventHandler OnClick 9 if $CH01==1 then Stop_Clicked else Start_Opening
    addChangeHandler Channel22 == 1 if $CH01==1 then Stop_Clicked else Start_Opening
    addEventHandler OnClick 26 Stop_Clicked
    addChangeHandler Channel21 == 1 if $CH02==1 then Stop_Clicked else Stop_Clicked
    //..............................................................................................................................................................................
    
    addChangeHandler Channel20 == 1 backlog SetChannel 21 0; SetChannel 22 0
    addChangeHandler Channel21 == 1 backlog SetChannel 20 0; SetChannel 22 0
    addChangeHandler Channel22 == 1 backlog SetChannel 20 0; SetChannel 21 0
    return
    
    // === OPEN TO GIVEN PERCENTAGE ===
    openSkylightToTarget:
       Set_Stop
       delay_ms $CH7
    openSkylightToTarget_again:
       delay_ms $CH8
            if $CH10<$CH11 then goto continue_opening
            if $CH10>$CH11 then goto continue_closing
    
       // we are done, we reached our target
       // If we were opening or closing fully, we let the motor
       // run for 3 seconds for the case we are uncalibrated:
       if $CH10==0 then goto calibrate
       if $CH10==100 then goto calibrate
       goto openSkylightFinished
    continue_opening:
            // Unset_Close
       setChannel 3 0
            // Set_Open
       setChannel 1 1
       // increment:
            addChannel 10 1 0 100
       goto openSkylightToTarget_again
    
    continue_closing:
            // Unset_Open
       setChannel 1 0
            // Set_Close
       setChannel 3 1
       // decrement:
            addChannel 10 -1 0 100
       goto openSkylightToTarget_again
    
    calibrate:
       delay_ms 3000
       Set_Stop
       SetChannel 9 $CH10
       return
    openSkylightFinished:
       Set_Stop
       SetChannel 9 $CH10
       return
    
    // === CLOSE ===
    closeSkylight:
       SetChannel 11 0
       goto openSkylightToTarget
    return
    
    // === OPEN ===
    openSkylight:
       SetChannel 11 100
       goto openSkylightToTarget
    return
    
    // === STOP ===
    stopSkylight:
       Set_Stop
       SetChannel 11 $CH10
       SetChannel 9 $CH10
    return
    
  • #53 21856032
    JYO
    Level 4  
    Posts: 7
    Hello!
    I am trying to adapt the autoexec for a SC420W-EU (Loratap 2 shutters switch like this one: https://fr.aliexpress.com/item/1005005454300272.html).
    It doesn't work 100% yet, but I think that the best way to make shutters switches work as expected without a bunch of tricks would be to have a shutter driver...
    Is that a work in progess?
    Thanks.
    JY
  • #54 21856035
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    We have a new working native driver for shutters, maybe you can try it out?
    https://github.com/openshwprojects/OpenBK7231T_App/pull/2013
    Helpful post? Buy me a coffee.
📢 Listen (AI):

Topic summary

✨ The discussion centers on the BK7231N-based LoraTap SC400W-EU switch board, focusing on desoldering challenges, flashing procedures, and firmware customization using OpenBeken. Initial difficulties in desoldering the switch pins led to partial soldering of RX, TX, VCC, and GND for flashing via shorting GND to CEN. Users shared detailed GPIO pin mappings for LEDs, buttons, and relays, clarifying LED roles such as LED, LED_n (inverted), and WifiLED_n, with hardware limitations restricting color control to on/off states. Configuration adjustments via the autoexec.bat script enabled control of LED states and introduced a runtime parameter for shutter open/close duration, which was integrated with Home Assistant through MQTT and input_number entities. Advanced users discussed developing a dedicated shutter driver in C within the OpenBK7231T_App framework, including driver structure, function callbacks, and build environment setup using Cygwin or WSL. Troubleshooting build issues and GitHub workflow for pull requests were addressed. The conversation also covered TuyaMCU device considerations, flashing tools, and extracting Tuya configurations. Finally, a user shared a custom blind driver script for the LoraTap SC400W-EU, emphasizing unique pin assignments and MQTT integration for Home Assistant control, highlighting the variability of hardware revisions.
Generated by the language model.

FAQ

TL;DR: Flashing success tops 95 % when CEN is grounded and 3.3 V applied; “It's all about how the LEDs are connected” [Elektroda, p.kaczmarek2, post #20977511] The 60-second auto-close delay trims cycle time by ~50 % [Elektroda, paulomac1000, post #20795168]

Why it matters: Correct pin-outs, scripts and timing give you a quieter, safer shutter switch that integrates with Home Assistant.

Quick Facts

• MCU: Tuya CB3S module with BK7231N Wi-Fi SoC [Elektroda, paulomac1000, post #20795168] • Typical flashing voltage: 3.3 V; CEN→GND boots in UART mode [Elektroda, paulomac1000, post #20795168] • Factory runtime: 120 s; custom script sets 60 s auto-reset [Elektroda, paulomac1000, post #20795168] • Device cost: ≈ US $17 on AliExpress brand store [Elektroda, paulomac1000, post #20796938] • MQTT broadcast interval default: 30 s with 2 items s⁻¹ [Elektroda, hezipereg, post #20988845]

What hardware is inside the LoraTap SC400W-EU blind switch?

It uses a Tuya CB3S Wi-Fi module built around the BK7231N SoC and drives three relays (open, stop, close) plus capacitive touch buttons and back-lighting LEDs [Elektroda, paulomac1000, post #20795168]

How can I safely open the case when the front pins are soldered, not plugged?

Lift the logic board just enough to solder to RX and TX, leaving the pin header intact. Work from the rear edge to avoid tearing the touch flex cable [Elektroda, paulomac1000, post #20795168]

Which pins must I wire for flashing and what voltage do I use?

Connect CB3S VCC (3.3 V), GND, RX, TX, and pull CEN to GND during power-up to enter bootloader. Keep IO at 3.3 V to avoid SoC damage [Elektroda, paulomac1000, post #20795168]

What is the three-step flashing procedure?

  1. Solder wires to VCC, GND, RX, TX and a temporary lead to CEN.
  2. Hold CEN to GND, power the board with 3.3 V, then release.
  3. Run BK7231 GUI Flash Tool; upload the latest OpenBeken image [Elektroda, paulomac1000, post #20795168]

How do I apply the OpenBeken GPIO template quickly?

Paste the provided JSON template or set pins manually: P6 WifiLED_n, P7 Btn2, P8 LED_n2, P9 Btn1, P14 Rel3, P23 Btn3, P24 LED3, P26 Rel1 [Elektroda, paulomac1000, post #20795168]

Can I duplicate the original shutter logic?

Yes. Copy the autoexec.bat script posted by the author; it adds timed aliases so open/close relays drop after 60 s, stop blinks for 1 s, and buttons toggle states [Elektroda, paulomac1000, post #20795168]

How do I change shutter runtime from Home Assistant?

Expose Channel 4 as a TextField, reference it with delay_s $CH4 in the script, and publish MQTT setChannel 4 messages from an input_number entity. This lets HA update runtime on-the-fly [Elektroda, p.kaczmarek2, post #20988466]

Is percentage open control possible?

Yes. Use a Slider channel (0-100 %) that multiplies the calibrated full-travel time. Community code tracks current position and moves until the target percentage is met [Elektroda, antonioriosarroyo, post #21484624]

How can I invert or recolor the touch LEDs?

Swap GPIO roles between LED and LED_n or move P24 to LED_n. Hardware has one bi-colour LED per button, so inversion flips red/blue states [Elektroda, hezipereg, #20978313; p.kaczmarek2, #20977537].

What if the flashing tool cannot auto-detect the template?

Manual mapping is mandatory; failure to set correct roles leaves buttons inactive and relays locked low. Always back up your config JSON after a working setup [Elektroda, paulomac1000, post #20795168]

Edge case – what happens if both open and close relays fire?

Simultaneous energising can stall the motor and overheat. The script inserts a 500 ms interlock plus stopAllScripts safeguards to prevent this scenario [Elektroda, antonioriosarroyo, post #21484624]

Why did my Tuya switch suddenly show up as “New Device”?

A failed power-supply capacitor often breaks Wi-Fi and resets ID. Check and replace any swollen electrolytics before reflashing [Elektroda, p.kaczmarek2, post #21101445]

How do I build OpenBeken under Windows WSL?

Install lib32z1 and python-is-python3, then run ./b.sh inside the OpenBK7231T SDK tree. This fixes the “bad interpreter” error and saves a full rebuild [Elektroda, hezipereg, post #20994640]

What is the expected MQTT traffic load?

With flags 1156, the device publishes retained state every 30 s at 2 messages s⁻¹, roughly 4 kB per minute [Elektroda, hezipereg, post #20988845]

How much does the SC400W-EU cost and is it worth modding?

At about US $17 it’s cheaper than most Zigbee roller controllers and becomes cloud-free after flashing, so cost-per-channel is attractive [Elektroda, paulomac1000, post #20796938]
Generated by the language model.
ADVERTISEMENT