Cloud functions



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

It is possible that the call will block for an indeterminate amount of time, possibly for as long as 10 minutes. This can occur if the system thread is busy trying to reconnect to cellular and is unable to do so. Doing operations that access the cellular modem or require access to the system thread (as is the case for Particle.timeSyncedLast()) from a separate worker thread is a good workaround.