Add function to set date/time with GPS clock if available and diffence >= 5s
This commit is contained in:
parent
5ed1b85280
commit
a758b2c3f4
@ -139,6 +139,22 @@ def update_neopixel(data):
|
||||
|
||||
return (rouge, vert, bleu)
|
||||
|
||||
def set_clock_from_GPS():
|
||||
if gps_enable and gps.has_fix:
|
||||
#Convert GPS timestamp into struct_time
|
||||
gps_datetime = time.struct_time((gps.timestamp_utc.tm_year,
|
||||
gps.timestamp_utc.tm_mon,
|
||||
gps.timestamp_utc.tm_mday,
|
||||
gps.timestamp_utc.tm_hour,
|
||||
gps.timestamp_utc.tm_min,
|
||||
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)) >= 5.0:
|
||||
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]))
|
||||
|
||||
#########
|
||||
# Setup #
|
||||
#########
|
||||
@ -148,7 +164,7 @@ gc.collect()
|
||||
|
||||
#Enable RTC of the feather M0 board
|
||||
clock = rtc.RTC()
|
||||
clock.datetime = time.struct_time((2018, 7, 29, 15, 31, 30, 0, 0, 0))
|
||||
#clock.datetime = time.struct_time((2018, 7, 29, 15, 31, 30, 0, 0, 0))
|
||||
|
||||
# BME280 sensors (I2C)
|
||||
i2c = I2C(board.SCL, board.SDA)
|
||||
@ -194,6 +210,7 @@ while True:
|
||||
current = time.monotonic()
|
||||
if current - last_update >= update_interval:
|
||||
last_update = current
|
||||
set_clock_from_GPS()
|
||||
data.update()
|
||||
if print_data:
|
||||
data.show()
|
||||
|
Loading…
Reference in New Issue
Block a user