Elektroda.com
Elektroda.com
X

Search our partners

Find the latest content on electronic components. Datasheets.com
Elektroda.com

Qiachip Smart Switch - BK7231N / CB2S - interior, programming

p.kaczmarek2 6453 86
This content has been translated flag-pl » flag-en View the original version here.
  • #61
    p.kaczmarek2
    Level 26  
    Rather, it converts RX to TX, that is, RX to TX and TX to RX. It is worth reading about UART.

    You can and on Windows and on the Raspberry pi. Try to install Python3 and then execute the code I gave.

    Make you have Python in CMD:
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming



    And so you can run the UART program with it:
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming


    Let me know how it will start and I will guide you through the process. Remember to make a backup of the software that is already there before uploading my software.

    Backup command:
    Code:

    python uartprogram backup_2mb_default.bin -d com9 -r -l 0x200000

    Second command worth using, with offset 0, also backup:
    Code:

    python uartprogram backup2_mb_ofs0x0.bin -d com9 -r -s 0x0 -l 0x200000


    You can put a backup copy on the forum, the tuya-cloudcutter project collects various batches from devices to prepare an OTA hack for them (you can change the firwmare without opening the case). Read the description of this project and remember that your SSID may be in flash.


    Also include photos from inside your device.
  • #62
    djlukas
    Level 27  
    I downloaded what you told me, I ran the install file and something was installing there.
    I was able to install Python on Windows.
    I ran cmd and typed python, now I have this window and I don't know what to do next
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
  • #63
    p.kaczmarek2
    Level 26  
    You don't have to enter the Python console this way.

    You just go to the directory where uartprogram is in the regular console and do:
    Code:

    python uartprogram backup_2mb_default.bin -d com9 -r -l 0x200000

    as a rule, do the same, but with offset 0:
    Code:

    python uartprogram backup2_mb_ofs0x0.bin -d com9 -r -s 0x0 -l 0x200000

    And that's all from the software side for now.

    Once you run uartroute, that will be the second issue to be solved. Ripping the batch (or uploading a new one) requires rebooting the system you are programming. There are two ways to do this:
    - cut-off / restore power to the board (but you need to power from a source other than the USB you have connected, because the capacitor on the board takes too much at the time of connection and overloads the USB ...)
    - temporary CEN short circuit to ground to perform a RESET (this can be problematic because you need to short-circuit exactly for a short moment, not for a long time)

    The sequence of steps is as follows:
    1.you connect usb to uart
    2. You enter and run the programming command
    3. while the program shows "getting bus" you are doing this reboot
    4. then the program will perform the batch read or write operations by itself
  • #65
    p.kaczmarek2
    Level 26  
    Hey @edwardtich , I will try to help you. I can see two potential issues.

    1. you are inside Python directory and not inside hid_download_py directory :
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    2. my python version is 3.10.2, yours look like 2.7?
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming

    Edit: what do you get when you enter "python -V" command?
  • #66
    edwardtich
    Level 3  
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming

    i copied all files to C:\Python27

    i installed the latest version

    same error
  • #67
    djlukas
    Level 27  
    After a hard fight with this cmd, I got to this level. I entered this comedy in the backup, I got "Read getting bus" shortened and released CEN to GND and it gets such a thing.

    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
  • #69
    edwardtich
    Level 3  
    p.kaczmarek2 wrote:
    Which windows version are you using?


    Windows 10
    python-3.10.6-amd64
  • #70
    p.kaczmarek2
    Level 26  
    Cannot get bus means you did not reboot while waiting.

    You have several options to improve this.
    1. try to connect these CEN to GND for literally a fraction of a second, it requires practice to hit a good timing
    2. Power the programmed circuit from a separate 5V power supply (and if necessary, by a separate 3.3V regulator), common ground (all GND together), TX and RX to USB, but powered from a separate power supply. And reboot by disconnecting and reconnecting this power supply (the simplest method, you don't need to use CEN at all)
    3.you can unsolder the 22uF capacitor, or how much is on the board, or 47uF there, and reboot by disconnecting the power from the USB dongle but without removing the USB (I do not recommend it)

    I recommend trying point 2 as with 1 doesn't go. Method 2 is the most reliable

    NOTE - if you have wrong RX and TX connected (to wrong TX or TX to TX and not swapped) you will receive same mistake so maybe as a rule verify and give photos if everything is ok ..


    Of course, there is also a very small shadow of a chance (but there is always) that you have a situation like me here: https://www.elektroda.pl/rtvforum/topic3895572.html
    and in your device on pin RX there is, for example, an additional resistor that interferes with the programming and you will have to unsolder it or cut the path. I don't know, I would need to see a good PCB picture
  • #73
    p.kaczmarek2
    Level 26  
    Well, I see two problems.
    First, what is this USB to UART? Users reported that CP2102 did not work, but CH340 did. Is that CP2102?

    And secondly ... it's probably a door sensor? The one on TuyaMCU?
    Although no, it's a humidity sensor, but rather it is also on TuyaMCU ...
    Same PCB as in the door opening sensor. I did its analysis, but I did not post on the forum:
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    This is a device that consists of a WiFi module (CB3S) and TuyaMCU (microcontroller). The microcontroller works all the time and only turns on the Wifi module (its power supply) with a transistor when it is necessary to send data. TuyaMCU communicates with the CB3S via UART (the same one used for programming).

    Look at the photo with my captions. See two things.
    1.RX and TX lines go to TuyaMCU (microcontroller in SOIC) so it interferes with programming
    2.The VDD (3.3V) line to the CB3S module goes through the transistor controlled by TuyaMCU, so TuyaMCU controls the power supply of CB3S (so you don't even power CB3S)

    At the moment, to program, you would have to unsolder TuyaMCU (chip in SOIC) or interrupt their paths, but this does not fully solve the matter because the protocol of this device is not supported at the moment.

    So either way, you won't fully release him for now, you'd have to wait for me to add support for that, unless ....

    If you are willing to shorten the battery life, you can remove the TuyaMCU completely (then the UART and RX / TX lines will slow down) and connect the water sensor directly to the CB3S, and modify the CB3S power supply so that it is always present. It could and would start. But in general, I haven't had this device yet.
  • #74
    djlukas
    Level 27  
    The converter is ftdi ft232rl.
    It's a pity that there is no integration, I wanted to free myself from the cloud and connect with HA. I bought three such sensors, I can send you one for testing.? The option without MCU is also not bad as I would only have some data in the HA.
  • #75
    p.kaczmarek2
    Level 26  
    @edwardtich Great! That's a progress.

    Now, how do you reset the device while the program is waiting to "Get bus"?

    The simplest solution is to do a power on/power off cycle.
  • #77
    p.kaczmarek2
    Level 26  
    Maybe your device is TuyaMCU or has a button on RX/TX line? Can you show photos of your device PCB and connection?
  • #78
    p.kaczmarek2
    Level 26  
    If you want, it's PW. I will be happy to discuss this sensor in another topic and I will play the tuya-cloudcutter batch from it, so that the next ones can be programmed without opening the housing.
    When it comes to integrations, basically the question is whether in your opinion the version that the WiFi module is directly connected is acceptable (we are kicking TuyaMCU). Something like this was done in older sensors, I have several sensors on the XR809 (I did a transplant on the ESP12F for one) and every WiFi module is still powered there.
    I would also have to take measurements as to what makes sense, at least until there is a better solution.
  • #80
    eazevedo88
    Level 2  
    Hello!

    I have a smart plug using this the "BK7321N" chip model.

    Qiachip Smart Switch - BK7231N / CB2S - interior, programming


    When I was trying to upload firmware, through python, I got stuck on the message : Unprotect Failed
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming


    In Beken Writer it said i successfully uploaded the BIN file. I could also backup and erase flash content but, even saying that there was no error, the hotspot for configuration does not appear on the wifi.
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    [edit] *** The Beken Writer just erased the flash, did not uploaded the new firmware*** [edit]

    Is there any procedure I can try to break this chip protection?

    Thanks in advance!

    Added after 1 [hours] 12 [minutes]:

    Made some evolution!

    I changed de baud rate to 115200 and now I can iniciate the writing!

    Now I tried like 50 x and it is the max that it goes.

    Qiachip Smart Switch - BK7231N / CB2S - interior, programming


    [EDIT 2] =========

    WRITE SUCCESSFUL!!

    I changed the UART adapter to the CH341A, and tried different baud rate.
    I got it to work at the rate of 15000. It took about 10 minutes but I got it.

    Thanks!

    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
  • #81
    p.kaczmarek2
    Level 26  
    @eazevedo88 good job, but I am wondering, is it a power-metering plug with BL0942 or BL0937 chip?
    EDIT: now looking at your pictures, I am not too much suprised that lower speed helped. In general, the rule is to keep connections as short as possible, especially at higher frequencies it's crucial to avoid the noise that causes communication errors

    @edwardtich sorry but I am not able to determine anything from a single photo. Can you show whole setup?
    Or can you check if:
    - is the device really correctly powered
    - is your USB to UART converter in 3.3V mode
    - is TX and RX swapped (you usually connect RX to TX and TX to RX)
    - is there anything soldered to TX/RX lines, like a button, or TuyaMCU, or a resistor, that can interfere with flashing?

    also, the CH340 USB to UART converter is preferred, some users reported issues with different ones
  • #82
    eazevedo88
    Level 2  
    Is there a command list of all possible commands?

    I need to set my device as a Static IP andI intend to use your project in a door sensor, but I also need you to increase the sleep time.

    How can I do this?


    Awesome Project! Thanks!
  • #83
    p.kaczmarek2
    Level 26  
    eazevedo88 wrote:
    Is there a command list of all possible commands?

    I am currently creating list of the commands in readme (then I will move it elsewhere):
    https://github.com/openshwprojects/OpenBK7231T_App

    eazevedo88 wrote:

    I need to set my device as a Static IP andI intend to use your project in a door sensor,

    Currently the best way to setup a IP reservation for device MAC on your router

    eazevedo88 wrote:

    but I also need you to increase the sleep time.

    What do you mean by sleep time? How your device looks like?
  • #84
    eazevedo88
    Level 2  
    p.kaczmarek2 wrote:
    What do you mean by sleep time? How your device looks like?


    I flashed this PB-69W WIFI Smart Wireless Magnetic Door and Window Sensor. (CB3S - BK7321N)

    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    .

    The original Tuya firmware puts the device in a deep sleep mode after about 10 seconds with no activities, to reduce battery consumption. Its even disconnects the Wifi.

    I've already mapped the magnet sensor, but cannot find the internal led, its always on (but no problem)

    P0 - Tamper alarm
    P7 - Magnet Sensor
    ?? - Internal Led

    Now, I need to increase the sleep [edit] time* [edit], or put it a deep sleep to increase the battery duration.