# Electron time sync failure

**URL:** <https://community.particle.io/t/electron-time-sync-failure/21175>\
**Category:** Cloud\
**Created:** [March 17, 2016, 5:43pm UTC](https://community.particle.io/t/electron-time-sync-failure/21175 "2016-03-17T17:43:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rryansilva](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rryansilva/32/9320_2.png) [@rryansilva](https://community.particle.io/u/rryansilva)\
**Post date:** [March 17, 2016, 5:43pm UTC](https://community.particle.io/t/electron-time-sync-failure/21175/1 "2016-03-17T17:43:24Z")

</div>

I have encountered a strange condition when attempting to sync time: one Electron does not sync correctly – I get a November 30, 1968 date from the cloud, but all other functions appear to work correctly. But when I run the same code on a _different_ Electron, I get the correct date and time and everything functions as expected.

The code in question is:

```
void setup()
{
     Serial.begin(57600); // Begin the Serial interface
    
     Serial.print (F("Hidrosonico online. Version "));
     Serial.println (VERSION);
    
     pinMode (PULSEPIN, INPUT); // Sonar pulse width pin

     if (Particle.connected() == true)
     {
          Serial.println(F("Connected to Particle Cloud."));
     }
     else
     {
          Serial.println(F("Not connected to Particle Cloud."));
     }
    
     unsigned int timeout = millis() + timeoutInterval;
     while (Time.year() <= 1970 && millis() <= timeout)
     {
          Particle.syncTime();
     }
    
     if (Time.year() <= 1970)
     {
          Serial.println(F("syncTime timed out; time is wrong."));
     }
    
     Particle.publish ("startup", VERSION, PRIVATE);
    
     Time.zone (UTCOFFSET); // Set the local time zone
    
     Serial.println (Time.timeStr()); // Print the time to Serial for confirmation
    
     Cellular.off(); // Turn the GSM module off to save power
     RGB.control (true); // Take control of the LED
     RGB.color (0, 0, 0); // Shut off the LED to save power
    
     Serial.println(F("Setup complete."));
 }

```

This seemed to start happening at about the same time that the malfunctioning unit went over 1MB usage, though I cannot say whether this is related.

Any insights welcomed.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 18, 2016, 6:58am UTC](https://community.particle.io/t/electron-time-sync-failure/21175/2 "2016-03-18T06:58:52Z")

</div>

Not directly addressing your issue, but you should not call `Particle.syncTime()` inside that loop, rather call `Particle.process()` instead.  
I fact you don’t need to call `Particle.syncTime()` at all in `setup()` as it is called by default during startup.

Since you don’t show your full code, I have to assume you are using default AUTOMATIC mode, hence I’d expect that your code will never start running unless your device got cloud connected, or have you ever seen a `"Not connected"` message?

BTW:  
In this environment the `F()` macro does absolutely nothing, so you can just leave it out 😉

---

<div class="post-metadata">

**Author:** ![rryansilva](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rryansilva/32/9320_2.png) [@rryansilva](https://community.particle.io/u/rryansilva)\
**Post date:** [March 19, 2016, 1:09am UTC](https://community.particle.io/t/electron-time-sync-failure/21175/3 "2016-03-19T01:09:49Z")

</div>

Thanks for that. I called `Particle.syncTime()` only because I was having trouble with pulling the correct time, and there were some older references to this as a solution to that problem. I am indeed using the default Automatic mode.

And thanks for the tip on Flash strings; I noticed that some of the code I ported over from the Arduino compiled with the `F()`, so I wondered if it was a thing on the Particle platforms and couldn’t find anything in the documentation.
