Elektroda.com
Elektroda.com
X

[CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin

p.kaczmarek2 1374 15
This content has been translated flag-pl » flag-en View the original version here.
  • [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    Here I will present an in-depth analysis and reverse engineering of the Tuya battery temperature/humidity sensor implemented on the basis of the TuyaMCU protocol, i.e. having a separate microcontroller (always on, but using sleep mode) and a WiFi module (its power supply activates the MCU when you need to report the status). Here I will show the protocol of this product, including variable roles (dpID TuyaMCU), its schematic, and finally I will change its firmware to free it from the cloud and pair it with Home Assistant.

    The theme was created in collaboration with @DeDaMrAz. We worked on the sensor remotely, I led the activities, and a colleague did packet capture, PCB analysis and drawing its schematic, as well as final tests with Home Assistant.

    Sensor purchase
    It is one of the most popular sensors of this type in the network. It is available in Zigbee and WiFi versions, here we discuss the WiFi version. You can buy it for several dozen zlotys. Below is a screenshot of an example auction:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    I do not even discuss the Tuya application and pairing, it has been described many times. Here we will focus on technical details and firmware changes .
    Instructions for pairing with the SmartLife application (if we want to use an open-source sensor, it is unnecessary for us):
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin

    The inside of the sensor
    We look inside. What do we see first?
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    This is a device based on TuyaMCU. We have a separate WiFi module (CB3S, i.e. BK7231N) and a microcontroller.
    TuyaMCU is a UART based protocol through which this MCU communicates with the WiFi module.
    CB3S pinouts are known:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    pin number Symbol I/O type functions
    1 RST I Low-level reset, high level active (the pin has been pulled high internally), correspond to CEN of the IC
    2 ADC3 AI ADC pin, which corresponds to P23 of the IC
    3 CEN I Enabling pin, which is pulled high internally to be compatible with other modules
    4 P14 I/O A common GPIO interface, which corresponds to P14 of the IC
    5 P26 I/O GPIOP_26, which corresponds to P26 of the IC, PWM 5
    6 P24 I/O GPIOP_24, which corresponds to P24 of the IC, PWM 4
    7 P6 I/O GPIOP_6, which corresponds to P6 of the IC, PWM 0
    8 VCC P Power supply pin (3.3V)
    9 GND P Power supply reference ground
    10 P9 I/O GPIOP_9, which corresponds to P9 of the IC, PWM 3
    11 TXD2 I/O UART2_TXD (used to display the module internal information), which corresponds to P0 of the IC
    12 CSN I/O Production test control pin. If it is used as a common I/O pin, it must be connected to the VCC externally. Do not connect it to the ground before the module is powered on.
    13 P8 I/O GPIOP_8, which corresponds to P8 of the IC, PWM 2
    14 P7 I/O GPIOP_7, which corresponds to P7 of the IC, PWM 1
    15 RXD1 I/O UART1_RXD (user serial interface), which corresponds to P10 of the IC. Do not connect it to the VCC. By default, the MCU serial port should be in low-level or high-impedance state.
    16 TXD1 I/O UART1_TXD (user serial interface), which corresponds to P11 of the IC. Do not connect it to the VCC. By default, the MCU serial port should be in low-level or high-impedance state.
    17 ADC3 AI (Not recommended. If needed, please use Pin 2) ADC port, which corresponds to P23 of the IC. Programmed SPI
    18 P22 I/O (Not recommended ) GPIOP_22, which corresponds to P22 of the IC. Programmed SPI
    19 CSN I/O The pull-up resistor is needed during usage of customers. Do not connect it to the ground before the module is powered on. Correspond to P21 of the IC.
    20 P20 I/O (Not recommended. ) GPIOP_20, which corresponds to P20 of the IC. Programmed SPI
    21 NC - -
    22 NC - -

    The MCU has not been identified, but this is how they are connected in general:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    It's just that in the case of TuyaMCU in battery devices, the MCU additionally controls the power supply of the WiFi module.
    Here is the diagram (drawn by a friend):
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    ESP12 in the diagram is illustrative, in fact it is CB3S. The CB3S power supply is controlled by the MCU via a MOSFET. The WiFi module communicates with the MCU via UART, through the TuyaMCU protocol. The MCU itself reads the measurements from the SHT30 via I2C (you can even see the pull up resistors).

    So what will have to be done to change the firmware of the WiFi module, i.e. to free the device from the manufacturer's cloud?
    - you need to properly handle communication with the MCU (TuyaMCU protocol)
    - you have to deal with the fact that the MCU will turn off the WiFi module during operation ...

    Power consumption in sleep mode
    By the way, you can do a small measurement - how much does the MCU itself consume with the WiFi module turned off?
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    5µA . I recommend to contrast this result with my sleep measurement of the WiFI module with BK7231 (in deep sleep mode) from this topic:
    https://www.elektroda.pl/rtvforum/topic3960149.html
    I got 6µA there. That's a 1µA difference, assuming the measurements are accurate enough to judge it. Just remember, the MCU sleeps here and the WiFi module has VDD completely disconnected, and the linked topic mentions the sleep of the WiFi module itself (which can be woken up by GPIO).

    TuyaMCU protocol
    This device uses the TuyaMCU protocol for battery powered devices. The documentation is here:
    https://developer.tuya.com/en/docs/iot/tuyacl...niversalserialaccessprotocol?id=K95afs9h4tjjh
    I also discussed the basis of TuyaMCU in this topic:
    https://www.elektroda.pl/rtvforum/topic3880546.html
    A related battery powered door open sensor on TuyaMCU I discussed here (except its protocol was a bit simpler, there was no dpCache):
    https://www.elektroda.pl/rtvforum/topic3914412.html
    You can use my analyzer to analyze TuyaMCU:
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20528459#20528459
    Here is a pre-processed UART dump from my program:
    
    //S 4/30/2023 8:49:32 PM WiFi send:
    55AA0001000000
    //R 4/30/2023 8:49:32 PM WiFi received:
    55AA000100247B2270223A226279757376756D656D65356969636164222C2276223A22312E302E30227D20
    //S 4/30/2023 8:49:33 PM WiFi send:
    55AA000200010305
    //R 4/30/2023 8:49:33 PM WiFi received:
    55AA0002000001
    //S 4/30/2023 8:51:50 PM WiFi send:
    55AA000200010406
    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA0002000001
    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA001000010010
    //S 4/30/2023 6:18:06 PM WiFi sent:
    55AA00100002010012
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA0005000801020004000000FC0F
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA0005000802020004000000273B
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA00050005030400010112
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA00050005090400010017
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080A0200040000021C3A
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080B020004FFFFFF88A2
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080C0200040000005A78
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080D0200040000000A29
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500050E040001021E
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA000500050F040001021F
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050008110200040000000124
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050008120200040000000125
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000813020004000000052A
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000814020004000000082E
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050005150100010020
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000801020004000000FD10
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000802020004000000273B
    //S 4/30/2023 8:52:13 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:15 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:17 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:19 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:21 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:23 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:25 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:27 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:29 PM WiFi send:
    55AA000500010005
    

    Below is the same but with comments from my analyzer:
    
    Sent by WiFi module:
    55 AA	00	01		00 00		00	
    HEADER	VER=00	Product		LEN		CHK	
    
    Received by WiFi module:
    55 AA	00	01		00 24	7B2270223A226279757376756D656D65356969636164222C2276223A22312E302E30227D	20	
    HEADER	VER=00	Product		LEN	{"p":"byusvumeme5iicad","v":"1.0.0"}	CHK	
    
    Sent by WiFi module:
    55 AA	00	02		00 01	03	05	
    HEADER	VER=00	McuConf		LEN	03	CHK	
    
    Received by WiFi module:
    55 AA	00	02		00 00		01	
    HEADER	VER=00	McuConf		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	02		00 01	04	06	
    HEADER	VER=00	McuConf		LEN	04	CHK	
    
    Received by WiFi module:
    55 AA	00	02		00 00		01	
    HEADER	VER=00	McuConf		LEN		CHK	
    
    Received by WiFi module:
    55 AA	00	10		00 01	00	10	
    HEADER	VER=00	ObtainDPcache		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	10		00 02	0100	12	
    HEADER	VER=00	ObtainDPcache		LEN		CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	01020004000000FC	0F	
    HEADER	VER=00	Unk		LEN	fnId=1 Val V=252	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0202000400000027	3B	
    HEADER	VER=00	Unk		LEN	fnId=2 Val V=39	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 05	0304000101	12	
    HEADER	VER=00	Unk		LEN	fnId=3 Enum V=1	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 05	0904000100	17	
    HEADER	VER=00	Unk		LEN	fnId=9 Enum V=0	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0A0200040000021C	3A	
    HEADER	VER=00	Unk		LEN	fnId=10 Val V=540	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0B020004FFFFFF88	A2	
    HEADER	VER=00	Unk		LEN	fnId=11 Val V=-120	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0C0200040000005A	78	
    HEADER	VER=00	Unk		LEN	fnId=12 Val V=90	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0D0200040000000A	29	
    HEADER	VER=00	Unk		LEN	fnId=13 Val V=10	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 05	0E04000102	1E	
    HEADER	VER=00	Unk		LEN	fnId=14 Enum V=2	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 05	0F04000102	1F	
    HEADER	VER=00	Unk		LEN	fnId=15 Enum V=2	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	1102000400000001	24	
    HEADER	VER=00	Unk		LEN	fnId=17 Val V=1	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	1202000400000001	25	
    HEADER	VER=00	Unk		LEN	fnId=18 Val V=1	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	1302000400000005	2A	
    HEADER	VER=00	Unk		LEN	fnId=19 Val V=5	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	1402000400000008	2E	
    HEADER	VER=00	Unk		LEN	fnId=20 Val V=8	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 05	1501000100	20	
    HEADER	VER=00	Unk		LEN	fnId=21 Bool V=0	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	01020004000000FD	10	
    HEADER	VER=00	Unk		LEN	fnId=1 Val V=253	CHK	
    
    Received by WiFi module:
    55 AA	00	05		00 08	0202000400000027	3B	
    HEADER	VER=00	Unk		LEN	fnId=2 Val V=39	CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    Sent by WiFi module:
    55 AA	00	05		00 01	00	05	
    HEADER	VER=00	Unk		LEN		CHK	
    
    


    And now a step-by-step analysis.
    1. The MCU turns on the power to the WiFi module. The WiFi module sends a request for identification to the MCU (package 0x01 - Query product information), and it responds and gives {"p":"byusvumeme5iicad","v":"1.0.0"} :
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    2. Now WiFi successively reports the connection status (type 0x02 - Report the network status of the device), first status 0x03 (WiFi connected), MCU confirms receipt, and then status 0x04 (cloud connected - in our OBK as MQTT):
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    Only these WiFi states 0x03 and 0x04 appear during normal operation. Below are all possible states:
    Status Description status value
    Status 1 smartconfig configuration mode 0x00
    Status 2 AP configuration status 0x01
    Status 3 Wi-Fi has been set up but is not connected to the router 0x02
    Status 4 Wi-Fi is set up and connected to the router 0x03
    Status 5 Wi-Fi is set up, connected to the router and to the cloud 0x04

    3. Then there is the ObtainDPCache data exchange, which exists only in devices with configuration remembered on the MCU, e.g. the door opening / closing sensor does not have it:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    Nothing has been sent in the screenshot above, but if we changed the reporting frequency in the settings, for example, this packet would contain information about it.

    ObtainDPCache works in such a way that when we want to, for example, set the time between measurements, the WiFi module downloads it from the cloud when the MCU turns it on and then waits for the MCU to ask it about these ObtainDPCache. The MCU first asks for ObtainDPCache and the WiFi module replies with a list of dpID/type/value variables. The MCU picks it up and saves it. Thus, the MCU knows how often to wake up and pass the measurement on.

    4. Then TuyaMCU reports variable values separately (package type 0x05 - Report the real-time status):
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    5. Then, after sending these variables to the cloud, the module sends confirmations as many times as it received variables:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin

    By guessing and testing with the Tuya application, the following variables (dpID) can be distinguished:
    fnID1 temperature as an integer multiplied by 10 - so 23.1 as 231
    fnID2 % humidity
    fnID3 battery level ( 0=Low, 1=Medium, 2=High)
    fnID9 choice of unit, C or F (0 = C and 1 = F)
    fnID10 minimum temperature setting
    fnID11 maximum temperature setting
    fnID12 maximum humidity setting
    fnID13 minimum humidity setting
    fnID17 temperature measurement frequency
    fnID18 humidity measurement frequency
    fnID19 temperature accuracy (sensitivity) times 10.5 means 0.5C
    fnID20 humidity accuracy in %
    fnID21 switch state (1 or 0, role unknown)


    So let's summarize what's going on in this communication, in a nutshell:
    - The MCU turns on the WiFi module by turning on its MOSFET transistor on the power supply
    - the WiFi module talks to the MCU, the MCU identifies itself
    - WiFi module informs about connection status, MCU confirms
    - The MCU asks for any settings such as reporting time, the WiFi module sends them if they are
    - MCU sends new measurements etc, WiFi module confirms
    - The MCU goes to sleep after the last confirmation and disconnects the power to the WiFi module

    The only new thing here compared to mine about the door status sensor there is a packet 0x10, the so-called Obtain DP cache command , i.e. downloading settings from the WiFi module. Here are two examples of its use. This is what the transaction looks like when the WiFi module does not set anything:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    This is how the same transaction looks like when we change the reporting frequency to 1 minute in the app (for temperature and humidity):
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin

    Final configuration of OpenBeken
    OpenBeken can be uploaded to this sensor very easily. Follow the steps:
    1. temporarily disconnect the UART between the MCU and the WiFi module, e.g. by unsoldering the resistors from the diagram (or cutting the paths), because the same UART port is used to upload the firmware. We artificially power the WiFi module from our 3.3V.
    2. upload OBK according to:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    3. We configure OpenBeken. We configure our WiFi, device names, MQTT, and also place the script autoexec.bat in Web App -> LittleFS OBK:
    
    startDriver TuyaMCU
    startDriver tmSensor
    
    // may be needed, depends on device, some also use 9600
    tuyaMCU_setBaudRate 115200
    
    // 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
    // dpID 3 is battery state - low(0), mid(1) and high(2)
    linkTuyaMCUOutputToChannel 3 enum 3
    setChannelType 3 ReadOnlyLowMidHigh
    setChannelLabel 3 Battery
    //
    // setup dpCache - temperature interval
    //
    // Show textfield for that
    setChannelType 5 TextField
    // setup display name
    setChannelLabel 5 Temperature Interval
    // Make value persistant (stored between reboots), 
    // start value -1 means "remember last"
    SetStartValue 5 -1
    // set default value if not set
    if $CH5==0 then setChannel 5 1
    // link dpID 17 to channel 5, the type is val, extra '1' means that its dpCache variable
    linkTuyaMCUOutputToChannel 17 val 5 1
    
    setChannelType 6 TextField
    setChannelLabel 6 Humidity Interval
    SetStartValue 6 -1
    if $CH6==0 then setChannel 6 1
    linkTuyaMCUOutputToChannel 18 val 6 1
    

    The autoexec.bat above scripts the dpID handling from TuyaMCU. Maps dpID to OBK channels. It sets the types of these channels, so Hass Discovery knows what this sensor offers. In addition, it displays the fields and values for the corresponding channels.
    OBK documentation:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/README.md
    This is what the OBK panel looks like then:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    4. We also pair with HA then.
    In the latest version of OBK, it supports Home Assistant Discovery even for scripted devices. Just select Discovery from Options and HA will see the device itself:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    5. Finally, when everything is ready, disconnect the programmer, disconnect the artificially connected 3.3V, reconstruct the UART paths and the sensor should start reporting data to the HA.


    Note: OBK supports setting the reporting time through visible fields on the panel. In this case, the dpID of the reporting period (17 and 18) have been mapped to channels 5 and 6. It is enough to set these channels to, for example, 60, and the module will wake up and report every 60 minutes. You can set it to 1 - it will report every minute. E.t.c.

    Here is an example of the final effect in HA:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin


    Short wake up and reporting test
    It is also worth checking how long the entire report cycle lasts. At the moment it comes out to 11 seconds, although static IP can probably improve it, as well as the implementation of the system will be improved.
    
    mqtt_pass hass_pass_secret
    mqtt_clientID temp_test
    mqtt_host 192.168.0.124:1883
    Info:MAIN:Time 6, idle 114159/s, free 71192, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 7, idle 181106/s, free 71232, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to temp_test/+/get
    Info:MQTT:Publishing val temp_test to temp_test/host retain=0
    Info:MAIN:Time 8, idle 183495/s, free 71232, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on May  1 2023 21:06:42 version 1.17.88 to temp_test/build retain=0
    Info:MAIN:Time 9, idle 190408/s, free 71232, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 1c:90:ff:2f:c0:f8  to temp_test/mac retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 10 00 01 00 10 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 16 (Unknown) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: unhandled type 16
    Info:MAIN:Time 10, idle 192374/s, free 71232, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=192.168.0.100 gate=192.168.0.1 mask=255.255.255.0 mac=1c:90:ff:2f:c0:f8 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-46,ssid=5G_FULL_POWER,bssid=ac:d5:64:2f:7f:f5 ,channel=6,cipher_type:CCMP
    Info:MQTT:Publishing val 2 to temp_test/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 01 02 00 04 00 00 00 E3 F6 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 227
    Info:GEN:CHANNEL_Set channel 1 has changed to 227 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 227 to channel 1 
    Info:MQTT:Publishing val 227 to temp_test/1/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 02 02 00 04 00 00 00 29 3D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 2, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 41
    Info:GEN:CHANNEL_Set channel 2 has changed to 41 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 41 to channel 2 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/1/get
    Info:MQTT:Publishing val 41 to temp_test/2/get retain=0
    Info:MAIN:Time 11, idle 205603/s, free 71232, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/2/get
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 767 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 22 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:5G_FULL_POWER key:MyP@ssw0rd
    Info:MAIN:Using SSID [5G_FULL_POWER]
    Info:MAIN:Using Pass [MyP@ssw0rd]
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to temperature_div10
    Info:GEN:Channel 2 type changed to Humidity
    Info:GEN:Channel 3 type changed to ReadOnly
    Info:MAIN:Time 1, idle 283411/s, free 70904, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 62 79 75 73 76 75 6D 65 6D 65 35 69 69 63 61 64 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 20 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"byusvumeme5iicad","v":"1.0.0"}
    Info:MAIN:Time 2, idle 186205/s, free 70840, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 67724/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 5, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass hass_pass_secret
    mqtt_clientID temp_test
    mqtt_host 192.168.0.124:1883
    Info:MAIN:Time 6, idle 109039/s, free 71208, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to temp_test/+/get
    Info:MQTT:Publishing val temp_test to temp_test/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 7, idle 171518/s, free 71040, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on May  1 2023 21:06:42 version 1.17.88 to temp_test/build retain=0
    Info:MAIN:Time 8, idle 180693/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 1c:90:ff:2f:c0:f8  to temp_test/mac retain=0
    Info:MAIN:Time 9, idle 187841/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 3 to temp_test/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 10 00 01 00 10 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 16 (Unknown) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: unhandled type 16
    Info:MAIN:Time 10, idle 188069/s, free 59552, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:GEN:dhcp=0 ip=192.168.0.100 gate=192.168.0.1 mask=255.255.255.0 mac=1c:90:ff:2f:c0:f8 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-49,ssid=5G_FULL_POWER,bssid=ac:d5:64:2f:7f:f5 ,channel=6,cipher_type:CCMP
    Info:MQTT:Publishing val -47 to temp_test/rssi retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 01 02 00 04 00 00 00 E3 F6 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 227
    Info:GEN:CHANNEL_Set channel 1 has changed to 227 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 227 to channel 1 
    Info:MQTT:Publishing val 227 to temp_test/1/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 02 02 00 04 00 00 00 29 3D 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/1/get
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 2, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 41
    Info:GEN:CHANNEL_Set channel 2 has changed to 41 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 41 to channel 2 
    Info:MQTT:Publishing val 41 to temp_test/2/get retain=0
    Info:MAIN:Time 11, idle 176355/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/2/get
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 768 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 22 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:5G_FULL_POWER key:MyP@ssw0rd
    Info:MAIN:Using SSID [5G_FULL_POWER]
    Info:MAIN:Using Pass [MyP@ssw0rd]
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to temperature_div10
    Info:GEN:Channel 2 type changed to Humidity
    Info:GEN:Channel 3 type changed to ReadOnly
    Info:MAIN:Time 1, idle 275646/s, free 70904, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 62 79 75 73 76 75 6D 65 6D 65 35 69 69 63 61 64 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 20 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"byusvumeme5iicad","v":"1.0.0"}
    Info:MAIN:Time 2, idle 184552/s, free 70904, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 64678/s, free 71152, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 71152, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 5, idle 0/s, free 71152, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass hass_pass_secret
    mqtt_clientID temp_test
    mqtt_host 192.168.0.124:1883
    Info:MAIN:Time 6, idle 108018/s, free 71080, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to temp_test/+/get
    Info:MQTT:Publishing val temp_test to temp_test/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 7, idle 176336/s, free 71312, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on May  1 2023 21:06:42 version 1.17.88 to temp_test/build retain=0
    Info:MAIN:Time 8, idle 359945/s, free 59616, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MQTT:Publishing val 1c:90:ff:2f:c0:f8  to temp_test/mac retain=0
    Info:MAIN:Time 9, idle 184565/s, free 71072, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 2 to temp_test/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 10 00 01 00 10 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 16 (Unknown) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: unhandled type 16
    Info:MAIN:Time 10, idle 189494/s, free 71312, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=192.168.0.100 gate=192.168.0.1 mask=255.255.255.0 mac=1c:90:ff:2f:c0:f8 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-38,ssid=5G_FULL_POWER,bssid=ac:d5:64:2f:7f:f5 ,channel=6,cipher_type:CCMP
    Info:MQTT:Publishing val -46 to temp_test/rssi retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 01 02 00 04 00 00 00 E4 F7 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 228
    Info:GEN:CHANNEL_Set channel 1 has changed to 228 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 228 to channel 1 
    Info:MQTT:Publishing val 228 to temp_test/1/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 02 02 00 04 00 00 00 29 3D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 2, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 41
    Info:GEN:CHANNEL_Set channel 2 has changed to 41 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 41 to channel 2 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/1/get
    Info:MQTT:Publishing val 41 to temp_test/2/get retain=0
    Info:MAIN:Time 11, idle 202098/s, free 71312, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/2/get
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 769 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 22 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:5G_FULL_POWER key:MyP@ssw0rd
    Info:MAIN:Using SSID [5G_FULL_POWER]
    Info:MAIN:Using Pass [MyP@ssw0rd]
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to temperature_div10
    Info:GEN:Channel 2 type changed to Humidity
    Info:GEN:Channel 3 type changed to ReadOnly
    Info:MAIN:Time 1, idle 280929/s, free 70904, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 62 79 75 73 76 75 6D 65 6D 65 35 69 69 63 61 64 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 20 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"byusvumeme5iicad","v":"1.0.0"}
    Info:MAIN:Time 2, idle 187005/s, free 70840, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 65855/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 5, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass hass_pass_secret
    mqtt_clientID temp_test
    mqtt_host 192.168.0.124:1883
    Info:MAIN:Time 6, idle 121870/s, free 71208, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to temp_test/+/get
    Info:MQTT:Publishing val temp_test to temp_test/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 7, idle 175294/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on May  1 2023 21:06:42 version 1.17.88 to temp_test/build retain=0
    Info:MAIN:Time 8, idle 186306/s, free 59280, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MQTT:Publishing val 1c:90:ff:2f:c0:f8  to temp_test/mac retain=0
    Info:MAIN:Time 9, idle 186065/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 2 to temp_test/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 10 00 01 00 10 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 16 (Unknown) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: unhandled type 16
    Info:MAIN:Time 10, idle 377667/s, free 71248, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=192.168.0.100 gate=192.168.0.1 mask=255.255.255.0 mac=1c:90:ff:2f:c0:f8 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-48,ssid=5G_FULL_POWER,bssid=ac:d5:64:2f:7f:f5 ,channel=6,cipher_type:CCMP
    Info:MQTT:Publishing val -49 to temp_test/rssi retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 01 02 00 04 00 00 00 E4 F7 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 228
    Info:GEN:CHANNEL_Set channel 1 has changed to 228 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 228 to channel 1 
    Info:MQTT:Publishing val 228 to temp_test/1/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 02 02 00 04 00 00 00 29 3D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 2, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 41
    Info:GEN:CHANNEL_Set channel 2 has changed to 41 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 41 to channel 2 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/1/get
    Info:MQTT:Publishing val 41 to temp_test/2/get retain=0
    Info:MAIN:Time 11, idle 205611/s, free 70712, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/2/get
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 770 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 22 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:5G_FULL_POWER key:MyP@ssw0rd
    Info:MAIN:Using SSID [5G_FULL_POWER]
    Info:MAIN:Using Pass [MyP@ssw0rd]
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/temp_test/ subT cmnd/temp_test/+
    Info:MQTT:MQTT_RegisterCallback called for bT temp_test/ subT temp_test/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to temperature_div10
    Info:GEN:Channel 2 type changed to Humidity
    Info:GEN:Channel 3 type changed to ReadOnly
    Info:MAIN:Time 1, idle 281763/s, free 70840, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 62 79 75 73 76 75 6D 65 6D 65 35 69 69 63 61 64 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 20 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"byusvumeme5iicad","v":"1.0.0"}
    Info:MAIN:Time 2, idle 187527/s, free 70840, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 65471/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 5, idle 0/s, free 71024, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName homeassistant
    mqtt_pass hass_pass_secret
    mqtt_clientID temp_test
    mqtt_host 192.168.0.124:1883
    Info:MAIN:Time 6, idle 114146/s, free 71200, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to temp_test/+/set
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to cmnd/temp_test/+
    Info:MQTT:mqtt_subscribed to temp_test/+/get
    Info:MQTT:Publishing val temp_test to temp_test/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 7, idle 185104/s, free 71240, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on May  1 2023 21:06:42 version 1.17.88 to temp_test/build retain=0
    Info:MAIN:Time 8, idle 182657/s, free 71240, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 1c:90:ff:2f:c0:f8  to temp_test/mac retain=0
    Info:MAIN:Time 9, idle 186337/s, free 71000, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 2 to temp_test/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 10 00 01 00 10 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 16 (Unknown) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: unhandled type 16
    Info:MAIN:Time 10, idle 189701/s, free 71008, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=192.168.0.100 gate=192.168.0.1 mask=255.255.255.0 mac=1c:90:ff:2f:c0:f8 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-38,ssid=5G_FULL_POWER,bssid=ac:d5:64:2f:7f:f5 ,channel=6,cipher_type:CCMP
    Info:MQTT:Publishing val -39 to temp_test/rssi retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 01 02 00 04 00 00 00 E4 F7 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 228
    Info:GEN:CHANNEL_Set channel 1 has changed to 228 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 228 to channel 1 
    Info:MQTT:Publishing val 228 to temp_test/1/get retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 08 02 02 00 04 00 00 00 29 3D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 15 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 2, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 4 int: 41
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/1/get
    Info:GEN:CHANNEL_Set channel 2 has changed to 41 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 41 to channel 2 
    Info:MQTT:Publishing val 41 to temp_test/2/get retain=0
    Info:MAIN:Time 11, idle 183799/s, free 71008, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic temp_test/2/get
    



    Summary
    This sensor is based on the TuyaMCU protocol. It can work with both the Tuya app and OpenBeken. The frequency of reporting can be changed in a large range, from a minute to 2 hours or more - we did not check longer periods. In deep sleep mode, it draws about 5µA. This is a good result, although the BK7231 itself, according to my tests, draws about 6µA in deep sleep mode with GPIO wake-up. Changing the firmware is a bit of work, because as usual, TuyaMCU is on the same UART port that is used for programming, but after a single upload everything should work fine. The topic contains ready-made scripts for this sensor.
    Thanks again to @DeDaMrAz for helping me develop this topic (we worked remotely together on this sensor).
    PS: It's worth seeing an older topic by another user with a similar sensor, here , there is also a sample YAML code for Home Assistant, which is now no longer needed since OBK supports HASS Discovery.

    Cool? Ranking DIY
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 4850 posts with rating 5183, helped 235 times. Been with us since 2014 year.
  • #2
    pier
    Level 24  
    Temperature is measured in percent, interesting.
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
  • #3
    p.kaczmarek2
    Moderator Smart Home
    Classic copy/paste error by the graphic designer, it was supposed to be humidity. But they still have to admit that, taking into account other Chinese products and offers, their English is quite understandable here. I hope that at least now, in the times of ChatGPT and good translators, the translations of Chinese products and instructions will be better and better.
  • #4
    spin55
    Level 14  
    I just saw this thread thanks to your link in the pir motion thread and I must confess that I had not seen it. Very good work.

    I see that you handle command 10 to vary the frequency of data updates. It would be interesting for the pir, to shorten the 1 minute 16 seconds that it currently has for the reset interval of the motion sensor.
  • #5
    p.kaczmarek2
    Moderator Smart Home
    Hello @spin55 , the following work was done with @DeDaMrAz , I do not have this device physically myself, but according to his testing, command 10 (ObtainDPCache) is working well and can indeed set report time.

    Command 10 (ObtainDPCache) is different than a typical TuyaMCU communication, because in case of ObtainDPCache , the MCU first asks the WiFi module for data and WiFI module has to reply with data from the cache. So, when linking OBK channel to dpID and variable type, for TuyaMCU, you must also add "1" as a dpCache flag:
    
    // link dpID 17 to channel 5, the type is val, extra '1' means that its dpCache variable
    linkTuyaMCUOutputToChannel 17 val 5 1
    

    If you do something like that, then at the time of 10 (ObtainDPCache ) processing, the OBK device will send the value from channel 5 to the dpID 5 with type "val" to TuyaMCU.

    If you want OBK to remember the channel between reboots, you can use start value -1 (magic value meaning "remember last"):
    
    // Make value persistant (stored between reboots), 
    // start value -1 means "remember last"
    SetStartValue 5 -1
    

    Then it is remembered in the flash memory, but don't worry about flash wear - our flash system is limiting the number of erase cycles, we erase once per many writes, so flash memory will not wear out too fast... and also, in this case, I'd think that people do not change the Report Interval often.

    I have tried recently ordering some more devices for testing, I've chosen two battery powered ones, but they came without MCUs:
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    Both devices from photos are working 100% good with OBK with DeepSleep system, but they are not TuyaMCU.

    I will order more when I get some more donation funds, but don't worry, the research is not closed! I will work on TuyaMCU more and do my best to ensure it's all good and well supported.

    @spin55 if you want to try to use command 0x10 to configure your TuyaMCU device sleep time, let me know, and maybe show some UART logs. I am not sure about that PIR sensor because, as far as I know, PIR sensor is not waking up periodically (or maybe just to check battery?), it's waking up when a movement is detected, so that's a different thing.
  • #6
    spin55
    Level 14  
    Thank you very much for the detailed explanation.

    //S 4/30/2023 8:49:32 PM WiFi send:
    55AA0001000000
    //R 4/30/2023 8:49:32 PM WiFi received:
    55AA000100247B2270223A226279757376756D656D65356969636164222C2276223A22312E302E30227D20
    //S 4/30/2023 8:49:33 PM WiFi send:
    55AA000200010305
    //R 4/30/2023 8:49:33 PM WiFi received:
    55AA0002000001
    //S 4/30/2023 8:51:50 PM WiFi send:
    55AA000200010406
    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA0002000001
    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA001000010010
    //S 4/30/2023 6:18:06 PM WiFi sent:
    55AA00100002010012
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA0005000801020004000000FC0F
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA0005000802020004000000273B
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA00050005030400010112
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA00050005090400010017
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080A0200040000021C3A
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080B020004FFFFFF88A2
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080C0200040000005A78
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500080D0200040000000A29
    //R 4/30/2023 8:51:58 PM WiFi received:
    55AA000500050E040001021E
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA000500050F040001021F
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050008110200040000000124
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050008120200040000000125
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000813020004000000052A
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000814020004000000082E
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA00050005150100010020
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000801020004000000FD10
    //R 4/30/2023 8:51:59 PM WiFi received:
    55AA0005000802020004000000273B
    //S 4/30/2023 8:52:13 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:15 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:17 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:19 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:21 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:23 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:25 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:27 PM WiFi send:
    55AA000500010005
    //S 4/30/2023 8:52:29 PM WiFi send:
    55AA000500010005


    Could you explain why there is that jet lag?

    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA001000010010
    //S 4/30/2023 6:18:06 PM WiFi sent:
    55AA00100002010012
  • #7
    p.kaczmarek2
    Moderator Smart Home
    spin55 wrote:

    Could you explain why there is that jet lag?

    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA001000010010
    //S 4/30/2023 6:18:06 PM WiFi sent:
    55AA00100002010012

    That 8:51:56 PM vs 6:18:06 PM lag should be ignored, it's just editing error. I had multiple dumps, also taken separately by first probing RX and then TX and I was composing them by hand into something more readable for humans. The following situation does not happen in reality.

    That being said, I will also note that latest BK7231 GUI Flasher can do dual UART capture, but it is still somewhat problematic, because it has turned out that COM/serial/USB to serial/whatever lag is so big that sometimes still gets packet order wrong so human post processing of packet capture is still required in some cases.

    Btw, the example you are quoting:
    //R 4/30/2023 8:51:56 PM WiFi received:
    55AA001000010010
    //S 4/30/2023 6:18:06 PM WiFi sent:
    55AA00100002010012
    [/quote]
    is an empty 0x10 packet reply, basically it says "There is nothing to report".

    If you want to capture some 0x10 data along with dpIDs, you must take following steps:
    1. setup capture
    2. then in Tuya app, change some kind of parameter, maybe "report period"
    3. then check capture for 0x10 packet and it should contain report period dpID, value and type.
    It will be like:
    
    55AA0010001201021102000400000001120200040000000155
    


    Another thing worth mentioning is that you can also extract dpIDs from Tuya API, but I don't know much about that. It was mentioned here:
    https://www.elektroda.pl/rtvforum/viewtopic.php?p=20581469#20581469

    Btw, if you are interested in TuyaMCU protocol in OpenBeken, you can also peek into our automatic self test system, which basically simulates TuyaMCU use cases and checks if the firmware is responding as expected. For example, see this file:
    https://github.com/openshwprojects/OpenBK7231...rc/selftest/selftest_tuyaMCU_batteryPowered.c
    This can be run on Windows build of OBK and it used to automatically check if TuyaMCU still works as expected after doing firmware changes and updates. Of course, it's not as good as testing on physical device, but it's better than nothing.
  • #8
    spin55
    Level 14  
    p.kaczmarek2 wrote:
    That being said, I will also note that latest BK7231 GUI Flasher can do dual UART capture, but it is still somewhat problematic, because it has turned out that COM/serial/USB to serial/whatever lag is so big that sometimes still gets packet order wrong so human post processing of packet capture is still required in some cases.


    Do you use two identical USB? I say this because I have a CP2102 that captures in Realterm at a speed of 20 characters per second (CPS: 20), and another FTDI232 that captures only 5 characters per second (CPS: 5). And that is very noticeable in the listings.

    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
  • #9
    p.kaczmarek2
    Moderator Smart Home
    I have two identical, CH340 dongles.
    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
    The issue is software related, I've tried even creating a thread per each port and constantly polling BytesToRead, but it still turned out to be problematic. It would be great to have some kind of immediate low level callback in C# for SerialPort, but I haven't found it so far. Maybe DataReceived? I will check it in the free time.
  • #10
    rakalexei
    Level 7  
    >>20584330

    Hey, I have 3 PIR sensors like that, I successfully flashed them, but couldn't figure out the correct config. Could you please share your?
  • #11
    spin55
    Level 14  
    I don't know if it will be the same, but the one I have has this configuration:

    Code: json
    Log in, to see the code


    Autoexec.bat
    
    setChannel 3 1
    addRepeatingEvent 30 -1 publishFloat "4" $CH4
    delay_s 60
    PinDeepSleep
    
  • #12
    p.kaczmarek2
    Moderator Smart Home
    @rakalexei do you have 2MB firmware backup, so we can extract GPIO with this tool:
    https://github.com/openshwprojects/BK7231GUIFlashTool

    @spin55 your autoexec.bat is working, but it's not optimal. You can reduce energy consumption by going to sleep earlier.
    WARNING! The following template and script is for a device WITHOUT TUYA MCU. Please do not confuse it! The device from first post is TuyaMCU.
    Something like:
    
    // set LED on???
    setChannel 3 1
    // every 1 second, publish value, just to be sure, should be not needed
    addRepeatingEvent 1 -1 publishFloat "4" $CH4
    // wait for MQTT connection to establish
    waitFor MQTTState 1
    // extra delay
    delay_s 3
    // go to sleep
    PinDeepSleep
    

    My script also has one drawback, it will wait forever if MQTT server is offline, you can fix it by adding a line:
    
    // after 60 seconds from now, force PinDeepSleep, even if MQTT was off
    addRepeatingEvent 60 -1 PinDeepSleep
    

    of course, it must be added before WAITFOR.
  • #13
    spin55
    Level 14  
    p.kaczmarek2 wrote:
    @spin55 your autoexec.bat is working, but it's not optimal. You can reduce energy consumption by going to sleep earlier.
    WARNING! The following template and script is for a device WITHOUT TUYA MCU. Please do not confuse it! The device from first post is TuyaMCU.


    The autoexec.bat is for reference. Logically you have to play with the values ​​of:
    addRepeatingEvent 30 -1 publishFloat "4" $CH4 and delay_s 60 to adapt it to the needs of each one.

    Without a doubt, your autoexec is best optimized for immediate use.

    [CB3S/BK7231N] Temperature/Humidity Sensor with TuyaMCU - Diagram, Reverse Engin
  • #14
    rakalexei
    Level 7  
    >>20585154

    No, I don't have a dump.
  • #15
    p.kaczmarek2
    Moderator Smart Home
    spin55 wrote:

    The autoexec.bat is for reference. Logically you have to play with the values ​​of:
    addRepeatingEvent 30 -1 publishFloat "4" $CH4 and delay_s 60 to adapt it to the needs of each one.

    I am also not sure, why do you have value 30 here? Every 30 seconds?
    It won't hurt to do a publish even every 1 second, if you have nothing against a little spam... just be sure.
    Still, if channel is used, OBK should publish it automatically on change. So in reality there may be no need for a manual publish. So, where did the 30s value came from?

    rakalexei wrote:

    No, I don't have a dump.

    I don't know which method you are using for flashing, but in general, 2MB backup is now very, very useful because we can extract GPIO from that.
  • #16
    spin55
    Level 14  
    p.kaczmarek2 wrote:
    I am also not sure, why do you have value 30 here? Every 30 seconds?
    It won't hurt to do a publish even every 1 second, if you have nothing against a little spam... just be sure.
    Still, if channel is used, OBK should publish it automatically on change. So in reality there may be no need for a manual publish. So, where did the 30s value came from?


    I put this in because OBK (same as TuyaMCU) only posts when there is a battery value change. And I put every 30 seconds so it wouldn't do more than one forced post. I did it because in the tests I feed the equipment with a 3.3V source and I needed to verify that the battery value was published in HA.

    Surely feeding the equipment with batteries or batteries, this command will not be necessary because when a variation occurs it will be published (I suppose, since I have not verified it).