From 4b9885d7a787acf2f49b1270e662838cf3b360d8 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Sun, 19 Aug 2018 00:01:23 +0200 Subject: [PATCH] Add GPS data to data on flash memory --- circuitpython/code/main.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 81b1eac..a8f598f 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -199,11 +199,25 @@ class Data: """Save the current data as csv file on SPI flash""" try: with open("data/data.csv", "a") as csv_file: - csv_file.write("{};{};{};{};{}\n".format(self.data['SYS']['time'], - self.data['BME']['temp'], - self.data['BME']['hum'], - self.data['BME']['press'], - self.data['SYS']['vbat'])) + if gps_enable: + csv_file.write("{};{};{};{};{};{};{};{};{};{}\n".format(self.data['SYS']['time'], + self.data['BME']['temp'], + self.data['BME']['hum'], + self.data['BME']['press'], + self.data['SYS']['vbat'], + self.data['GPS']['time'], + self.data['GPS']['lon'], + self.data['GPS']['lat'], + self.data['GPS']['alt'], + self.data['GPS']['qual'], + )) + else: + csv_file.write("{};{};{};{};{};;;;;\n".format(self.data['SYS']['time'], + self.data['BME']['temp'], + self.data['BME']['hum'], + self.data['BME']['press'], + self.data['SYS']['vbat'] + )) except OSError as e: print("Err {}: readonly".format(e)) backup_data = False #to avoid trying again till next reset