[Ovmsdev] Persistent metrics
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:
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:
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,
+ ms_v_bat_soc = new OvmsMetricFloat(MS_V_BAT_SOC, SM_STALE_HIGH,
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.)
OVMS# metrics persist ?
Usage: metrics persist [-r]
OVMS# metrics persist
slots used 13 of 16
More information about the OvmsDev