Particle.connected()
is a class function/method not a class field.
Hence you are missing the parenthesis in if (Particle.connected)
. This way you just “check” whether the function exists, but don’t acutally call it.
You need to write it as if (Particle.connected())
But I’d rather go with this
Particle.connect();
if (waitFor(Particle.connected, 60000)) {
digitalWrite(D7, HIGH);
delay(2000);
Serial.printlnf("Connected to Particle Cloud.");
Serial.printlnf("Start synchronization.");
Particle.syncTime();
waitUntil(Particle.syncTimeDone);
if (Time.isValid()) {
Serial.printlnf("Time is valid.");
}
else {
Serial.printlnf("Time is still invalid.");
}
// Print current time
Serial.println(Time.timeStr());
}
else {
Serial.println("Not yet connected");
delay(1000);
}
We can’t see the context of your code snippet, but if you’d call Paticle.connect()
over and over while a connection attempt is still ongoing, you may be interfering with the actual connecting.