6 posts / 0 new
Last post
Stanton
Stanton's picture
Help with log retrieval

Can anyone point me to some examples of HOW you retrive grid.log (and trip.log) data? I don't see where/how these are linked to my account.

dexter
dexter's picture
Help with log retrieval

There are many options to retrieve these logs.

The easiest option is if the OVMS server web frontend provides some download tool, as I do on dexters-web.de -- simply select the logs you want to download, click download and you get a ZIP. Or enable a daily ZIP mail so you've got an archive in case you miss downloading in time before record expiry.

The dexters-web download tool can also be accessed by a REST API, see "CSV download" here: https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/issues/624#issuecomment-832180726

The drupal server plugin running e.g. on the openvehicles.com web frontend doesn't provide a download tool, so if you're on this server, you need to use the builtin server APIs to retrieve the logs. To do so you've got two options: a) the HTTP/HTTPS REST API, b) the TCP API.

The HTTP API can be accessed using any HTTP client, e.g. your browser or "curl". The endpoints are described here: https://docs.openvehicles.com/en/latest/protocol_httpapi/index.html

The grid & trip log are "historical" records, so you'll use the "GET /api/historical/<VEHICLEID>/<DATATYPE>" call for these. Example:

> curl -X GET -c cookiejar 'https://ovms.dexters-web.de:6869/api/cookie?username=<WEBLOGIN>&password=<WEBPASSWORD>'

> curl -X GET -b cookiejar 'https://ovms.dexters-web.de:6869/api/historical/<VEHICLEID>/*-LOG-Grid' > log-grid.json

You then need to extract the "h_data" fields from the JSON array, these contain the CSV data:

> cat log-grid.json | jq -r '.[] | .h_data' > log-grid.csv

The TCP API has a set of simple command line clients. These are written in perl, so you need to install perl + some modules first. The tools and installation info can be found here: https://github.com/openvehicles/Open-Vehicle-Server/tree/master/clients

To retrieve a historical record via the TCP API, you'll use commands 31 and 32. 31 tells you which logs are available and how many records are stored per log:

> ./cmd.pl 31 "*" 0

The number of records is given in the field before the type. To avoid using the timeout at the end, provide the number of records to retrieve instead of "0" for all. Example:

> cmd.pl 32 "*-LOG-Grid" 200 > log-grid.csv

…will get the first 200 records. The result is already a CSV, but you may want to strip the protocol fields.

Neither of the builtin APIs provides CSV headers, so you need to add them manually from the record structure description. See the "rt_…" example scripts on how to automate this.

The download tool on dexters-web automatically adds a header line to every record type known.

Regards,
Michael

Stanton
Stanton's picture
Thanks for the reply: you had

Thanks for the reply: you had me up until "The drupal server plugin running e.g. on the openvehicles.com web frontend doesn't provide a download tool". That's the only server I know of (no disrespect to what you have), and I have no idea how to interpret the HTTP/API commands (I'm not going to install something else to use TCP API).

I have enabled grid and trip notifications via the web configuration page, but I'm at a loss as to why these things are so hard to retrieve. Do I need to "join" your server for easy download? What happens to my current account/configuration that I have working? The doc you referenced is a bit cryptic for me.

Stanton
Stanton's picture
A better question: how do I

A better question: how do I run the curl commands in Firefox?

dexter
dexter's picture
Help with log retrieval

I have implemented a simple download tool for other servers:

https://dexters-web.de/downloadtool

Enter your openvehicles.com login & password, your vehicle ID and the table you'd like to download.

The tool uses the HTTP(S) API, and adds known headers automatically.

Regards,
Michael

Stanton
Stanton's picture
Wow: that's exactly what I

Wow: that's exactly what I was looking for! I was able to download my files and import them into a spreadsheet.

I really appreciate your help and hope that others in the same situation as me find this thread.

Log in or register to post comments