Electron - Long Term Solar Charging Uptime Testing

I disabled System Threading so that means I no longer need to call this code before going into:

System.sleep(SLEEP_MODE_DEEP, 3600); to get the cellular modem to turn off right?

  Cellular.on();
  delay(10000);
  Cellular.command("AT+CPWROFF\r\n");
  delay(2000);
  //FuelGauge().sleep();
  //delay(2000);

Putting a new Electron outside now with the new code to see how that goes :smiley:

1 Like

@Bdub FYI - I am seeing the AT Commands on the serial debug logs with only putting this line of code above setup(); :

SerialLogHandler logHandler(LOG_LEVEL_ALL);

That is unless the Electron comes with Tinker preloaded :smiley:

I manually flashed 0.6.1_RC.1 with no Tinker firmware via the CLI.

1 Like

@BDub Quick update :smiley:

I set up a new Electron + New 2000 mAh battery using the firmware posted below and now I’m seeing no problems with the unit reconnecting to the cellular network after sleeping although so far I have not been in deep sleep mode for more than 12 hours yet. Before once I hit 20% SOC and went into deep sleep it would not connect again.

Looking at the voltage & SOC plotting below you can see it shuts off at 20% SOC and turns back on as the battery voltage rises above 20%.

One thing to note is that the battery charging is allowed even though the outside temp is 8F. That is fine with me since it keeps the unit charged and online but not sure how this will affect battery life.:

It also looks like this new Electron is allowing charging currents above the 100 mA threshold since charging is happening much quicker than with the other unit. My firmware sets the charging current to 1 Amp but this Electron seems to hold the 1 Amp charging rate where the other unit did not.

All is good now, it looks like there may have been issues with the other Electron even though it did work most of the time.

For others here is the code I ended up using so far for my solar charging project.


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

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

SerialLogHandler logHandler(LOG_LEVEL_ALL);  //This serial prints system process via USB incase you need to debug any problems you may be having with the system.

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


int button = D0;         // Connect a Button to Pin D0 to Wake the Electron when in System Sleep mode. 
int ledPin = D7;         // LED connected to D1
int sleepInterval = 60;  // This is used below for sleep times and is equal to 60 seconds of time. 


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); //This name will automatically show up in Ubidots the first time you post data. 
 
 PMIC pmic; //Initalize the PMIC class so you can call the Power Management functions below. 
 pmic.setChargeCurrent(0,0,1,0,0,0); //Set charging current to 1024mA (512 + 512 offset)
 pmic.setInputVoltageLimit(4840);   //Set the lowest input voltage to 4.84 volts. This keeps my 5v solar panel from operating below 4.84 volts.  
}

void loop() {
    
FuelGauge fuel; // Initalize the Fuel Gauge so we can call the fuel gauge functions below. 
 
    
if(fuel.getSoC() > 20) // If the battery SOC is above 20% then we will turn on the modem and then send the sensor data. 
  {
   
   float value1 = fuel.getVCell();
   float value2 = fuel.getSoC();
   
  ubidots.add("Volts", value1);  // Change for your variable name
  ubidots.add("SOC", value2);    

  Cellular.connect();  // This command turns on the Cellular Modem and tells it to connect to the cellular network. 
  
   if (!waitFor(Cellular.ready, 600000)) { //If the cellular modem does not successfuly connect to the cellular network in 10 mins then go back to sleep via the sleep command below. After 5 mins of not successfuly connecting the modem will reset.  
    
    System.sleep(D0, RISING,sleepInterval * 2, SLEEP_NETWORK_STANDBY); //Put the Electron into Sleep Mode for 2 Mins + leave the Modem in Sleep Standby mode so when you wake up the modem is ready to send data vs a full reconnection process.  
    
}  
  
     ubidots.sendAll(); // Send fuel gauge data to your Ubidots account. 

     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); //Put the Electron into Sleep Mode for 2 Mins + leave the Modem in Sleep Standby mode so when you wake up the modem is ready to send data vs a full reconnection process.  
    
  }
  else //If the battery SOC is below 20% then we will flash the LED 4 times so we know. Then put the device into deep sleep for 1 hour and check SOC again. 
  {
      
  //The 6 lines of code below are needed to turn off the Modem before sleeping if your using SYSTEM_THREAD(ENABLED); with the current 0.6.0 firmware. It's a AT Command problem currently. 
  //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);                   // 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);                   // 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, 3600);  //Put the Electron into Deep Sleep for 1 Hour. 
  
  }
}    
1 Like

That’s good to hear @RWB. Was the other electron a beta unit by any chance?

Also your code example is a good one, but the forum is butchering code these days pretty badly (it’s driving me nuts, maybe we need to upgrade Discourse). Until then I added your code to a Gist and reformatted some of the comments so it’s a little more clear.

I do not think it was a beta unit because it has the white silkscreen on the side of the pins to identify what each pin is.

I’ll give an update again once we have some more cloudy weather that puts the device into sleep mode for at least 24 hours before the solar panel brings the battery back above 20%.

1 Like

@BDub The Electron has been plugging along for weeks now running off solar during good and inclement weather. It’s been going into deep sleep and waking up every hour until sunny weather charges the battery back up above 20%.

Today is the first day I saw the Electron get into a stuck state where the LED was stuck in the breathing green and would have stayed there until the battery was empty which is not good.

I have event logging turned on so I plugged it into my laptop to see if I could see the cause for the stuck breathing green state but zero output since it was stuck. It was in the breathing green state for many hours and I just left it to see if it would fix itself before I picked it up.

I decided to add the Watchdog Timer code to my app to hopefully fix this if it ever happens again.

I used this code and set the Watchdog Timer to 11 mins since the cellular connect code resets the modem after 5 mins of failed cellular attempts and this happens 2 times I believe.

Is this watchdog code OK for what I’m trying to do?

ApplicationWatchdog wd(660000, System.reset);

I was able to bring the stuck Electron with the breathing green LED back to a working state after hitting the reset button and then holding the mode button down to get into SAFE mode to then update the firmware over cellular.

Any advice is appreciated :smiley:

@RWB, the topic is about cold weather so your post may not be appropriate here. Perhaps you should start a new topic. Nonetheless, the Application Watchdog relies on FreeRTOS running so if that fails, it will not work. You will need to test. :wink:

If the Led is still breathing does that mean the processor is still running?

@RWB, yes, if the LED is breathing the processor and FreeRTOS should be running.

Sweet, that’s the condition I got stuck in for some reason. Watchdog should work then :smiley:

@RWB, as long as the part of your code that refreshes the WD timer doesn’t run, it will trigger the reset.

Working on getting the Electron code to a point it can be left in a remote location for years without needing human interaction to reset it.

1 Like

Any news on the ruggedised / industrial version of the Electron?