Particle Tracker One: Inconsistent Delay and Slow EEPROM Write?

I am currently having 2 issues with the particle tracker one (I used Boron on my previous project and it was a successful project).

---- First Issue: Slow EEPROM Writes ----

Here is the test code:


    // Must call this on every loop
    Tracker::instance().loop();
	
    // EEPROM Test Write
    tempCtr = 0;
    Log.info("EEP Test Write 1");
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);

    tempCtr = 0;
    Log.info("EEP Test Write 2");
// more test code below

Here are the timings:
HH:MM:ss.sss
00:20:55.458 → 0000048501 [app] INFO: EEP Test Write 1
00:20:57.181 → 0000050273 [app] INFO: EEP Test Write 2

Another test:
00:21:17.496 → 0000070611 [app] INFO: EEP Test Write 1
00:21:19.273 → 0000072363 [app] INFO: EEP Test Write 2

It goes past 1 second and for this small set of data, we were actually expecting it to be less than 100 milliseconds.I am wondering about this because on my previous project using the Boron, the EEPROM write is incredibly fast.

Maybe there is a configuration we are missing for the EEPROM write? We are using the tracker edge firmware as the template. This project uses CAN, in case that info matters. But on this examples, no CAN transactions were used.

----- Second Issue: Delay ----


    // Must call this on every loop
    Tracker::instance().loop();


    // EEPROM Test Write
    Log.info("EEP Test Write 1 Start");
    uint8_t tempCtr = 0;
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    EEPROM.write(tempCtr++, tempCtr);
    Log.info("EEP Test Write 1 End");
    delay(5000);

The delay(5000) is inconsistent and sometimes I am seeing a delay of up to 15 seconds on this part.

I created my own delay to replace that:


void DelayMs(uint32_t delayms)
{
    uint32_t recordedmillis = millis();
    while(millis()-recordedmillis<delayms)
    {
        Tracker::instance().loop(); // maybe I need to keep on calling this
    }
}

Then I use

DelayMs(5000);

Even with this, I am getting inconsistent delays. I am ok with 1 or 2 seconds discrepancy in delays, however I am sometimes seeing 15 to 20 seconds delay on this.

The emulated EEPROM should work the same between all Gen 3 devices. The only known issue is that if you’ve completed filled up the flash file system on the device it could be a lot slower on any device, because the EEPROM is just a file on the flash file system and it works better when not too full.

I’d guess that you have something that’s using an usual amount of processing time. Since you mentioned CAN, that is a possibility. If you are doing lengthy processing of large numbers of CAN messages, this could affect the performance of the system.

What I’d do is try turning off or temporarily disabling some features and see if it has an effect.

Also increase the logging level to LOG_LEVEL_TRACE and see if anything interesting is being displayed.

And make sure you still have SYSTEM_THREAD(ENABLED) in your code as the Tracker probably won’t run well without it.

Hi, I used EEPROM.put and that worked. I am not sure about the EEPROM.write why it is very slow even with just a few bytes.

Regarding the timing, I removed the SYSTEM_THREAD(ENABLED) and the delays worked very well. If the System Thread needs to be enabled, how do I make the delays work?

You are close. Assuming the code you posted is IN the loop(), Try:

    // Must call this on every loop
    Tracker::instance().loop();
    
    static uint32_t tmsDelay = 0; //this is really a TIMER rather than delay
    if (millis() - tmsDelay >= 5000) {       
        tmsDelay  = millis();
        //your Working EEPROM code here
        //...
    }

Now, very important:

Please follow this advice from @rickkas7 . With the above timing change AND including

SYSTEM_THREAD(ENABLED);       

your code just might work the way you wish.

If you need more help please post your improved code.

thanks. it is working now. eeprom.write messes up the timing. it was resolved by using eeprom.put