Has anyone else experienced an issue where they haven’t been able to communicate with the particle cloud, or have noticed their device lock up and… it was fixed by clearing EEPROM?
Trying to figure out what I did wrong to avoid it occurring again.
The issue ocurred after testing some pretty beefy firmware that resulted in a few stack overflows. I was forced to put it into DFU mode, flash tinker then reflash some blank firmware. During this process - the device powered down a few times during start mode and while the light was white.
I looked at > 'EEPROM' persistence issue and determined that it could be related… but the issues there were about EEPROM being cleared. Where I had to clear EEPROM before any of my Particle.publish commands would hit the Particle cloud.
Note: I was doing a looped read check (to check for changes) every 2 minutes. But I doubt that caused any ‘high demand’ read issues on it.
Two questions, I hope we can solve:
1. Why would EEPROM cause Particle.Publish to block and not send? Or… is it just some really odd fluke and the 20th restart brought it alive again?
2. Is there anything in the below EEPROM read/write code that would impair the use of EEPROM?
Code I used
STARTUP(cellular_credentials_set("telstra.extranet", "", "", NULL));
void setup() {
Particle.function("test", functionname);
Particle.function("clearMem", clearMemory);
}
void loop() {
}
int functionname(String input)
{
Particle.publish("Hello", "Hello", PRIVATE);
return 1;
}
int clearMemory(String clear)
{
EEPROM.clear();
return 1;
}
Some of the code I used to store EEPROM variables.
I know the spacing between storage locations is inefficient - but I wasn’t sure how to safely calculate the exact distances between variables at the time of writing - so instead left very big gaps.
//Memory Storage Details
//Alert Mobile Memory details
char defaultAlertNumber[15] = "+61xxxx";
char alertNumberInChar[15] = "Loading";
char alertNumber[15] = "+61xxxxx";
int mob_versionCheckHold = 0;
int mob_versionAddress = 1;
int mob_versionValueToBe = 200;
int mob_mobileAddress = 20;
//Customer ID Memory details
int cId_versionCheckHold = 0;
int cId_versionAddress = 100;
int cId_versionValueToBe = 200;
int cId_cIdAddress = 120;
int cId_defaultValue = 1999991;
int cId_currentValue = cId_defaultValue;
//Module Friendly ID Memory details
int mId_versionCheckHold = 0;
int mId_versionAddress = 300;
int mId_versionValueToBe = 200;
int mId_cIdAddress = 320;
char mIdDefault[64] = "Pump Controller";
char moduleID[64] = "Pump Controller";
//String mIdDefault = "Pump Controller";
//String moduleID = mIdDefault;
//User Pass Code
int uCode_versionCheckHold = 0;
int uCode_versionAddress = 400;
int uCode_versionValueToBe = 200;
int uCode_Address = 420;
char uCode_Default[10] = "123456";
char uCode_Current[10] = "123456";
int reqPassLength = 6;
//Ignition Delay
int igDelay_versionCheckHold = 0;
int igDelay_versionAddress = 500;
int igDelay_versionValueToBe = 200;
int igDelay_Address = 520;
int igDelay_Default = 2500;
int igDelay_Current = igDelay_Default;
//Pump Duration with Smoke
int smkStoredDuration_versionCheckHold = 0;
int smkStoredDuration_versionAddress = 600;
int smkStoredDuration_versionValueToBe = 200;
int smkStoredDuration_Address = 620;
int smkDuration_Default = 900;
int smokeInterval = smkDuration_Default;
//Pump Duration with Heat
int heatStoredDuration_versionCheckHold = 0;
int heatStoredDuration_versionAddress = 700;
int heatStoredDuration_versionValueToBe = 200;
int heatStoredDuration_Address = 720;
int heatDuration_Default = 900;
int heatInterval = heatDuration_Default;
When storing these I use this code:
int saveMobileToMemory(char inputVal[15])
{
if (strlen(inputVal) != 12)
{
return 999;
}
EEPROM.put(mob_mobileAddress, inputVal);
EEPROM.put(mob_versionAddress, mob_versionValueToBe);
strcpy(alertNumber, inputVal);
delayMicroseconds(2000000); //Reduces the chance of an error in the webside locking the device through too many publishes
if(Particle.connected())
{
Particle.publish("MobileChange", String(inputVal), 60, PRIVATE);
}
return 1;
}
When reading, I use this code
//Mobile Alert Number - Refresh to current memory
EEPROM.get(mob_versionAddress, mob_versionCheckHold);
if (mob_versionCheckHold == mob_versionValueToBe)
{
EEPROM.get(mob_mobileAddress, alertNumberInChar);
strcpy(alertNumber, alertNumberInChar);
}
else
{
strcpy(alertNumber, defaultAlertNumber);
}
Any thoughts would be greatly appreciated!