logo elektroda
logo elektroda
X
logo elektroda

TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware

patentjyp 3054 10
ADVERTISEMENT
  • #1 20482271
    patentjyp
    Level 5  
    Hi,

    I am new to OpenBeken firmware but I have some experience with an ESP8266.

    I have a 6-gang switch with TuyaMCU and CB3S.

    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware

    I desoldered and flashed CB3S with OpenBK7231N_QIO_1.15.580.bin and soldered it back on the board.

    It connects to my router without any problem and I uploaded autoexec.bat.

    startDriver TuyaMCU
    setChannelType 1 toggle
    linkTuyaMCUOutputToChannel 1 1 1

    setChannelType 2 toggle
    linkTuyaMCUOutputToChannel 2 1 2

    setChannelType 3 toggle
    linkTuyaMCUOutputToChannel 3 1 3

    setChannelType 4 toggle
    linkTuyaMCUOutputToChannel 4 1 4

    setChannelType 5 toggle
    linkTuyaMCUOutputToChannel 5 1 5

    setChannelType 6 toggle
    linkTuyaMCUOutputToChannel 6 1 6

    Now the web interface shows six ON/OFF buttons like this.


    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware


    It looks like everything is working as intended in setting up OpenBeken.

    However, the relays neither turn on nor turn off by pressing web interface buttons.

    I looked at the log and it looks like the CB3S is not able to communicate with the TuyaMCU.

    ExtraDebug:TuyaMCU:TuyaMCU heartbeat_valid = 0, product_information_valid=0, self_processing_mode = 1, wifi_state_valid = 0, wifi_state_timer=0

    Nothing is received when I press the touch button on the wall switch.

    I think this problem is due to serial baud rate.

    I have a few of the same wall switches and replaced one of them with ESP-12F flashed with Tasmota.

    I had to set TuyaMCU serial baud rate to 115200bps in Tasmota using the command "SetOption97=1" in order to establish communication with TuyaMCU.

    Is there any way to set the TuyaMCU serial baud rate to 115200bps in OpenBeken?

    I could not find any option or command for changing the baud rate.

    Any help would be appreciated.
  • ADVERTISEMENT
  • #2 20482289
    p.kaczmarek2
    Moderator Smart Home
    Hello, if you open the autogenerated md-docs:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/docs
    and then commands list:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    then while searching for 'baud', you will find:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20483759
    patentjyp
    Level 5  
    Thank you for your answer.

    The wall switch is now in communication with TuyaMCU.

    I have another question regarding this Tuya device.

    After I set the baudrate to 115200, the CB3S started to receive data from TuyaMCU.

    I was able to turn on and turn off relay from Web UI.

    However, when I press the touch button on the wall switch, the states of relays were not reflected to Web UI. That is, when I turn on the relay by pressing the touch switch, nothing changed on Web UI (the same for turning off).

    Then I tried the command "tuyaMcu_defWiFiState 4" and it worked!

    The states of the relays were reflected on the Web UI and everything is working.

    It seems that this particular version of TuyaMCU requires certain hex value representing "tuyaMcu_defWiFiState 4" to be sent

    Now my question is:

    What hex value is sent to TuyaMCU when the command "tuyaMcu_defWiFiState 4" is issued?

    Is it 55aa000300010306?

    Thank you for your help in advance.
  • ADVERTISEMENT
  • #4 20483899
    p.kaczmarek2
    Moderator Smart Home
    Wow, you have solved it very quickly. Good job.
    Regarding this:
    patentjyp wrote:

    Then I tried the command "tuyaMcu_defWiFiState 4" and it worked!

    This is very interesting. I didn't experience it with my devices.
    I think the same could be achieved by connecting both MQTT and WiFi, because by default our software sends it when it has also MQTT connection:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    The following sends 0x03 command with payload 0x04:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    And if you break it down:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    On the other hand, the packet you have posted contains that:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    So your proposed hex packet is very similar, but not the same. It has payload 0x03 instead od 0x04.
    Here is the difference between 0x04 and 0x03 network states in TuyaMCU:
    Connection StatusDescription Status ValueLED Indicator Status
    Smart network configuration0x00The indicator blinks at 250 ms intervals.
    AP network configuration0x01The indicator blinks at 1500 ms intervals.
    The Wi-Fi is configured. However, the device fails to connect to the router.0x02The indicator is off.
    The Wi-Fi is configured, and the device successfully connects to router.0x03The indicator is steady on.
    The device connects to the router0x04The indicator is steady on.
    The Wi-Fi device is in low power consumption mode.0x05The indicator is off.

    So, in the end, it's virtually the same. It's just interesting that Tuya decided to lock their device before it's paired.

    Btw, please, can you post here your full config and information what kind of device is that (model name? photo? where was it bought?) so I can add it to templates list?

    Added after 8 [minutes]:

    EDIT: following topic has been added to docs and FAQ
    Helpful post? Buy me a coffee.
  • #5 20484142
    patentjyp
    Level 5  
    Thanks again for your help.

    Here are the photos of the 6-gang wall switch.

    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware

    I bought them from:

    https://www.aliexpress.com/item/1005004136972...order_list.order_list_main.295.59351802kaqxEY

    I bought 4 of them and I replaced one of the switches' CB3S with ESP-12F flashed with Tasmota.

    However, I was stuck at not receiving any response including the states of the relays (therefore no change in the Web UI the same as OpenBeken).

    That is why I turn to OpenBeken to see how it goes.

    It looks like the commands "tuyaMcu_setBaudRate 115200" and "tuyaMcu_defWiFiState 4" must be issued at boot to be able to receive any response from TuyaMCU.

    After posting this ("tuyaMcu_defWiFiState 4"), I looked into Tuya serial protocol and found out that hex code 55AA000300010407 makes TuyaMCU begin reporting the states of the relays.

    According to Tuya serial protocol, hex code 55AA000300010407 represents "Wi-fi is connected". (may be the same as tuyaMcu_defWiFiState 4?)

    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware

    I tried this hex code with Tasmota by issuing the command "serialsend5 55AA000300010407" and the wall switch started working immediately just like the one with OpenBeken.

    Anyway, here is my autoexec.bat

    
    startDriver TuyaMCU
    
    tuyaMcu_setBaudRate 115200
    
    tuyaMcu_defWiFiState 4
    
    setChannelType 1 toggle
    linkTuyaMCUOutputToChannel 1 1 1
    
    setChannelType 2 toggle
    linkTuyaMCUOutputToChannel 2 1 2
    
    setChannelType 3 toggle
    linkTuyaMCUOutputToChannel 3 1 3
    
    setChannelType 4 toggle
    linkTuyaMCUOutputToChannel 4 1 4
    
    setChannelType 5 toggle
    linkTuyaMCUOutputToChannel 5 1 5
    
    setChannelType 6 toggle
    linkTuyaMCUOutputToChannel 6 1 6
    


    Without your help, I would never figure this out.
    Thanks again for your help.
  • #6 20484235
    p.kaczmarek2
    Moderator Smart Home
    It was a pleasure to help you. If you have any questions, feel free to ask. Btw, I don't think there is a need to replace BK with ESP, as OpenBeken is fully functional now and you can get daily help here at elektroda.

    It's interesting to see that device is advertised as 'brasil switch':
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    Brazil 4x4 Tuya WiFi Smart Light Switch 4/6 Gang Touch Wall 110-240V Screen Panel APP Neutral Wire Work With Alexa Google Home


    Added after 27 [seconds]:

    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware

    Added after 2 [minutes]:

    PS: 55AA000300010407 is the same as WiFi state packet with 0x04 argument:
    TuyaMCU & CB3S 6-Gang Switch: Changing Serial Baud Rate to 115200bps with OpenBeken Firmware
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21130029
    yasirshahzad918
    Level 5  
    Can anyone tell me which touch IC is used here? I am looking for a touch IC for my custom touch PCB. @patentjyp, I think you can solve my problem. The picture you posted has clear markings, whereas the markings on other touch PCBs are removed.
  • #8 21130077
    patentjyp
    Level 5  
    >>21130029

    This is a Tuya MCU device with only ONE PCB. Two photos are front and back sides of the PCB.

    There is only one chip (except CB3S) at the center of the PCB as shown in the photo.

    This chip is Tuya MCU and it looks like this chip handles touch without separate touch chip.

    I hope this helps.
  • #9 21130212
    p.kaczmarek2
    Moderator Smart Home
    Are you looking for a particular touch button IC, or do you need a generic, proven solution for your design? I'd recommend to look into the TTP223 chip. It's very popular and well proven. You can get it (just IC or along with test board) cheaply on many places in the internet.
    TTP223 touch modules with displayed price of 1.01 USD
    Helpful post? Buy me a coffee.
  • #10 21130968
    yasirshahzad918
    Level 5  
    >>21130212 Hi @p.kaczmarek2, thanks for the reply. The TTP223 has good sensitivity, but the problem with the TTP223 is that it goes into recalibration mode or malfunctions when used near the magnetic field of an SMPS, causing delayed touch and ghost switching.

    Added after 5 [minutes]:

    >>21130077 Hi @patentjyp, the center IC of PCB is not a Tuya MCU; it actually features a touch IC. Could you please provide the exact markings on that central IC? If I can obtain the markings of that IC, it would greatly assist in resolving my main issue
  • #11 21130997
    p.kaczmarek2
    Moderator Smart Home
    Actually it's TuyaMCU (MCU, programmable, with UART bus). It's connected to WiFi module via UART:
    Close-up of a circuit board with a WiFi module and TuyaMCU microcontroller connected via UART bus.
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around configuring a 6-gang switch utilizing TuyaMCU and CB3S with OpenBeken firmware. The user successfully flashed the CB3S with OpenBK7231N_QIO_1.15.580.bin and established communication with the TuyaMCU. After setting the baud rate to 115200, the user encountered an issue where the relay states were not reflected in the web interface when toggled via the physical switch. The solution involved issuing the command "tuyaMcu_defWiFiState 4," which allowed the relay states to synchronize with the web UI. Further inquiries focused on the specific hex value sent to TuyaMCU for this command, with discussions on the differences between various command packets. Additionally, there were inquiries about the touch IC used in the device, with suggestions for alternatives like the TTP223 chip.
Summary generated by the language model.
ADVERTISEMENT