I’ve got some Electron in weak cellular connection area that sometimes they stop send data.
I’ve same hardware / software at home and it runs very well for weeks / months, then my conclusion is that I have something wrong managing the connection to the cellular / cloud.
In the latest code I’ve put all the data sent by http directly instead event on the cloud, but after a while it stops anyway.
When I’ve got the chance to have a look on the device sometime is flashing green sometime is off.
I am running in semi-automatic mode and this is the main loop. Any suggestion?
void loop() {
// Check cellular connection
if(!Cellular.ready() && !Cellular.connecting()) {
printLog("Cellular not ready, trying to connect..");
Cellular.connect();
delay(500);
printLog("Now is " + Time.timeStr());
}
// Check particle connection
if(!Particle.connected() && Cellular.ready()) {
printLog("Not connected, trying to connect..");
Particle.connect();
delay(1000);
Particle.keepAlive(30);
}
// Collect wind speed every 10 seconds and compute gust
if(millis() - windMillis >= 10000) {
windMillis = millis();
float _windSpeed = readWindMPH();
if (_windSpeed > windGustMPH) windGustMPH = _windSpeed;
printLog("Wind reading value [" + String(_windSpeed) + "] - gust value [" + String(windGustMPH) + "]");
}
// Go sleep 4 seconds (2 loop cycles) after publishing
if (publishMillis > 0 && (millis() - publishMillis >= 4000)) {
printLog("Publish done, go sleep");
sleep();
}
int _nowMinute = Time.minute();
// Routines when connected and never published
if(Cellular.ready() && publishMillis == 0) {
// Publish interval
if(_nowMinute == 0 or _nowMinute % publishInterval == 0) {
publishMillis = millis();
printLog("Ready to publish...");
httpPublishRoutine();
thingSpeakPublishRoutine();
}
// Force publish after 2min sec of run
if(millis() - runMillis >= 2*60*1000) {
publishMillis = millis();
printLog("Two minutes publish watchdog");
httpPublishRoutine();
thingSpeakPublishRoutine();
}
}
// Force reset after 5 minutes of run
if(millis() - runMillis >= 300000) {
printLog("Ten minutes running force reset");
System.reset();
}
printLog("Loop cycle");
delay(2000);
}