Store data in an array on the Electron


I’m using an electron and I would like to read 4 times a sensor per hour and store inside the Electron. After 4 times, send the 4 readings to the server.

Anybody knows how is possible to do that?

Thank’s in advance

The actual question is: “Why should it not work?”

What have you tried?

Hi ScruffR,

May be I did not explain correctly. My question is, if somebody did it and if somebody could show me an example…because I have not idea how to store data and how to extract to publish later.


What exactly are you intending to do with your devices?
Will you send it to deep sleep or only stop mode sleep between measurements?
Will there be a risk of battery loss?
How important will the last readings be in case of battery loss?

The answer to these fundamental questions greatly impact the way to go


Sorry about my poor explanation.

1º The electron wakes up
2º Read the sensors
3º Deep sleep till 15 minutes

Now I’m publishing after every read process, the problem what I have is the batt life. Maybe if I read, store and publish every hour not every quarter maybe the batt will be up more time

See attached the code

void setup() {

if ((Time.hour() >= 05) && (Time.hour()  <= 22) && (Time.weekday() != 1))
            digitalWrite(D4, HIGH);
            //Reading Temperature Fresh
            double tempeatureFresh = sensor.celsius();
            digitalWrite(D4, LOW);
            //Reading Temperature Frozen
            digitalWrite(D5, HIGH);
            double temperatureFrozen = sensor2.celsius();
            digitalWrite(D5, LOW);
            //Reading battery level
            FuelGauge fuel;
            float batt;
            batt = fuel.getVCell();
            //Publishing Json to Particle
            sprintf(publishString,"{\"tempeatureFresh\": %.2f, \"temperatureFrozen\": %.2f, \"batt\": %.2f}",tempeatureFresh,temperatureFrozen,batt);
            // Sleep for 15 minutes to save battery
            System.sleep(SLEEP_MODE_DEEP, 15 * 60);

    if ((Time.hour() >= 0) && (Time.hour()  <= 5) )    
    int tWake = 5*3600 + 0*60 + 0;
    int tNow1 = Time.local() % 86400;
    int secondwakeup1= tWake - tNow1;
    //Serial.println("entre 00 y 05");
    System.sleep(SLEEP_MODE_DEEP, secondwakeup1);
    int tend = 86400;
    int tNow2 = Time.local() % 86400;
    int secondwakeup2= (tend - tNow2)+18000;
    //Serial.println("entre 22 y 24");
    System.sleep(SLEEP_MODE_DEEP, secondwakeup2);

First, you seem to be missing pinMode() for your pins.

And to store your values across deep sleeps, you’d most comfortably use retained variables


retained double values[4] = { 0.0, 0.0, 0.0, 0.0 };

After that you can just store the values in the array which will stay unchanged as long the device can keep the Backup RAM powered.

1 Like