logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

OpenBeken Charts Driver - configurable and flexible measurement history on your device

p.kaczmarek2 6045 66

TL;DR

  • OpenBeken adds a scriptable charts driver for plotting arbitrary variables and multiple axes directly on the device, without Home Assistant.
  • The workflow uses chart_create, chart_setVar, chart_setAxis, and chart_add/chart_addNow in autoexec.bat, with NTP time or repeating events for live history.
  • Sample configs show 16-sample charts, including temperature-only, temperature plus humidity on two axes, and even VCP voltage/current/power on three axes.
  • A DHT11 demo uses chart_create 48 2 2, starts NTP, and logs temperature and humidity every 60 seconds with addRepeatingEvent.
  • Early builds may need IndexRefreshInterval 100000, and planned features include per-variable RGB colors, alternative chart.js paths, and persistent storage.
ADVERTISEMENT
📢 Listen (AI):
  • #61 21261598
    max4elektroda
    Level 24  
    jkwim wrote:
    One issue that I found when the chart is working is that the bottom part of the screen cannot be kept without scrolling back to chart window.

    Yes, I see what you mean.
    We will need to change the "redrawing". Actually the chart is destroyed and a new instance is created.
    I think I already have a solution, will open an PR soon and post it here.
    In my test I could change this to "update" the chart, which doesn't seem to refocus to the chart.

    Added after 1 [hours] 29 [minutes]:

    Please try the builds from PR #1389.
    For this does redrawing w/o setting the focus on the chart ...

    Web page with line chart and navigation buttons.
  • ADVERTISEMENT
  • #62 21261957
    jkwim
    Level 13  
    Will give it a try
    Thanks

    Added after 11 [hours] 32 [minutes]:

    Upgraded to OpenBK7231T_App_1389_merge_b1e0d8dd960f.

    It works fine now.

    Thanks for your quick update.
  • ADVERTISEMENT
  • #63 21262367
    max4elektroda
    Level 24  
    Thanks for your feedback!

    @p.kaczmarek2: Just found a nasty little "bug" with charts: When setting things, we don't care for the indexes, so the device might crash on wrong input.

    Windows emulator e.g. will crash if you define a single value graph
    chart_create 96 1 1 and later do
    chart_addNow 10 20. Same will happen, if you later call
    chart_setVar 1 "XX" "YY"

    We should check for "<=numVars" or "<=numAxes" before setting them.

    I would propose to do this in the "calling commands" (CMD_Chart_SetAxis/CMD_Chart_SetVar/CMD_Chart_AddNow/CMD_Chart_Add) and mayby, just to be sure, also in the code actually doing the settings (Chart_SetAxis/Chart_SetVar/Chart_SetSample).

    Open is the question, what to do in this case when adding samples?
    Only taking as much samples as defined or reject the whole command?
  • ADVERTISEMENT
  • #64 21262676
    p.kaczmarek2
    Moderator Smart Home
    Nice find, I'd just return out of command with INVALID_ARG return code (or how was this enumeration called in Obk)...
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #65 21263018
    max4elektroda
    Level 24  
    I extend PR #1389 to take care of this, too.

    I took this one because I would also merge the change to use update() for the charts.

    It was not so evident to me when I focussed on the charts, that every refresh used to set the focus on the chart, which is annoying if you scrolled down to the buttons and the browser switches back all the time.

    Some tests would be great, now the update should not move the view of the page and all input should be checked against the charts properties.
    So if you could try if it's intercepting all kinds of "false" input that would be great.

    Add names for non-existent axes or vars, setting more samples than defined ...

    I hope it's stable regarding this now.
  • #66 21440659
    Zogdan
    Level 10  
    Checked on ESP32C3 and works fine.

    Just a suggestion : Could it be an idea to include a DIFF option?
    I would like to see the difference with the last added value in the chart (eg for energy consumption)

    Thinking loud : It could work a bit like this.

    mydiffvar = chart_getVar 0 -1
    would mean : mydiffvar is always the previous value of chart var 0
    this would allow to add that to the chart, publish it to mqtt or whatever.

    mydiffvar = chart_getVar 0 -2 would be 2 hops back in time

    So suppose the chart series is this :

    t | 500
    t-1 | 450
    t-2 | 300

    then


    | Var0 | chart_getVar 0 -1 | chart_getVar 0 -2
    t | 500 | 50 | 200
    t-1 | 450 | 150 | null
    t-2 | 300 | null | null
  • #67 21758887
    p.kaczmarek2
    Moderator Smart Home
    @Zogdan interesting idea, if anyone is willing to give it a go I can accept PR.

    I've tested charts with ESP8266 and DHT11, works fine.
    OpenESP8266 dashboard with temperature and humidity charts
    Built on Nov 22 2025 13:00:05

    Added after 5 [minutes]:

    Flashlight test (it heats up the sensor), then flashlight is removed:
    Line chart showing temperature and humidity changes over time
    Helpful post? Buy me a coffee.
📢 Listen (AI):

Topic summary

