logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] [CB3S] [AHT20] TH01 Generic Temperature and Humidity Sensor Teardown

anthonythomas 33462 129
ADVERTISEMENT
  • #61 20921442
    Wen2024
    Level 7  

    >>20910745
    p.kaczmarek2 you are right. After cutting of the RX and TX traces at the Tuya MCU, I was able to flash with the Windows flasher.Close-up of a PCB with a yellow marking around an integrated circuit.
    Now I have the same problem as grericht and maxen0815 Post #31 to #39. We don't get any useful data on any channel... all are set to 0!!!
    I think that our TH01 sensor is nearly similar to DeDaMrAz but it is different. The PCB is different: we don't have the hole in the middle and the Tuya MCU is 90 degrees offset.

    My only two logs are:
    "Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 6C 66 33 36 79 35 6E 77 62 38 6A 6B 78 77 67 67 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 99
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"lf36y5nwb8jkxwgg","v":"1.0.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!"

    He has a lot of logs:
    "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: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: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
    and more ..."
    Any idea? (I think we had to adapt the driver...)
  • ADVERTISEMENT
  • #63 20923103
    gabybriet
    Level 3  

    Screenshot of Home Assistant configuration with a message about MQTT discovery being queued. Screenshot of MQTT configuration in Home Assistant showing no devices or entities connected to core-mosquitto. Screenshot of the configuration interface for Test Sonde T&H3 sensor with temperature, humidity data, and MQTT status.

    Hello, I have a problem connecting to Home Assistant.
    MQTT is connected but there is nothing on HA.
    In "Home Assistant configuration" there is nothing written, is this normal?
    Thank you for your help, I couldn't find anything even if I started from the beginning.
  • ADVERTISEMENT
  • #64 20923263
    Wen2024
    Level 7  

    Hello gabybriet, do you have the same TH01 PCB and can you get temperature, humidity, and battery data? Can you provide a photo of the PCB?
    Mine doesn't work.
    Thank you, Wen2024
  • ADVERTISEMENT
  • #65 20923288
    p.kaczmarek2
    Moderator Smart Home
    @Wen2024 , just to be clear, do you test it by letting it to power itself up on its own? You should not power the WiFi module externally!

    i am asking because I saw that kind of behaviour in the past when I was tampering with the sensor on my own.

    Second question: Do you have MQTT configured? This will wait for your MQTT to connect, so... so you need to have MQTT.

    @gabybriet the YAML code field can be empty, it will still work if you press the Discovery button
    Helpful post? Buy me a coffee.
  • #67 20923325
    Wen2024
    Level 7  

    Hello p.kaczmarek2,
    I supply the modules during the tests via the original battery + and - pins.
    I have not configured MQTT because I want to send the data to my server. This works very well with simulated values...

    Screenshot showing communication between the WiFi module and OpenBeken TH01.
    This is captured OpenBeken TH01 communication with TuyaMCUAnalyzer. Flashed with Version: 1.17.408. No MQTT
    This autoexec.bat:
    startDriver tuyaMCU
    startDriver tmSensor
    linkTuyaMCUOutputToChannel 1 val 1
    setChannelType 1 temperature_div10
    linkTuyaMCUOutputToChannel 2 val 2
    setChannelType 2 Humidity
    linkTuyaMCUOutputToChannel 3 val 3
    setChannelType 3 ReadOnly

    Added after 4 [minutes]:

    Thank you for photos gabybriet. This is the same PCB as mine.
  • #68 20923343
    gabybriet
    Level 3  

    Broker options window with fields for MQTT configuration. MQTT connection configuration form with fields to fill in. @p.kaczmarek2 I press the Discovery button, a window opens but nothing happens on HA.
    Maybe a bad configuration?
    I am a beginner.
  • ADVERTISEMENT
  • #69 20923402
    Wen2024
    Level 7  

    Hello p.kaczmarek2,
    This is problem?: "Info:MQTT:mqtt_host empty, not starting mqtt"

    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 19, idle 174794/s, free 73920, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    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 20, idle 187903/s, free 73960, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=192.168.178.44 gate=192.168.178.1 mask=255.255.255.0 mac=1c:90:ff:65:35:24
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-48,ssid=MW_Home,bssid=c8:0e:14:b0:a7:33,channel=1,cipher_type:CCMP
    Info:MAIN:Time 21, idle 183697/s, free 73960, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 22, idle 187522/s, free 73960, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38

    Is there a solution without MQTT?
    With the original Tuya smart app, you don't need MQTT either. Is it not possible to generate the sequence in the same way as with the Tuya sequence?
    Best regards,
    Wen2024
  • #70 20928454
    Wen2024
    Level 7  

    Hello, I have installed a local Mosquitto MQTT broker on a Windows machine and it runs. I am able to send data to my HTTPS server:

    Temperature monitoring graph showing temperature, humidity, and battery status with labels and time data.
    For testing, this is OK, but I need this functionality without the additional MQTT broker. If the TuyaMCU driver is started, communication always takes place with the MQTT broker. That can't be switched off, can it? Any help is welcome. Thank you!

    Added after 17 [minutes]:

    Hello divadiow (post 51),
    I have flashed such a module and it behaves analogously to the other modules in this article:

    Close-up of an electronic module with several wires attached to a PCB on a white background.
    Best regards, Wen2024
  • #71 20930089
    nacxoffw
    Level 5  

    Hi, I have a similar board but without shared RX/TX pinouts and with easy solder points. After all the process (flash, config wifi, names, autoexe, and MQTT), it's alive in Home Assistant but shows 0 values!!

    Can you help me? Electronic module with components and connector Computer screen displaying OpenBK7231N and Home Assistant software, showing temperature and humidity settings.

    Added after 1 [hour]:

    Another question :)

    Besides, I have two of these boards.
    Both lose the connection on every try after a few seconds. I do the CEN short very quickly. One time, the read process finished but the checks fail. Any tip?

    Thanks!
    Close-up of a green circuit board with connected wires. Computer screen showing Reading failed message in the BK7231 flashing program.
  • #72 20930271
    p.kaczmarek2
    Moderator Smart Home
    Wen2024 wrote:

    Is there a solution without MQTT?
    With the original Tuya smart app, you don't need MQTT either. Is it not possible to generate the sequence in the same way as with the Tuya sequence?

    Well, you don't need MQTT for Tuya smart app, but you need a cloud connection. So, OpenBeken, instead of connecting to cloud, waits for your MQTT to connect:
    Screenshot of Visual Studio editor displaying source code of the OpenBeken application.
    We even have an enumerator for that - this specific state is called TM0_STATE_AWAITING_MQTT, that's where your device hangs.
    This is required by TuyaMCU because we need to know when we are ready to report data to MQTT.

    In order to work without MQTT, we would need to slightly alter our TuyaMCU driver. It's possible, but it's debatable how should we do it. Maybe some kind of flag or a time out...
    Helpful post? Buy me a coffee.
  • #73 20931207
    Wen2024
    Level 7  

    Hello nacxoffw,
    first question: Go to Launch Web Application. Then go to Logs. Power on the device on the battery terminals. See logs. This will give you clues to the error.
    second question: I assume that you have disconnected the Tx/Rx pins to the MCU (see post 61). Try it several times. Sometimes it works immediately, sometimes not. I have also reduced the baud rate but that didn't help either. I can't say why it suddenly worked again with the 912600 baud rate. I am also a beginner in this stuff.

    Hello p.kaczmarek2,
    I would prefer the flag. The module start wouldn't lose any time due to the timeout and it is probably more error resistant at slow WIFI. Could the flag solution work like this:

    autoexec.bat:

    // FLAG_NO_MQTT == true
    SetFlag 999 1

    startDriver tuyaMCU
    startDriver tmSensor
    ....

    drv_tuyaMCU.c:

    ...
    else {
    addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!");
    }
    if (g_sensorMode) {
    if (g_tuyaBatteryPoweredState == TM0_STATE_AWAITING_WIFI) {
    g_tuyaBatteryPoweredState = TM0_STATE_AWAITING_MQTT;
    if (FLAG_NO_MQTT == true) {
    g_tuyaBatteryPoweredState = TM0_STATE_AWAITING_STATES;
    g_tuyaNextRequestDelay = 0;
    }
    }
    else if (g_tuyaBatteryPoweredState == TM0_STATE_AWAITING_MQTT) {
    g_tuyaBatteryPoweredState = TM0_STATE_AWAITING_STATES;
    g_tuyaNextRequestDelay = 0;
    }
    }
    break;
    ...

    Best regards,
    Wen2024
  • #74 20931252
    p.kaczmarek2
    Moderator Smart Home
    So maybe instead of a flag, I can just... just check for disabled MQTT? For an empty MQTT host field in the config?
    Helpful post? Buy me a coffee.
  • #75 20931316
    Wen2024
    Level 7  

    No, it's the situation from post 69:
    See logs:

    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Time 24, idle 185191/s, free 72568, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38
    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:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 26, idle 191902/s, free 64000, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 27, idle 189351/s, free 72608, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 29, idle 188510/s, free 49000, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 5/38
    Info:MAIN:Time 30, idle 184653/s, free 49200, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 4/38

    ...

    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 74, idle 187486/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 75, idle 192245/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 77, idle 189504/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 78, idle 188563/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 81, idle 186964/s, free 64000, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 82, idle 189501/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 84, idle 190339/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing 1, socks 2/38
    Info:MAIN:Time 87, idle 192773/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing 4, socks 2/38
    Info:MAIN:Time 88, idle 191812/s, free 72608, MQTT 0(4), bWifi 1, secondsWithNoPing 5, socks 2/38
    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 25, idle 186494/s, free 72512, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 33, idle 189593/s, free 64120, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 46, idle 191906/s, free 64120, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MAIN:Time 51, idle 180164/s, free 72728, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 55, idle 187307/s, free 72728, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 80, idle 192419/s, free 72512, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:GEN:dhcp=0 ip=192.168.178.45 gate=192.168.178.1 mask=255.255.255.0 mac=18:de:50:bf:7e:75
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-53,ssid=MW_Home,bssid=c8:0e:14:b0:a7:33,channel=1,cipher_type:CCMP
  • #76 20931335
    p.kaczmarek2
    Moderator Smart Home
    Why do you think that a flag is better than a check for empty MQTT hostname?

    It would work exactly the same, but it would be more intuitive.

    The code would just check if MQTT hostname is set, and if not, it will proceed, it will work just like the flag solution you proposed.
    Helpful post? Buy me a coffee.
  • #77 20931344
    Wen2024
    Level 7  

    Yes, you're right. It's easier to understand.

    Added after 2 [minutes]:

    That was a misunderstanding. I tried out what happens when the field is empty and sent you the logs.
  • #78 20931402
    p.kaczmarek2
    Moderator Smart Home
    I've checked the code again, and you know what? We could just have set the default Wifi state to 0x04 and it would have worked anyway.
    Code snippet in an editor with highlighted lines and comments.
    Still, here is a new version, it's more intuitive anyway:
    Snippet of code in a text editor showing logic for setting Wi-Fi and MQTT states.
    Here is the commit:
    https://github.com/openshwprojects/OpenBK7231...mmit/e226c8c0806f8d6b8fa64e118ef0b245c0be758a

    So, to sum up, if you want to use tmSensor device without MQTT, you need to do one of two things:
    Option 1: add to script:
    
    tuyaMcu_defWiFiState 0x04
    

    Option 2: make sure that your device has MQTT hostname field empty

    Without any of this, the device will wait until MQTT connects...
    Helpful post? Buy me a coffee.
  • #79 20931413
    nacxoffw
    Level 5  

    >>20931207
    Only one question, actually if I put only 3v with batteries the wifi does not work (suppose that it only appears every x minutes). If I put 3v in the wifi chipset then I can access these logs... Is this the normal work, correct?
  • #80 20931520
    Wen2024
    Level 7  

    Hello p.kaczmarek2, thank you for your help!!! I tried to flash my module with OpenBK7231N_QIO_1.17.427.bin but I always get writing errors. For today, I have to give up but as soon as I get a module flashed, I will get back to you. Thank you very much!!!
  • #81 20931853
    gabybriet
    Level 3  
    >>20923343
    I found the problem
    I used special character "&" for name
  • #83 20933025
    p.kaczmarek2
    Moderator Smart Home
    gabybriet wrote:

    I used special character "&" for name

    Which name? It seems we need to disable special characters for names...
    Helpful post? Buy me a coffee.
  • #84 20935196
    Wen2024
    Level 7  

    Hello p.kaczmarek2 (post #78),
    I have flashed my TH01 modules with your modified version 1.17.427. I left the MQTT hostname field empty
    and here is the result:

    Graph monitoring temperature, humidity, and battery status with TH01 device.

    The TH01 device runs without MQTT connection!!!
    Next, I need to work on the big variation in the data acquisition interval. In the first test they are between 1:58 and 6:56 minutes.
    Thank's a lot for your work,
    @Wen2024

    Added after 10 [minutes]:

    Hello nacxoffw (post #82),
    Do you have a stable 3.3V power supply? Have you connected the + and - from the power supply to the Uart and Wifi Module (both to both)?
    Regards,
    @Wen2024
  • #86 20971334
    Wen2024
    Level 7  

    Hello nacxoffw,
    are your MQTT (Config/Configure MQTT) entries correct? A good idea is to look at auntlydia's post #40. It's a good guide to solve your problem. Have you looked at the logs (Launch Web Application / Logs)?
    Best regards,
    Wen2024
  • #87 21094681
    carlig833
    Level 7  

    Hello there,
    I have the same device as @nacxoffw and I am experiencing frequent issues with device connectivity with my router.
    I can connect to the device access point and configure the SSID and password of my router, but frequently the device does not connect to the router.

    My question is how can I inspect the logs of the device to troubleshoot the cause of the issue?
    I wonder if either one of the two options below is viable:

    1. collect and decode the logs in real-time using RX/TX connection to the device.
    2. configure "persistent logs" so that I can collect them when the device is failing to connect to my router, then revert to access point mode and download the logs

    Do you have any link that covers 1 or 2?
  • #88 21162076
    carlig833
    Level 7  
    I have this [BK7231N] [CB3S] [AHT20] sensor and I wonder if the temperature/humidity reporting interval can be configured in OBK or not.

    These devices usually report a new measure based on the measured quantity (temperature or humidity) being different compared with the previous reading more or less than a configured offset. Or they report a new measure, regardless of difference from previous reported value when a given time interval is elapsed. Is there anything that can be configured in OBK to influence (I would say reduce) the frequency of temp/humidity readings so that the battery will last longer?
  • #89 21162096
    DeDaMrAz
    Level 19  
    carlig833 wrote:
    I have this [BK7231N] [CB3S] [AHT20] sensor and I wonder if the temperature/humidity reporting interval can be configured in OBK or not.

    These devices usually report a new measure based on the measured quantity (temperature or humidity) being different compared with the previous reading more or less than a configured offset. Or they report a new measure, regardless of difference from previous reported value when a given time interval is elapsed. Is there anything that can be configured in OBK to influence (I would say reduce) the frequency of temp/humidity readings so that the battery will last longer?


    What you are looking for can be found in the docs section in GitHub, search for AHT - https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md

    AHT2X_Cycle [IntervalSeconds]
  • #90 21319810
    GastonL
    Level 4  
    >>20905557
    I have the same question. Is there a way to prevent so many zeros after the decimal?

Topic summary

The discussion revolves around the teardown and firmware flashing of the TH01 Generic Temperature and Humidity Sensor, specifically using OpenBK7231N firmware. Users share their experiences with flashing the device, configuring it for WiFi and MQTT, and troubleshooting issues related to data reporting and connectivity. Key points include the necessity of severing RX/TX connections to the MCU for successful flashing, configuring autoexec.bat for driver initialization, and addressing problems with data values being reported as zero. Users also discuss the impact of power supply configurations on device performance and the importance of correctly setting up MQTT for data transmission. Various solutions and configurations are proposed to enhance device functionality and battery life.
Summary generated by the language model.
ADVERTISEMENT