diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 0f61e0a..b08dd47 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -115,9 +115,10 @@ class Data: if not self.data[source] == None: for d in self.data[source].items(): print("\t{0}: {1}".format(d[0], d[1])) + @property def json(self): - """Serialize data to json-formatted string""" + """Serialized data to json-formatted string""" output = '{' first_source = True for source in self.data.keys(): @@ -143,7 +144,8 @@ class Data: @property def rgb(self): - """Convert atmospheric data from BME280 sensor into NeoPixel color + """Convert atmospheric data from BME280 sensor into NeoPixel color as + a tuple (RED, BLUE, GREEN): * RED => temperature : max = 35degC, min =10degC (range 25°C) * BLUE => humidity : max= 100%, mini=0% * GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa) @@ -196,7 +198,11 @@ def check_data_dir(): elif 'daily' not in os.listdir('data'): os.mkdir('data/daily') -def set_clock_from_GPS(): +def set_clock_from_GPS(treshold=5.0): + """Compare internal RTC and date-time from GPS (if enable and fixed) and set + the RTC date time to GPS date-time if the difference is more or equal to + threshold (in seconds)""" + if gps_enable and gps.has_fix: #Congreen GPS timestamp into struct_time gps_datetime = time.struct_time((gps.timestamp_utc.tm_year, @@ -206,7 +212,7 @@ def set_clock_from_GPS(): 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: + 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])) clock.datetime = gps_datetime #Trust GPS if there is a bias