Storing and send the info requested

Does anybody did something like I’¡m imagining?

For example I have an electron in the middle of nothing, powered by solar pannel. I take some temp measures every 15min, but a problem happens:
1º In order to save power and data, is it possible to store the last 3 measures and when reach the number 4, send the 4 last measures?

2º If temp is for example -4º not wait and send the info now! and the stored ones?

Thank’s

Eduard

That’s actually the recommended way to save both power and data. So yes, both are possible, now you just have to code it :wink:

1 Like

Hi,

Thank you very much, anybody did it or have an example? it’s just to see the way to go…I’m not a developper :-s

Thank’s again

you can find a few examples from doing a google search, here is one from the particle documentation,
https://docs.particle.io/guide/getting-started/examples/electron/#electron-combined-publish

Hi @dkryder

Thank’s for your guide, this help to me

Regards from Barcelona

Eduard

The docs do also have a dedicated search feature which will provide you with hits that will be better targetted than a general Google search :wink:

Hi Guys
I did the following script to store the info and after 5th reading send a string to particle.

But how could I do:

1º I want to sleep the machine and store the Variable i (counter) and the temp array into the internal memory.
2º After wakeup, retreive the counter (i) and do the loop again.

thank’s again guys

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_BMP280.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

Adafruit_BMP280 bmp; // I2C
int temp[5];

// The variable we'll use to keep track of where we are in the array
int i = 0;

void setup() {
Time.zone(+2); 
bmp.begin();

       temp[i] = bmp.readTemperature();

if(i == 4){

            Particle.publish("L", String::format("%d,%d,%d,%d,%d", temp[0],temp[1],temp[2],temp[3],temp[4]));
            // Reset index to 0
            i = 0;
        }
        else {
            // increase the index by 1
            i++;
            
        }

/////////////////////////Sleep for 15 minutes to save battery/////////////////////////
System.sleep(SLEEP_MODE_DEEP, 15 * 60);    
}
void loop() {
}

Retained variables would be your easiest option, with EEPROM being the alternative. Have a look at those in the docs :slight_smile:

2 Likes

Meaningful indentation of your code would be nice too :wink:

1 Like

@Moors7 soo let’s go to read, thank’s
@ScruffR I’m sorry, I’not a developer I’m a finance man :stuck_out_tongue:

1 Like

yes, that is very true. but i find that the search in the particle docs works best for specific terms and google works best for hazy terminology. for instance using google search “particle electron save recorded data to send later?” and you get this,
https://goo.gl/jGVf8k
the 2nd hit returned was what i used and then did not look any further since it was not important for my use case at the time.
enter the same terms into particle doc search and it returns nothing found in this case and sometimes in other cases way too many hits that are not relevant.
i realize that more specific search terms in the particle search would yield better results but in the OP case they may not have known what specifically to search for. i find google more forgiving if i do not have specific search terms rather general concepts.

2 Likes

Hi all,

After several hours reading and practising with my code I’m really impressed about retained variables. I implemented the retained in my code, but I’m doing something wrong.
It restarts after sleep correctly but did not publish after 5 readings, anybody could help me where is my mistake?

Thank’s again

Eduard

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_BMP280.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

Adafruit_BMP280 bmp; // I2C
int temp[5];

// The variable we'll use to keep track of where we are in the array
retained int counter = 0;

void setup() {
  Time.zone(+2);
  bmp.begin();

  temp[counter] = bmp.readTemperature();

  if (counter == 4) {

    Particle.publish("L", String::format("%d,%d,%d,%d,%d", temp[0], temp[1], temp[2], temp[3], temp[4]));
    Particle.publish("retained", String(counter));
    // Reset index to 0
    counter = 0;
  }
  else {
    // increase the index by 1
    counter++;
    Particle.publish("retained", String(counter));

  }

  /////////////////////////Sleep for 15 minutes to save battery/////////////////////////
  System.sleep(SLEEP_MODE_DEEP, 1 * 60);
}
void loop() {
}

If you are not using an Electron or 0.7.0-rc.3 on your Photon you need to add a delay(5000) before going to sleep to ensure successful delivery.

And I’d also check for (counter >= 4) and use retained unsigned int counter; just in case.
Your temp[] wants to be retained too, I guess.

1 Like

Hi @ScruffR

Now the code is working perfect, thaaaaank you very much :slight_smile:

Best Eduard

1 Like