Cloud Functions


Particle.timeSyncedLast, timeSyncedLast


SerialLogHandler logHandler;

#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)

void loop() {
  time_t lastSyncTimestamp;
  unsigned long lastSync = Particle.timeSyncedLast(lastSyncTimestamp);
  if (millis() - lastSync > ONE_DAY_MILLIS) {
    unsigned long cur = millis();"Time was last synchronized %lu milliseconds ago", millis() - lastSync);
    if (lastSyncTimestamp > 0)
    {"Time received from Particle Device Cloud was: ", Time.timeStr(lastSyncTimestamp).c_str());
    // Request time synchronization from Particle Device Cloud
    // Wait until the device receives time from Particle Device Cloud (or connection to Particle Device Cloud is lost)
    // Check if synchronized successfully
    if (Particle.timeSyncedLast() >= cur)
      // Print current time"Current time: %s", Time.timeStr().c_str());

Since 0.6.1:

Used to check when time was last synchronized with Particle Device Cloud.


Returns the number of milliseconds since the device began running the current program when last time synchronization with Particle Device Cloud was performed.

This function takes one optional argument:

  • timestamp: time_t variable that will contain a UNIX timestamp received from Particle Device Cloud during last time synchronization