[Ovmsdev] Persistent metrics

Craig Leres leres at xse.com
Sun Jun 7 04:02:55 HKT 2020


On 2020-04-21 20:21, Mark Webb-Johnson wrote:
> There is a small amount of RTC ram that is retained through a reboot.
> Perhaps we could have a mechanism to save+restore certain metrics there?
> But not at all simple.

I figured out how to do this and implemented it with this pull request:


https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/pull/377

The trick is the RTC_NOINIT_ATTR macro which places data into RTC slow
memory, in a memory section that is not initialized on boot:


https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/general-notes.html

There is a new persist argument that can be used when creating a metric:

    -  ms_v_bat_soc = new OvmsMetricFloat(MS_V_BAT_SOC, SM_STALE_HIGH,
Percentage);
    +  ms_v_bat_soc = new OvmsMetricFloat(MS_V_BAT_SOC, SM_STALE_HIGH,
Percentage, true);

This is only implemented for OvmsMetricFloat and I only enabled it for a
small set of metrics. "metrics persist" shows what's being saved, how
many bytes are in use, etc. (It just occurred to me it would be better
to add a flag to "metrics list" to only show persist metrics ...)

The changes solve my desire for v.b.soc to be visible in the app after a
reboot. I wanted to use it for v.p.direction but minor drifts in the
calculated gps position foil that. I enabled it for the tpms metrics but
since my cars don't have working tpms code even when I manually populate
values (e.g. "metrics set v.tp.fl.p 202.29") the app doesn't show them
because (I believe) they are stale.

I expect there are metrics you "big battery" guys will want to add. (And
it won't hurt my feelings if somebody completely rewrites this.)

		Craig

OVMS# metrics persist ?
Usage: metrics persist [-r]
OVMS# metrics persist
version                                  1
serial                                   2
size                                     340
slots used                               13 of 16
v.b.soc                                  82.0
v.b.temp                                 19.0
v.m.temp                                 0.0
v.e.temp                                 20.0
v.p.odometer                             0.0
v.tp.fl.t                                0.0
v.tp.fr.t                                0.0
v.tp.rr.t                                0.0
v.tp.rl.t                                0.0
v.tp.fl.p                                0.0
v.tp.fr.p                                0.0
v.tp.rr.p                                0.0
v.tp.rl.p                                0.0


More information about the OvmsDev mailing list