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

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector

p.kaczmarek2 17490 35

TL;DR

  • TuyaMCU Analyzer decodes eavesdropped TuyaMCU UART packets into dpID variables, showing each packet’s type, length, and values.
  • It accepts hex logs from RealTerm, colorizes packet bytes, auto-detects variable IDs, and includes sample files plus a compare tool.
  • The analyzer helps identify values such as dimmer levels that usually range from 0 to 1000, making it easier to map Tuya controls.
  • Examples cover switches, dimmers, thermometers, hygrometers, fan-speed controls, timers, and energy-monitor readings mapped into OpenBeken channels.
  • It cannot universally decode raw multi-measurement dpIDs from advanced Tuya electricity meters, because their byte format is device-dependent.
Summary generated by AI based on the discussion content.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • Screenshot of TuyaMCU Explorer showing packet data in hex format and decoded.
    Here is a small program that allows you to analyze the content of TuyaMCU eavesdropped packets. The program shows the type, length and content of the packet, broken down into dpID variables, their types and values. The program allows you to quickly find out what the dpID we overheard contain - whether it is, for example, a dimmer value or, for example, a relay state, or maybe it is a voltage or current value. The program shown here is useful in the process of releasing a given IoT product from the cloud, because this process requires us to determine the available dpIDs for a given product, because these dpIDs are different for different products.

    Related Topics
    TuyaMCU is a UART-based protocol through which the WiFi module communicates with an additional microcontroller on board the device. In the case of devices with TuyaMCU, the WiFi module usually only reports data to the network, and the MCU itself supports relays, buttons, LCD or sensors and measuring systems.
    For more details, I invite you to the topic about TuyaMCU itself: TuyaMCU protocol - communication between the microcontroller and the WiFi module
    In addition, it is worth seeing examples of devices using TuyaMCU:
    - WF-DS01 SmartLife/Tuya WiFi switch/dimmer for box - diagram
    - EDM-01AA-EU 300W dimmer for BK7231 and TuyaMCU - configuration
    - HomeMate Wi-Fi + Bluetooth Smart 4 Gang Touch Switch
    - Tuya ATORCH AT4P(WP/BW) Smartlife Energy monitor (BK7231N) (C3BS) (CH573F) (BL0924)
    - QIACHIP Universal WIFI Ceiling Fan Light Remote Control Kit - BK7231N - CB2S
    - Energy-saving (?) battery door/window sensor for WiFi DS06

    TuyaMCU packet capture
    Capturing TuyaMCU packets is really very simple. One USB to UART converter is enough:
    USB to TTL UART converter CH340G.
    Just power from USB ( not from the web! everything should be unplugged ) our device, connect 5V from USB before the 3.3V LDO regulator on board, which will also provide a stable 3.3V for the WiFi module, and then solder with ground and signal wires on RX and TX. For example, for WB3S:
    Diagram of an electronic module with pins labeled TXD1 and RXD1.
    In the case of Tuya modules, the same UART is used to program the module via the bootloader and to communicate with TuyaMCU, which can sometimes be problematic. When changing the firmware, I often have to desolder the WiFi module in this case or break the path (and then reconstruct it).
    UART is a bi-directional bus, so first we capture from the TuyaMCU TX line -> WiFi RX module, and then from the WiFi line TX module -> TuyaMCU RX

    Capturing is easy to do in RealTerm:
    Screenshot of RealTerm: Serial Capture Program version 2.0.0.70 with open interface.
    It is best to choose hex with spaces (not binary):
    Screenshot of RealTerm program with ASCII display format selected.
    Then you should enable writing to the file, so it's more convenient:
    Screenshot of RealTerm program for capturing serial communication.
    Capture Steps:
    1. connect the USB to UART converter to the device, but do not connect the 5V from USB to its power yet (do not turn on the device)
    2. start capturing, first e.g. from TuyaMCU TX line -> WiFi RX module
    3. perform selected operations on the device
    4. finish capturing
    5. repeat points 1, 2, 3 and 4, but in point 2, connect to the WiFi line of the TX module -> TuyaMCU RX

    I recommend doing separate packet captures for different operations, e.g.:
    - separately for starting the device
    - separately, e.g. for dimmer status changes (changes in brightness level)
    - separately for on/off
    - separately for other settings (if available), e.g. in the case of devices with energy measurement, it is worth doing a separate capture for different voltages and saving these voltages, then you can compare packets on this basis and look for where the voltage value is saved, etc. Same with power - do a capture when measuring the load 30W and then 100W, etc.

    Using two USB to UART converters it could be improved, but it would also be nice to have some software that saves communication from two COM ports at once.

    TuyaMCU analyzer
    The program can be downloaded from Github, already in compiled form:
    https://github.com/openshwprojects/TuyaMCUAnalyzer
    After running the program, we already have a sample package entered:
    Screenshot of the TuyaMCU Explorer tool for packet data analysis.
    To the field Raw packet data we can paste the hex record of packets captured by, for example, Realterm. The system allows spaces and transitions to the next line between hex codes, this is used to increase readability.
    Field Tuya packets display shows each packet twice - first it breaks its bytes into divisions according to their role and colors them, and below it gives their roles and interpretations.
    Plus a section List of automatically detected variable IDs contains a summary of detected dpIDs along with their captured values. This can help, for example, in determining which value is, for example, the brightness level of the dimmer, i.e. it usually has values from 0 to 1000. On the other hand, the relay states can only be 0 or 1.

    In addition, the program offers a set of sample packages loaded from the folder samples , they are available in this menu:
    Screenshot of TuyaMCU Explorer with a dropdown menu.
    The .bin extension means a binary file, with packets as bytes, while .txt means a text file, where packets are already saved as hex codes (already in ASCII, human readable).

    Also, there is a bookmark Compare tool , which is a tiny tool useful for determining what has changed in the packages when, for example, we changed the color of the lamp (e.g. the Miboxer led strip controller uses TuyaMCU):
    Screenshot of the TuyaMCU Explorer application showing a tool for comparing hexadecimal strings.
    The program treats each line as a separate packet. If the given byte in each line is the same, it is highlighted in green, otherwise it is in red.


    Some examples
    Examples are included in the samples directory. Here is a short presentation of some of them.
    Dimmer from TuyaMCU:
    Screenshot of the TuyaMCU Explorer program with encoded packet data.
    The above packets were intercepted on the line WiFi module TX -> TuyaMCU RX. Here in the summary you can see that dpID 1 of type bool has values 1 and 0, that is, the state of the switch, on or off. In turn, dpID 2, of the value type, has values from 0 to 570, which is probably a dimmer. 570 is the maximum value recorded during the tests, while you can guess from this that the full brightness of the light is 1000, as usual.
    Thermometer/Hygrometer/Clock/Calendar TH06:
    Screenshot of TuyaMCU Explorer tool showing data packets in hexadecimal format.
    This set of packets shows how the WiFi module sends time to the main MCU from TH06. On the other hand, broadcast by the MCU we have:
    Screenshot of TuyaMCU Explorer showing data packet decoding.
    The MCU supports the thermometer and hygrometer, so it sends these measurements to the WiFi module. The temperature is multiplied by 10, because the values here must be integers, and the manufacturer wanted to support up to one digit after the decimal point.

    What does the program not help with?
    Basically, there is one situation where this program cannot help. Some of the more advanced Tuya electricity meters (higher-end, already DIN rail, in the price range of PLN 100 or more) use TuyaMCU to report measurements, but often report a group of measurements in one dpID. Then such a dpID is of the Raw type (no longer Value) and contains several bytes in which (depending on the device) data such as the current value of voltage, current, power, sometimes frequency are stored. Such a raw package has a device-dependent format and it is difficult to decode it more universally.
    Cheaper products with energy measurement, in turn, do not use TuyaMCU, rather BL0937 or BL0942 are directly connected to the WiFI module there.

    Application for OpenBeken
    This analyzer allows you to set up quickly OpenBeken to work on your device with TuyaMCU. Here it is autoexec.bat from the OBK. These scripts map values from TuyaMCU (those dpID) to OBK variables and allow further processing of these values, determine how values are displayed on the web panel, etc.:


    - EDM-01AA-EU dimmer
    
    setChannelType 1 toggle
    setChannelType 2 dimmer
    tuyaMcu_setBaudRate 115200
    tuyaMcu_setDimmerRange 1 1000
    // linkTuyaMCUOutputToChannel dpId verType tgChannel
    linkTuyaMCUOutputToChannel 1 bool 1
    linkTuyaMCUOutputToChannel 2 val 2
    

    dpID 1 is a bool type, it is the on/off state of the light. dpID 2 is value, value from 1 to 1000 is dimmer level.


    - QIACHIP Universal WIFI Ceiling Fan Light (fan and light)
    
    startDriver TuyaMCU
    // let's say that channel 1 is dpid1 - fan on/off
    setChannelType 1 toggle
    // map dpid1 to channel1, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 1 1 1
    // let's say that channel 2 is dpid9 - light on/off
    setChannelType 2 toggle
    // map dpid9 to channel2, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 9 1 2
    //channel 3 is dpid3 - fan speed
    setChannelType 3 LowMidHigh
    // map dpid3 to channel3, var type 4 (enum)
    linkTuyaMCUOutputToChannel 3 4 3
    //dpId 17 = beep on/off
    setChannelType 4 toggle
    linkTuyaMCUOutputToChannel 17 1 4
    //
    //
    //dpId 6, dataType 4-DP_TYPE_ENUM = set timer
    setChannelType 5 TextField
    linkTuyaMCUOutputToChannel 6 4 5
    //
    //
    //dpId 7, dataType 2-DP_TYPE_VALUE = timer remaining
    setChannelType 6 ReadOnly
    linkTuyaMCUOutputToChannel 7 2 6
    

    Here dpID 1 is bool, it turns the fan on and off. dpID 9 is the state of the light - on or off, also boolean. dpID 3 is the fan speed - three possible values, 0, 1, 2, low, mid or high. Next, dpID 6 is the setting of the timer (countdown) after which the device will turn off, this timer already supports the MCU. Then dpID 7 is the read only variable, the current value of the countdown timer. There is also dpID 17, which controls the sound signal when configured, e.g. from the RF remote control (on or off)


    - configuration TH06 hygrometer/LCD/calendar
    
    startDriver TuyaMCU
    startDriver NTP
    // dpID 1 is tempererature div 10
    setChannelType 1 temperature_div10
    linkTuyaMCUOutputToChannel 1 val 1
    // dpID 2 is % humidity
    setChannelType 2 Humidity
    linkTuyaMCUOutputToChannel 2 val 2
    

    Here, dpID 2 is the humidity level, and dpID 1 is the temperature, where the temperature is multiplied by 10 because val is an integer type and the manufacturer wanted to transfer values of the type 20.5 degrees


    - BlitzWolf BW-AF1 fryer:
    
    startDriver TuyaMCU
    
    // cook on/off 
    setChannelType 1 Toggle
    setChannelLabel 1 "Cook"
    linkTuyaMCUOutputToChannel 111 bool 1 
    // power on/off
    setChannelLabel 2 "Power"
    setChannelType 2 Toggle
    linkTuyaMCUOutputToChannel 101 bool 2 
    
    // set temperature
    setChannelLabel 3 "New Temperature"
    setChannelType 3 TextField
    linkTuyaMCUOutputToChannel 103 val 3
    
    // currenttemperature
    setChannelLabel 4 "Current Temperature"
    setChannelType 4 ReadOnly
    linkTuyaMCUOutputToChannel 104 val 4
    
    // set time
    setChannelLabel 5 "New Time"
    setChannelType 5 TextField
    linkTuyaMCUOutputToChannel 105 val 5
    
    // read time
    setChannelLabel 6 "Current Time"
    setChannelType 6 ReadOnly
    linkTuyaMCUOutputToChannel 106 val 6
    
    
    alias cook185c15min backlog setChannel 2 1; setChannel 3 185; setChannel 5 15; setChannel 1 1
    alias cook170c30min backlog setChannel 2 1; setChannel 3 170; setChannel 5 30; setChannel 1 1
    
    
    
    startDriver httpButtons
    setButtonEnabled 0 1
    setButtonLabel 0 "Set 185C 15minutes"
    setButtonCommand 0 "cook185c15min "
    setButtonColor 0 "orange"
    
    
    setButtonEnabled 1 1
    setButtonLabel 1 "Set 170C 30minutes"
    setButtonCommand 1 "cook170c30min "
    setButtonColor 1 "orange"
    
    

    About the fryer topic is here:
    https://www.elektroda.pl/rtvforum/topic3958909.html#20448156


    - ATORCH AT4P(WP/BW) energy monitor meter:
    
    startDriver TuyaMCU
    startDriver NTP
    tuyaMcu_setBaudRate 115200
    setChannelType 1 toggle
    setChannelType 2 Voltage_div10
    setChannelType 3 Power
    setChannelType 4 Current_div1000
    setChannelType 5 Frequency_div100
    setChannelType 6 ReadOnly
    setChannelType 7 Temperature
    setChannelType 8 ReadOnly
    setChannelType 9 ReadOnly
    
    //ch 1 (dpid 1) power relay control
    linkTuyaMCUOutputToChannel 1 bool 1
    //ch 2(dpid 20) voltage
    linkTuyaMCUOutputToChannel  20 1 2
    //ch 3(dpid 19) power watts
    linkTuyaMCUOutputToChannel 19 1 3
    //ch 4 (dpid 18)current Amps
    linkTuyaMCUOutputToChannel 18 1 4
    //ch 5 (dpid (133) frequency 
    linkTuyaMCUOutputToChannel 133 1 5
    //ch 6 (dpid  102) energy cost used
    linkTuyaMCUOutputToChannel 102 1 6
    // ch 7 (dpid 135) temp
    linkTuyaMCUOutputToChannel 135 1 7
    //ch 8 (dpid  134) power factor 
    linkTuyaMCUOutputToChannel 134 raw 8
    //ch 9 (dpid  123) energy consumed
    linkTuyaMCUOutputToChannel 123 1 9
    

    Without much comment, but here it is clear how many different variables can be available, usually in the form multiplied by 10 or 100 (or even 1000) to push numbers with a decimal point as integers.

    Summary
    The program was written quickly, even "on the knee" but turned out to be really very useful. Thanks to it, I can quickly analyze the captured data from Tuya products, see what dpIDs are used and what their values look like. Syntax coloring (specific bytes) from the package also speeds up the whole process, and for me it greatly increases their readability.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 14693 posts with rating 12723, helped 656 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 20562010
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    TuyaMCU analyzer has been updated. The ability to do dual UART capture with two USB dongles has been added. It's not perfect, because sometimes order of request/reply packets is wrong due to the C# SerialPort class handing lag, but we're constantly improving it further. Some misc options like file opening dialog, etc, has been also added.
    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector
    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector
    https://github.com/openshwprojects/TuyaMCUAnalyzer/releases/tag/v0.2
    Helpful post? Buy me a coffee.
  • #3 20625147
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    hi, just to clarify
    the chip should be in the stock tuya firmware so I could compare if the details in the tuya app matches with the tuya mcu analyzer? (light sensor, presence etc)
    And I should power it using dedicated board (for 3.3v pin) like arduino uno so the chip boots up?
  • #4 20625222
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Chip must be in stock Tuya firmware and most likely paired and connected to cloud (0x04 wifi state) so you can get full tuya experience and record full transactions of TuyaMCU.

    You have to power your device in a safe way, so either 3.3V to chip 3.3V or if it has on board AMS1117-3.3V, you can connect 5V to the input of AMS1117-3.3, so you still get 3.3V on WiFi module.

    Both MCU and WiFI modules has to be powered for it to work.
    Helpful post? Buy me a coffee.
  • #5 20630409
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    Hi, I'm not sure if I'm doing it right
    I connect the necessary pins, using arduino uno for 3.3v
    I can see the led lights blinking on the pcb, on the tuya app device is not online
    I can't be sure where to find the input of AMS1117-3.3 on the pcb.

    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector



  • #6 20630423
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    First of all, you have to press "Change" to apply baud change. You change baud to 9600 in the combobox, but you don't apply change. Please see the marked area in the screenshot:
    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector
    Helpful post? Buy me a coffee.
  • #7 20630469
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    ok, i've changed it this time



  • #8 20630487
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    How do you know it's really a TuyaMCU device? You can also try alternate baud: 115200.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #10 20630536
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Where did you connect USB to UART converter RX?
    Helpful post? Buy me a coffee.
  • #11 20630553
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    Like this

    UART TX -> CBU RX
    UART RX -> CBU TX
  • ADVERTISEMENT
  • #12 20630570
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Where are RX and TX of CBU connected? Please check with multimeter.

    Are you sure that this second module/MCU also gets power? You can check that with multimeter as well.

    Which CBU pins are used on this PCB (except the obvious RX, TX, and power)?

    Do you have 2MB flash backup so I can check for TuyaMCU baud there?
    Helpful post? Buy me a coffee.
  • #13 20630604
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    p.kaczmarek2 wrote:
    Where are RX and TX of CBU connected? Please check with multimeter.

    I'll do that once I have my multimeter

    p.kaczmarek2 wrote:
    Are you sure that this second module/MCU also gets power? You can check that with multimeter as well.

    How do I check on the second module using the multimeter?

    p.kaczmarek2 wrote:
    Do you have 2MB flash backup so I can check for TuyaMCU baud there?

    Not yet, probably due to the tx/rx connected another module on the pcb. i'll have to desolder the chip and do a backup from there.
  • #14 20631771
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    @p.kaczmarek2 hi, desoldered the chip and this is the backup firmware bin
    Attachments:
    • readResult_BK7231N_QIO_radar_2023-26-6--21-21-42.bin (2 MB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #15 20631789
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    It looks like there is a baud setting in this flash:
    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector
    So there is a fair chance it's a TuyaMCU.

    Maybe the second module is not powered or something. How is it powered? Or maybe it's like a battery powered device, where second module only sometimes enables wifi module power to report data to cloud. We need more information.
    Helpful post? Buy me a coffee.
  • #16 20631846
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    @p.kaczmarek2 if i power the device by connecting to the mains, is it safe to just connect cbu tx/rx-> uart tx/rx -> pc ?

    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector
  • #17 20632329
    DeDaMrAz
    Level 22  
    Posts: 615
    Help: 34
    Rate: 130
    ferbulous wrote:
    @p.kaczmarek2 if i power the device by connecting to the mains, is it safe to just connect cbu tx/rx-> uart tx/rx -> pc ?

    TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector TuyaMCU analyzer - UART packet decoder for Tuya devices - dpID detector


    NO!!! DO NOT connect anything that is directly mains powered directly!!!

    Use some kind of isolator for communication sniffing!!! Don't ask me how I know.

    This is the device I am testing now for example - https://www.ebay.com/itm/295442212026?var=593559756835
  • #18 20632416
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    DeDaMrAz wrote:
    Use some kind of isolator for communication sniffing

    I don't know how to use that, I'd appreciate some instruction

    @p.kaczmarek2 from this smart breaker post, any idea how @tomanyusers connect tx/rx to sniff the packets with load connected?
  • #19 20632476
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Well, to be honest, if your power supply is an isolated one, then there should be no problems. The question is, is your power supply an isolated one.

    Also, maybe your device would work if you were to connect USB 5V to 12V input? If there is a step down converter, then it should work.

    Maybe you can also check the circuit. Why do they use 12V and not 5V there? That's interesting.
    Helpful post? Buy me a coffee.
  • #20 20632666
    ferbulous
    Level 18  
    Posts: 419
    Help: 8
    Rate: 56
    How to determine if it’s isolated?

    Also since there’s 2 pads on the pcb, the second pad for zigbee chip with cbu pinout.
    Could i just solder:
    1st pad - cbu with tuya firmware
    2nd pad - another cbu with openbk

    Then i check the dpid using the openbk web ui and compare the values with the tuya app. If it’s possible
  • #21 20723628
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    It depends on the power supply inside. Flybacks have isolation, and bucks do not.

    Using another OBK for that is planned but I am not sure if it will work at the moment.

    Okay, back to the main topic... I am updating the analyzer:
    TuyaMCU Explorer/Analyzer interface displaying data packet analysis.
    Helpful post? Buy me a coffee.
  • #22 20723748
    DeDaMrAz
    Level 22  
    Posts: 615
    Help: 34
    Rate: 130
    TuyaMCU analyzer version 0.4 is released - https://github.com/openshwprojects/TuyaMCUAnalyzer/releases

    Improvements:
    - added ability to hide heartbeat packets
    - decoding colors is available now for tuyaMCU controlled lights
    - strings can now be shown as HEX or ASCII
    - app window can now be maximized
  • #23 20729095
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Version 0.5 released:
    https://github.com/openshwprojects/TuyaMCUAnalyzer/releases/tag/v0.5

    Includes:
    - crash fix on packet with datetime
    - pause option for realtime capture
    - some little useful buttons like "copy raw" and "copy decoded", etc
    Helpful post? Buy me a coffee.
  • Helpful post
    #24 21277196
    theosoft
    Level 10  
    Posts: 37
    Help: 1
    Rate: 2
    I do have changed some things.
    Decoded window now as list.
    Windows do have a movable splitter
    Handling on decoding messages.
    Anti flickering
    Date filter added.
    Layout & font changed.

    TuyaMCU Explorer/Analyzer interface with visible data packets
  • #25 21277208
    divadiow
    Level 38  
    Posts: 5134
    Help: 442
    Rate: 905
    cool. I like it. It's easier to read and the refresh/flickering was annoying.

    there's a typo - Lenght=Length

    and is "//R by file ..." the equivalent of "Received by WiFi module:"?
  • #26 21277215
    theosoft
    Level 10  
    Posts: 37
    Help: 1
    Rate: 2
    >>21277208
    Typo fixed :-)
    And yes. But is more to keep the same decoding machine.....
  • #27 21279107
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Nice, I've reviewed the changes and decided to merge them. I can make soon a release. Do you plan to add more features? I would like to see futher updates.
    Helpful post? Buy me a coffee.
  • XML-based TuyaMCU decoder engine overhaul

    #28 21284085
    theosoft
    Level 10  
    Posts: 37
    Help: 1
    Rate: 2
    >>21279107
    OK, i think, i made a huge modification :-)
    Not finished, but usable.
    The main points:
    decoder engine for commands and datapoints are new implemented.
    Specification is done by using a XML file.
    loadable. So everybody is able to define / correct / edit in his own language etc...
    The data view is now a datagrid. Listview was limited.
    When the XML's are not loaded, the old engine is available, but some parts are deleted.
    To many if then else :-)

    Improvements left:
    Porting some colors
    Define Specification for unknown DP.
    I have no specification for DP1 DP2 etc. Only Light till now

    XML sample below ....
    <?xml version="1.0" encoding="UTF-8"?>
    <Specification>
    <Headline name="Tuya Commands" type="cmd-decoder" version="1.0" owner="theosoft"/>
    <Enums>
    <Enum name="Status_03">
    <Value name="Pairing in EZ mode" value="0"/>
    <Value name="Pairing in AP mode" value="1"/>
    <Value name="The Wi-Fi network is setup, but the device is not connected to the router." value="2"/>
    <Value name="The Wi-Fi network is setup, and the device is connected to the router" value="3"/>
    <Value name="The device is connected to the cloud." value="4"/>
    <Value name="Tuya’s network module is in low power mode" value="5"/>
    <Value name="EZ mode and AP mode coexist" value="6"/>
    </Enum>
    <Enum name="Status_14">
    <Value name="Failure" value="0"/>
    <Value name="Success" value="1"/>
    </Enum>
    <Enum name="Status_55">
    <Value name="Success" value="0"/>
    <Value name="Invalid Data" value="1"/>
    <Value name="Failure" value="2"/>
    </Enum>
    </Enums>
    <Commands>
    <Command id="0" version="0" name="Send heartbeats">
    <!-- Spezifikationen für Command 0x00 -->
    <Item id="DataLength" position="0" length="4" type="int16"/>
    <Item id="Data" position="4" length="0" type="value"/>
    <Item id="Checksum" position="4" length="2" type="value"/>
    </Command>
    <Command id="0" version="3" name="Send heartbeats answer">
    <!-- Spezifikationen für Command 0x00 -->
    <Item id="DataLength" position="0" length="4" type="int16"/>
    <Item id="Heardbeats" position="4" length="2" type="value"/>
    <Item id="Checksum" position="6" length="2" type="value"/>
    </Command>
    <Command id="1" version="0" name="Query product information">
    <!-- Spezifikationen für Command 0x01 -->
    <Item id="DataLength" position="0" length="4" type="int16"/>
    <Item id="Data" position="4" length="0" type="value"/>
    <Item id="Checksum" position="4" length="2" type="value"/>
    </Command>
    and so on ...

    Here is a sample for DP in light:

    <Datapoint id="24" name ="HSV color">
    <!-- Spezifikationen für DP24 -->
    <Item id="DPid" position="0" length="2" type="int8"/>
    <Item id="DPtype" position="2" length="2" type="enum" enumType="DPType"/>
    <Item id="DPLen" position="4" length="4" type="int16"/>
    <Item id="Hue" position="8" length="8" type="hue-ascii"/>
    <Item id="Saturation" position="16" length="8" type="sat-ascii"/>
    <Item id="Value" position="24" length="8" type="val-ascii"/>
    </Datapoint>
    <Datapoint id="25" name ="scene">
    <!-- Spezifikationen für DP25 -->
    <Item id="DPid" position="0" length="2" type="int8"/>
    <Item id="DPtype" position="2" length="2" type="enum" enumType="DPType"/>
    <Item id="DPLen" position="4" length="4" type="int16"/>
    <Item id="SceneID" position="8" length="2" type="value"/>
    <Block>
    <Item id="TransitionInterval" position="0" length="2" type="value"/>
    <Item id="LightingModeDuration" position="2" length="2" type="enum" enumType="DPType"/>
    <Item id="LightingMode" position="4" length="2" type="enum" enumType="LightingMode3"/>
    <Item id="Hue" position="6" length="4" type="hue-hex"/>
    <Item id="Saturation" position="10" length="4" type="sat-hex"/>
    <Item id="Value" position="14" length="4" type="val-hex"/>
    <Item id="Brightness" position="16" length="4" type="bright-hex"/>
    <Item id="ColorTemperature" position="20" length="4" type="temperature-hex"/>
    </Block>

    It is possible to:
    1. Handle dynamic len. lenght="-1" and position="-1"
    2. Use enums directly from XML
    3. Handle N blocks (repeating DP i.e.)
    4. use different type's to handle different value. I.e: "temperature-hex" --> value is shown in a Range from 2700K - 6500K


    Screenshot of TuyaMCU Explorer/Analyzer showing a user interface with a data table and decoding options.
  • #29 21287814
    theosoft
    Level 10  
    Posts: 37
    Help: 1
    Rate: 2
    Today, i released this version. The pull request should be checked and released.
    Old engine is removed ....
    Have fun. I do have a XML for my RGB 5in1 controller and all are decoded correct :-)
    Only DP101 is missing. The value stays constant.

    regards
    theosoft

    Screenshot of TuyaMCU Explorer/Analyser software showing data analysis for an RGB controller.
  • #30 21291374
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14693
    Help: 656
    Rate: 12723
    Very nice update, but I'm curious about one thing. Would it be possible to also support (import?) this dpID format:
    https://www.elektroda.com/rtvforum/topic4021129.html
    Helpful post? Buy me a coffee.
