Electron console intermittent data loss

Hi, fist time posting so let me know if anything info is missing.

I’ve got a pair of electrons running remote data collection, physically side by side, with the below reporting code being called about every minute in the main loop (some other code generates those strings but for simplicity…). Whenever I test it the console its getting all the data and I’m logging it on thingspeak, no problems. But over long time periods, say a couple days, I’ll find random blocks of missing data, sometimes minutes, sometimes hours, also seemingly random is which of the 2 electrons drop out.

Is there anything I can do to make the data collection more reliable?

void reportSystemStatusOnline() {
std::string name = “”;

std::string data = “”;
data += 1,42.69,9.94,-386.00,41.94,5.59,77.10;

Particle.publish(name.c_str(), data.c_str(), 60, PRIVATE);


Your symptoms do smell like heap fragmentation, so I’d start with replacing std::string with boring old char[] with all these nice old str...() and snprintf() functions :wink:


Okay I’m trying something like below, will run it for awhile and see how it goes, thanks.

 char nameBuffer[10]; 
 sprintf(nameBuffer, "%c", STATUS_TRANSMIT_CODE); //'s'
char dataBuffer[100];
 sprintf(dataBuffer, "%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",1,42.69,9.94,-386.00,41.94,5.59,77.10); //but in variable form
Particle.publish(nameBuffer, dataBuffer, 60, PRIVATE);
1 Like

ran it over the weekend, seems to be working well with the above modifications. Should have collected about 3130 data points and got 3100 over a 3.5 day period. Thanks for the assist, never would have thought of std::string being an issue.

1 Like