How do I update and store GPS variables once a day? [SOLVED]

Hi All. I’m trying to minimise my Electron Asset Tracker V2 GPS power consumption. How do I update and store GPS data/variables once a day?

Initially, I thought of running my Tracker GPS mid-night every day and storing the GPS data in the Electron memory, but I’m not 100% sure how to save non-volatile variables in Electron memory.

Any example code would be much appreciated. Cheers.

@samb375, searching the docs never hurts. Take a look here:

https://docs.particle.io/reference/firmware/electron/#storing-data-in-backup-ram-sram-

https://docs.particle.io/reference/firmware/electron/#eeprom

:wink:

3 Likes

What I do currently (I also obtain GPS data at midnight):

float lat, lng, acc;

int addLat = 100;
int addLng = 105;
int addAcc = 110;

void setup() {

}

void loop() {

EEPROM.put(addLat, lat);
EEPROM.put(addLng, lng);
EEPROM.put(addAcc, acc);

EEPROM.get(addLat, lat);
EEPROM.get(addLng, lng);
EEPROM.get(addAcc, acc);

}

EEPROM.put() stores data in the EEPROM. EEPROM.get() obtains data from the EEPROM. Make sure that the addresses in the EEPROM don’t overlap (i.e. pay attention to the size of each variable). The EEPROM has a size of 2047 bytes. Whatever is stored in the EEPROM remains there even through Deep Sleep or disconnecting power.

or use your structs and handle it all in one put()/get()

const uint16_t EEPROM_LOCATION = 100;

struct LocationInfo {
  double lat;
  double lon;
  double acc;
};

void setup() {
}

void loop() {
  LocationInfo location = { 0.0, 0.0, 0.0};
  EEPROM.put(EEPROM_LOCATION, location);
  //...
  EEPROM.get(EEPROM_LOCATION, location);
}
5 Likes

This is great! Thank you. I will try, and get back to you on how it goes. Cheers

This works perfectly @BulldogLowell Thank you all.

1 Like