📢 Listen (AI):

Topic summary

✨ Discussion about TuyaMCU Analyzer, a UART packet decoder for Tuya devices used to sniff and decode TuyaMCU traffic into dpID, type, length, and value fields. The tool helps identify device datapoints such as relay state, dimmer level, voltage, current, and other sensor values when releasing IoT devices from the Tuya cloud. The thread covers software updates including dual-UART capture, baud-rate handling, packet display improvements, heartbeat filtering, color decoding for lights, pause/copy functions, and later a major rewrite with an XML-based decoder engine and support for custom specifications. Several troubleshooting exchanges focus on correct baud selection, power supply requirements, safe UART sniffing on mains-powered devices, isolated vs non-isolated supplies, CH340/CH342 adapters, and verifying whether a board actually contains a TuyaMCU.
Summary generated by AI based on the discussion content.

FAQ

TL;DR: TuyaMCUAnalyzer helps decode 15+ Tuya UART packet cases; the core rule is "Both MCU and WiFI modules has to be powered." This FAQ is for OpenBeken and Tuya hackers who need dpID detection, safe UART sniffing, and RX/TX capture guidance. [#20625222] Why it matters: Correct dpID decoding turns captured Tuya traffic into usable relay, dimmer, sensor, and energy-monitor channels.

Option Specific use Thread value
One USB-to-UART adapter Capture one direction at a time RX line only, repeat for the other line
Two CH340 adapters Capture both UART directions One RX on MCU RX, one RX on MCU TX
CH342 adapter Dual capture with one USB device 2 UARTs on one chip
RealTerm text capture File-based packet capture Hex with spaces

Key insight: Do not guess dpIDs from the product type. Capture stock TuyaMCU traffic, compare values, then map the confirmed dpIDs into OpenBeken channels.

Quick Facts

  • TuyaMCU uses UART between the WiFi module and a separate MCU; that MCU can handle relays, buttons, LCDs, sensors, and metering circuits. [#20528459]
  • The safe capture setup powers the board from USB, not mains, with 5 V fed before the onboard 3.3 V regulator when present. [#20528459]
  • Common TuyaMCU dpID clues include bool values 0/1 for relays and value ranges like 0–570 or 1–1000 for dimmers. [#20528459]
  • Version 0.2 added dual UART capture with two USB dongles, plus file-opening and miscellaneous UI options. [#20562010]
  • Version 0.5 added a datetime crash fix, realtime capture pause, and buttons such as “copy raw” and “copy decoded.” [#20729095]

What is TuyaMCU and how does it let a Tuya WiFi module communicate with a separate MCU over UART?

TuyaMCU is a UART protocol linking the Tuya WiFi module to a separate device MCU. "TuyaMCU is a UART-based protocol that lets a WiFi module exchange commands and datapoints with an onboard microcontroller, while the MCU handles local hardware such as relays, buttons, LCDs, sensors, and measurement systems." The WiFi module often reports data to the network, while the MCU drives the product hardware. [#20528459]

How do I capture TuyaMCU UART packets safely with a USB-to-UART adapter and RealTerm?

Capture TuyaMCU packets by powering the device from USB and logging UART as spaced hex in RealTerm. 1. Connect USB-to-UART ground and RX/TX, but keep 5 V disconnected first. 2. Start RealTerm capture in “hex with spaces” and write to a file. 3. Power the board from USB, perform one operation, stop capture, then repeat for the opposite UART direction. The thread explicitly says not to power from mains during this method. [#20528459]

What are Tuya dpIDs and how can TuyaMCUAnalyzer help identify relay states, dimmer levels, voltage, current, or sensor values?

dpIDs are Tuya datapoint identifiers that label each reported variable inside TuyaMCU packets. "dpID is a Tuya datapoint identifier that marks one device variable, such as a relay state, dimmer value, humidity reading, voltage, current, or raw measurement block, with a type and payload length." TuyaMCUAnalyzer lists detected dpIDs, types, lengths, and captured values. Bool dpID values 0/1 suggest relays. Dimmer values can appear from 0 to 570 during testing, with 1000 as a common full-scale target. [#20528459]

Why should a TuyaMCU device stay on stock Tuya firmware and be paired to the cloud before sniffing packets?

Keep stock Tuya firmware so the analyzer captures the original TuyaMCU transactions. The device should also be paired and connected to the cloud, showing WiFi state 0x04. That state gives the “full Tuya experience” and records complete TuyaMCU exchanges. If you replace firmware first, you can lose the original app-driven behavior needed to identify light sensors, presence values, or other dpIDs. [#20625222]

How do I power both the WiFi module and the TuyaMCU safely while capturing UART data without using mains power?

Power both chips from a safe low-voltage source, not directly from mains. Use 3.3 V on the WiFi module’s 3.3 V pin, or feed 5 V into the input of an onboard AMS1117-3.3 regulator. That regulator then supplies stable 3.3 V to the WiFi module. The separate MCU must also receive power, or no TuyaMCU communication will appear. [#20625222]

What baud rates should I try when TuyaMCUAnalyzer shows no packets, and why are 9600 and 115200 commonly tested?

Try 9600 first, apply the baud change, then test 115200 if no packets appear. One troubleshooting case failed because the baud combobox changed to 9600 without pressing “Change.” The author then suggested trying the alternate baud rate, 115200. A later firmware backup showed a baud setting, supporting the chance that the device used TuyaMCU. [#20630423]

How can I tell whether a Tuya device really uses TuyaMCU if I cannot identify a separate MCU on the PCB?

Check the PCB traces, power rails, and firmware evidence before assuming TuyaMCU. Use a multimeter to see where CBU RX and TX connect, and verify that a second module or MCU receives power. A 2 MB flash backup can reveal TuyaMCU baud settings. In the thread, a baud setting in flash gave “a fair chance” that the board used TuyaMCU. [#20631789]

How do I use two CH340 USB-serial adapters, or a CH342 dual UART adapter, to capture both TuyaMCU RX and TX lines at the same time?

Connect only the RX input of each adapter to one UART direction. Use one CH340 RX on MCU RX and another CH340 RX on MCU TX, with a shared ground when safe. This listens to both directions without driving the bus. A CH342 can replace two CH340 boards because it provides 2 UARTs on one chip and one USB connection. [#21835480]

CH340 vs CH342 — which is more convenient for dual UART TuyaMCU packet sniffing?

CH342 is more convenient for dual UART sniffing because it provides 2 UARTs through one USB device. Two CH340 adapters also work, but they occupy two USB connections and require matching two serial ports. The thread confirms the dual-CH340 wiring and recommends CH342 as a single-chip, single-USB alternative for convenience. [#21835480]

What does it mean if a CH340 adapter shows 3.4 V or 5.2 V on its RX line, and how should I handle 3.3 V versus 5 V UART levels?

A voltage on the CH340 RX line can be normal, but level mismatch is the real danger. One user measured 3.4 V on a newer CH340 RX line and 5.2 V on an older one. The warning was specific: problems arise when attaching a 3.3 V UART to a 5 V device, or the reverse. Match UART logic levels before connecting. [#21835641]

How can I determine whether a Tuya device power supply is isolated, and what is the difference between flyback and buck supplies for UART safety?

Identify the supply topology: flyback supplies have isolation, while buck supplies do not. This matters because a non-isolated buck design can reference the low-voltage UART section to mains. The thread gives the practical rule in one line: “Flybacks have isolation, and bucks do not.” If unsure, do not attach PC-grounded serial hardware. [#20723628]

Why is it dangerous to connect a PC USB-to-UART adapter directly to a mains-powered Tuya device, and what kind of isolator should be used for sniffing?

A direct PC USB-to-UART link can be dangerous when the Tuya device is mains powered and not isolated. One warning states: “NO!!! DO NOT connect anything that is directly mains powered directly!!!” Use a communication isolator for UART sniffing, or power the board from an isolated low-voltage supply instead. The key risk is tying PC ground to a live-referenced circuit. [#20632329]

How do I map detected TuyaMCU dpIDs to OpenBeken channels using commands like linkTuyaMCUOutputToChannel?

Map each confirmed dpID to an OpenBeken channel with its Tuya type and target channel number. Example: EDM-01AA-EU uses channel 1 as toggle and channel 2 as dimmer. The script links dpID 1 bool to channel 1, then dpID 2 val to channel 2. It also sets baud to 115200 and dimmer range to 1–1000. [#20528459]

What changed in TuyaMCUAnalyzer versions 0.4 and 0.5, including heartbeat hiding, light color decoding, ASCII/HEX strings, pause, and copy buttons?

Version 0.4 improved filtering and decoding, while version 0.5 improved capture workflow and stability. Version 0.4 added heartbeat hiding, TuyaMCU light color decoding, ASCII or HEX string display, and a maximizable window. Version 0.5 fixed a crash on datetime packets, added realtime capture pause, and added buttons such as “copy raw” and “copy decoded.” [#20729095]

How can I troubleshoot errors while retrieving data from a Tuya module in TuyaMCUAnalyzer?

Start with wiring, baud, power, and device-state checks before blaming the analyzer. Confirm 9600 and 115200 baud, press “Change” after selecting baud, and verify both WiFi module and MCU power. Keep stock Tuya firmware paired to cloud state 0x04 for complete traffic. If no packets appear, check RX/TX continuity with a multimeter and confirm the board really uses TuyaMCU. [#20625222]
Summary generated by AI based on the discussion content.
ADVERTISEMENT