Bug Bounty: Electron not booting after battery discharges completely

@BDub I have a quick coding question for a Solar Powered Electron I’m testing.

I let the Electron run until there was cloudy day and the batteries PCM cut the output off to Electron to protect the battery from over discharging.

The next day when the sun came back out the red PCIM led lit up to indicate it was charging but the Electron gets stuck in a state where the main LED is White and never recovers and starts running again. I can hit the reset and mode buttons a few times and eventually it will recover and my code starts working again.

I’m thinking the easiest way to prevent this from happening is to put the Electron to sleep when the Battery SOC hits something like 20% which will keep the Electron properly sleeping until it’s solar charged above 20% again when the sun comes out the next day.

I ended up just writing this code to prevent the Electron from connecting to cellular network unless the battery SOC is above 20%. Let me know if you see any obvious ways to improve it.

I ended up not putting the fuel gauge to sleep because it caused the fuel gauge SOC level to make sudden jumps in SOC when it’s turned OFF and ON. I saw lower sleep power consumption when not putting the fuel gauge to sleep for some reason also.

I’m only sending data to Ubidots and not connecting to the Particle Cloud in this test which makes sending data to Ubidots super quick and I only see the system awake to publish for 1 second every time it wakes up. Connecting to the Particle Cloud usually takes much longer even when using SLEEP_NETWORK_STANDBY

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"

#define TOKEN "YourToken#"  // Put here your Ubidots TOKEN
#define DATA_SOURCE_NAME "ElectronSleepNew"


Ubidots ubidots(TOKEN); // A data source with particle name will be created in your Ubidots account


int button = D0; 
int ledPin = D7;              // LED connected to D1
int sleepInterval = 60;


void setup() {
 //Serial.begin(115200);
 pinMode(button, INPUT_PULLDOWN);    // sets pin as input
 pinMode(ledPin, OUTPUT);    // sets pin as output

 ubidots.setDatasourceName(DATA_SOURCE_NAME);
 
 PMIC pmic;
 //set charging current to 1024mA (512 + 512 offset)
 pmic.setChargeCurrent(0,0,1,0,0,0); 
 pmic.setInputVoltageLimit(4840);    
}

void loop() {
    
FuelGauge fuel;
 
    
if(fuel.getSoC() > 20)
  {
   
   float value1 = fuel.getVCell();
   float value2 = fuel.getSoC();
   
  ubidots.add("Volts", value1);  // Change for your variable name
  ubidots.add("SOC", value2);

  Cellular.connect();
  Cellular.ready();
  
  ubidots.sendAll();;

  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(250);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(250);                  // waits for a second
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(250);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  
  System.sleep(D0, RISING,sleepInterval * 2, SLEEP_NETWORK_STANDBY);
    
  }
  else
  {
      
  Cellular.on();
  delay(10000);
  Cellular.command("AT+CPWROFF\r\n");
  delay(2000);
  //FuelGauge().sleep();
  //delay(2000);
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(150);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(150);                  // waits for a second
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(150);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(150);
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(150);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(150);                  // waits for a second
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(150);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  System.sleep(SLEEP_MODE_DEEP, 30);
  }
    
}