arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.19k stars 4.81k forks source link

DS3231 internal Temperature sensor data only updated when teleperiod #18129

Closed pyys closed 1 year ago

pyys commented 1 year ago

PROBLEM DESCRIPTION

saving DS3231's internal Temperature sensor data to script variable got error

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
-not using
- [ ] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:

TO REPRODUCE

Steps to reproduce the behavior:

compiling parameter

define PROJECT "***"

define DEVICE_NAME "***"

define FRIENDLY_NAME "***"

define MQTT_USE true

define MQTT_HOST "***"

define MQTT_PORT "***"

define MQTT_USER "***"

define MQTT_PASS "***"

define WEB_PASSWORD "***"

define NTP_SERVER1 "pool.ntp.org"

define MODULE USER_MODULE

define USE_I2C

define APP_TIMEZONE 9

define USE_DS3231

define USE_RTC_CHIPS

define USE_RTC_ADDR 0x68

define DS3231_ADDRESS 0x68

define DS3231_ENABLE_TEMP

define USE_BERRY_DEBUG

ifndef USE_SCRIPT

define USE_SCRIPT

endif

define SDCARD_DIR

define USE_SCRIPT_FATFS_EXT

define USE_SCRIPT_FATFS

define USE_UFILESYS

define USE_SDCARD

define SDCARD_CS_PIN 4

define USE_SPI

Thank's for tasmota compiler update for DS3231's internal temp sensor.

define DS3231_ENABLE_TEMP <- this parameter really help me.

but when if I use script like this

D temp=0 T temp=DS3231#Temperature S print Temperature=%temp%

I''ve got return like this

18:01:43.907 Temperature=0.00 18:01:44.907 Temperature=0.00 18:01:45.924 Temperature=0.00 18:01:46.932 Temperature=0.00 18:01:47.968 Temperature=0.00 18:01:48.933 Temperature=0.00 18:01:49.933 Temperature=0.00 18:01:50.969 Temperature=0.00 18:01:51.933 Temperature=0.00 18:01:52.933 Temperature=0.00

but when my tasmota send MQTT mesage, temp value change

18:01:53.969 Temperature=0.00 18:01:54.933 Temperature=0.00 18:01:55.933 Temperature=0.00 18:01:56.978 MQT: tele/**/STATE = {"Time":"2023-03-07T18:01:56","Uptime":"0T01:25:44","UptimeSec":5144,"Heap":127,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"Berry":{"HeapUsed":3,"Objects":33},"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":1,"SSId":"","BSSId":"","Channel":7,"Mode":"11n","RSSI":100,"Signal":-34,"LinkCount":1,"Downtime":"0T00:00:04"}} 18:01:57.030 MQT: tele/***/SENSOR = {"Time":"2023-03-07T18:01:56","ANALOG":{"A1":1128},"DS3231":{"Temperature":26.2},"TempUnit":"C"} 18:01:57.038 Temperature=26.20 18:01:57.896 Temperature=26.20 18:01:58.896 Temperature=26.20 18:01:59.896 Temperature=26.20 18:02:00.896 Temperature=26.20

"temp" variable only change when tasmota send MQTT.

EXPECTED BEHAVIOUR

It Seems like script that I use, only update DS3231's intenal sensor data when teleperiod come. I hope DS3231's intenal sensor data update rate is independant with teleperiod.

p.s when if I use script like this

D volt=0 T volt=ANALOG#A1 S print voltage=%volt%

it update 'volt' variable every second.

what is differce with "volt=ANALOG#A1" and "temp=DS3231#Temperature" ?

SCREENSHOTS

If applicable, add screenshots to help explain your problem. image

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

sfromis commented 1 year ago

I can add that fast updates are not happening for rules either. After a cursory look, I noticed that the code in support_tasmota.ino only seems to call XdrvRulesProcess for TelePeriod processing, but not for the other handling there.

barbudor commented 1 year ago

Script >T section is supposed to be executed not only on FUNC_TELEPERIOD_RULES_PROCESS but also on FUNC_EVERY_100_MSECOND

However there are tricks in the 100ms loop 1) Only 1 sensor is checked at each 100ms. There's a round robin through every enabled sensor which could reduced the polling rate of a given sensor 2) The DS3231 driver is not a sensor driver, but a RTC driver. Which means it is not included into that 100ms polling and only in the Teleperiod polling

So that's the main difference between ANALOG (which is a 'sensor' driver) while DS3231 is a standard 'driver'

My main question would be : why do you want to have a temperature measurments faster than teleperiod ? Temperature sensors are generally slow

One possibility would be a dual-implementation on the DS3231 driver : both a RTC driver and a sensor

pyys commented 1 year ago

Script >T section is supposed to be executed not only on FUNC_TELEPERIOD_RULES_PROCESS but also on FUNC_EVERY_100_MSECOND

However there are tricks in the 100ms loop

1. Only 1 sensor is checked at each 100ms. There's a round robin through every enabled sensor which could reduced the polling rate of a given sensor

2. The DS3231 driver is not a sensor driver, but a RTC driver. Which means it is not included into that 100ms polling and only in the Teleperiod polling

So that's the main difference between ANALOG (which is a 'sensor' driver) while DS3231 is a standard 'driver'

My main question would be : why do you want to have a temperature measurments faster than teleperiod ? Temperature sensors are generally slow

One possibility would be a dual-implementation on the DS3231 driver : both a RTC driver and a sensor

For my project, teleperiod would be 3600second. (or disabled. we are not sure to use MQTT) but I need check volt(by analog in, gpio34) and temperature(by ds3231. my project dosen't sesitive accuracy, but need to reduce pin using. we are aready using 9pin, and need 6 more, or more), and relay stat every 300second and write it to sdcard.(for making watchdog log file)

It's okay to me that teleperiod is longer than 60 second. but I need update volt and temp data when triggered situation. thats why I hope I could update DS3231's temp data by manual trigger. not by teleperiod.

p.s I've already tried reduce teleperiod to 30 second, for update DS3231's Temp data. and it satisfy bottom point of my project. but I hope I could touch better solution.

sfromis commented 1 year ago

To get "when triggered", issuing the Status 10 command will publish extra telemetry data, instead of waiting for the next scheduled telemetry period.

Or get a "now" telemetry message by issuing the TelePeiod command without an argument. Allows rules to be triggered.

pyys commented 1 year ago

To get "when triggered", issuing the Status 10 command will publish extra telemetry data, instead of waiting for the next scheduled telemetry period.

Or get a "now" telemetry message by issuing the TelePeiod command without an argument. Allows rules to be triggered.

thank you for reply. I'll try and look that I could use in my code. at tomorrow. (I'm in GMT+9 , here are AM 01:50 :) )

barbudor commented 1 year ago

Without using more pins as you already have I2c, you could use a Hdc1080 (temp+Hum) sensor or TMP75 which are real 'sensor' drivers and won't suffer from the same problem.

Jason2866 commented 1 year ago

Moving to discussions, since not an issue/bug.