logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 4749 65
ADVERTISEMENT
📢 Listen (AI):
  • #31 21239182
    max4elektroda
    Level 20  
    Build Simulator
    p.kaczmarek2 wrote:
    Well, for me it looks like it actually is, but maybe you meant something else?

    Oh, this is embarrassing, you are totally right.

    I didn't actually download the artifacts and looked for "windows" in the checks - not seeing the first point "Build Simulator" :-(.

    Thanks again!
  • ADVERTISEMENT
  • #32 21239586
    divadiow
    Level 34  
    sorry about lack of progress. tired. brain go-slow. I can carry on with LN/W800 tomorrow if wanted. My W600 isn't ideal for testing sensors (Air602 is in the post though).

    OpenBL602 user interface with temperature and humidity charts.

    BL602 started with command:

    Code: Text
    Log in, to see the code


    I can do XR809 but still need to remove XR3 from P06 device.

    Added after 29 [minutes]:

    Screenshot of the OpenW800_CDD5556C interface showing error messages in the console.

    Added after 1 [minutes]:

    would need sensor driver too (AHT, SHT or 83XX) I guess. Unless I did it on LED channel and flicked them on and off for a while?
  • ADVERTISEMENT
  • #33 21239671
    max4elektroda
    Level 20  
    W800 uses DISABLE_ALL_DRIVERS so you need to do some tweaks to allow loading and using drivers at all.
    I locally enabled this to use DS1820, so it's working for me as long as I define DS1820, too.
    XR809 is the same, but I never tried to enable it here, for I don't have any of those modules...
  • #34 21239751
    divadiow
    Level 34  
    ah yep sure. I just took their presence in your zip as a sign they were good to be tested ;)

    no worries. lmk if there's anything more you want me to do.
  • #35 21239901
    max4elektroda
    Level 20  
    divadiow wrote:
    I just took their presence in your zip as a sign they were good to be tested

    ... and you were absolutely right, it should have been that way!
    I just didn't consider that I started with a new checkout that didn't include my local changes.

    So, let's try again, also (brand new and never tested) a version for XR809 ...

    Just as a note to myself:

    
    ... /OpenBK7231T_App/sdk/OpenXR809$ git diff project/oxr_sharedApp/gcc/
    
    diff --git a/project/oxr_sharedApp/gcc/Makefile b/project/oxr_sharedApp/gcc/Makefile
    index a1dcca1..129c8cd 100644
    --- a/project/oxr_sharedApp/gcc/Makefile
    +++ b/project/oxr_sharedApp/gcc/Makefile
    @@ -67,6 +67,8 @@ SRCS += ../shared/src/driver/drv_main
     SRCS += ../shared/src/driver/drv_ntp
     SRCS += ../shared/src/driver/drv_tuyaMCU
     SRCS += ../shared/src/driver/drv_uart
    +SRCS += ../shared/src/driver/drv_charts
    +
     
     SRCS += ../shared/src/i2c/drv_i2c_main
     SRCS += ../shared/src/i2c/drv_i2c_mcp23017
    
    
    
    ... /OpenBK7231T_App/sdk/OpenW800$ git diff
    diff --git a/app/Makefile b/app/Makefile
    index b844221..d3bedc9 100644
    --- a/app/Makefile
    +++ b/app/Makefile
    @@ -48,6 +48,7 @@ CSRCS += $(_SHARED_APP)/rgb2hsv.c
     CSRCS += $(_SHARED_APP)/tiny_crc8.c
     CSRCS += $(_SHARED_APP)/driver/drv_main.c
     CSRCS += $(_SHARED_APP)/driver/drv_ds1820_simple.c
    +CSRCS += $(_SHARED_APP)/driver/drv_charts.c
     CSRCS += $(_SHARED_APP)/user_main.c
     CSRCS += main.c
     
  • #36 21239907
    p.kaczmarek2
    Moderator Smart Home
    Good job on testing, altough I wouldn't focus on XR809. The first thing I would check would be the buffer wrap around, so, setup a buffer with like 30 samples and wait 31 cycles and see if the samples are still in order. Then wait 60 cycles, etc.
    Helpful post? Buy me a coffee.
  • #37 21240837
    divadiow
    Level 34  
    I know XR809 isn't the focus, but this on the bench right now for other work.

    not sure how far I can get with no ntp driver. shall I forget XR809?

    OpenXR809 interface with toggles and temperature and humidity charts.

    this is me toggling switches manually.

    same backlog single line of commands as BL602 above. it's filling the bottom with sample dots and the pattern moves off the the left without issue. Not sure if this the test you're looking for.
  • #38 21240972
    max4elektroda
    Level 20  
    Thats fine, thanks. If the chart is drawn, that's all we need to know, for the handling of data is the same for all devices.
    I didn't want to focus on XR809, it was only a good opportunity to test the idea of a "reduced" driver support for devices with DISABLE_ALL_DRIVERS.
    I came to the same situation while doing the DS1820 driver for W800 and used it again here for the charts driver.
    It's simply allowing three functions: starting a driver, calling "on every second" and adding HTML to status page.
    So your feedback is very helpful for me, showing it works for different platforms.
    Details filled in soon, it's just three lines or so.

    Added after 34 [minutes]:

    It's now also in the second commit in the PR:

    https://github.com/openshwprojects/OpenBK7231...mits/732a6c5f468e952575de96304360231ab9a8dee9

    in obk_config.h it's for the device to allow the driver

    
    #define OBK_DISABLE_ALL_DRIVERS      1
    // Even with OBK_DISABLE_ALL_DRIVERS defined
    // allow to start a driver and display on HTML Page:
    // enables:
    //      DRV_OnEverySecond(); and DRV_Generic_Init(); in usr_main.c
    //       DRV_AppendInformationToHTTPIndexPage(request); in http_fns.c
    // used for charts driver
    #define OBK_ALLOW_DRIVERS_START      1
    


    and two changes to the actual code for the new "#define OBK_ALLOW_DRIVERS_START" in http_fns.c

    - #ifndef OBK_DISABLE_ALL_DRIVERS
    + #if ! OBK_DISABLE_ALL_DRIVERS || OBK_ALLOW_DRIVERS_START
       DRV_AppendInformationToHTTPIndexPage(request);
      #endif
    



    and in user_main.c

    - #ifndef OBK_DISABLE_ALL_DRIVERS
    + #if ! OBK_DISABLE_ALL_DRIVERS || OBK_ALLOW_DRIVERS_START
      DRV_OnEverySecond();
      #if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602)
         UART_RunEverySecond();
      #endif
      #endif
    
    
    - #ifndef OBK_DISABLE_ALL_DRIVERS
    + #if ! OBK_DISABLE_ALL_DRIVERS || OBK_ALLOW_DRIVERS_START
         DRV_Generic_Init();
      #endif


    Added after 23 [minutes]:

    BTW, you shouldn't need "IndexRefreshInterval 1000" any more after the chart has moved down on the page.
    At least that's the idea

    Added after 11 [minutes]:

    divadiow wrote:
    not sure how far I can get with no ntp driver

    Maybe a hint to update my approach for timekeeping w/o ntp to the actual code...
  • #39 21241000
    divadiow
    Level 34  
    max4elektroda wrote:
    BTW, you shouldn't need "IndexRefreshInterval 1000" any more after the chart has moved down on the page.
    At least that's the idea

    ah. i've been blindly using old command. thanks. although I had noted:
    p.kaczmarek2 wrote:
    This may be fixed soon. The dynamic charts update is not yet ready.


    Added after 1 [hours] 42 [minutes]:

    on a totally unrelated note. memo to me: powersave 1 will kill XR809 and there's no safe mode it seems. not that anyone seems to have XR809 devices.

    Code: Text
    Log in, to see the code
  • Helpful post
    #40 21241366
    max4elektroda
    Level 20  
    Just as an idea, this should "emulate" some temp and hum data, even without time/ntp:

    backlog  startDriver charts; chart_create 96 2 2; chart_setVar 0 "Pseudo Temperature" "axtemp"; chart_setVar 1 "Pseudo Humidity" "axhum"; chart_setAxis 0 "axtemp" 0 "Temperature (C)"; chart_setAxis 1 "axhum" 1 "Humidity (%)"; addRepeatingEvent 2 -1 chart_add 1727438906+$uptime 20+5*$rand01 40+5*$rand01;
  • #41 21242165
    divadiow
    Level 34  
    cheers. that gives me a single straight line on W800. This is even more manual but still serves to demonstrate:

    Code: Text
    Log in, to see the code


    W800 startup command doesn't seem to support very long strings, so has to be run from WebApp.

    Temperature chart on the OpenW800 interface with system status described.

    seems stable. not eating memory
    Screenshot of system logs showing information on time, idleness, and available memory.

    Is leaving that above command running overnight on several platforms a worthy test or are you pretty confident at this point and PR is ready for merging?

    Added after 8 [minutes]:

    and with humidity, just because.

    Code: Text
    Log in, to see the code

    Screenshot of the OpenW800_CDCE9078 interface displaying temperature and humidity data.
  • #42 21242368
    max4elektroda
    Level 20  
    Ah, thanks. I didn't take into account, that y axis isn't f type "time", but only "labels", so even if you add something for the same timestamp again later, it will just "go back in time", but adding it to the right of the chart. So my calculation of a "running clock" was just overdone...

    Since allocation of memory for the ring buffer is done once on start of charts driver, I wouldn't expect a memory leak over the time from the charts driver.

    From my point of view, this is "ready for production".

    If you would like to do some more testing, maybe the implementation with a separate circular buffer in PR #1358.
    Since this will again need changes to sdk Makefiles, I will attach some of the versions not in artifacts here...

    Added after 2 [hours] 22 [minutes]:

    Here are builds for LN882H, W800 and XR809
  • ADVERTISEMENT
  • #44 21243884
    divadiow
    Level 34  
    max4elektroda wrote:
    Completed zip, now contains LN882H, W600, W800, BL602 and XR809

    just flash and run the above static charts command for a few mins? is that a good test of the changes in this build?
  • #45 21243906
    max4elektroda
    Level 20  
    Yes, thanks, that would be great - and a little "long time test" would be even better...
    Another possible test could also be a "small" chart and testing "by hand" (or so slow, that it can be observed), if adding points will be o.k on the crucial points:
    with a few points
    when all points are used and its "rolling over"

    are the correct values shown?

    Thanks!!!!
  • #46 21244282
    divadiow
    Level 34  
    I appreciate this is only one test, but I'll leave this W600 going all night. Shows W600 working anyway.

    OpenW600 user interface with temperature and humidity chart.

    Added after 7 [hours] 35 [minutes]:

    so this may not have anything to do with Charts driver, but W600 is unresponsive this morning.

    Code: Text
    Log in, to see the code


    the following was true:
    -web app logs page was left open in the browser
    -OBK main GUI with chart drawing was left open in another tab
    -the device is still responding to pings

    These are the last logs visible
    Code: Text
    Log in, to see the code


    I'll start W600 again but with no pages left open.
  • #47 21244433
    max4elektroda
    Level 20  
    Thanks for your patience in testing!

    Reading the source in src/httpserver/new_http.c

    https://github.com/openshwprojects/OpenBK7231...9539d7e2677b65/src/httpserver/new_http.c#L628

    this means, there was a request on HTTP port other than the supportet methods ("GET", "PUT", "POST", "OPTIONS"):

    The code line for this error message is:
    ADDLOGF_ERROR("unsupported method %7s", recvbuf);

    "counting" the content of "recbuf":

    Error:HTTP:unsupported method      #
    ------------------------------1234567


    looking in the source of your post, there is a char 0x05 (^E) after the "#", don't know if this is from the output or from copying the output:
    Screenshot of logs with HTTP error messages.

    So at least the error messages seem to be from another source than the charts driver or the used ringbuffer.

    The constant memory usage also looks good for me ...
  • #48 21244441
    divadiow
    Level 34  
    very interesting. thank you.

    since earlier, it's been up for over twice the length of time now. Again, this is with no active browser sessions to device.

    Code: Text
    Log in, to see the code


    Screenshot of OpenW600_CD0239CC control panel with charts and configuration options.

    Added after 1 [minutes]:

    max4elektroda wrote:
    don't know if this is from the output or from copying the output

    hmm. can't recall. I should have screenshot. If this is of interest I can try to replicate and screenshot...
  • ADVERTISEMENT
  • #49 21244602
    max4elektroda
    Level 20  
    divadiow wrote:
    If this is of interest I can try to replicate and screenshot...

    Na, I don't think that's necessary.
  • #50 21245464
    jpduhen
    Level 2  
    newbie question: how do I plot $power and $voltage variables every 5 sec in a chart (I managed to get the driver-enabled firmware on my BK7231N LSC power metering plug)
    My autoexec.bat:

    // example setup
    
    IndexRefreshInterval 100000
    startDriver charts
    startDriver NTP
    waitFor NTPState 1
    
    // Staphorst
    ntp_setLatLong 52.642430 6.201190;
    ntp_timeZoneOfs 1
    
    // history energy stats
    SetupEnergyStats 1 30 120 1
    chart_create 48 2 2
    
    // set variables along with their axes
    chart_setVar 0 "Voltage" "axv"
    chart_setVar 1 "Power" "axw"
    
    // setup axes
    // axis_index, name, flags, label
    chart_setAxis 0 "axv" 0 "Voltage (V)"
    // flags 1 means this axis is on the right
    chart_setAxis 1 "axw" 1 "Power (W)"
    
    // every 5 seconds, -1 means infinite repeats
    // assumes that $voltage div10 and $power
    addRepeatingEvent 5 -1 chart_addNow $voltage*0.1 $power
  • #51 21245745
    max4elektroda
    Level 20  
    For me this command works:

    backlog startDriver charts; startDriver NTP; waitFor NTPState 1; chart_create 48 2 2; 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


    Screen with energy data and a graph of voltage and power.
  • #52 21245982
    divadiow
    Level 34  
    still going. not done anything more with other platforms yet
    Screenshot of the OpenW600 interface showing temperature and humidity graphs.
  • #53 21246385
    jpduhen
    Level 2  
    >>21245745 Thanks, it now shows the graphs.
  • #54 21249276
    divadiow
    Level 34  
    just playing with a W600 and a real sensor.

    Code: Text
    Log in, to see the code


    gives

    Info:MAIN:Started NTP.
    Error:CMD:cmd waitFor NOT found (args NTPState 1)
    Info:CMD:addRepeatingEvent: interval 2.000000, repeats -1, command [chart_addNow $CH1*0.1 $CH2]
    Info:CMD:[WebApp Cmd 'backlog startDriver charts; startDriver NTP; waitFor NTPState 1; chart_create 96 2 2; chart_setVar 0 "Temperature" "axtemp"; chart_setVar 1 "Humidity" "axhum"; chart_setAxis 0 "axtemp" 0 "Temperature (C)"; chart_setAxis 1 "axhum" 1 "Humidity (%)"; addRepeatingEvent 2 -1 chart_addNow $CH1*0.1 $CH2' Result] Unknown command

    and the temp isn't /10

    User interface with temperature and humidity charts and device configuration details.
  • #55 21249588
    max4elektroda
    Level 20  
    Is calculating possible at all for W600 in actual configuration?
    I'm not sure, but wasn't there a define needed for this, that was not obvious in the first place?
    Maybe #define ENABLE_EXPAND_CONSTANT

    Just a guess, and maybe I'm totally wrong...
  • #56 21254373
    jkwim
    Level 12  
    Wanted try out the feature.

    On build 1.17.740.

    startDriver charts
    gives:

    Info:MAIN:Driver charts is not known in this build.
    Info:MAIN:Available drivers: 
    Info:MAIN:TuyaMCU
    Info:MAIN:, tmSensor
    Info:MAIN:, PixelAnim
    Info:MAIN:, NTP
    Info:MAIN:, HTTPButtons
    Info:MAIN:, I2C
    Info:MAIN:, RN8209
    Info:MAIN:, BL0942
    Info:MAIN:, BL0942SPI
    Info:MAIN:, BL0937
    Info:MAIN:, CSE7766
    Info:MAIN:, SM16703P
    Info:MAIN:, SM15155E
    Info:MAIN:, IR
    Info:MAIN:, DDP
    Info:MAIN:, SSDP
    Info:MAIN:, DGR
    Info:MAIN:, Wemo
    Info:MAIN:, Hue
    Info:MAIN:, PWMToggler
    Info:MAIN:, DoorSensor
    Info:MAIN:, SM2135
    Info:MAIN:, BP5758D
    Info:MAIN:, BP1658CJ
    Info:MAIN:, SM2235
    Info:MAIN:, BMP280
    Info:MAIN:, CHT83XX
    Info:MAIN:, MCP9808
    Info:MAIN:, KP18058
    Info:MAIN:, ADCSmoother
    Info:MAIN:, SHT3X
    Info:MAIN:, SGP
    Info:MAIN:, ShiftRegister
    Info:MAIN:, DS1820
    Info:MAIN:, Battery
    Info:MAIN:, Bridge
    Info:CMD:[WebApp Cmd 'startDriver charts' Result] OK


    However when I look at
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/obk_config.h

    It shows:
    Screenshot of code from a configuration file showing ENABLE_DRIVER_CHARTS set.

    So does it mean that the feature is enabled by default now?

    UPDATE:
    I was looking under wrong module type.

    Submitted the following pull request.

    https://github.com/openshwprojects/OpenBK7231T_App/pull/1383

    So next step is for you to approve it only for automatic build? Am I understanding the process correctly?
  • #57 21254431
    max4elektroda
    Level 20  
    The drive is not enabled for all platforms. The line you mention (line 79) belongs to the Windows build.
    Which device are you trying?

    Added after 8 [minutes]:

    jkwim wrote:
    So next step is for you to approve it only for automatic build? Am I understanding the process correctly?

    Yes, that's the way.
    If you can live with an older version, you can scan the last PRs, iirc there were quite some for enabling graphs on different platforms...
  • #58 21254467
    jkwim
    Level 12  
    My pull request can be ignored.

    I used the build from pull request :
    Update obk_config.h #1374 - add charts driver to OBK for beken

    and was able to get the driver to load.

    Added after 36 [minutes]:

    max4elektroda wrote:
    For me this command works:

    backlog startDriver charts; startDriver NTP; waitFor NTPState 1; chart_create 48 2 2; 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


    Screen with energy data and a graph of voltage and power.


    @max4elektroda
    How did you pick and ?

    Do they correspond to MQTT topics power and voltage?


    I am using a Smart Plug CB2S BK7231N WHDZ03 (CB2S + BL0937).

    Added after 1 [hours] 34 [minutes]:

    Finally got it working:
    Graph showing changes in voltage and power over time.

    alias mode_wifi setPinRole 8 WifiLED_n
    alias mode_relay setPinRole 8 LED_n
    // at reboot, set WiFiLEd
    mode_wifi
    // then, setup handlers
    addChangeHandler WiFiState == 4 mode_relay 
    addChangeHandler WiFiState != 4 mode_wifi 
    
    startDriver BL0937
    startDriver NTP
    waitFor NTPState 1
    ntp_setServer 192.168.1.2
    ntp_timeZoneOfs +05:30
    
    startDriver charts
    // chart with max 48 samples, 2 variables and 2 vertical axes
    chart_create 48 2 2
    // set variables along with their axes
    chart_setVar 0 "Voltage" "axv"
    chart_setVar 1 "Power" "axp"
    // setup axes
    // axis_index, name, flags, label
    chart_setAxis 0 "axv" 0 "Voltage (V)"
    chart_setAxis 1 "axp" 1 "Power (W)"
    addRepeatingEvent 5 -1 chart_addNow $voltage $power
  • #59 21254813
    max4elektroda
    Level 20  
    jkwim wrote:
    How did you pick "$voltage" and "$power?"
    Do they correspond to MQTT topics power and voltage?


    Yes, it took me a while, but it's all in the docs folder, here it's constants.md.
  • #60 21261197
    jkwim
    Level 12  
    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.

    In other words the bottom part cannot be viewed as it gets scrolled down automatically when the chart gets updated.
📢 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.
Summary generated by the language model.
ADVERTISEMENT