[BK7231N CBU] Generic Temperature and Humidity Sensor

Chasbrot 15267 212
  • #181
    Level 5  
    Hi guys, I've used this sensor for a while, and in autoexec.bat was "waitFor MQTTState 1".
    A couple of days ago my mqtt server was offline all day long and the sensor seems waited indefinitely and completely drains battery.
    After that sensor did not work anymore. I try to reflash firmware and it is successful, but it doesn't boot, not connect to my wifi nor showing own AP.
    Maybe some internal EEPROM or something corrupted during battery drainage? Can it be completely erased somehow?
    I've measured the current and it consumes now 2mA constantly, which seems doing nothing.
  • #182
    Level 5  
    Can someone share their working config with battery saving methods? And where should I save the script? autoexec.bat?

    I just managed to flash mine and I'm looking for the best script with recent power saving features before I install the sensor on my house.
  • #183
    Level 2  
    Hi, I had flashed a couple of devices withut problem, I have one of this humidity sensor, I flashed and all was ok, the only thing I did after flashing the firmware is setup the wifi, and after that I can not see it in the LAN and I can't see the OpenBeken wifi ssid, I tried with a new battery and the same.

    Is it possible that I typed the wrong password/ssid? Any way to recover the device or I have to reflash it? I tried prssing the reset button, but I guess if it's not setup it's not gonna do anything

    Edit: I just found out that if you do five restart cycles device enter in safe mode. I was able to retype the password, and it was the same, but I retyped the SSID ( I swear it was the same) and now it's working :)
    Sorry, and thanks
  • #184
    Moderator Smart Home
    Yes, our safe mode can be very useful. Check out our FAQ for more hints like that:
  • #185
    Level 2  
    I'm using DeDaMrAz setup, pins and autoexec.bat script, the device came to life each 900 seconds and post some values on the MQTT server, but none of them looks like the temperature, and the one that looks like humidity (57) I am getting that as the obk55C3556B/battery/get, I also get 2577 as the obk55C3556B/voltage/get


    I see there are three sensors posting to the mqtt 0, 2 and 4, with values 61, 247, 0
    Any clue on how I can read the temperature on the MQTT server? Thanks
  • #186
    Moderator Smart Home
    Maybe SHT GPIOs has changed. Please attach 2MB firmware backup of your device. If you don't have one , you can also attach just Tuya config partition:

    Or... maybe that value 247 is temperature and you are just missing the prescale values flag?
    [BK7231N CBU] Generic Temperature and Humidity Sensor
  • #187
    Level 2  
    I did as in the video and extracted this (I removed the psk/auth values)

    I did it twice because there are some values on the json that are borked, but I got the same. I think I have a backup firmware but not sure, I need to check that in the other computer

    	"mst_ver_3":"null }3Awf_start_mdll",
    	"dns_prio":"030-Atls_ca_cnt0 2Agw_wsm{nc_tp",
    	"fac_pin":"g2y6z3p3ja2qhyav }{nc_tp",
    	"psk21_key":"null }0\Ais_stride0{abi",

    I enabled the flag 33, and changed the pins to
    7 : SHT3X_SCX,0
    8: SHT3X_SDA,2,3

    But I still get some values, that don't match the temperature, now I'm getting

    60 can be the humidity, but 262 is not the almost high 28º or 29º we have here. I'll let ut running for some time to see if it adjust.
    I'll attach the picture of the model
    [BK7231N CBU] Generic Temperature and Humidity Sensor

    EDIT: Is there any way to get out of DeepSleep mode, each time I have to do any setup I have to enter safe mode use the wifi to enter the device. Can I send a command via MQTT or something so next time it gets up, It get out of the deep sleep mode?
  • #188
    Moderator Smart Home
    The script you are using is forcing deep sleep mode. Maybe just try to edit it in AP mode and comment out the "DeepSleep" command?

    Then, while the deep sleep is not working, check what HTTP panel says. Is it reading really 26 degrees?

    Maybe you need to calibrate? I think there was a function for that.
  • #189
    Level 31  
    Hello, I have uploaded the OpenBK soft thermometer to this thermometer, but I have a problem with its configuration. In general, I see that there is a good brothel and it's hard to find anything.

    So yes, I connected to my wifi, set the pins for battery and SHT30. When I enter the thermometer's IP, it shows me the values. Now I would like to make the module wake up, send me sensor values and battery voltage via HTTP and put it to sleep for a certain time.
    I created a file autoexec.bat and pasted the following commands there:

    startDriver SHT3X
    delay_s 3
    sendPOST http://mojeip:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$CH4
    DeepSleep 120

    And unfortunately it fell, I can't access the thermometer, nor does it send me anything to the server.
    Before creating this autoxec, if I sent the command "sendPOST http://myip:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$CH4" then I see on the server that the thermometer sends me values. Outside the battery, I have a value of 0 there, you probably need to use another variable, but what...
  • #190
    Moderator Smart Home
    Hello, I'd love to help you get this working, but can you tell me where did you get this code from?

    This code waits 3 seconds after starting, then tries to post and immediately falls asleep for 120 seconds.
    It's not supposed to work. The device will go to sleep before it does anything. He will fall asleep even before he connects to WiFi. You should not run such codes, because you block the device.

    It's like if you gave a script on a PC that immediately after logging into Windows it should shut down - then you won't do anything either.

    I'll edit your post later so as not to confuse anyone...

    How do you want to do it:
    // start driver
    startDriver SHT3X
    // wait for MQTT to connect
    waitFor MQTTState 1
    // extra wait
    delay_s 1
    // measure
    // send data
    SendGET http://mojeip:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$CH4
    // wait for GET to be sent
    delay_s 5
    // sleep for 120 seconds and then wake up (from blank state)
    DeepSleep 120

    1. it is worth waiting for an MQTT or WiFi connection before sending data:
    waitFor MQTTState 1


    // wait for wifi to become WIFI_STA_CONNECTED
    waitFor WiFiState 4

    2. When sending GET data, use SendGet:
    SendGET http://mojeip:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$CH4

    3. After uploading, wait a few seconds for everything to upload
    SendGET http://mojeip:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$CH4
    // wait for post to be sent
    delay_s 5

    If you don't have access to the device now (and you certainly don't, because it goes to sleep after 3 seconds from booting) then try to perform 5 quick power on/off cycles to activate AP mode and edit or delete autoexec.bat there. Worse, probably in sleep mode the device consumes so little energy that the capacitors on board keep it working and this can make it difficult to perform power off and it ... maybe remove the batteries, short the VDD resistor to GND to discharge the capacitors completely to 0, and then do 5 cycles of power on/off, of course they must be cycles faster than 3 seconds for the OBK to count them and enter AP (safe mode) and not fall asleep again.

    If necessary, you can also try to remove autoexec.bat with a flasher, if that helps too.

    It is possible that I will try to prepare a better script or automatic driver for this, because I can see that it is problematic, but it is difficult to do such a non-profit project being one person and keep everything up to date
  • #191
    Level 31  
    I took the code from this topic, from the previous page, but I removed the MQTT entries from it, which I do not currently use.
    I don't know if I can't find it or if some basic configuration description is missing. For example, on this page with the list of devices there is a config to copy and where I should paste it later. Same after that autoexec.bat. There are no examples for a beginner for some popular devices such as a socket, a light bulb, and I'm just struggling with a thermometer. If there is no such thing, a topic with a similar schedule to the one you pasted would be useful.
    I was able to delete this autoexec.bat file by shorting CEN to ground 5 times. And then in commands I typed lfs_format.

    So yeah, I made this code and it almost works fine for me:
    // start driver
    startDriver SHT3X
    //hold button to get into safe mode
    addEventHandler OnHold 20 SafeMode
    // wait for wifi to become WIFI_STA_CONNECTED
    waitFor WiFiState 4
    Battery_Setup 2500 4200 2.29 2400 4096
    publishFloat "voltage" $CH4/1000
    //publishFloat "battery" $CH4/25
    // extra wait
    delay_s 5
    // measure
    // send data
    SendGET http://adres:port/czujnik1.php?temp=$CH2&wilg=$CH3&bat=$voltage
    // wait for GET to be sent
    delay_s 5
    // sleep for 120 seconds and then wake up (from blank state)
    DeepSleep 120

    That is:
    - when it wakes up, if I hold the button for 3 seconds, it switches to safe mode, but it works on average
    - battery voltage and percentages from the Battery_Setup command also need to be calibrated, but in general it shows correctly - 4200 is set because I power it with 18650, so I know it's too high voltage for the module, but they have been sitting on the original software for half a year, powered by this and live
    - now sends me temperature and humidity variables to the server after waking up and then goes to sleep for about 2 minutes
    - unfortunately, I can't deal with the battery voltage variable, I always have a value of 0, could you tell me how to configure it?
  • #192
    Moderator Smart Home
    Most devices don't need autoexec.bat, but you're generally right. We are trying to build such a database of examples here:
    We will also add your code there when we improve it.

    The problem with some devices is that I just don't have them, so scripts aren't always ready for them.

    //hold button for 3 seconds to get into safe mode
    addEventHandler OnHold 20 SafeMode 3

    These 3 here are not holding time. I'm not sure where it came from, but these 3 are doing nothing at the moment, I'm about to post a patch that takes these 3 as the time in seconds to reboot into safe mode.

    As for the battery, I don't think the author of this driver has derived it into variables. It's not a problem, I can upload an update soon which will make two new variables available:
    [BK7231N CBU] Generic Temperature and Humidity Sensor
  • #193
    Level 31  
    Thanks, I uploaded the new version and the voltage measurement works ok.
  • #194
    Moderator Smart Home
    So let's go back to SafeMode. Does the current script work for you correctly? Safe Mode always starts when you press the button in time? Change those "3" to "1" so that it turns on after 1 second.

    I understand that the ideal option would be if the Safe Mode button was always turned on, and not only during the measurement, but at the moment we have a small problem with configuring simultaneous sleep "on time" and waking up via GPIO in the SDK. That's why we have to mix it up.

    I'd like to finalize your script and maybe include it in the examples once we're sure it's fully done.
  • #195
    Level 31  
    I uploaded version ...216 and it seems to work. When the module wakes up - the LED starts flashing, then I press the button and hold it until it goes out, and the module goes into AP and safe mode.
    Yes, ideally, pressing the button would wake the module, not necessarily going to safe mode, but blocking DeepSleep until reboot.

    The script currently looks like this:
    // start driver
    startDriver SHT3X
    //hold button to get into safe mode
    addEventHandler OnHold 20 SafeMode 1
    // wait for wifi to become WIFI_STA_CONNECTED
    waitFor WiFiState 4
    //battery 18650 4.2V, min 2.5V
    Battery_Setup 2500 4200 2.29 2400 4096
    // extra wait
    delay_s 3
    // measure
    SHT_Calibrate -0.8 2
    // send data
    // wait for GET to be sent
    delay_s 3
    // sleep for ~5minutes and then wake up (from blank state)
    DeepSleep 274

    I'm probably going to change something, but it seems to work as I wanted. I hope this soft will not drain the battery more than the original one. On the original one, it discharged from about 4.1V to 3.8V for 6 months, so it's not bad.
  • #196
    Moderator Smart Home
    It's up to you to decide. You can report the status of measurements less often.

    I see one more problem - what if there is no WiFi? It will hang forever on waitFor.
    Add before waitFor:
    // no matter what happens, start DeepSleep 500 in 30 seconds
    // NOTE: addRepeatingEvent [RepeatTime] [RepeatCount]
    addRepeatingEvent 30 1 DeepSleep 500
  • #197
    Level 31  
    Yes, I will eventually increase the time to 15 or even 30 minutes. Currently testing how it works.
    I added this extra command.
  • #198
    Moderator Smart Home
    Let me know when you think it works stable, then I'll add the script to the examples on the repository. Then others will benefit too. Maybe I'll update the first post as well.
  • #199
    Level 1  

    I'm also stuck on this, the sensor lost power and now I can't see it or put it into AP mode. I've read most of the comments but there are a lot. Is there a solution or am I missing something? The sensor had PowerSave 1 in startup command.

    I've power cycled 5 times and nothing, not really sure how to reflash OpenBK without AP mode.

  • #200
    Moderator Smart Home
    Hello @biomassfreak . Can you try to RESET via CEN? 5 times? Do you get anything on UART2 output (debug log), U2TX aka TX2? Maybe the device just sleeps thanks to the electrolytic capacitors that are on the board?

    In worst case you can always do Clear All in OBK flasher and then flash OBK again, but you will lose RF calibration that way. Still, I heard that it helps.
  • #201
    Level 2  
    Finally I think I have it with this script

    Battery_Setup 2000 3000 2.02 2400 4096
    startDriver SHT3X
    //measure batt every 2s
    Battery_cycle 2
    //measure temp and humidity every 2 seconds
    SHT_cycle 15
    //hold button to get into safe mode
    addEventHandler OnHold 20 SafeMode
    //broadcast as fast as possible for all the channels 
    mqtt_broadcastInterval 1
    mqtt_broadcastItemsPerSec 5
    //this delay is the actual awake time for the sensor, increase it if you don't get correct readings to >30s
    delay_s 25
    //this is the interval of device sleep in seconds increase value to preserve batt
    DeepSleep 900

    I think the calibrate command (SHT_Calibrate) was not needed, now the temp looks like the real one. With that autoexec I did a python scrip to monitor the mqtt and I got some temperatures that match when I put the A/C on and off (Temps are 281 --> 28.1º)

    17/08/2023 20:04:57 : 281
    17/08/2023 20:05:04 : 283
    17/08/2023 20:20:42 : 276
    17/08/2023 20:20:49 : 277
    17/08/2023 20:36:28 : 280
    17/08/2023 20:52:18 : 283
    17/08/2023 20:52:21 : 284
    17/08/2023 21:08:00 : 286
    17/08/2023 21:08:07 : 287
    17/08/2023 21:23:46 : 288
    17/08/2023 21:23:53 : 289
    17/08/2023 21:39:32 : 290
    17/08/2023 21:39:39 : 292
    17/08/2023 21:55:20 : 291
    17/08/2023 21:55:26 : 292
    17/08/2023 22:11:05 : 292
    17/08/2023 22:26:51 : 286
    17/08/2023 22:42:37 : 277
    17/08/2023 22:42:44 : 278
    17/08/2023 22:58:23 : 270
    17/08/2023 22:58:30 : 271
    17/08/2023 23:14:09 : 268
    17/08/2023 23:29:56 : 267
    17/08/2023 23:30:01 : 266
    17/08/2023 23:45:41 : 275
    18/08/2023 00:01:27 : 285
  • #202
    Moderator Smart Home
    This is almost perfect, but I had edited this line:
    //hold button to get into safe mode
    addEventHandler OnHold 20 SafeMode

    because the SafeMode argument is not the time of how long you hold the button. I don't know how it started, but people started copying it without testing...
    The SafeMode should have no arguments, I would say.
  • #203
    Level 31  
    It seems to be working properly. Still testing.
    I also reprogrammed another art, this time using cloudcutter. It worked. I had to select the device: tuya-generic-temperature-and-humidity-sensor-v1.1.17.
    I also reprogrammed the Aubess 20A sockets without dismantling. I didn't need to disassemble one first, I could try this cloudcutter first.

    I still have a question, does this firmware support Dallas 18B20 sensors? Because I don't see them on the list.
  • #204
    Moderator Smart Home
    Not at the moment, but if I find a moment, I can add a driver to it. Where did this idea come from, do you need 18B20 for DIY, do you have a device with it?

    I rather use the DHT11 family. Here is an example on the W600 platform:

  • #205
    Level 31  
    I don't have a device with it, but it's a sensor that is small and can be easily connected anywhere. Unlike large DHT.
    I was thinking whether to solder Dallas to these door sensors and then I would have 2in1.
  • #206
    Level 6  
    I think this thought is directed mostly to p.kaczmarek2
    I observed how my other similar sensor CB3S reports the temperature, and it seems it has nothing to do with the timer, but the sensor seems to decide by itself whether the temperature threshold has been exceeded in order to report something.
    Hence my idea if something like this is possible to implement.
    Before reporting, all battery devices should check whether the threshold for reporting has been exceeded, if not, the session will be postponed. The logic could be like this, deep sleep timer - when the time has come - check if the threshold has been exceeded - if the threshold has not been exceeded - back to deep sleep - if the threshold has been exceeded - report immediately.
    By eliminating unnecessary sessions and depending on the environment where the sensor is located, such behavior could extend the battery life by a third or up to two times!
  • #207
    Level 3  

    Hi all, I just finished my home project "migrate temperature sensor" to the Tuya.
    The main reason for the migration was the hardware. Hardware I made myself and I don't know why, but sometimes the I2c sensor stuck the only one that helped was switch off, switch on. I fought with it for months. Right now everything works fine I thank you for the OpenBK project. It is really good job!!!

    At present, I using OpenBK and this "China Generic sensor". Everything works fine and I have a comparison in the chart.
    As you can see in the attachment, my old measurements seem to be more stable. The main reason is, the oscillation of measurement, because during measurement, I used for loop and measured 10 times (https://github.com/karotka/smart.home/blob/main/temp.sensor.mqtt/temp.sensor.old.ino#L66) and calculated the average.
    My question is is possible to call this method (https://github.com/openshwprojects/OpenBK7231T_App/blob/7fae04a9e3f95569b23fbc38564ff8fc5eeb3631/src/driver/drv_sht3x.c#L203C17-L203C30) in for cycle and calculate average?

    [BK7231N CBU] Generic Temperature and Humidity Sensor [BK7231N CBU] Generic Temperature and Humidity Sensor
  • #208
    Level 2  

    how you have powered the device during flash?
    I have soldered RX and TX but i cant flash device with BK7231 Gui Flashtool with batteries 😕
  • #209
    Level 3  
    It is hard to flash this device with battery power. You need to connect to an external power source 3.3V.
    I using something like this https://www.aliexpress.com/item/1005004155106235.html
    You need to connect Vcc, GND, RX, TX and Reset.
    After that you run flash software a pull down the Reset to the ground for a while

    [BK7231N CBU] Generic Temperature and Humidity Sensor
  • #210
    Level 2  

    Thanks for your reply.

    I have soldered RX TX RST

    [BK7231N CBU] Generic Temperature and Humidity Sensor

    Brown tx, red rx, oragnge rst

    Seems i did not need to solder

    Can u explain your colors?

    I would use my USB dongle for powering
    [BK7231N CBU] Generic Temperature and Humidity Sensor

    I got it flashed with power and my soldered cables 😃

    What are your green and yellow cables and this black left side?