You are right.
I started with.
Code: Select all
if (!empty($data['attributesMap']['gps_lat']))
{
if (cget('BMW_GPS_LAT') != $gps_lat) cset('BMW_GPS_LAT',$gps_lat);
}
if (!empty($data['attributesMap']['gps_lng']))
{
if (cget('BMW_GPS_LON') != $gps_lon) cset('BMW_GPS_LON',$gps_lon);
}
This creates 2 entries in the Pass2PHP database log table. BMW_GPS_LAT_mode and BMW_GPS_LON_mode.
Maybe change that later to only one device to avoid flooding the log
Code: Select all
if (!empty($data['attributesMap']['gps_lat']) && !empty($data['attributesMap']['gps_lng']))
{
$coordinates=$gps_lat';'$gps_lon;
if (cget('BMW_GPS') != $gps_lat) cset('BMW_GPS',$coordinates);
}
The Database contains the timestamp and the location.
Code: Select all
('2020-01-04 12:01:26', 'BMW_GPS_LAT_mode', '50.48331'),
('2020-01-04 12:01:26', 'BMW_GPS_LON_mode', '5,3696233'),
('2020-01-04 12:02:17', 'BMW_GPS_LAT_mode', '52.57511'),
('2020-01-04 12:02:17', 'BMW_GPS_LON_mode', '5,3696233'),
('2020-01-04 12:03:13', 'BMW_GPS_LAT_mode', '52.57511'),
('2020-01-04 12:03:13', 'BMW_GPS_LON_mode', '5,3696233'),
('2020-01-04 12:04:17', 'BMW_GPS_LAT_mode', '52.57511'),
('2020-01-04 12:04:17', 'BMW_GPS_LON_mode', '5,3696233'),
('2020-01-04 12:05:15', 'BMW_GPS_LAT_mode', '52.57511'),
('2020-01-04 12:05:15', 'BMW_GPS_LON_mode', '5,369623');
That needs a nice MSQL query to have 1 line with 1 GPS coordinate..... for 1 day. I use the existing Pass2PHP db connection. takes aroud 60 sec.... to complete... on a raspberry Pi. Any query takes quite some time even an ordinary
select. CPU usage spikes
Code: Select all
select timestamp, group_concat(`device` separator ',') as `GPS`
from
(
select timestamp,
group_concat(`status` separator ',') as `device`
from log
WHERE `device` in ('BMW_GPS_LAT_mode','BMW_GPS_LON_mode') and DATE(`timestamp`) = CURDATE()
group by timestamp, `device`
) tbl
group by timestamp;
Will give some output we can work with..
Code: Select all
('2020-01-04 12:01:26', '52.57511,5,3696233'),
('2020-01-04 12:02:17', '52.57511,5,3696233'),
('2020-01-04 12:03:13', '52.57511,5,3696233'),
('2020-01-04 12:04:17', '52.57511,5,3696233'),
('2020-01-04 12:05:15', '52.57511,5,369623');
These can be plotted on a map. Now to find out how to do it for free. Google requires me to signup at lease with valid credit card and obtain a free $200 credit per month. However I don't feel like signing up.