Add clock check before writing data
This commit is contained in:
parent
e84682c391
commit
cca0c082c8
@ -426,7 +426,7 @@ def set_clock_from_localtime(clock, threshold=2.0, debug=False):
|
||||
print(err)
|
||||
print("Local time source : " + TIME_FORMAT.format(*time.localtime()[0:6]))
|
||||
print("Wait some time to have proper time from time source...")
|
||||
return 1
|
||||
return False
|
||||
|
||||
# Max difference between GPS and internal RTC (in seconds):
|
||||
if abs(local_seconds - time.mktime(clock.datetime)) >= threshold:
|
||||
@ -435,4 +435,4 @@ def set_clock_from_localtime(clock, threshold=2.0, debug=False):
|
||||
clock.datetime = time.localtime() # Trust localtime if there is a bias
|
||||
print("Clocks synced !")
|
||||
|
||||
return 0
|
||||
return True
|
||||
|
@ -41,12 +41,12 @@ TODO for v1 :
|
||||
* send data through UART (work-in-progress)
|
||||
"""
|
||||
__author__ = "arofarn"
|
||||
__version__ = 0.2
|
||||
__version__ = 0.3
|
||||
|
||||
#######################
|
||||
import time
|
||||
import rtc
|
||||
import gc
|
||||
import rtc
|
||||
import board
|
||||
from busio import UART
|
||||
# import micropython
|
||||
@ -95,8 +95,8 @@ gps_data = cameteo.GPSData(debug=False)
|
||||
|
||||
data = [sys_data, gps_data, bme_data]
|
||||
|
||||
rtc.set_time_source(gps_data, debug=True)
|
||||
|
||||
rtc.set_time_source(gps_data)
|
||||
CLOCK_SYNCED = False
|
||||
|
||||
#############
|
||||
# Main loop #
|
||||
@ -108,16 +108,16 @@ while True:
|
||||
|
||||
for src in data:
|
||||
src.update(current_time, verbose=PRINT_DATA)
|
||||
cameteo.set_clock_from_localtime(CLOCK, threshold=2.0)
|
||||
|
||||
# Sync clocks
|
||||
CLOCK_SYNCED = cameteo.set_clock_from_localtime(CLOCK, threshold=2.0, debug=True)
|
||||
|
||||
for src in data:
|
||||
#Only write data when clocks are OK
|
||||
if CLOCK_SYNCED:
|
||||
src.write_on_flash(current_time)
|
||||
src.send_json(current_time, uart=rpi_uart, verbose=True)
|
||||
|
||||
# # First check if files need to rotate
|
||||
# last_rotation = rotate_files(last_rotation)
|
||||
|
||||
|
||||
gc.collect()
|
||||
# micropython.mem_info(1)
|
||||
# print('Memory free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))
|
||||
|
Loading…
Reference in New Issue
Block a user