EDIT: I have split the Tuya-cloudcutter wireless flashing discussion into separate topic, see:
BK7231 flashing sensor via tuya-cloudcutter, not connecting to network
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tamminchutu wrote:
PowerSave
startDriver SHT3X
SHT_Calibrate -3.2 +6
SHT_Measure
Battery_Setup 2000 3030 2.29
battery_measure
publishFloat "voltage" $CH4/1000
publishFloat "battery" $CH4/25
mqtt_broadcastInterval 300
scheduleHADiscovery
addRepeatingEvent 300 -1 SHT_Measure
PowerSave
startDriver SHT3X
SHT_Calibrate -4 +6
SHT_Measure
scheduleHADiscovery
// wait for MQTT connect (this will block execution)
waitFor MQTTState 1
// wait one more second so things can settle down
delay_s 1
// publish soemthing
publishFloat "voltage" $CH4/1000
publishFloat "battery" $CH4/25
// shut down and deep sleep for 120 seconds (it will reboot from scratch after that)
DeepSleep 120
Battery_Setup 2000 3000 2.02 2400 4096
Battery_cycle 10
SHT_Calibrate -4 3
delay_s 30
DeepSleep 300 "pins": {
"7": "SHT3X_SCK;0",
"8": "SHT3X_SDA;2",
"17": "BAT_Relay;5",
"23": "BAT_ADC;4",
"26": "WifiLED;1"
} "pins": {
"7": "SHT3X_SCK;0",
"8": "SHT3X_SDA;2",
"17": "BAT_Relay;5",
"20": "Btn;6",
"23": "BAT_ADC;4",
"26": "WifiLED;1"
},//2.02 is Vdevider, measure and adjust to your device, 2000 is Vmin the device will still work I don't recomend changing bellow that value
Battery_Setup 2000 3000 2.02 2400 4096
//measure batt every 2s
Battery_cycle 2
//calibrate SHT sensor with -4'C and +3% for humidity in this case
SHT_Calibrate -4 3
//measure temp and humidity every 2 seconds
SHT_cycle 2
//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
// do anything on startup
startDriver NTP
startDriver SSDP
// now wait for MQTT
waitFor MQTTState 1
// extra delay, to be sure
delay_s 1
publish myVariable 2022
p.kaczmarek2 wrote:I think the sample usage can be modified. We could put a DeepSleep command just after last publish (with a delay) and make device go to sleep just after state is published.
minusync wrote:p.kaczmarek2 wrote:I think the sample usage can be modified. We could put a DeepSleep command just after last publish (with a delay) and make device go to sleep just after state is published.
Maybe someone can tell if there has been any progress with this sensor setup? I also have a small problem, I have version 1.15.581 but for some reason the OTA update to the latest version is no longer possible. The web application says starting OTA and then nothing happens, or after really long time it says rebooting but wakes up in safe mode, still with the old version and all settings wiped clean.
thanks
DeDaMrAz wrote:I have one such sensor and my solution was to flash it with BK Flasher to a new version (not via OTA), you can save the config and autoexec if you have them and reapply that after updating the FW.
minusync wrote:DeDaMrAz wrote:I have one such sensor and my solution was to flash it with BK Flasher to a new version (not via OTA), you can save the config and autoexec if you have them and reapply that after updating the FW.
Sure I can try (at least I hope) that, but fiddling with solder and wires again is really annoying. Also, there is always the possibility to screw something up with solder. OTA worked for me before and I did hope that maybe simply something with the procedure has changed
DeDaMrAz wrote:Pin assignment from the web app:
Code: text Expand Select all Copy to clipboard "pins": {
"7": "SHT3X_SCK;0",
"8": "SHT3X_SDA;2",
"17": "BAT_Relay;5",
"20": "Btn;6",
"23": "BAT_ADC;4",
"26": "WifiLED;1"
},
Script with explanation:
Code: text Expand Select all Copy to clipboard//2.02 is Vdevider, measure and adjust to your device, 2000 is Vmin the device will still work I don't recomend changing bellow that value
Battery_Setup 2000 3000 2.02 2400 4096
//measure batt every 2s
Battery_cycle 2
//calibrate SHT sensor with -4'C and +3% for humidity in this case
SHT_Calibrate -4 3
//measure temp and humidity every 2 seconds
SHT_cycle 2
//hold button on P20 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
Attached is the tar file you can drag and drop to create autoexec.bat.
minusync wrote:I would also like to ask whether there are any developments regarding the mentioned possibility of bringing the publish time down to 5 seconds.
minusync wrote:For some reason, it now shows with brand new batterys, battery 0 and voltage -1.18
DeDaMrAz wrote:- Flag 37 is to be enabled - Flag 37 - [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)
- static IP address has to be set
- and Uptime seconds required to mark boot as ok: to be set to 3
addEventHandler OnHold 10 SafeModeDeDaMrAz wrote:ou can use this command in your autoexec to utilize the button on the device to go into safe mode.
Code: text Expand Select all Copy to clipboardaddEventHandler OnHold 10 SafeMode
Moderated By p.kaczmarek:It should be SafeMode without arguments. The number after OnHold is GPIO index where the button is. I have edited this post.
minusync wrote:Anyway, safe mode is not truly test mode. In safe mode, I need to connect to the sensor's local network, which means I can not same time use web application,...
minusync wrote:I looked at the battery syntax but are there some rules to set v_divider or is it more like trial and error. I managed with a negative setup (-2.3) to get to the positive 1.34mV value but the battery % is still zero.
minusync wrote:Thanks, I got things working for the most part. How does measuring every 2 seconds affect battery consumption? If I update the results once an hour, does the change in the measurement interval also have any benefit in terms of battery life?
DeDaMrAz wrote:Can you post your autoexec file and a picture of your device so we can try to guide you somehow to the solution for your batt problems?
TL;DR: Stock firmware can empty two AAA cells in just 6 h at a 10-min refresh rate [Elektroda, dheenhasty, post #20385425] “SHT30 seems very simple to support” [Elektroda, p.kaczmarek2, post #20362193] Use DeepSleep + PowerSave to cut current by >90 %.
Why it matters: Proper scripting turns a one-week gadget into a months-long sensor.
• MCU: Beken BK7231N CBU module, 3.3 V core, Wi-Fi b/g/n [Elektroda, p.kaczmarek2, post #20362193] • Temp/Humidity chips: SHT30 or CHT8310/8315, I²C @ 100 kHz [Sensirion, 2023] • Battery range: 2.0 – 3.0 V (two AAA) [Elektroda, user_param_key dump] • DeepSleep current: ≈ 6 µA; active Wi-Fi current: ≈ 70 mA [Elektroda, dheenhasty, post #20393117] • Typical script wake-time: 8–12 s, 15-min cycle ⇒ ~1 % duty-cycle power use.
addRepeatingEventID 30 1 999 DeepSleep 900 before waitFor MQTTState 1; if MQTT is still down after 30 s the sensor sleeps for 15 min [Elektroda, erdeidominik1999, post #20792052]PowerSave. 2 ) measure once, publish, sleep:startDriver SHT3X → waitFor MQTTState 1 → SHT_Measure → publishChannels → DeepSleep 900. 3 ) Use flag 37 for quick Wi-Fi connect. Users report >30 days on AAA with a 15-min cycle [Elektroda, dheenhasty, post #20456982]mqtt_broadcastInterval left at 1 s sends five retained topics, stretching awake time. Set it to 60 s or disable extra broadcasts to avoid triple publishes [Elektroda, Xinayder, post #20882846]SHT_Calibrate <TempOffset> <RHOffset> once in autoexec, e.g. SHT_Calibrate -2.4 3 lowers reported temperature by 2.4 °C and raises humidity by 3 % RH [Elektroda, dheenhasty, post #20458926]PowerSave active and no WebLog, idle current falls from ~70 mA to 6 - 8 mA, a 90 % reduction [Elektroda, dheenhasty, post #20393117]OBK_XXXX AP.temperature_div10 for 0.1 °C granularity or divide in publish: publishFloat temp $CH2/10. OBK trims trailing zeros from JSON [Elektroda, p.kaczmarek2, post #20458933]autoexec.bat, letting you reconfigure via AP without UART [Elektroda, p.kaczmarek2, post #21014538]