use RTC time for my timestamp (works across deep sleep)
This commit is contained in:
+19
-4
@@ -1,10 +1,13 @@
|
||||
|
||||
#include "GPS.h"
|
||||
#include "time.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
// stuff that really should be in in the instance instead...
|
||||
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
||||
uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
||||
uint64_t zeroOffset; // GPS based time in millis since 1970 - only updated once on initial lock
|
||||
bool timeSetFromGPS; // We only reset our time once per wake
|
||||
|
||||
GPS gps;
|
||||
|
||||
@@ -14,6 +17,17 @@ GPS::GPS() : PeriodicTask(30 * 1000)
|
||||
|
||||
void GPS::setup()
|
||||
{
|
||||
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
||||
|
||||
if (!gettimeofday(&tv, NULL))
|
||||
{
|
||||
uint32_t now = millis();
|
||||
|
||||
DEBUG_MSG("Read RTC time as %ld (cur millis %u)\n", tv.tv_sec, now);
|
||||
timeStartMsec = now;
|
||||
zeroOffset = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
|
||||
}
|
||||
|
||||
#ifdef GPS_RX_PIN
|
||||
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||
#endif
|
||||
@@ -30,8 +44,9 @@ void GPS::loop()
|
||||
encode(_serial_gps.read());
|
||||
}
|
||||
|
||||
if (!timeStartMsec && time.isValid() && date.isValid())
|
||||
if (!timeSetFromGPS && time.isValid() && date.isValid())
|
||||
{
|
||||
timeSetFromGPS = true;
|
||||
timeStartMsec = millis();
|
||||
|
||||
// FIXME, this is a shit not right version of the standard def of unix time!!!
|
||||
@@ -44,8 +59,9 @@ void GPS::loop()
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t GPS::getTime() {
|
||||
return ((uint64_t) millis() - timeStartMsec) + zeroOffset;
|
||||
uint64_t GPS::getTime()
|
||||
{
|
||||
return ((uint64_t)millis() - timeStartMsec) + zeroOffset;
|
||||
}
|
||||
|
||||
void GPS::doTask()
|
||||
@@ -57,7 +73,6 @@ void GPS::doTask()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String GPS::getTimeStr()
|
||||
{
|
||||
static char t[12]; // used to sprintf for Serial output
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ void MeshService::sendToMesh(MeshPacket *p)
|
||||
|
||||
// Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it
|
||||
if(radio.send(p) != ERRNO_OK)
|
||||
DEBUG_MSG("Dropped packet because send queue was full!");
|
||||
DEBUG_MSG("Dropped packet because send queue was full!\n");
|
||||
}
|
||||
|
||||
MeshPacket *MeshService::allocForSending()
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// If not defined, we will wait for lock forever
|
||||
|
||||
#define MINWAKE_MSECS (5 * 60 * 1000) // stay awake a long time (30 mins) for debugging
|
||||
#define MINWAKE_MSECS (10 * 60 * 1000) // stay awake a long time (30 mins) for debugging
|
||||
// #define MINWAKE_MSECS (30 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
+2
-2
@@ -33,6 +33,8 @@
|
||||
#include "screen.h"
|
||||
#include "NodeDB.h"
|
||||
#include "Periodic.h"
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
|
||||
#ifdef T_BEAM_V10
|
||||
#include "axp20x.h"
|
||||
@@ -147,8 +149,6 @@ void doDeepSleep(uint64_t msecToWake)
|
||||
esp_deep_sleep_start(); // TBD mA sleep current (battery)
|
||||
}
|
||||
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
|
||||
/**
|
||||
* enable modem sleep mode as needed and available. Should lower our CPU current draw to an average of about 20mA.
|
||||
|
||||
Reference in New Issue
Block a user