✨ The OpenBeken firmware introduces a configurable and scriptable charts driver enabling visualization of multiple variables with multiple axes directly on supported devices without requiring Home Assistant. The driver supports platforms based on BK7231T, BK7231N, BK7231M, T34, BL2028N, XR809, W800, LN882H, BL602, and others. Users configure charts via commands such as chart_create, chart_setVar, chart_setAxis, and addRepeatingEvent to plot variables like temperature, humidity, voltage, and power. Initial issues included crashes due to missing null checks in chart_setVar and chart_setAxis before chart_create, heap corruption from uninitialized memory, and platform-specific bugs such as vsnprintf handling null pointers. These were addressed through patches adding null checks, memory zeroing, and input validation to prevent crashes on invalid indexes. The charts driver was integrated with a ring buffer for data storage, with ongoing improvements to reduce flickering by updating charts instead of recreating them, and repositioning the chart below the "state" div to avoid page scroll jumps. Users reported stable long-term operation on various devices, including W600 and BL602, with some platform-specific driver enablement required in obk_config.h and Makefiles. The Windows simulator supports testing charts, facilitating development. Suggestions for future enhancements include adding a DIFF function to compute differences between consecutive samples. The driver supports variable expansion (e.g., $voltage*0.1) if ENABLE_EXPAND_CONSTANT is enabled. Sample configurations and troubleshooting tips were shared, including manual command sequences to generate pseudo-random data for testing. The charts driver is now considered production-ready with ongoing refinements and cross-platform support.

FAQ

TL;DR: One 48-sample, 2-axis chart adds ≈3 kB RAM load while free heap stayed >30 kB during 9 000 s uptime [Elektroda, divadiow, post #21244441] “Trust me, being able to run OBK on Windows is a blessing” [Elektroda, p.kaczmarek2, post #21224744] Why it matters: Built-in charts let BK/Tuya devices log and visualise data without Home Assistant or external servers.

Quick Facts

• Max tested samples: 96 per chart with 4 variables [Elektroda, divadiow, post #21225816] • RAM overhead: ~65 B per sample–variable pair (≈3 kB for 48×2) [Elektroda, divadiow, post #21244441] • Data add speed: 2 s minimum interval proven stable 24 h [Elektroda, divadiow, post #21244282] • Supported MCUs: BK7231T/N/M, BL602/BL702, ESP32, W600/W800, LN882H, XR809, Windows simulator [Elektroda, p.kaczmarek2, post #21223630] • Build flag: ENABLE_DRIVER_CHARTS 1 in obk_config.h [Elektroda, p.kaczmarek2, post #21223630]

How do I enable the OpenBeken charts driver?

Re-compile the firmware with ENABLE_DRIVER_CHARTS set to 1 in the platform’s obk_config.h, then flash and run startDriver charts at the console. Pre-built PR images already include the flag for most BK, ESP32, BL602, W600/800 and simulator targets [Elektroda, max4elektroda, post #21254431]

What is the minimal script to plot two power-meter channels every 5 s?

  1. startDriver charts; startDriver NTP; waitFor NTPState 1
  2. chart_create 48 2 2
  3. chart_setVar 0 "Voltage" "axv" ; chart_setVar 1 "Power" "axp" ; chart_setAxis 0 "axv" 0 "Voltage (V)" ; chart_setAxis 1 "axp" 1 "Power (W)" ; addRepeatingEvent 5 -1 chart_addNow $voltage $power [Elektroda, jkwim, post #21254467]

Can I scale raw sensor values inside chart_addNow?

Yes, if ENABLE_EXPAND_CONSTANT is 1. Example: chart_addNow $CH1*0.1 converts deci-degrees to °C. Devices built without this flag (early ESP-IDF, W600) will ignore the expression and plot raw numbers [Elektroda, max4elektroda, post #21224804]

How much memory does a chart consume?

Each sample–variable pair costs about 65 bytes including timestamp. A 48-sample, 2-variable chart therefore uses ≈3 kB RAM, leaving >30 kB free on a W600 after eight hours logging [Elektroda, divadiow, post #21244441]

Why did my device reboot after chart_create?

Early commits lacked NULL checks; calling chart_setVar or chart_setAxis before chart_create corrupted heap and caused panics (EXCVADDR 0x0) [Elektroda, insmod, post #21224676] Upgrade to firmware ≥ merge b1e0d8dd960f or later.

Page keeps jumping back to the chart—can I stop that?

Firmware from PR #1389 uses chart.update() instead of destroy/create, so the browser no longer scrolls automatically. Flash build 1.17.8xx or newer [Elektroda, max4elektroda, post #21261598]

What if NTP is unavailable?

Use chart_add with a synthetic timestamp like 1727438906+$uptime, or simply log relative ticks. Charts accept any increasing integer for X-axis [Elektroda, max4elektroda, post #21241366]

Can I read back or diff stored values?

Current API is write-only. A feature request to expose chart_getVar for delta energy computation has been logged [Elektroda, Zogdan, post #21440659]

How do I avoid heap corruption when recreating charts?

Always call chart_destroy (planned) or reboot before issuing a second chart_create. Multiple create calls without freeing triggered multi_heap.c errors on ESP-IDF [Elektroda, insmod, post #21224708]

What causes "unsupported method" HTTP errors in logs?

A client sent a non-GET/POST request. It is unrelated to charts and does not affect logging unless the socket table fills up; reboot clears it [Elektroda, max4elektroda, post #21244433]

Is live refresh heavy on network traffic?

After PR #1352 the static Chart.js script loads once; subsequent updates transmit only JSON data, roughly 0.4 kB per refresh for a 2-variable chart [Elektroda, max4elektroda, post #21235589]
ADVERTISEMENT