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.11k stars 4.79k forks source link

Scripting Google Chart "cnth" Problem with Tasmota 12.x #17038

Closed ottelo9 closed 1 year ago

ottelo9 commented 1 year ago

PROBLEM DESCRIPTION

Scripting (not berry) problem with the Google Chart function "cnth" (cnthX/Y not yet in the documentation). @gemu2015 added this functionality to "xdrv_10_scripter.ino" on 31. March 2022 . With this you can create charts with seconds at x-axis. With cstr="cnth"+s(hours*240)+"/240" and then $gc(lt s4h "wr" "Leistung [W]" cstr2). I can downgrade to 11.0.0.6 and upload the script via the ScriptEditor and everything is working fine. Upgrade to 12.x and the problem reappears :(. My big array s4h[960] is filled up like this:

09:56:57.158 CMD: script?s4h
09:56:57.297 RSL: RESULT = {"script":{"s4h":[483,841,351,943,308,519,403,462,331,168,798,460,0,0,0,0,0,0,0 ..... ]

REQUESTED INFORMATION

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

TO REPRODUCE

Self compiled via TasmoCompiler and these defines to use SML and google chart:

#ifndef USE_SML_M
#define USE_SML_M
#endif
#ifndef USE_SML_SCRIPT_CMD
#define USE_SML_SCRIPT_CMD
#endif
#ifndef USE_GOOGLE_CHARTS
#define USE_GOOGLE_CHARTS
#endif
#ifndef LARGE_ARRAYS
#define LARGE_ARRAYS
#endif
#ifndef USE_SCRIPT_WEB_DISPLAY
#define USE_SCRIPT_WEB_DISPLAY
#endif
#ifndef USE_EEPROM
#define USE_EEPROM
#endif
#ifdef EEP_SCRIPT_SIZE
#undef EEP_SCRIPT_SIZE
#endif
#define EEP_SCRIPT_SIZE 6200

Create a new script (I upload my big script via the ScriptEditor):

>D 40
hour=0
; 4h power chart
M:s4h=0 960

>S
hour=hours
;put a random number into array for testing every 15s
if (secs%15==0)
then
    s4h=rnd(1000)
endif

; set x axis index to 4 hours a 15 sec therefore /240, no decimal point
hour-=4
if (hour<0)
then
    cstr2="cnth"+s(1.0((24-4+hours)*240)+(mins*4))+"/240"
else
    cstr2="cnth"+s(1.0((hours-4)*240)+(mins*4))+"/240"
endif
hour=hours

>W
; 4h power chart
$<div id="chart1" style="text-align:center;width:400px;height:100%%;padding:0px"></div>
$gc(lt s4h "wr" "Leistung [W]" cstr2)
$var options = {
$chartArea:{left:60,width:'83%%'},
$width:'100%%',
$legend:'none',
$vAxis:{format:'# W',viewWindow:{min:-300}},
$explorer:{actions:['dragToZoom', 'rightClickToReset']},
$title:'Verbrauch 4 Stunden [Watt]'
$};
$gc(e)

EXPECTED BEHAVIOUR

With Tasmota 11.0.0.6 (includes the new cnth) the 4h chart (last 4h) works perfect. See screenshots.

SCREENSHOTS

Working 4h Google Chart with cstr2="cnth"+s(1.0((hours-4)240)+(mins4))+"/240". Full 4 hours and on the right side is the actual time (left = -4h). The 24h chart below has no issues with the x-axis labels. Correct time stamps. Tasmota 11 0 0 6 Google Chart

With Tasmota 12.1 or 12.2 I got this here. On the right side is the actual time-2h. And only ~2 hours on X-Axis. And take a look at the 24h chart labels. Tasmota 12 2 0 Google Chart

After restart/boot I got this: Tasmota 12 2 0 Google Chart boot Then after few secs: Tasmota 12 2 0 Google Chart error And after ~30s this: Tasmota 12 2 0 Google Chart boot 2

ADDITIONAL CONTEXT

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

Jason2866 commented 1 year ago

@gemu2015 Can you have a look and help?

gemu2015 commented 1 year ago

i am already in contact with @ottelo9 at another forum about this issue. i think we can close this here

MarcoLeoncino commented 1 year ago

Hi everyone, I am using the following code, based on the example you gave here above.

`>D hour=0 temp=0 M:s4h=0 960 cstr2="cnth0/120"

T temp=DS18B20#Temperature

S hour=hours

if (secs%15==0) then s4h=temp endif

hour-=4 if (hour<0) then cstr2="cnth"+s(1.0((24-4+hours)240)+(mins4))+"/240" else cstr2="cnth"+s(1.0((hours-4)240)+(mins4))+"/240" endif hour=hours

W $

$gc(lt s4h "wr" "Temperature [°C]" cstr2) $var options = { $chartArea:{left:30,width:'90%%',right:10}, $width:'90%%', $legend:'none', $vAxis:{format:'# °C',viewWindow:{min:0},viewWindow:{max:80}}, $title:'Boiler temperature last 4 hours [°C]' $}; $gc(e)

`

and I get a well working google chart.

I have tried to replace the hours to 12, the minutes to 720, but I cannot get a working 12 h plot. Can you give me an hint about how the above code shall be modified to have a 12 hours plot? Thanks a lot!

gemu2015 commented 1 year ago

you can not keep 15 seconds resolution with 12 hours on an esp8266, so we switch to every minute

>D
hour=0
temp=0
M:s4h=0 720
cstr2="cnth0/120"

>T
temp=DS18B20#Temperature
>S
hour=hours
if (secs%60==0)
then
s4h=temp
endif

hour-=12
if (hour<0)
then
cstr2="cnth"+s(1.0((24-12+hours)*60)+mins)+"/60"
else
cstr2="cnth"+s(1.0((hours-12)*60)+mins)+"/60"
endif

>W
$<div id="chart1" style="text-align:center;width:400px;height:100%%;padding:0px"></div>
$gc(lt s4h "wr" "Temperature [°C]" cstr2)
$var options = {
$chartArea:{left:30,width:'90%%',right:10},
$width:'90%%',
$legend:'none',
$vAxis:{format:'# °C',viewWindow:{min:0},viewWindow:{max:80}},
$title:'Boiler temperature last 12 hours [°C]'
$};
$gc(e)
#
MarcoLeoncino commented 1 year ago

Thanks! Every 60 seconds is perfect!