Elektroda.com
Elektroda.com
X

C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

williamgibsonwg 858 26
  • Here I will present the short teardown and OpenBK7231 programming procedure for a family of LED controllers.
    They are based on CBU module, BK7231N

    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    Unfortunately the CBU module is sandwiched between two boards, making access difficult.
    Here is the generic controller board, both sides:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    The generic controller has PWM outputs RGBCW to the mode-specific base board.

    The PWM outputs are not attached to the CBU module!
    The CBU module is connected via UART to a CMS32L051 microcontroller, which is also attached to the bluetooth radio and provides the PWM outputs buffered by a 74HC245.

    I did not know how to get OpenBeken to connect to this CMS32L051 over uart, so the plan was to remove it and jumper to the CBU PWM pins:

    To flash the CBU I desoldered the CMS32L051 which gave access to RX/TX on pins 5/6 (there is a series 1k resistor on both lines)
    Connect:
    CBU:16 RX or CMS32L051:6 - FTDI TTL-232R-3V3 Orange
    CBU:15 TX or CMS32L051:5 - FTDI TTL-232R-3V3 Yellow
    Flashing with the windows tool and a 3v3 FTDI cable was smooth.
    Note: I had disconnected 1k resistors and connected directly on CBU pins.
    I know with CMS32L051 installed, flashing is not possible.
    I assume flashing will work through 1k resistors if CMS32L051 is removed, but this was not tested.


    The RCBCW PWM lines are available on CMS32L051 pins 13/14/15/16/10

    I have a C02W so I jumpered:
    CMS32L051:10 to CBU:8 or P8, and configured this as Channel 5
    CMS32L051:16 to CBU:9 or P7, and configured this as Channel 4

    Doing this without desoldering the controller from the base board would be quite challenging but not impossible. I did split the boards apart as part of my investigation, but it was difficult to remove enough solder even with a desoldering gun.

    For some reason OpenBeken would not set the outputs (i.e. Channel 0 = 0.00, Channel 1 = 0.00, Channel 2 = 0.00, Channel 4 = 0.00, Channel 5 = 0.00) if I only configured channels 4 and 5.
    So I also configured P6 as channel 1 and P9 as channel 2 which makes this a RGBCW device, and now channels 4/5 work, with channels 1/2 not connected to anything and channel 3 not configured.

    I now have a C02W working with OpenBeken.

    There is very likely a better technique, but this was my first OpenBeken device. Any advice would be welcome - I want several such modules but I'm not sure it's worth the hassle.

    Cool? Ranking DIY
    About Author
    williamgibsonwg
    Level 3  
    Offline 
    williamgibsonwg wrote 6 posts with rating 2. Been with us since 2023 year.
  • #2
    p.kaczmarek2
    Moderator Smart Home
    Hello, there are several ways to improve the workflow here.
    1. you can do a 2MB flash backup of this device and use it then to flash next pieces without soldering wires
    2. removing MCU and using PWMs for LED control is good, but you can also just use TuyaMCU driver. For that purpose, you might need first just solder ground ,RX1 and TX1 wires and capture packets with RealtTerm in text hex format. When capturing packets, do separate captures for activities on Tuya APP , like:
    - setting 100% warm
    - setting 100% cool
    - setting red color
    - setting brightness 25%, 50%, 60%, etc
    Then we can use our TuyaMCU analyzer to figure out which dpIDs are used to control colours, etc by the device. And then just use TuyaMCU protocol to control the MCU via OBK UART....

    Here is an example of captured data:
    
    55AA032B00002D55AA0307000801020004000000BBD355AA03070008020200040000001F3855AA03000001010455AA032400002655AA031C00001E55AA032B00002D
    

    And now pasted into the analyzer:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
  • #3
    williamgibsonwg
    Level 3  
    Thanks for the suggestions!
    I did take a backup of the original firmware if it is of use to anyone, let me know.

    I'm not sure what you mean about 'flash without flashing'.

    That's great there is a MCU decoder. Is that available for users or do I post the serial messages in a future teardown?

    Also do you have any suggestions why a cool/warm only LED device was not setting outputs? It looks like the OpenBeken RGBCW controller has a 'rgb' mode and a 'cw' mode and it's as if it was not switching into 'cw', so everything stayed off. That's pure speculation though.
  • #4
    p.kaczmarek2
    Moderator Smart Home
    Sorry, it seems that part of my message was lost during edit. I meant that doing 2MB backup allows you to flash without soldering wires, remotely, via the cloudcutter program. That way you can upload OpenBeken without soldering wires.

    I will be releasing analyzer tool, but for now please post hex data. Maybe I will just attach a build here so you can play with it.

    OpenBeken should work correctly in all common cases, including:
    - single PWM (set channel 0 or 1)
    - two PWMS (set channel 0 and 1, it should just work), as CW
    - three PWMs ( set channel 0, 1, 2 ) - as RGB
    - five PWMs (set channel 0, 1, 2, 3, 4) - RGBCW
    The order of set channels matters. You can start indexing with 0 or with 1, but order matters, and order is: RGBCW. The CW case can also handle special case, if you have two PWMs, the device will know it was meant to be use CW.

    Here is a screenshot from Windows Simulator with CW strip in OBK:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
  • #5
    williamgibsonwg
    Level 3  
    Hi,

    I got another device and recorded the UART as requested.
    9600 baud 8N1 on pin 5

    Unfortunately the device isn't recognized as Cool/Warm, it appears as just a single channel "Smart Wi-Fi Dimmer" in both "Tuya Smart" and "Smart Life" apps, so I just get brightness and on/off. Both cool and warm are operated equally. I hope you can guess which is which - I would guess the protocol is consistent with RGBCW ordering since that's the pin layout on the main board.
    Let me know what else I can provide!


    
    ON 10%
    55 AA 00 06 00 05 14 01 00 01 01 21                                     
    
    OFF
    55 AA 00 06 00 05 14 01 00 01 00 20                                     
    
    Change to 100% by swiping                                                                       
    55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 30 30 30 30 30 30 30 30 
    30 38 66 30 33 65 38 C1 55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 
    30 30 30 30 30 30 30 30 33 36 37 30 33 65 38 93 55 AA 00 06 00 19 1C 03 
    00 15 31 30 30 30 30 30 30 30 30 30 30 30 30 30 33 37 62 30 33 65 38 BF 
    55 AA 00 06 00 08 16 02 00 04 00 00 03 75 A1 55 AA 00 06 00 05 14 01 00 
    01 01 21 55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 30 30 30 30 30 
    30 30 30 33 65 38 30 33 65 38 C3 55 AA 00 06 00 08 16 02 00 04 00 00 03 
    E8 14 55 AA 00 06 00 05 14 01 00 01 01 21                               
    55 AA 00 00 00 00 FF                                                    
    
    
    OFF
    55 AA 00 06 00 05 14 01 00 01 00 20  
    
    ON 100%                                   
    55 AA 00 06 00 05 14 01 00 01 01 21 
    
    Occasional random message
    55 AA 00 00 00 00 FF 
    
    "Good Night"
    55 AA 00 06 00 05 14 01 00 01 01 21 55 AA 00 06 00 05 15 04 00 01 02 26 
    55 AA 00 06 00 20 19 03 00 1C 30 30 30 65 30 64 30 30 30 30 30 30 30 30 
    30 30 30 30 30 30 30 30 63 38 30 30 30 30 41                            
    
    "Reading"                                                                        
    55 AA 00 06 00 05 14 01 00 01 01 21 55 AA 00 06 00 05 15 04 00 01 02 26 
    55 AA 00 06 00 20 19 03 00 1C 30 31 30 65 30 64 30 30 30 30 30 30 30 30 
    30 30 30 30 30 30 30 33 65 38 30 31 66 34 82                            
    
    "Working"                                                                        
    55 AA 00 00 00 00 FF 55 AA 00 06 00 05 14 01 00 01 01 21 55 AA 00 06 00 
    05 15 04 00 01 02 26 55 AA 00 06 00 20 19 03 00 1C 30 32 30 65 30 64 30 
    30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 65 38 30 33 65 38 88
    
    Brightness 1%
    55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 30 30 30 30 30 30 30 30 
    30 30 61 30 33 65 38 B4 55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 
    30 30 30 30 30 30 30 30 30 30 61 30 33 65 38 B4 55 AA 00 00 00 00 FF 55
    
    Brightness 75%
    55 AA 00 06 00 19 1C 03 00 15 31 30 30 
    30 30 30 30 30 30 30 30 30 30 30 32 65 31 30 33 65 38 BB 55 AA 00 06 00 
    19 1C 03 00 15 31 30 30 30 30 30 30 30 30 30 30 30 30 30 32 65 37 30 33 
    65 38 C1 55 AA 00 06 00 19 1C 03 00 15 31 30 30 30 30 30 30 30 30 30 30 
    30 30 30 32 65 61 30 33 65 38 EB 55 AA 00 06 00 08 16 02 00 04 00 00 02 
    EA 15 
  • #6
    p.kaczmarek2
    Moderator Smart Home
    Here is the tool used:
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20528459#20528459
    Here is interpretation:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    The packet above is only turn on, no brightness change.

    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    dpID20 = power?

    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    dpID 22 = dimmer?
    What are those strange extra values?


    "Good night":
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    What may be this?
    fnId=25 Str V=30 30 30 65 30 64 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 63 38 30 30 30 30
    A string? What if we decode as ASCII...
    
    30 30 30 65 30 64 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 63 38 30 30 30 30
    00 0e 0d 00 00 00 00 00 00 00 00 c8 00 00
    

    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol


    "Working"
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol


    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    I am not sure yet what are those strings. It seems that device is sending also some string ASCII data, maybe ASCII colour codes? I wonder why...
    
    55 AA	00	06		00 19	1C030015313030303030303030303030303032656130336538	EB	
    HEADER	VER=00	Unk		LEN	fnId=28 Str V=31 30 30 30 30 30 30 30 30 30 30 30 30 30 32 65 61 30 33 65 38	CHK	
    


    So there is a dpID for power, for dimmer, and at least two strange dpIDs with string data.

    We need to figure what are those strings. Tell me again, you have only CW version which is seen by app as single color? Or do you have access to RGB / RGBCW version as well?
  • #7
    williamgibsonwg
    Level 3  
    Thanks for your help. I've been at it for a few hours, not figured out yet.

    I have only one kind, cool/warm. The app detects it as monochromatic. I can't seem to manually add a C/W version either, it always autodetects.

    Since there are resistors on UART lines I can actually write serial commands with RealTerm and have them accepted.
    Frustratingly the crc isn't a RealTerm standard so I have to manually calculate it (I found out your app doesn't verify checksums, but it is really helpful, thanks for releasing it!)

    Read startup sequence on RX/TX (below). This lists variables:
    20 (bool) power 0/1
    21 (enum) Manual=0 Scene=2
    22 (int) Brightness 0=1000
    26 (int) ?? V=0
    34 (bool) ?? V=0
    33 (RAW) ?? V=00 01 00 00 03 E8 03 E8 03 E8 03 E8

    Note the string used by the app is NOT here.
    I've tried to create a Write 33 message by changing status message to command; not working:
    
    Status 55 AA	03	07		00 10	21 00 00 0C 0001000003E803E803E803E8 		F3	
    Write 0x55 0xAA 0x00 0x06 0x00 0x10 0x21 0x00 0x00 0x0C 0x00 0x01 0x00 0x00 0x03 0xE8 0x03 0xE8 0x03 0xE8 0x03 0xE8 0xEE


    On Startup:
    
    55 AA 00 00 00 00 FF 55 AA 00 01 00 00 00 55 AA 00 02 00 00 01 55 
    AA 00 08 00 00 07 55 AA 00 03 00 01 03 06 55 AA 00 03 00 01 04 07 55 AA 
    00 00 00 00 FF
    55 AA	00	00		00 00		FF	
    HEADER	VER=00	Heartbeat		LEN		CHK	
    
    55 AA	00	01		00 00		00	
    HEADER	VER=00	Product		LEN		CHK	
    
    55 AA	00	02		00 00		01	
    HEADER	VER=00	McuConf		LEN		CHK	
    
    0x55 0xAA 0x00 0x08 0x00 0x00 0x07
    55 AA	00	08		00 00		07	
    HEADER	VER=00	Unk		LEN	INVALID date		CHK	
    
    55 AA	00	03		00 01	03	06	
    HEADER	VER=00	WifiState		LEN	03	CHK	
    
    55 AA	00	03		00 01	04	07	
    HEADER	VER=00	WifiState		LEN	04	CHK	
    
    
    
    Pin 6:
    On Startup:
    55 AA 03 00 00 01 00 03 55 AA 03 01 00 32 7B 22 70 22 3A 22 6E 77 61 
    72 36 77 6F 76 61 71 79 63 78 78 7A 7A 22 2C 22 76 22 3A 22 31 2E 30 2E 
    30 22 2C 22 6D 22 3A 32 2C 22 6D 74 22 3A 31 30 7D C1 55 AA 03 02 00 00 
    04 55 AA 03 07 00 05 14 01 00 01 01 25 55 AA 03 07 00 05 22 01 00 01 00 
    32 55 AA 03 07 00 05 15 04 00 01 02 2A 55 AA 03 07 00 08 16 02 00 04 00 
    00 03 C0 F0 55 AA 03 03 00 00 05 55 AA 03 03 00 00 05 55 AA 03 00 00 01 
    01 04 55 AA 03 07 00 10 21 00 00 0C 00 01 00 00 03 E8 03 E8 03 E8 03 E8 
    F3 55 AA 03 07 00 08 1A 02 00 04 00 00 00 00 31
    Decoded:
    55 AA	03	00		00 01	00	03	
    HEADER	VER=03	Heartbeat		LEN	00	CHK	
    
    55 AA	03	01		00 32	7B2270223A226E77617236776F766171796378787A7A222C2276223A22312E302E30222C226D223A322C226D74223A31307D	C1	
    HEADER	VER=03	Product		LEN	{"p":"nwar6wovaqycxxzz","v":"1.0.0","m":2,"mt":10}	CHK	
    
    55 AA	03	02		00 00		04	
    HEADER	VER=03	McuConf		LEN		CHK	
    
    55 AA	03	07		00 05	14 01 00 01 01 		25	
    HEADER	VER=03	State		LEN	fnId=20 Bool V=1	CHK	
    
    55 AA	03	07		00 05	22 01 00 01 00 		32	
    HEADER	VER=03	State		LEN	fnId=34 Bool V=0	CHK	
    
    55 AA	03	07		00 05	15 04 00 01 02 		2A	
    HEADER	VER=03	State		LEN	fnId=21 Enum V=2	CHK	
    
    55 AA	03	07		00 08	16 02 00 04 000003C0 		F0	
    HEADER	VER=03	State		LEN	fnId=22 Val V=960	CHK	
    
    55 AA	03	03		00 00		05	
    HEADER	VER=03	WifiState		LEN		CHK	
    
    55 AA	03	03		00 00		05	
    HEADER	VER=03	WifiState		LEN		CHK	
    
    55 AA	03	00		00 01	01	04	
    HEADER	VER=03	Heartbeat		LEN	01	CHK	
    
    55 AA	03	07		00 10	21 00 00 0C 0001000003E803E803E803E8 		F3	
    HEADER	VER=03	State		LEN	fnId=33 Raw V=00 01 00 00 03 E8 03 E8 03 E8 03 E8	CHK	
    
    55 AA	03	07		00 08	1A 02 00 04 00000000 		31	
    HEADER	VER=03	State		LEN	fnId=26 Val V=0	CHK	
    


    Through a lot of slow effort I simplified some cases for the strings:
    
    0000000000000000000000100000 1%
    0000000000000000000000300000 2%
    0000000000000000000000500000 3%
    0000000000000000000001000000 11%
    0000000000000000000002000000 32%
    0000000000000000000003000000 62%
    
    0000000000000000000010000000 99.9%
    0000000000000000000020000000 32% (weird)
    0000000000000000000030000000 99.9% 
    0000000000000000000040000000 99.9% 
    0000000000000000000050000000 0%
    
    0000000000000000001000000000 1%
    0000000000000000003000000000 2%
    0000000000000000005000000000 3%
    0000000000000000010000000000 11% (same pattern)
    
    0000000000000000100000000000 99.9% (same weird pattern)
    
    A 1 in any other position (0x31 character) results in OFF/0%
    In all cases, R=G=B=0 and C=W=%
    
  • #8
    jrhenk
    Level 9  
    Hi Everyone,
    I also got this device today, the CW01 version. Flashing with cloudcutter worked flawlessly, however the config seems a bit more demanding.
    - With the Tuya App the device worked as expected, so I'd say the hardware is OK
    - With openbeken and the config from the screenshot above (pwms at 24,26 and the rest as on the screenshot) I can't change anything. Not even switch on/off. Just for fun I also tried 6, 7, 8, 9 for PWM but also nothing yet.
    - Another issue I haven't seen with openbeken before: While I can edit the pins via the Web App, if I click on the Module section in the UI the firmware just crashes on loading the page (often does not get beyond field 7 or so)

    Happy to help troubleshooting if I can, checked the weblog but did not see any obvious yet there.

    Edit: One potentially interesting thing I noticed: Nevertheless the device runs openbeken now, if I click the button it shows the same dimming up/down as if it would still be running the tuya firmware. Maybe my device actually works with a TuyaMCU? Well I guess all tuya devices have one, but I mean we might need to use the TuyaMCU driver instead of configuring PINs directly? Do I actually understand right how this works? lol

    Added after 8 [minutes]:

    >>20550441
    I can at least help with this :)
    Before I flashed it, I played around with it a bit more and the "Good Night" is a Tuya Scene that just sets the device to some pre-configure brightness :)
  • #9
    williamgibsonwg
    Level 3  
    Hi jrhenk,

    You might have missed the part where I desoldered the TuyaMCU and directly soldered wires to the CBU.
    I don't recommend you follow this procedure though, since it's a pain.

    Thanks to p.kaczmarek2 I captured the serial RX/TX between TuyaMCU and CBU.

    p.kaczmarek2 - the captures I provided above are from a C01W, not a C02W like I thought.
    I think the strange string we discussed is unnecessary. Sending the on/off and brightness commands over serial did perform as expected.
    dpID20 = power
    dpID 22 = dimmer
    How can we make the TuyaMCU module for jrhenk's C01W?

    I will attempt a capture from a C02W when it arrives.
  • #10
    jrhenk
    Level 9  
    Thanks for the quick reply! I saw that but also the follow up that it's not necessary if you load the tuya driver, made me not getting my solder iron out :) I also saw the info about the dpIDs yet I'm not 100% what to do with it.
    I put "startDriver TuyaMCU" in the autoexec.bat and under "Channel Types" in the Web App configured power for 20 and dimmer for 22 but that didn't work and I also only see a slider for "power" on the www ui which seems wrong... it feels like I'm very close :)
  • #11
    p.kaczmarek2
    Moderator Smart Home
    Hello, good job, assuming that this is true:
    williamgibsonwg wrote:

    p.kaczmarek2 - the captures I provided above are from a C01W, not a C02W like I thought.
    I think the strange string we discussed is unnecessary. Sending the on/off and brightness commands over serial did perform as expected.
    dpID20 = power
    dpID 22 = dimmer

    You can use approach from this topics:
    Dimmer EDM-01AA-EU 300W for BK7231 and TuyaMCU - configuration
    MoesHouse DIY Smart WiFi Light LED Dimmer Switch Smart Life
    Please read both of the guides above, but basically, here is a proposed config:
    
    
    startDriver TuyaMCU
    setChannelType 1 toggle
    setChannelType 2 dimmer
    // not needed here?
    //tuyaMcu_setBaudRate 115200
    tuyaMcu_setDimmerRange 1 1000
    // dpID 20 is power
    linkTuyaMCUOutputToChannel 20 bool 1
    // dpID 22 is dimmer
    linkTuyaMCUOutputToChannel 22 val 2
    

    but I am not sure if it's all that is required.
    Don't we also need to send that strange ASCII RGB string packet?
  • #12
    jrhenk
    Level 9  
    Oh yes, it's completely working now, thanks so much for the config!!! Thanks to it, I also have a better chance now to translate the initial findings into a config syntax since I had now idea how to do that yesterday :)
    BTW: I bought this module for a little test and was not sure how it goes, as I didn't want to use it for a LED strip but for 12v LED Spots. I reckoned that if you dim the 12V itself and not a power supply that provides the 12V the dimming must be nicer, and this is indeed the case! It's the smoothest dimming I saw for 12V spots so far.

    After using the config I can also go to the Module configuration in the WWW UI without the firmware crashing.

    The only thing that could still be improved now is the boot time, for some reason this module needs significantly longer compared to all other openbeken flashed modules I have until it is initialized. As well on power disconnect/connect as on reboot it needs around 60-80 seconds before it's up.
  • #13
    p.kaczmarek2
    Moderator Smart Home
    What does the log say during boot? Connect UART to USB converter RX to TX2 pin of your module.
  • #14
    jrhenk
    Level 9  
    Is there any way to do this remotely? Already installed it into a ceiling and also a bit afraid I break it after all with my still beginner's soldering skills

    edit: interesting, after configuring mqtt startup is down to 40sec , still a bit long but definitely better already
  • #15
    p.kaczmarek2
    Moderator Smart Home
    open web app log, press reboot, clear log, and wait for the log to update, it will show a great chunk of things that happen at startup
  • #16
    jrhenk
    Level 9  
    Ah ok! I thought you'll see even more when connecting cables, here's what it shows:


    Info:MAIN:Module reboot in 1...
    001/2/set
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 0 for ch 1
    Info:GEN:No change in channel 1 (still set to 0) - ignoring

    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 36 for ch 2
    Info:GEN:CHANNEL_Set channel 2 has changed to 36 (flags 0)

    Info:MQTT:Channel has changed! Publishing 36 to channel 2
    Info:MQTT:Publishing val 36 to openbk/12V_dimmer001/2/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk/12V_dimmer001/2/get
    Info:MQTT:Publishing val 12V_dimmer001 to openbk/12V_dimmer001/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 16 02 00 04 00 00 01 68 96
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 15 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 22, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 360
    Info:GEN:CHANNEL_Set channel 2 has changed to 35 (flags 0)

    Info:MQTT:Channel has changed! Publishing 35 to channel 2
    Info:MQTT:Publishing val 35 to openbk/12V_dimmer001/2/get retain=0
    Info:MAIN:Time 27, idle 361150/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk/12V_dimmer001/2/get
    Info:MQTT:Publishing val Build on Apr 28 2023 08:55:26 version 1.17.60 to openbk/12V_dimmer001/build retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 03 00 00 05
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 3 (WiFiState) with 7 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 06 1F 00 00 02 00 00 30
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 13 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 31, dataType 0-DP_TYPE_RAW and 2 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 00 20
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: discarding packet bad expected checksum, expected 32 and got checksum 9
    Info:TuyaMCU:Consumed 6 unwanted non-header byte in Tuya MCU buffer
    Info:TuyaMCU:Skipped data (part) 00 00 02 00 00 31
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 06 D2 00 00 02 00 00 E3
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 13 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 210, dataType 0-DP_TYPE_RAW and 2 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 22 01 00 01 00 32
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 34, dataType 1-DP_TYPE_BOOL and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte:
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 10 21 00 00 0C 00 01 00 00 03 E8 03 E8 03 E8 03 E8 F3
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 23 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 33, dataType 0-DP_TYPE_RAW and 12 data bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 1A 02 00 04 00 00 00 00 31
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 15 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 26, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 0
    Info:MAIN:Time 28, idle 177066/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Publishing val 1c:90:ff:43:a2:0c to openbk/12V_dimmer001/mac retain=0
    Info:MAIN:Time 29, idle 158262/s, free 72536, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Publishing val 2 to openbk/12V_dimmer001/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 30, idle 347209/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.1.85 gate=192.168.1.1 mask=255.255.255.0 mac=1c:90:ff:43:a2:0c
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-68,ssid=tripleXV/0,bssid=28:d1:27:4c:4c:13 ,channel=3,cipher_type:MIXED
    Info:MQTT:Publishing val -67 to openbk/12V_dimmer001/rssi retain=0
    Info:MAIN:Time 31, idle 179807/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Publishing val 31 to openbk/12V_dimmer001/uptime retain=0
    Info:MAIN:Time 32, idle 189078/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Publishing val 72792 to openbk/12V_dimmer001/freeheap retain=0
    Info:MAIN:Time 33, idle 187251/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Publishing val 192.168.1.85 to openbk/12V_dimmer001/ip retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 34, idle 189541/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Channel has changed! Publishing 0 to channel 1
    Info:MQTT:Publishing val 0 to openbk/12V_dimmer001/1/get retain=0
    Info:MAIN:Time 35, idle 194308/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk/12V_dimmer001/1/get
    Info:MQTT:Channel has changed! Publishing 35 to channel 2
    Info:MQTT:Publishing val 35 to openbk/12V_dimmer001/2/get retain=0
    Info:MAIN:Time 36, idle 188306/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk/12V_dimmer001/2/get
    Info:MAIN:Time 37, idle 183630/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 38, idle 190844/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 39, idle 188607/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 40, idle 190307/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.1.85 gate=192.168.1.1 mask=255.255.255.0 mac=1c:90:ff:43:a2:0c
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-68,ssid=tripleXV/0,bssid=28:d1:27:4c:4c:13 ,channel=3,cipher_type:MIXED
    Info:MAIN:Time 41, idle 185223/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 42, idle 192612/s, free 72792, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
  • #17
    jrhenk
    Level 9  
    alright, with the newest firmware and the wifi quickconnect flag set I won a couple of more seconds, and it's now down to 20 which is pretty much the same that I also get with a couple of other devices, some still seem to be faster though
    two questions if you don't mind:
    - On github I saw this issue report about NTP delay and in the logs it looks like that device is connected after just 5 seconds. With the C01W and a couple of RGBW spots it seems it just does not get under 20 sec... can this still be improved or does the driver just need this time to initialize?
    - Since one of the last firmware updates mqtt discovery is kind of working, but it seems I can still only control brightness if I add the device manually via the yaml file: is there something I can already do about it or is this going to be addressed in one of the next updates? I remember you said somewhere that tuyamcu discovery is still work in progress

    Thanks in advance!
  • #18
    p.kaczmarek2
    Moderator Smart Home
    jrhenk wrote:

    - On github I saw this issue report about NTP delay and in the logs it looks like that device is connected after just 5 seconds. With the C01W and a couple of RGBW spots it seems it just does not get under 20 sec... can this still be improved or does the driver just need this time to initialize?

    The issue is closed. I can't think how it can be any faster.

    Here's a sample from my WB3S LED strip, I need 7 seconds to get to NTP ready:
    
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 45 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 11 changes count.
    Error:CMD:no file early.bat err -2
    Info:GEN:PIN_SetupPins pins have been set up.
    Info:MAIN:Main_Init_Before_Delay done
    Info:MAIN:Main_Init_Delay
    Info:MAIN:Main_Init_Delay done
    Info:MAIN:Main_Init_After_Delay
    Info:MAIN:ssid:qqqqqqqqqqqqqqqqqqqqqqqqqqqq
    Info:MAIN:Using SSID [qqqqqqqqqqqq]
    Info:MAIN:Using Pass [qqqqqqqqqqqqqqqqq]
    Info:MQTT:MQTT_RegisterCallback called for bT obkLEDstripWindow/ subT obkLEDstripWindow/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT bekens/ subT bekens/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/obkLEDstripWindow/ subT cmnd/obkLEDstripWindow/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/bekens/ subT cmnd/bekens/+
    Info:MQTT:MQTT_RegisterCallback called for bT obkLEDstripWindow/ subT obkLEDstripWindow/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:NTP:NTP driver initialized with server=217.147.223.78, offset=0
    Info:MAIN:Started NTP.
    Info:MAIN:Time 1, idle 240138/s, free 84304, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 2, idle 215726/s, free 84304, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 74493/s, free 84368, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 84368, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Time 5, idle 10399/s, free 82808, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass qqqqqqqqqq
    mqtt_clientID obkLEDstripWindow
    mqtt_host 192.168.0.113:1883
    Info:MAIN:Time 6, idle 244856/s, free 84264, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:NTP:Seconds since Jan 1 1900 = 3891990453
    Info:NTP:Unix time  : 1683001653
    Info:NTP:Local Time : 2023/05/02 04:27:33
    Info:MAIN:Time 7, idle 214557/s, free 84496, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:CMD:"NTP is ready"
    


    jrhenk wrote:

    - Since one of the last firmware updates mqtt discovery is kind of working, but it seems I can still only control brightness if I add the device manually via the yaml file: is there something I can already do about it or is this going to be addressed in one of the next updates? I remember you said somewhere that tuyamcu discovery is still work in progress

    The discovery of TuyaMCU combo Toggle+brightness is still missing, but I can maybe try adding it today or tomorrow, would you be able to help with testing?
  • #19
    jrhenk
    Level 9  
    Thanks for the reply and it wasn't so much about the NTP I was just jealous about the quicker bootup time :)
    In the meantime I think I actually found a fix!! For some reason if you start using the Wifi Quick Connect Flag a simple reboot does not change a lot - it saves a couple of seconds but not more. Disconnecting the device from power and reconnecting it however leads to a significant change, now the same two devices that took 20sec to boot are up in 5-7 seconds, very cool! Dunno if this is specifically connected to these devices, but maybe it could make sense to add this as info to the flag 35
    Edit: Also tried it with RGBW spots (they use the SM2135 driver, the other two the tuyamcu one) and it shows the same behavior... so based on this I think it could make sense to add this tip to the flag

    About the brightness setting: Happy to help testing and share how it goes!!
  • #20
    p.kaczmarek2
    Moderator Smart Home
    I didn't know about that "full power off and power on" requirement. This is new to me. Maybe it didn't occur with my devices. @DeDaMrAz have you noticed anything like that?

    I will try to add that full discovery tomorrow. I haven't managed to do it today. I was working on TuyaMCU humidity/temperature sensor, a teardown with detailed guide will be posted in few days.
  • #21
    jrhenk
    Level 9  
    Great! You are crazy fast with answering questions here and updates anyway, so take your time... should all remain fun especially for you!
  • #22
    DeDaMrAz
    Level 10  
    p.kaczmarek2 wrote:
    I didn't know about that "full power off and power on" requirement. This is new to me. Maybe it didn't occur with my devices. @DeDaMrAz have you noticed anything like that?

    I will try to add that full discovery tomorrow. I haven't managed to do it today. I was working on TuyaMCU humidity/temperature sensor, a teardown with detailed guide will be posted in few days.


    :D I am not the best one to answer as I set up my devices on the bench and often do full power cycle while testing :)
  • #23
    jrhenk
    Level 9  
    Hahaha it's these unconscious steps one tends to forget about that can turn out to be very important. But this was actually the way that led me to it: I have a C01W dimmer not yet installed where I noticed the faster startup after starting to play with it again, and a different dimmer that is already in the ceiling yet I can switch mains on it. After I noticed the quicker startup in the C01W I just thought: Could that be it? and it was, at least in my case :)
  • #24
    jrhenk
    Level 9  
    >>20564123
    Hi! I tried the latest firmwares but I guess you did not come around to include the brightness for autodiscovery yet, let me know when you do, happy to help with testing!

    About the C01W: I noticed that while the Moes MS 105 safe the channel states correctly (with the code posted in the other thread), this seem not to fully work yet for this device, guess it does not safe the channel 1 correctly..maybe there's a mistake in my code? On power disconnect/reconnect it sets the light on (to the last level when it was on) and only after reconnecting to mqtt it sets it off again. This does not happen on a reboot without disconnecting power. Here's my complete autoexec.bat - I added the part underneath and I think it's should work?

    
    startDriver TuyaMCU
    setChannelType 1 toggle
    setChannelType 2 dimmer
    // not needed here?
    //tuyaMcu_setBaudRate 115200
    tuyaMcu_setDimmerRange 1 1000
    // dpID 20 is power
    linkTuyaMCUOutputToChannel 20 bool 1
    // dpID 22 is dimmer
    linkTuyaMCUOutputToChannel 22 val 2
    ///////
    // when channel 1 changes, save it to flash channel 201
    addEventHandler OnChannelChange 1 setChannel 201 $CH1
    // when channel 2 changes, save it to flash channel 202
    addEventHandler OnChannelChange 2 setChannel 202 $CH2
    addRepeatingEvent 1 1 backlog setChannel 1 $CH201; setChannel 2 $CH202
    
  • #25
    p.kaczmarek2
    Moderator Smart Home
    Hello, I haven't the time to test it yet, but the basic Toggle + Dimmer combo for HASS discovery should be working now. I will try out it today, please wait a moment..

    Added after 31 [minutes]:

    EDIT: wait, it seems to work for me! Take a look:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    With latest codebase, after doing again HASS Discovery:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    So it works for me, currently for Toggle channel + Dimmer channel combo.
  • #26
    williamgibsonwg
    Level 3  
    I've finally got working C02W (d'oh)

    I have determined the string coordinates setting all values simultaneously.
    For non-scene control:
    dpID 21 = 0 (non-scene)
    dpID 22 = dimmer (0-1000)
    dpID 23 = Colour (0 = warm, 1000 = cool)
    dpID 28 = string ("10000000000000", 2 bytes dpID 22, 2 bytes dpID 23)
    -e.g. 100000000000003e803e8 for 100% Cool, 100000000000003e80000 for 100% Warm
    Assuming 1 0000 0000 0000 03e8 0000 is "1 R G B DIM COOL" for anyone with C03W/C04W/C05W, but I can't guess what dpIDs these correspond to sorry.

    When using the Tuya apps, it always uses dpID 28 while scrolling values, and then sets 23/22 after the smooth motion stops. I assume setting 23/22 independently will be OK.

    For scene control:
    dpID 21 = 2 (scene)
    dpID 25 = string :
    1 byte scene number (probably unimportant)
    repeating set of:
    2 bytes timing (100=4.5s, 72=3.2s, 52 = 2.3sm 40=0.5s, something like byte[decimal] = 33.8*exp(0.23*seconds))
    1 byte type (0=constant 1=flash 2=breathe)
    6 bytes zero (almost certainly reserved for RGB)
    2 bytes dpID 22, 2 bytes dpID 23
    for every item you want in the sequence.
    Smart Life only has 1 or 2 items in sequence, but format looks like maybe you could add more.

    Details:
    Spoiler:
    Set scene #4 to flash 100%C/100%W, slow (4.5s):
    dpID25 = "04 64640100000000000003e803e8 64640100000000000003e80000"

    Set scene #4 to flash 100%C/100%W, fast:
    dpID25 = "04 28280100000000000003e803e8 28280100000000000003e80000"

    Set scene #4 to breathe 100%C/100%W, fast (0.5s):
    dpID25 = "04 28280200000000000003e803e8 28280200000000000003e80000"

    C02W startup sequence:
    Product {"p":"3szijijz5uwozmjm","v":"1.0.0","m":2,"mt":10}
    dpID 20=1 (power)
    dpID 21=2 (scene)
    dpID 22=1000 (dimmer)
    dpID 23=1000 (colour)
    dpID 26 = 0 (??)
    dpID 33 = RAW: 00 01 00 00 03 E8 03 E8 03 E8 03 E8 (looks like scene info?)
    dpID 34=0 (??)




    Question: Is there a list of TypeString that setChannelType accepts somewhere? I couldn't find it, looked here.
    I'm not sure how to configure dpID 23.

    Does OpenBeken support constructing these strings? I don't think I care for my application but it was fun reverse engineering it a bit.
  • #27
    jrhenk
    Level 9  
    >>20567163
    Thanks for looking into it again, for some reason here it isn't working yet with the autodiscovery running 1.17.104
    This is the entity I added in the yaml:
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol
    ... and this is via the MQTT autodiscovery, just on/off so far
    C01W/C02W/C03W/C04W WiFi&BT LED Controller with TuyaMCU UART protocol

    Edit: just to be sure I deleted the autodiscovered entity again and let it be autodiscovered again, but still just on/off. Also tried with changing the name in case it's some home assistant issue, but same still ... let me know if I should try something else