Boron Sleep Method for Hourly Wake

Hello,

I need my boron to wake up frequently (every 1-2 hours) and send out data. Is this the best approach in terms of saving battery and re-establishing cellular connection?

SYSTEM_MODE(MANUAL);

void sleep(){
Serial.println(); // for formatting
Serial.println(“going to sleep”);
Serial.println("\n");
SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
.gpio(WKP, RISING)
.duration(60min);
System.sleep(config);
}

doInternetStuff(){
// do inerternet stuff
sleep();
}

void cellular(int humidity, int temperature, int fourInchMoisture, int eightInchMoisture,int solar){
//Cellular.off();
Cellular.on();
delay(2500); //give cellular module time to initialize
Cellular.connect();
delay(1000);

while(Cellular.connecting()){
Serial.println(“attempting lte connection…”);
delay(1000);
for (int counter = 0; counter < 30; counter++) {
Serial.println(“attempting cellular connection…”);
delay(1000);
if(Cellular.ready()){
Serial.println(“successfully obtained cellular connection”);
Serial.println(); //for formatting
doInternetStuff();
}
else {
//
}
}
Serial.println(“lte connection taking too long…going to sleep to conserve battery”);
}
sleep()
}

Any help is appreciated!

I’d recommend keeping it in Automatic mode and letting sleep take care of shutting down the modem.
Stop mode sleep with the default code should do what you need.
Take measurements, publish, and go to sleep.
As of DeviceOS 2.x this works really well.

Is there a way to prevent it from talking to the particle cloud (there’s no need for it in the current application) in automatic mode? Is my understanding of automatic mode correct that

void myCode(){
}

void setup(){
}
void loop(){
}

are blocked from execution until cellular connection is established?

In all modes - when the device is connecting to the cloud, the user app is blocked.
You can however turn on threading which will allow your code to continue running.
See
Particle System Thread and especially AN005 Threading Explainer | Datasheets | Particle.

Semi-Automatic would work as well if you need to do things while the device is offline - for example waking every 5 minutes to collect data before connecting on the hour to publish the gathered data.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.