logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 6375 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.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • #61 21261598
    max4elektroda
    Level 24  
    Posts: 746
    Help: 48
    Rate: 184
    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  
    Posts: 186
    Help: 4
    Rate: 25
    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  
    Posts: 746
    Help: 48
    Rate: 184
    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?
  • #64 21262676
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14451
    Help: 650
    Rate: 12432
    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  
    Posts: 746
    Help: 48
    Rate: 184
    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.
  • ADVERTISEMENT
  • #66 21440659
    Zogdan
    Level 10  
    Posts: 25
    Help: 6
    Rate: 13
    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
    Posts: 14451
    Help: 650
    Rate: 12432
    @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.
Generated by the language model.

FAQ

TL;DR: With 48 samples and 2 axes, OpenBeken can log history directly on-device; as one maintainer put it, "No Home Assistant, no external server" is needed for temperature, humidity, voltage, or power charts. This FAQ is for OpenBeken users who want local measurement history, setup examples, and fixes for crashes, refresh issues, and platform quirks. [#21223630]

Why it matters: It lets small IoT devices keep useful measurement history without adding Home Assistant, a database, or another always-on server.

Approach Extra infrastructure Where history lives Best for
OpenBeken charts driver None beyond the device and browser On the OBK device Small standalone setups
Home Assistant history Home Assistant instance and integration External system Larger automations and central dashboards

Key insight: The charts driver became practical after fixes for NULL checks, repeated chart_create, redraw flicker, and input validation. Once enabled for your platform, the core setup is simple: create the chart, map variables to axes, then add samples on a timer. [#21263018]

Quick Facts

  • The basic chart workflow has 5 steps: start the driver, create the chart, assign variables, configure axes, and add data samples. [#21223630]
  • A working DHT11 demo used 48 samples, 2 variables, 2 axes, and logged values every 60 seconds with chart_addNow. [#21223630]
  • The driver can plot mixed units on separate axes, including examples such as temperature (°C), humidity (%), battery voltage (V), pressure (hPa), current (A), and power (W). [#21223630]
  • One crash investigation showed about 60 kB free RAM on a BK7231 test device, so missing charts were not always a low-memory issue. [#21224054]
  • Long-run testing on W600 showed stable free memory around 30,848 bytes for hours, which suggests the chart buffer itself was not leaking over time. [#21244441]

How do I set up the OpenBeken charts driver in autoexec.bat to log temperature, humidity, voltage, or power history directly on the device?

Create the chart in autoexec.bat, then add samples on a timer. 1. Start charts and usually NTP. 2. Run chart_create samples vars axes, then chart_setVar and chart_setAxis. 3. Use addRepeatingEvent with chart_addNow or chart_add. A working DHT11 example used chart_create 48 2 2 and logged temperature plus humidity every 60 seconds. [#21223630]

What is the OpenBeken charts driver, and how is it different from using Home Assistant for measurement history?

It is an on-device charting feature that stores a rolling measurement history inside the OpenBeken device. "Charts driver" is a built-in OpenBeken component that renders measurement history in the device web UI, using configurable variables, axes, and a looped sample buffer. Unlike Home Assistant, it needs no external server. The thread’s main use case was a single IoT device showing its own temperature, humidity, voltage, or power history locally. [#21223630]

Why does chart_create panic or reboot some OpenBeken builds, and what fixes were discussed for NULL checks, uninitialized memory, and malloc failures?

The panics came from several code bugs, not one cause. The thread identified missing NULL checks in chart_setVar and chart_setAxis, uninitialized pointers after allocation, repeated chart_create freeing garbage data, and a rare malloc-failure path. One ESP build showed CORRUPT HEAP and rebooted. Later patches added NULL checks, zero-initialization, repeated-create fixes, and handling for malloc failure. [#21224739]

What is ENABLE_DRIVER_CHARTS in obk_config.h, and how do I enable the charts driver for my specific OpenBeken platform?

ENABLE_DRIVER_CHARTS is the build flag that includes the charts driver for a given platform. If startDriver charts says the driver is unknown, enable #define ENABLE_DRIVER_CHARTS 1 in that platform’s obk_config.h, then build that target. The original guide said to set it in the chosen platform config and use the custom online build flow if your binary lacks charts. [#21223630]

How can I use chart_addNow with NTP to plot live DHT11, AHT20, BMP280, or power-monitor readings in OpenBeken?

Start NTP, wait until time sync is ready, then schedule chart_addNow with your live variables. The DHT11 example used startDriver NTP, waitFor NTPState 1, chart_create 48 2 2, and addRepeatingEvent 60 -1 chart_addNow $CH1*0.1 $CH2. A BMP280 plus AHT20 test used chart_create 96 4 3 and logged four channels every 900 seconds. The same pattern also works for power-monitor variables such as $voltage and $power. [#21225816]

Why does $CH0*0.1 or $CH1*0.1 fail to evaluate on some ESP32, W600, or other OpenBeken builds, and what does ENABLE_EXPAND_CONSTANT do?

It fails when the build cannot expand expressions inside command arguments. On affected builds, chart_addNow $CH0*0.1 $CH1 can pass the raw token instead of the calculated value, so temperature appears unscaled. The thread pointed to #define ENABLE_EXPAND_CONSTANT 1 as the needed feature flag. An ESP fork lacking that define was the suspected reason expression expansion did not work there. [#21224804]

What causes waitFor NTPState 1 to return 'command not found' on some platforms like W600, and how can I work around missing waitFor support?

That error means the platform build does not include the waitFor command parser. A W600 test printed waitFor NOT found, then still created a chart, but expression handling also looked incomplete. The practical workaround is to skip waitFor and either use fixed timestamps with chart_add, or delay charting until time becomes available by another mechanism. One helper command used chart_add 1727438906+$uptime ... to emulate running time without NTP. [#21241366]

How do I chart $power and $voltage every 5 seconds on a BK7231N smart plug with BL0937 in OpenBeken?

Use NTP, create a 2-variable chart, then sample $voltage and $power every 5 seconds. A confirmed working setup on a BK7231N smart plug with BL0937 used chart_create 48 2 2, mapped Voltage and Power to separate axes, and finished with addRepeatingEvent 5 -1 chart_addNow $voltage $power. The user reported it worked after enabling a build that included the charts driver. [#21254467]

Why was the chart not refreshing live in Firefox or Chromium, and how did moving the chart below the state div reduce flicker and page focus issues?

The page kept redrawing the chart inside the state div during status refreshes. That reloaded script content, caused flicker, and could pull browser focus back to the chart. A later PR moved the chart below the state div and changed redraw behavior so updated data refreshed smoothly. Users then reported the graph no longer flickered and the page stopped jumping back while they viewed controls below. [#21237266]

What is a ring buffer in the context of the OpenBeken charts driver, and how does buffer wrap-around affect sample order and long-term logging?

It is the fixed-size loop that stores the newest N samples and overwrites the oldest ones when full. "Ring buffer" is a circular data structure that reuses the same memory block, keeps a rolling history window, and wraps from the end back to the beginning instead of growing indefinitely. In practice, a 30-sample test should still show correct order after 31, then 60 cycles, if wrap-around logic is correct. [#21239907]

OpenBeken charts on-device vs Home Assistant history graphs — which approach makes more sense for a small standalone IoT setup?

OpenBeken charts make more sense when you want one device to keep its own history with no extra infrastructure. The thread explicitly positioned the driver for users who do not want to set up Home Assistant. If you only need local graphs for temperature, humidity, voltage, or power on a single device, on-device charts are simpler. Use Home Assistant when you want centralized dashboards across many devices. [#21223630]

How can I test whether the charts driver is stable across platforms like BK7231N, BL602, W600, W800, XR809, ESP32, and the Windows simulator?

Run the same small chart script, watch memory, then test wrap-around and live refresh. The thread used manual chart_create checks, overnight runs, repeated sample insertion, and platform-specific builds on BL602, W600, W800, XR809, ESP32, and the Windows simulator. One maintainer specifically recommended a small buffer, such as 30 samples, then verifying order after 31 and 60 cycles to confirm wrap-around behavior. [#21239907]

What should I check when charts are missing from the OpenBeken web UI even though startDriver charts appears to run?

First verify that the build actually contains the charts driver, then confirm chart_create really ran. Missing UI output can happen when the driver is running but no g_chart object exists, so the HTML canvas and script never get generated. The thread also suggested checking whether autoexec.bat executed correctly, whether whitespace broke parsing, and whether free memory was still healthy; one example showed about 60 kB free. [#21224054]

How do I add charts support to platforms that use DISABLE_ALL_DRIVERS or require manual Makefile entries, such as W800, LN882H, W600, or XR809?

You must both compile drv_charts.c and allow driver startup hooks. For reduced-driver platforms, the thread proposed OBK_ALLOW_DRIVERS_START 1 together with code paths that still call DRV_Generic_Init, DRV_OnEverySecond, and DRV_AppendInformationToHTTPIndexPage. For SDKs with explicit source lists, such as W800 or XR809, drv_charts.c also had to be added manually to the Makefile source entries. [#21240972]

How could a chart_getVar diff-style feature work in OpenBeken for showing changes between the latest and previous energy or sensor values?

The suggested design was to let chart_getVar return the delta against older samples. The proposal used chart_getVar 0 -1 for the difference to the previous value and chart_getVar 0 -2 for two steps back. In the example series 500, 450, 300, the newest point would report diffs of 50 and 200. The maintainer said the idea was interesting and invited a pull request. [#21440659]
Generated by the language model.
ADVERTISEMENT