Small data storage on Electron

trying to wrap my head around data storage. I have a string that will publish, but what if there is no connection to the cloud at the time. I would like to store the data temporarily (without overloading the heap). it seems the EEPROM storage would work, but I cannot find an example I can understand. I am logging data from the assettracker and publishing every 2 minutes the vehicle is moving. Due to the cellular signal in my area, i may need up to 10 (20 min) of data stored and sent out when particle connects again. Each string is roughly 80 bytes.

    // begin code 
    if(Particle.connected()) {             
                  lat = (t.readLatDeg());
                  lon = (t.readLonDeg());
                  speedKnots = t.getSpeed(); 
                  speedMph = speedKnots*1.151;
                  if(speedMph < 2.5) { 
                  speedMph = 0; }
                  Pconn = "yes";
                  devHour = Time.hour();
                  devMin = Time.minute();
                  devSec = Time.second();
              devYear = Time.year();
              devMonth = Time.month();
              devDay = Time.day();
            char data[256];
            snprintf(data, sizeof(data), "{%f,%f,%.2f,%.2f,%s,%i,%i,%i,%i,%i,%i,%i,%s}", lat, lon, speedMph, fuel.getVCell(), devicepre , unitId, devHour, devMin, devSec, devYear, devMonth, devDay, Pconn);
            Particle.publish("CELL", data, PRIVATE);
            lastPublish = millis();
            lastPubSpeed = speedMph;
            pubOffset = 0;
            increaseTime = 0;
                     } else {
              lat = (t.readLatDeg());
              lon = (t.readLonDeg());
              speedKnots = t.getSpeed(); 
              speedMph = speedKnots*1.151;
              if(speedMph < 2) { 
              speedMph = 0; }
              Pconn = "no";
              devHour = Time.hour();
              devMin = Time.minute();
              devSec = Time.second();
              devYear = Time.year();
                  devMonth = Time.month();
                  devDay = Time.day();
                       //SD is Saved Data
                       if(SD < 10) {
        // the problem with this is you would only the last string that wasn't published or the 10th depending how long service wasn't avail
                      SD=SD+1;
                      char data[256];
                      snprintf(data, sizeof(data), "{%f,%f,%.2f,%.2f,%s,%i,%i,%i,%i,%i,%i,%i,%s}", lat, lon, speedMph, fuel.getVCell(), devicepre , unitId, devHour, devMin, devSec, devYear, devMonth, devDay, Pconn);
                    Sdata = data;
                    lastPubSpeed = speedMph;
                    lastPublish = millis();
                    pubOffset = 0;
                    increaseTime = 0;
                   }

    // now i need some sort of a way to break up the individual data stored and send them in intervals when the cloud is connected. 
               if(SD>0 && Particle.connected() {
                  for(int d=1;d<SD;d=d++) {
                /* still i have only one string to send , i have tried Sdata[d] but i     don't think that is anywhere close to    being correct. in PHP I can parse a large string by delimitators, but i cannot figure that out in c++   i tried adding Sdata = Sdata + " : " + NewData , something similar i have tried a lot of different things  */
                 char data[256];
                 snprintf(data, sizeof(data), Sdata);
                 Particle.publish("CELL", data, PRIVATE);
                 delay(2000); // could delay longer here

                 }
                SD=0;
                 }            
               // end code 

any help is very much appreciated

Check out this library :slight_smile:

Does " publishManager.publish(“pubData”,data); " have to be called in setup() ? or is that just for examples to add to the cashe before connecting?

in the loop() should I call for " Particle.publish(“pubData”,data); " or " publishManager.publish(“pubData”,data); " ?

From the library read me " A Particle library for managing your Particle.publish() events. Store’s your Particle.publish() events while you’re offline and makes sure you don’t exceed the maximum publish rate of 1/second by caching Particle.publish() events.
PublishManager implements a First-In-First-Out (FIFO), circular buffer so that Particle.publish()'s are published in the same order they are created and if you aren’t generating publishes faster than 1/second, publish events will be sent at the same time they are created. "

Thanks!!

The calls in setup() are just for illustration and of course you need to call publishManager.publish() in order to have the manager manage the publishes, if you call Particle.publish() the event will be sent “unmanaged” - the library won’t change the behaviour of the stock functions (that would be a potential security risk).