From a4f8ad6138466973643eefe4ae5ee85b5bfe4fbc Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 20 Jun 2019 13:56:08 +0100 Subject: [PATCH] Start working on a debug program to test battery life, but it's not finished yet --- iot/main/gps.cpp | 8 ++++++-- iot/main/gps.h | 10 ++++++++-- iot/main/main.ino | 20 +++++++++++++++++++- iot/main/power.cpp | 6 ++++++ iot/main/settings.h | 4 ++++ iot/main/storage.cpp | 7 +++++++ iot/main/storage.h | 2 ++ 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/iot/main/gps.cpp b/iot/main/gps.cpp index 54aeee9..bbfe2dd 100644 --- a/iot/main/gps.cpp +++ b/iot/main/gps.cpp @@ -11,7 +11,7 @@ void gps_begin() { serial_gps.begin(BAUD_GPS); } -TinyGPSLocation gps_location() { +void gps_fetch() { Serial.print("[gps] Getting location: "); uint32_t ms_last_update = millis(); // We WILL discover our location - if it's the last thing we do! @@ -41,10 +41,14 @@ TinyGPSLocation gps_location() { // Hooray! Serial.println("ok"); - return gps.location; + return; } } +TinyGPSPlus gps_info() { + return gps; +} + void gps_end() { Serial.println(F("[warning] Putting the GPS device to sleep isn't implemented yet.")); } diff --git a/iot/main/gps.h b/iot/main/gps.h index b03ef4e..40d2ee4 100644 --- a/iot/main/gps.h +++ b/iot/main/gps.h @@ -12,11 +12,17 @@ void gps_begin(); /** - * Fetches the current location from the GPS device. + * Fetches new data from the GPS module. * May take a moment, as the GPS device needs time to acquire a satellite fix. + */ +void gps_fetch(); + +/** + * Fetches the latest information from the GPS device. + * Call gps_fetch() first. * @return TinyGPSLocation The current location. */ -TinyGPSLocation gps_location(); +TinyGPSLocation gps_info(); /** * Ends the connection to the GPS device and puts it to sleep in order to save diff --git a/iot/main/main.ino b/iot/main/main.ino index 54bca15..73b100b 100644 --- a/iot/main/main.ino +++ b/iot/main/main.ino @@ -1,5 +1,6 @@ #include #include +#include #include "settings.h" #include "random.h" @@ -16,7 +17,7 @@ void setup() { gps_begin(); - TinyGPSLocation loc = gps_location(); + TinyGPSPlus gps_data = gps_location(); gps_end(); Serial.print("[main] Location: ("); Serial.print(loc.lat()); Serial.print(", "); Serial.print(loc.lng()); Serial.println(")"); @@ -26,6 +27,23 @@ void setup() { Serial.print("[main] id: "); Serial.println(id); + store_init(); + store_reading(id, gps_data.location); + char debug_message[64]; + int chars = snprintf(debug_message, 64, "%d-%d-%d %d:%d:%d | %f %f", + gps_data.date.year(), + gps_data.date.month(), + gps_data.date.day(), + gps_data.time.hour(), + gps_data.time.minute(), + gps_data.time.second(), + gps_data.location.lat(), + gps_data.location.lng(), + ); + store_debug(debug_message, chars); + store_close(); + + power_off(); // Doesn't return } void loop() { diff --git a/iot/main/power.cpp b/iot/main/power.cpp index c359e72..7dbf3f0 100644 --- a/iot/main/power.cpp +++ b/iot/main/power.cpp @@ -12,8 +12,14 @@ void power_gps_standby() { } void power_off() { + Serial.println(F("[power] Beginning shutdown sequence")); + Serial.println(F("[power] Switching GPS module to standby")); power_gps_standby(); + Serial.println(F("[power] Signalling TPL5111")); pinMode(PIN_TPL_DONE, OUTPUT); digitalWrite(PIN_TPL_DONE, HIGH); + + // Wait until we're turned off + while(true) delay(100); } diff --git a/iot/main/settings.h b/iot/main/settings.h index 5e82105..df2f353 100644 --- a/iot/main/settings.h +++ b/iot/main/settings.h @@ -34,4 +34,8 @@ // The chip select pin that activates the connection to the microSD card over SPI. #define PIN_SD_SPI_CHIP_SELECT 3 +// The filename on the microSD card to store data in. #define SD_FILENAME "data.tsv" + +// The filename on the microSD card to store debug information in +#define SD_FILENAME_DEBUG "debug.log" diff --git a/iot/main/storage.cpp b/iot/main/storage.cpp index 8f5be90..3448d1a 100644 --- a/iot/main/storage.cpp +++ b/iot/main/storage.cpp @@ -4,6 +4,8 @@ #include "settings.h" +File _debug_handle; + void store_init() { // NOTE: If this doesn't work, then we need to use pinMode() & specify the data pin here instead. if(!SD.begin(PIN_SD_SPI_CHIP_SELECT)) { @@ -29,6 +31,11 @@ void store_reading(uint32_t id, TinyGPSLocation location) { handle.close(); } +void store_debug(char* buffer, int size) { + File handle = SD.open(SD_FILENAME_DEBUG, FILE_WRITE); + +} + void store_close() { SD.end(); } diff --git a/iot/main/storage.h b/iot/main/storage.h index 6642718..d5386c4 100644 --- a/iot/main/storage.h +++ b/iot/main/storage.h @@ -9,4 +9,6 @@ void store_init(); void store_reading(uint32_t id, TinyGPSLocation location); +void store_debug(char* buffer, int size); + void store_close();