[Ovmsdev] OvmsMetricVector<string> causing console.log error

Michael Balzer dexter at expeedo.de
Sun Sep 6 21:19:20 HKT 2020


Derek,

see ovms_metrics.h:

/**
 * OvmsMetricVector<type>: metric wrapper for std::vector<type>
 *  - string representation as comma separated values
 *  - TODO: escaping / string encoding for non-numeric types
…

The template hasn't been specialized for non-numeric types yet, simply
as they haven't been needed up to now.

You're welcome to add this template specialization.

DukPush() works without specialization because the DukContext.Push()
method has specializations for the most common types, and Duktape knows
about the types added to the array.

AsString() and SetValue(string) need special handling for string vectors
(quotes & escapes).

AsJSON() is used for the websocket transport of metrics. If you can use
json_encode() for AsString(), AsJSON() doesn't need additional handling,
but you'll need to add a string parser to SetValue(), as std::quoted
cannot handle JSON encoded strings.

Regards,
Michael


Am 06.09.20 um 12:07 schrieb Derek Caudwell:
> Hi,
>
> I am trying to resolve the ovms web interface throwing an "undefined"
> error because the following metric is defined
> with OvmsMetricVector<string> and does not get quoted when parsed to
> JSON.parse(ev.data) in ovms.js.
>
> Output from console error log:
> "xnl.v.c.duration.label":[full.l2,full.l1,full.l0,range.l2,range.l1,range.l0]
>
> However, when using
> JSON.print(OvmsMetrics.GetValues("xnl.v.c.duration.label")) a properly
> formed json string is returned:
>   "xnl.v.c.duration.label": [
>     "full.l2",
>     "full.l1",
>     "full.l0",
>     "range.l2",
>     "range.l1",
>     "range.l0"
>   ]
>
> Can this be corrected at the ev.data source or use JSON.print on
> ev.data before parsing it?
>
> Kind regards
> Derek
>
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev

-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20200906/5956af72/attachment.htm>


More information about the OvmsDev mailing list