Every now and then my electron freezes up and I want to use watchdog to restart the device. However, every time I implement watchdog I lose all my functions, I lose connection to the cloud and my electron stop sending GPS coordenates (I’m using Asset tracker).
Two things I see at first glance. Your variable lastPublish is declared as long… it should be unsigned long. I believe the default declaration would be a signed long and may cause issues. Also, can you move your function declarations to the top of the setup? There was another thread recently about declaring variables and functions as soon as possible in the setup.
I don’t see your implementation of the watchdog in this code.
Also, the use of Strings could lead to stack corruption as @ScruffR is always reminding people, which could lead to lockup after some time.
snprintf(buffer, sizeof(buffer), "%s,%d,%d", (const char*)t.readLatLon(), 0, iBikeBatValue);
Particle.publish("AWSTEST", buffer, PRIVATE); //Aqui mandamos el estado de la bateria y la localizacion
This should do the same thing with less effort and risk for heap fragmentation.
Apart from the superfluous action to “concatenate” to an empty string and append another empty string at the end.
And snprintf() is the way to go with all these other String instances too.
Also, you appear to be using a 3rd-party SIM card, but are not setting the keepAlive value. This will almost certainly cause problems.
I’m not sure what the value is for AT&T in Mexico, but for AT&T in the United States it’s 30 seconds. If you don’t set the keepAlive, you’ll be unable to use functions, variables, subscribe, and OTA code flash reliably.
No, as long as you are publishing with a period less than the keepAlive you don’t need to set it.
However, if you don’t have a GPS fix you won’t be publishing, so would lose your cloud connection until you got a GPS fix again in that case. There’s really no downside to setting the keepAlive; they are only transmitted if needed, so in your case they would rarely be needed but it’s good to have it set just in case.