Hi everyone. I have a Boron transmitting data for a weather station at a remote paragliding site. The Boron operated continuously from May 25th 2024 to August 9th 2024, when it went offline. I went to the site and inspected it - it was still on and running. I swapped the Boron for a new one because I assumed that something was wrong with it. The new Boron transmitted data for 3.5 hours before going offline as well.
I am unsure of how to troubleshoot this issue. I don't think my Boron is banned from the network because it is only transmitting data every 8 minutes. What I want to get feedback on first is whether there's a problem in the code I wrote for handling reconnections. Here it is:
#include "Particle.h"
#include <algorithm>
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
const int ULP_SLEEP_TIME_MS = 8 * 60 * 1000;
void ulpSleep(int durationInMs) {
systemSleepConfig.mode(SystemSleepMode::ULTRA_LOW_POWER)
.duration(durationInMs)
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
System.sleep(systemSleepConfig);
}
void sleepIfBatteryChargeIsLow() {
while (true) {
batteryStateOfCharge = System.batteryCharge();
Log.info("Battery: %2f", batteryStateOfCharge);
if (batteryStateOfCharge > 10 || batteryStateOfCharge < 0) {
// We have enough battery to operate.
// System.batteryCharge() returns -1 when battery state cannot be determined.
return;
} else {
Log.info("Battery low. Going to sleep.");
ulpSleep(ULP_SLEEP_TIME_MS);
}
}
}
void setup()
{
sleepIfBatteryChargeIsLow();
// ... Setup things for sampling the weather sensors.
// Connect to the Particle cloud so the Boron's clock is accurate.
if (Particle.connected() == false) {
Log.info("Connecting to Particle Cloud.");
Particle.connect();
if (waitFor(Particle.connected, 100000)) {
Log.info("Connected to Particle Cloud.");
} else {
Log.info("Failed to connect to the Particle Cloud.");
}
}
}
void loop()
{
sleepIfBatteryChargeIsLow();
// Sample weather sensors for 8 minutes.
// Then we transmit the data:
if (Particle.connected() == false) {
Log.info("Connecting to Particle Cloud.");
Particle.connect();
if (waitFor(Particle.connected, 100000)) {
Log.info("Connected to Particle Cloud.");
} else {
Log.info("Failed to connect to the Particle Cloud.");
// We don't try to send the data since the connect failed.
return;
}
}
// kd = Kaaikop Data
bool success = Particle.publish("kd", jsonArrayOfWeatherReadings, PRIVATE, WITH_ACK);
Log.info("Publish result: %d", success);
}
The code basically does the following:
- During setup, connects to the particle network. It's ok if we fail to connect.
- During the loop, we sample the weather sensors for 8 minutes, then we try to transmit the data. It's ok if we fail to transmit the data, we just move on to the next 8 minute block of sampling and try again.
Am I making a mistake that could cause my Boron to end up stuck and not try to reconnect?
Thank you all for your time.