logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Failed Attempts at Flashing Generic Tuya OEM WiFi Door Sensor with CB3S Chip using BK7231 Tools

sandyk 4350 13
ADVERTISEMENT
  • #1 20638418
    sandyk
    Level 3  
    Hi all,
    First of all, this is my first post on this forum, so apologies if it's not in the correct forum/topic.
    I recently purchased a generic (Tuya OEM?) WiFi door sensor which has a CB3S chip (runs on 2xAAA) as shown in the attached photos from Aliexpress.
    I tried flashing it with the BK7231 GUI Flash Tool and with bk_writer1.60 as well, but both are giving errors.
    I also tried flashing OpenBK7231N_QIO_1.17.165.bin with "BK7231Flasher," but it gives an error as shown in the screenshot.
    While bk_writer1.60 throws an error with "unprotecting failed" as shown in the screenshot.

    BK7231 flasher, while taking backup, provided the following configuration it thought exists:
    Code: JSON
    Log in, to see the code


    I'm not sure what I'm missing. Can someone help?

    Failed Attempts at Flashing Generic Tuya OEM WiFi Door Sensor with CB3S Chip using BK7231 Tools Failed Attempts at Flashing Generic Tuya OEM WiFi Door Sensor with CB3S Chip using BK7231 Tools Failed Attempts at Flashing Generic Tuya OEM WiFi Door Sensor with CB3S Chip using BK7231 Tools Failed Attempts at Flashing Generic Tuya OEM WiFi Door Sensor with CB3S Chip using BK7231 Tools
  • ADVERTISEMENT
  • #2 20638561
    p.kaczmarek2
    Moderator Smart Home
    Hello, can you try the hid_download_py method from this video?



    https: //github.com/OpenBekenIOT/hid_download_py
    Please also provide us a firmware backup if you have it.

    Keep in mind that after flashing you will have to configure door sensor with deep sleep in order to avoid draining the battery too quickly.
    Helpful post? Buy me a coffee.
  • #3 20638748
    sandyk
    Level 3  

    Thanks for the video link. I am not able to find the procedure to install the Python program you have mentioned. Can you provide a documentation link?
    Attached is the backup.
    Attachments:
    • readResult_BK7231N_QIO_2023-01-7--20-55-35.bin (2 MB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #4 20638961
    sandyk
    Level 3  

    >>20638561
    Got the hid_download_py installed, however still not able to flash. Error below:

    python3 uartprogram OpenBK7231N_QIO_1.17.165.bin --unprotect -d COM10 -w --startaddr 0x0
    UartDownloader....
    program....
    WriteSector 1 Failed: |##3 |[ 2.42k/s]

    Added after 17 [minutes]:

    Failed with reduced baud as well:

    python3 uartprogram OpenBK7231N_QIO_1.17.165.bin --unprotect -d COM10 -b 115200 -w -s 0x0
    UartDownloader....
    program....
    WriteSector 1 Failed: |##3 |[ 1.43k/s]

    Is the internal flash write protected purposefully to inhibit others from flashing it with open source firmware?
  • #5 20639637
    DeDaMrAz
    Level 22  
    Some questions:

    - are the batteries present? (if not you can use the power from the USB to UART adapter - just be sure you are using 3.3V not 5V!!!)
    - try lowering your port speed to 115200 does that work?
    - can you provide the link to the product (link form AliExpress store)?
  • ADVERTISEMENT
  • #7 20639735
    DeDaMrAz
    Level 22  
    sandyk wrote:
    @DeDaMrAz
    Hi
    Yes, the AAA batteries are present. Using FTDI with common ground & RX/TX pins (not using power from the FTDI).
    Here is the Aliexpress link for the product:
    https://www.aliexpress.com/item/1005005021005....order_list.order_list_main.17.282f1802iGFLTZ
    Tried with lower baud but that is not fixing it.
    Thanks


    Start the GUIflasher and then ground for the short time CEN pin on the module as the module will not self reset if powered previously.

    Also try 115200 for the port speed.
  • ADVERTISEMENT
  • Helpful post
    #8 20639750
    p.kaczmarek2
    Moderator Smart Home
    Maybe the device goes asleep before you try to flash? Try pressing onboard pair button several times before and during flashing.

    Maybe try another USB dongle?
    Helpful post? Buy me a coffee.
  • #9 20640435
    sandyk
    Level 3  

    @p.kaczmarek2 Changing the FTDI adapter seemed to have helped. I am able to flash the device, and it is now configured to connect to my WiFi.
    Now the next hurdle is to figure out the pin mapping/configuration. Based on the configuration the flashing tool was able to detect, are you able to help with the correct pin mapping in OpenBK, please?
    Thanks in advance.
  • #10 20640444
    p.kaczmarek2
    Moderator Smart Home

    Pin mapping can be automatically extracted from a 2MB backup of the device flash. It can also be recovered from OBK after flashing. Here's a tutorial:



    Helpful post? Buy me a coffee.
  • #11 20654213
    mminkov
    Level 5  

    Are you thinking of only replacing the Tuya firmware with OpenBeken and continuing to work "Online" with Tuya servers (original config still on the chip), and having additional extras like web access and all OpenBeken (like MQTT) features, only as an option to "work like a Tuya device"?
  • #12 20661873
    p.kaczmarek2
    Moderator Smart Home
    I am not sure how feasible it would be. The idea seems good but no one else so far requested it and keeping it working with Tuya would basically mean that we would need to somehow reimplement all Tuya functionality and of course we would need to understand how their protocols are working. Maybe we could use their open source SDKs as reference, but still, that would be a very hard task.
    Helpful post? Buy me a coffee.
  • #13 21014184
    cdtdsilva
    Level 10  

    mminkov wrote:

    Are you thinking of only replacing the Tuya firmware with OpenBeken and continuing to work "Online" with Tuya servers (original config still on the chip), and having additional extras like web access and all OpenBeken (like MQTT) features, only as an option to "work like a Tuya device"?


    Hmm, as far as no one requested... hey that would be cool! But I agree, hard to implement as Tuya keeps changing things.

    Technically one can add Tuya to Home Assistant. I've done so for years and to be fair, it works well and allows integrations with various other brands and custom commands, just like flashed devices do. Sure it doesn't tackle the privacy issues, or if Tuya ever pulls the plug leaving us in the dark. But hopefully something better would have taken by then.

    Perhaps worth to mention that Tuya also has Zigbee sensors, and those don't need any hacking to get into HA. Only a suitable radio to pair.
    They are more expensive, but worth it on the time saved messing with things, IMHO. And you can always go back to Tuya with them, if you wish.
  • #14 21014404
    p.kaczmarek2
    Moderator Smart Home
    Zigbee is more energy-efficient so I always recommend it for battery-powered devices. It's also much easier to handle in case of such sensors. The only drawback is that you actually have to have HA, and in case of WiFi devices I can just access them directly via WiFi.
    Helpful post? Buy me a coffee.

Topic summary

✨ A user encountered difficulties flashing a generic Tuya OEM WiFi door sensor equipped with a CB3S chip using various BK7231 tools, including the BK7231 GUI Flash Tool and bk_writer1.60, which resulted in errors such as "unprotecting failed." After several attempts, including using the hid_download_py method, the user was able to successfully flash the device by changing the FTDI adapter. The discussion also covered the importance of ensuring the device is powered correctly, using appropriate baud rates, and the potential for pin mapping extraction post-flashing. Additionally, there were considerations regarding maintaining compatibility with Tuya servers and the feasibility of integrating Tuya functionality with OpenBeken firmware.

FAQ

TL;DR: Fix CB3S flashing errors by swapping the USB‑UART, using 115200 baud, and keeping the device awake; a 2 MB backup restores pin mapping. "Pin mapping can be automatically extracted from a 2MB backup of the device flash." [Elektroda, p.kaczmarek2, post #20640444]

Why it matters: This helps owners of Tuya CB3S Wi‑Fi door sensors flash OpenBeken reliably and avoid battery drain.

Quick facts:

Quick Facts

How do I fix “WriteSector 1 Failed” or “unprotecting failed” when flashing a CB3S door sensor?

These errors often come from the USB‑UART interface, not flash protection. Replace your FTDI/USB‑UART adapter and retry the same procedure. The author solved both errors after swapping adapters and completed Wi‑Fi setup successfully. [Elektroda, sandyk, post #20640435]

The device keeps sleeping during flashing—how can I keep it awake?

Keep the sensor alive by pressing the onboard pairing button several times before and during flashing. If problems persist, try a different USB dongle as well. [Elektroda, p.kaczmarek2, post #20639750]

How do I reset the CB3S into download mode if it won’t self‑reset?

Some units won’t self‑reset if previously powered. Do this:
  1. Start the GUI flasher.
  2. Briefly short the CEN pin to GND to reset the module.
  3. Set the port speed to 115200 and begin flashing. [Elektroda, DeDaMrAz, post #20639735]

Which tool should I use to flash BK7231 on a CB3S module?

Use the hid_download_py method for BK7231 devices. Follow the linked video and GitHub repo, and keep a firmware backup. This path avoids common GUI tool issues and works over UART. [Elektroda, p.kaczmarek2, post #20638561]

Do I need batteries installed, and what voltage should my UART use?

You can flash with or without the AAA batteries installed. If you power from the USB‑to‑UART, supply 3.3 V, never 5 V. Share a common ground and verify RX/TX orientation. [Elektroda, DeDaMrAz, post #20639637]

Is the CB3S flash purposely write‑protected by the OEM?

No. The failure in this case was the USB‑UART adapter, not protection. After replacing the adapter, the device flashed and joined Wi‑Fi normally. [Elektroda, sandyk, post #20640435]

How can I recover the correct pin mapping after flashing OpenBeken?

"Pin mapping can be automatically extracted from a 2MB backup of the device flash." Make a full 2 MB backup, then use OpenBeken’s recovery to import pins. How‑To: 1) Create a 2 MB backup. 2) Flash OBK. 3) Import pins via OBK tools and verify. [Elektroda, p.kaczmarek2, post #20640444]

How do I prevent fast battery drain after flashing a Wi‑Fi door sensor?

Enable deep sleep in OpenBeken for the door sensor profile. Without deep sleep, battery life on Wi‑Fi sensors drops rapidly. Configure it immediately after pairing to your network. [Elektroda, p.kaczmarek2, post #20638561]

Can I keep Tuya cloud functionality after installing OpenBeken?

Maintaining Tuya cloud while running OpenBeken is not feasible today. It would require re‑implementing Tuya’s protocols and tracking changes. As noted by the maintainer, that would be a very hard task. [Elektroda, p.kaczmarek2, post #20661873]

Is Zigbee a better choice for battery‑powered door sensors than Wi‑Fi?

Yes. "Zigbee is more energy‑efficient so I always recommend it for battery‑powered devices." Zigbee reduces idle overhead versus Wi‑Fi. The trade‑off is you need a Zigbee stack, such as HA with a radio. [Elektroda, p.kaczmarek2, post #21014404]

What baud rate should I use when flashing BK7231 if faster speeds fail?

Lower the port speed to 115200 baud and retry the write. Many adapters are more stable at that rate for BK7231 flashing. [Elektroda, DeDaMrAz, post #20639637]

Which UART pins do I need to connect on CB3S for flashing?

Connect your USB‑UART’s RX and TX lines and a common ground to the module. You can leave batteries installed if you are not powering from the adapter. [Elektroda, sandyk, post #20639732]
ADVERTISEMENT