Electron: SLEEP_MODE_DEEP - wake up and not reestablish network

I want to wake up the electron every hour from deep sleep to measure the ambient temperature, and store that in a retained variable. However, the data should be only send once per day. In order to save battery, the electron should reestablish after wake up only once per day the network connection. Is there any method not having the cellular switching on automatically after a wake up from deep sleep?

Yes, you would need to use SYSTEM_MODE(SEMI_AUTOMATIC);

Then you will need to call your connection to the cellular network manually in your code using these commands:

Cellular.connect();
Cellular.ready();

Here is example code I use to send data to Ubidots using the Electron:

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

#define TOKEN "1234567890"  // 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;
int cellularConnectFails = 0;

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();
  
   if (!waitFor(Cellular.ready, 60000)) {
       
    cellularConnectFails = ++
      
    System.sleep(D0, RISING,sleepInterval * 2, SLEEP_NETWORK_STANDBY);
}
  
     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, 3600);
  }
    
}    
    
3 Likes

@blub you can use SYSTEM_MODE(MANUAL) or SYSTEM_MODE(SEMI_AUTOMATIC).

Here’s an example of exactly what you want to do with a minimal amount of code. You would want to use Particle.connect() and waitFor(Particle.connected, 300000) in either mode if your end goal is to use Particle.publish().

1 Like

Thanks!