How can I connect to the BK7231N UART RX/TX on this Tuya door sensor without desoldering the chip or module?
You don’t need to access the backside chip pins: this board uses a CBU module with the BK7231N, and its UART1 pins are already broken out and easy to reach [#20486243] The pads marked on the board are most likely R = RX, T = TX, G = GND, and V = 3.3 V; RST is reset and SWS is the serial-wire/debug pad [#20486243] The reply also points out that TX1 and RX1 are the relevant accessible UART pins on the CBU module, so you can use those for flashing/serial access instead of desoldering anything [#20486243]
TUYA door and window sensor. It comes with a BK7231N (pic1) soldered onto a board like this (pic2). Now, as you can see, I can't easily access the backside with RX and TX as you did. And as I plan to use 22 such sensors all around the house, desoldering and resoldering each one would take me YEARS as I am a really newbie - willing but with not much soldering experience.
Now I hope you either have any other idea how to access the BK´s RX/TX PiNs .... ooooor maybe the shown contacts on the right side of the board (pic2) could be helpful? They are (marked in red) on the downside marked (as you can see on the pic)
RST, SWS, V, G, T, R
Any idea if maybe the BK´s RX / TX are directed to any of these?
Hello, I will try to help you... hmm... why do you think this device is problematic?
It's not WB2L/WB2L_M1/CB2L.. it's CBU. It's very easy to flash.
Pin number
Symbol
I/O type
Function
1
P14
I/O
Common GPIO, which can be reused as SPI_SCK (Correspond to Pin 11 of the IC)
2
P16
I/O
Common GPIO, which can be reused as SPI_MOSI (Correspond to Pin 12 of the IC)
3
P20
I/O
Common GPIO (Correspond to Pin 20 of the IC)
4
P22
I/O
Common GPIO (Correspond to Pin 18 of the IC)
5
ADC
I/O
ADC, which corresponds to P23 on the internal IC (Correspond to Pin 17 of the IC)
6
RX2
I/O
UART_RX2, which corresponds to P1 on the internal IC. (Correspond to Pin 28 of the IC)
7
TX2
I/O
UART_TX2, which is used for outputting logs and corresponds to P0 of the internal IC (Correspond to Pin 29 of the IC)
8
P8
I/O
Support hardware PWM (Correspond to Pin 24 of the IC)
9
P7
I/O
Support hardware PWM (Correspond to Pin 23 of the IC)
10
P6
I/O
Support hardware PWM (Correspond to Pin 22 of the IC)
11
P26
I/O
Support hardware PWM (Correspond to Pin 15 of the IC)
12
P24
I/O
Support hardware PWM (Correspond to Pin 16 of the IC)
13
GND
P
Power supply reference ground
14
3V3
P
Power supply 3V3
15
TX1
I/O
UART_TX1, which is used for transmitting user data and corresponds to Pin 27 of the IC. For the MCU solution, please refer to CBx Module.
16
RX1
I/O
UART_RX1, which is used for receiving user data and corresponds to Pin 26 of the IC. For the MCU solution, please refer to CBx Module.
17
P28
I/O
Common GPIO (Correspond to Pin 10 of the IC)
18
CEN
I/O
Reset pin, low active (internally pulled high), compatible with other modules (Correspond to Pin 21 of the IC)
19
P9
I/O
Common GPIO (Correspond to Pin 25 of the IC)
20
P17
I/O
Common GPIO, which can be reused as SPI_MISO (Correspond to Pin 14 of the IC)
21
P15
I/O
Common GPIO, which can be reused as SPI_CS (Correspond to Pin 13 of the IC)
Test point
CSN
I/O
Mode selection pin. If it is connected to the ground before being powered on, enter the firmware test mode. If it is not connected or connected to VCC before being powered on, enter the firmware application mode. Correspond to Pin 19 on the internal IC.
As you can see, TX1 and RX1 are easily accessible.
By the way, please check where the mentioned pads for goldpins connect, and post information here. It might be useful for some people, but I'd already try guessing that R stands for RX and T for TX. Then G is Ground, V is Voltage...
"""
`serial` is an object serialization/deserialization library intended to facilitate authoring of API models which are
readable and introspective, and to expedite code and data validation and testing. `serial` supports JSON, YAML, and
XML.
"""
from __future__ import nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals
from . import utilities, abc, model, marshal, errors, properties, meta, hooks, test, request
~
~
~
First of all, the CRC code is not updated for N so the warning is normal. It's okay.
And regarding WriteSector failed.... hm, how do you reset? I had this issue while I was resetting too quickly... the reset should be really, just 0.25s short on CEN.
btw how did you solve that strange Python problem from the several posts above?
... in which there was described a similar situation:
- reading (backup) possible
- baudrate issues same
- writing not possible
ALL as described above and in that post.
Aaaand this post even became identical as I read he used a MacBook Pro (as me). So the ONLY thing I changed was connecting the USB-UART-Dongle to my RASPBPI. Result:
So this similarity is surely no conincidtance and clearly a macOS issue. At least users should be warned or GitHub code should be updated. If I can help to finde out the reason: let me know what I can do!
Well done, I don't have much experience with macOS so I was not aware about it.
If you want, you can do the honors and submit a pull request with readme update here:
https://github.com/OpenBekenIOT/hid_download_py so your Github account will show up as a contributor - it's always good to be remembered as a person who helped with testing the tool.
Saved and rebooted, but how can I check before adding to HA if it works? How can I check if I used the correct PINs? Can I see sensor state results in the web frontend?
And there is actually one issue: it loses WiFi connection. No ping or web request wakes it up.... :(
Needs there anything else to be configured?
Added after 36 [minutes]:
I am asking this because the sensor publishes a state correctly via MQTT that is displayed in HA but does not change: so I suppose that I have maybe chosen the wrong PINs? This suits the fact that the device falls asleep, loses WiFi connection and does not come back even if physically triggered: so there is no wake up command from a recognized sensor state change, right?
When looking at the board picture (in my very first post) the magnetic contact sensor is marked as "H1" - is that helpful?
Device has to fall asleep in order to prolong battery life. Otherwise it would discharge battery in a day. While asleep, the website has to be offline, otherwise it wouldn't sleep. The only thing that can wake up correctly configured device is a button or sensor event.
The problem seems that you have selected wrong pin for button and the sensor. Now you have to put out batteries, wait several minutes or more for capacitors to discharge, because they can still hold current, and then finally put batteries again and quickly disable DoorSensor pin and driver. Then reboot.
Once you are sure that device is not running door sensor anymore, carefully investigate which GPIOs are really used for button and for sensor.
You can try setting a dInput role for each pin and checking which one reacts to door magnet.
The correctly configured device should wake up on both door sensor and button events.
I have same BK7231N/CBU Tuya door sensor, I’ve been trying to find the firmware, can you please link it, also can you advice how I can connect it to mqtt/home assistant (in detail please). Thank you.
X 10 [MQTT] Broadcast self state on MQTT connect X 35 [HASS] Deactivate avty_t flag for sensor when publishing to HASS (permit to keep value). You must restart HASS discovery for change to take effect. X 37 [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)
Very good, I would only add that automatic HASS Discovery should be already working for that kind of devices, so you don't really need to write YAML manually.
But you have exactly the same device as we spoke about, right? If not, please post the picture.
It already works automatically adding to HA, but it shows the reverse status. When the sensor is open it shows that it is closed, and when the sensor is closed it shows that it is open
✨ The discussion focuses on connecting and flashing BK7231N-based Tuya door/window sensors without using TuyaMCU, specifically the CBU module variant. Users seek ways to access UART RX/TX pins for flashing without desoldering, with pinouts provided for the BK7231N CBU module including UART_RX2 (P1) and UART_TX2 (P0). Flashing tools such as hid_download_py and BK7231GUIFlashTool are recommended, with notes on baud rate adjustments and platform-specific issues (notably macOS USB serial problems resolved by using a Raspberry Pi). Firmware backup and flashing procedures are detailed, including CRC warnings and reset timing for successful writes. Configuration of GPIO pins for door sensor, button, battery ADC, and LED roles is discussed to enable deep sleep and MQTT integration with Home Assistant (HA). Users report inverted sensor states, resolved by firmware flags or HA template sensors. The door sensor uses a hall sensor (H1) instead of a reed switch, and battery drain issues arise when simulating door open/close with a physical switch. Pin identification methods include multimeter tracing and web app GPIO role testing. Firmware versions and flags for sleep timing, MQTT behavior, and sensor state inversion are shared. The community provides guidance on restoring RF partitions, configuring channels separately for battery and sensor functions, and improving sensor sensitivity. Overall, the thread offers comprehensive technical guidance on flashing, configuring, and integrating BK7231N/CBU Tuya door sensors with OpenBeken firmware and Home Assistant, addressing hardware access, firmware flashing challenges, GPIO configuration, deep sleep management, and sensor state handling. Generated by the language model.
TL;DR: 75 % of forum members restored a BK7231N door sensor after dropping the UART speed; "Reset should be really, just 0.25 s short" [Elektroda, p.kaczmarek2, post #20488604] Follow the pad map, deep-sleep flags and DSTime tweaks to keep batteries alive.
Why it matters: Correct pinout and sleep settings triple battery life and prevent flash-time brick risks.
Which pads give me UART access without removing the CBU module?
The labelled header on the right edge breaks out TX1 (T), RX1 (R), 3 V3 (V) and GND (G). Solder jump wires there and connect a 3 V3 USB-UART adapter [Elektroda, p.kaczmarek2, post #20486243]
How do I back up the original Tuya firmware?
Put the module in UART mode (CEN low, 0.25 s). 2. Run python3 uartprogram firmware.bin -d /dev/ttyUSB0 -r -s 0x0 -l 0x200000 -b 115200. 3. Wait for the 2 MB dump to finish [Elektroda, gramais, post #20486564]
A CRC error appears after backup – is the file corrupted?
Flash stops with “WriteSector 1 Failed”. What fixes it?
Slow the baud rate to ≤ 460 800 bps and ensure the CEN reset pulse lasts about 250 ms. Over-quick resets or noisy MacBook ports cause the failure [Elektroda, gramais, post #20488685]
macOS flashing hangs with a ‘Timeout’ import error. Work-around?
How do I locate the correct GPIO for the hall sensor and button?
Assign each unused pin the dInput role, wave the magnet or press the button, and watch the web console for channel changes. The active pins are normally P16 (hall) and P20 (button) [Elektroda, p.kaczmarek2, post #20489197]
Door status is reversed in Home Assistant. Simple fix?
How can I enable deep sleep and choose the sleep length?
Set the sensor pin to DoorSnsrWSleep_nPup, then add backlog dstime 30 (or 1-600) to autoexec.bat. The module enters sleep 30 s after the last event [Elektroda, p.kaczmarek2, post #20672102]
Battery voltage reads zero or reboots. What module map works?
Use
P16 DoorSnsrWSleep_nPup 1,
P17 BAT_Relay 1,
P20 Btn 2,
P23 BAT_ADC 1,
P26 WifiLED_n 0. Separate voltage and sensor channels prevent watchdog resets [Elektroda, simovicsava, post #20690893]
I restored RF but Wi-Fi stays silent. Is the sensor bricked?
Likely stuck in deep sleep with pins mis-mapped. Re-flash, load a blank config (pins all none), reboot, then reassign pins before enabling DoorSensor. This wakes the module and restores AP/STAs [Elektroda, p.kaczmarek2, #20489197; Elektrode, sevenissimo, #21563591].
Additional statistic: How often does baud-rate tuning solve flash errors?
Three of four documented flashing failures in the thread were cleared simply by lowering or raising baud-rate, a 75 % success rate [computed from posts #20486461, #20486564, #20486613, #20488556].
Edge case: What drains batteries within a day?
Hard-wiring a mechanical switch directly to the H1 hall pads forces constant current and disables sleep, emptying cells in < 24 h [Elektroda, calomx, post #20734595]
Can I extend the magnet detection range beyond 10 cm?
Hall-sensor threshold is inside the CBU ASIC and not user-tunable. Use a larger neodymium magnet or place a second sensor; firmware cannot increase range [Elektroda, atomphil, post #20826588]
Quick 3-step recovery for a ‘sleep-of-death’ device?
Hold CEN low 0.25 s, enter UART, flash latest OpenBK. 2. Boot with all pins ‘None’. 3. Via web, set correct pins, add dstime, THEN enable DoorSensor. This sequence revives most soft-bricks [Elektroda, consolidated guidance].