diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 70a661e..3075c2c 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -10,7 +10,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - """ ########################## # Weather and GPS logger # @@ -41,8 +40,8 @@ TODO for v1 : * write data on flash drive (work-in-progress) * send data through UART (work-in-progress) """ -__version__ = 0.2 __author__ = "arofarn" +__version__ = 0.2 ####################### import time @@ -115,13 +114,6 @@ class Data: self._gps_current_fix = int(time.monotonic()) if gps.has_fix: self._gps_last_fix = self._gps_current_fix - self.data['GPS']['time'] = TIME_FORMAT.format( - 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) self.data['GPS']['lat'] = gps.latitude self.data['GPS']['lon'] = gps.longitude self.data['GPS']['alt'] = gps.altitude_m @@ -135,34 +127,34 @@ class Data: def show(self): """Serialize data for visualization on serial console""" - for source in self.data.keys(): + for source, val in self.data.items(): print(source + ": ") - if not self.data[source] is None: - for d in self.data[source].items(): - print("\t{0}: {1}".format(d[0], d[1])) + if val is not None: + for name, value in val.items(): + print("\t{0}: {1}".format(name, value)) @property def json(self): """Serialized data to compact json-formatted string""" output = '{' first_source = True - for source in self.data.keys(): + for source, val in self.data.items(): if first_source: first_source = False comma_src = "" else: comma_src = "," output = '{}{}"{}":'.format(output, comma_src, source) - if not self.data[source] is None: + if val is not None: output = output + '{' first_data = True - for d in self.data[source].items(): + for name, value in val.items(): if first_data: comma = "" first_data = False else: comma = "," - output = '{}{}"{}":"{}"'.format(output, comma, d[0], d[1]) + output = '{}{}"{}":"{}"'.format(output, comma, name, value) output = output + '}' output = output + '}' return output @@ -315,7 +307,7 @@ def measure_vbat(samples=10, timestep=0.01): # 3.3 : Vref = 3.3V # 65536 : 16bit ADC val = 0 - for i in range(samples): + for sample in range(samples): val = val + vbat.value time.sleep(timestep) return val/samples*0.000100708