Boron sleep modes appear unreliable

Basic loop is below. What I am experiencing after about 24hours the Boron no longer reliably wakes up from stop mode. I can’t find any documentation to whether or not it is the boron at fault or something else. In the mean time I have added a xenon as a quick and dirty external watchdog.

SYSTEM_MODE(SEMI_AUTOMATIC);

//web variables
#define SLEEP_INTERVAL 15
ApplicationWatchdog wd(60000, System.reset);

#define DEBUG 0
//state machine
#define SLEEPSTATE  3
#define WAITSTATE   4
#define UPLOADSTATE 5

int state = UPLOADSTATE;

void setup() {
    Particle.connect();
    state = UPLOADSTATE;
}

int count = 0;
void loop() {
	
    switch(state) {
		case UPLOADSTATE: {
			CellularSignal sig = Cellular.RSSI();
			float v = fuel.getVCell();
			float bat = fuel.getSoC();
	        
	        int rssi = -1;
	        if((int)sig.rssi < -1){
	            rssi = (int)sig.rssi;
	        }
	        
	     	
		
			String json = String::format("{\"0\":%0.1f,\"1\":%d,\"2\":%0.1f}",
				bat,
				rssi,
				v
		    );
		Particle.publish("pub", json, 60, PRIVATE);

			state = WAITSTATE;
			break;
		}
		case WAITSTATE:{
		    if(DEBUG){
	    		Particle.publish(String(state,DEC));
		    }
			delay(30*1000);
			state= SLEEPSTATE;
			break;
		}
		case SLEEPSTATE: {
			float bat = fuel.getSoC();
			
		    if(DEBUG){
	    		Particle.publish(String(state,DEC));
		    }
			else if(bat > 90){
    		    delayWithWD(SLEEP_INTERVAL);
	    	}
    		else{
    			sleepNetwork(SLEEP_INTERVAL);				
    			state = UPLOADSTATE;
    		}
        
		state = UPLOADSTATE;
		}
		default:{
			state = UPLOADSTATE;
			break;
		}
    }
}

void delayWithWD(int sleepMinutes){
    for(int i=0;i<sleepMinutes*2;i++){
        delay(30*1000);
        Particle.process();
        wd.checkin();
    }
    
}

void sleepNetwork(int min) {
	if(min > 0) {
	        pinMode(D8,INPUT);
	        digitalWrite(D8,LOW);
			System.sleep(D8,RISING,SLEEP_NETWORK_STANDBY, min*60); // Does not turn off network
	}
	else{
		delay(30*1000);
	}
}

I have replied on another thread about using long delays in the loop() - it is not a good idea because the device OS really works best when the loop cadence is as high as possible. Try replacing your delay(30*1000); with a timer or a simple timestart = millis(); and a test for millis()-timestart >= 30000 to move control to the next state.

Edit: There was a post about a week or so ago about KeepAlive - there may be something in that you need to consider as well. Try the loop cadence first.

I understand that Ideally a timer comparison is better than using the delay function. But would that affect the Boron not waking from stop mode?

I agree that the Boron should wake after SLEEP_INTERVAL minutes but this is likely due to the state it is in when you call System.sleep(). For example;

You are not waiting for or testing for Particle.connected() before Particle.publish() this could leave the Boron in a bad state and is blocking.

Why are you declaring the pinMode() repeated within your function sleepNetwork() and not in setup().

Are you certain that after System.sleep() that it is not waking on the RTC ? You could test for this?

You could be running out of heap/free memory - I would test for that.

By not waking reliably do you mean it does not continue after the System.sleep() or it does not connect and publish? When running SYSTEM_MODE(SEMI_AUTOMATIC); I have found it necessary to test for a cloud connection and call Particle.connect();

2 Likes

I am thinking I might just use automatic mode. The semi automatic mode was for battery checking left over from electron code. As far as I know the blocking code should fire the application watchdog.

Declaring pinMode and setting the state before sleep is something I was taught to do as part of “best practices” when I am relying on a pin to wake up, I want to be as sure as possible the pin is set correctly.

The system was originally set to allow the rgb to run using Particle’s color commands to know what I was doing. Each time it failed it was still in sleep mode (for hours). Toggling the pin woke it up.

I am using code straight from the demo page. My system firmware says it is 0.9.0. Is it possible something is corrupt? When I try to upload the bootloader from 0.9.0 over the cli I get the error:
unknown module function 2, use --force to override

void setup() {
}

void loop() {	
	//sleepNetwork(SLEEP_INTERVAL);
	Particle.publish("sleep");
    delay(3*1000);
	System.sleep(D1, RISING, 60);
}

Don't use the --force switch without first checking via particle binary inspect <yourFirmware.bin> that this actually is a compatible binary.

1 Like

particle binary inspect bootloader-0.9.0-boron.bin

bootloader-0.9.0-boron.bin
CRC is ok (fb1693a0)
Compiled for boron
This is a bootloader number 0 at version 300

(compiled from build.particle.io targeting 0.9.0)

particle binary inspect firmware.bin

CRC is ok (0d4936c9)
Compiled for boron
This is an application module number 1 at version 5
It depends on a system module number 1 at version 403