Description

This function reads the latest GPS time in form of epoch time. The GPS time is UTC. The DICE_GPS and RTCSAMC libraries will translate this in UTC time when setting the embedded RTC of the device. Call isTimeValid() before reading the time from the GPS library to ensure it was received from GPS. The GPS library automatically updates the embedded RTC of the device in the background. This is why it might be better to always use the rtc.getEpoch() function instead.

Syntax

GPS.getTime() – returns the current UTC in epoch time format (that is seconds since 1.1.1970)

GPS.isTimeValid() – returns true if a valid GPS time is available

Parameters

none

Returns

unsigned long– holding the number of seconds since 1.1.1970 (midnight)
bool– for the isTimeValid() method.

Example Code

The following example runs on any dice device. It either receives the GPS data with its embedded receiver or gets it from a capable node on the CAN bus (via data pool). It shows the epoch time from the GPS library and the time of the RTC (real time clock) accordingly.

#include "DICE_GPS.h"
void setup()
{
  GPS.begin();
  while(!Serial);
  Serial.println("Waiting for GPS reception");
}
void loop()
{
  while(!GPS.isTimeValid()) { yield(); };
  Serial.println("TIME:");
  Serial.println("-time gps: "+String(GPS.getTime()));
  Serial.println("-time rtc: "+rtc.printTime());
  Serial.println("-date rtc: "+rtc.printDate());
  delay(1000);
}

Notes and Warnings

Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE_GPS ->

See also

begin()
end()
Reading GPS values
Datapools
RTCSAMC