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?
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() {
}
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.
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() {
}