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