Add age (in seconds) of the last GPS fix

This commit is contained in:
Pierrick C 2018-08-04 16:20:51 +02:00
parent d88a47d793
commit 3718666890
1 changed files with 11 additions and 7 deletions

View File

@ -74,8 +74,11 @@ class Data:
'lat': float(),
'lon': float(),
'alt': float(),
'qual': int()}
'qual': int(),
'age': int() }
}
self._gps_last_fix = int()
self._gps_current_fix = int()
def update(self):
"""Read the data from various sensors and update the data dict variable"""
@ -90,7 +93,9 @@ class Data:
self.data['BME']['press'] = round(bme280.pressure, 2)
if gps_enable:
self._gps_current_fix = int(time.monotonic())
if gps.has_fix:
self._gps_last_fix = self._gps_current_fix
self.data['GPS']['time'] = datetime_format.format(gps.timestamp_utc.tm_year,
gps.timestamp_utc.tm_mon,
gps.timestamp_utc.tm_mday,
@ -101,10 +106,9 @@ class Data:
self.data['GPS']['lon'] = gps.longitude
self.data['GPS']['alt'] = gps.altitude_m
self.data['GPS']['qual'] = gps.fix_quality
self.data['GPS']['age'] = 0
else:
self.data['GPS']['lat'] = None
self.data['GPS']['lon'] = None
self.data['GPS']['alt'] = None
self.data['GPS']['age'] = int(self._gps_current_fix - self._gps_last_fix)
else:
self.data['GPS'] = None
@ -220,10 +224,10 @@ def set_clock_from_GPS(treshold=5.0):
gps.timestamp_utc.tm_sec, 0, 0, 0))
#Max difference between GPS and internal RTC (in seconds):
if abs(time.mktime(gps_datetime) - time.mktime(clock.datetime)) >= treshold:
print("Clock difference with GPS!")
print("Previous date/time : " + datetime_format.format(*clock.datetime[0:6]))
# print("Clock difference with GPS!")
# print("Previous date/time : " + datetime_format.format(*clock.datetime[0:6]))
clock.datetime = gps_datetime #Trust GPS if there is a bias
print("New date/time : " + datetime_format.format(*clock.datetime[0:6]))
print("Clocks synced !")
def measure_vbat(samples=10, timestep=0.01):
"""Measure Vbattery as the mean of n samples with timestep second between