Hello,
I have searched high and low for an answer sadly to no avail, so my appologies if this has been answered.
I have a boron 2g/3g that I am trying to get working in SEMI_AUTOMATIC mode. The unit simply will not go past green flashing light stage when running the code. If it is put into magenta mode it connects within seconds, so I deduce there is no problems with the cloud or cellular.
6 moths ago I found a work around for earlier firmware:
if (publish = true){
Cellular.on();
Cellular.connect();
if (waitFor(Cellular.ready, 60000)){}
Particle.connect();
if (waitFor(Particle.connected, 60000)){}
This doesnt seem to do the job anymore (2.0.1 & 3.0.0-rc1). Neither does just Particle.connect()
I’m hoping there’s a resolution, I understood this was an open issue a while back. I really do not wish to spend another day trying to bodge another workaround.
here you are assigningtrue and not checking for == true.
We also don’t know how frequently this part of your code is called. Doing it too often while a previous attempt is still ongoing may actually prolong or even hinder the process.
For that a cellular connection may take longer than 60 seconds to be established and hence Particle.connect() may come to early. Hence you should allow for up to 300 seconds (5 minutes) for Cellular.connect() after that Particle.connect() should not take much longer than 30 seconds max.
Neither do we have any idea what your other code may contribute to the issue.
BTW, you won’t need a “dummy condition” if() {} around a waitFor(). If you are not interested in the result, you can just call it without ever catching the result.
However, in your code flow Particle.connect() only makes sense once the previous waitFor() actually worked out true, so you should put that part of your code inside the conditional block.
Thankyou for the quick response. I can confirm I am a numpty, having sat down and gone through it.
Sorry for the terrible code, I was getting myself in a muddle yesterday with memories of the past. I get very anxious going near Particle these days.
For anyone struggling this code seems to work well:
Cellular.connect();
waitFor(Cellular.ready, 180000); //Apparently this can take as long as 180000 (180secs)
digitalWrite(D7, HIGH);
Particle.connect();
waitFor(Particle.connected, 60000);
Particle.publish("Hour", String(Time.hour()));
Notes: The Cellular wait for is not vital but it does seem to connect quicker with it. WaitFor or WaitUntil work. You do need to wait for the particle connected otherwise the publish does not seem to work.
Just to clarify, that 180sec doesn't mean this call will take that long. If the connection can be established in less than this, that's when the waiting ends, but it's not allowed to take any longer before the waiting ends and your code should address it.
Hence I'd suggest you do something along this line of thought
Cellular.connect();
if (waitFor(Cellular.ready, 180000)) { // wait up to 180secs for a cell connection
digitalWrite(D7, HIGH);
Particle.connect();
if(waitFor(Particle.connected, 60000)) {
char h[4];
snprintf(h, sizeof(h), "%02d", Time.hour());
Particle.publish("Hour", h);
}
else {
Log.warn("Particle.connect() failed");
Particle.disconnect(); // prevent further connection attempts for the time being
}
}
else {
Log.warn("Cellular.connect() failed");
Cellular.disconnect(); // prevent further connection attempts for the time being
}