Hi,
I am working on a solar monitor system. One photon is publishing a string that I read on the other photon.
void ParsePV(const char *event1, const char *data1)
{
char* Controller1 = strtok(strdup(data1), ",");
PV = atoi(strtok(NULL, ","));
counter = atoi(strtok(NULL, ","));
}
The code above works but produces a ‘memory leak’, leading to a wifi disconnect after 1hr15min. A system reset solves this, but it is not very elegant. By commenting out my particle.subscribe I have no memory leak.
I declared the controller1 string globally by moving this to the beginning of the sketch:
char* Controller1;
and
void ParsePV(const char *event1, const char *data1)
{
Controller1 = strtok(strdup(data1), ",");
PV = atoi(strtok(NULL, ","));
counter = atoi(strtok(NULL, ","));
}
now there is a smaller memory leak. I tried moving data1 and event1 to the global variables as well:
char*event1;
char*data1;
char* Controller1;
and
void ParsePV(event1, data1)
{
//char*
Controller1 = strtok(strdup(data1), ",");
PV = atoi(strtok(NULL, ","));
counter = atoi(strtok(NULL, ","));
}
But now it doesn’t compile because event1 and data1 are not declared in this scope.
I know it has something to do with the strings, but I don’t understand how to do this. Maybe cleanup the memory allocated to the string after each read/process to integers?
Cheers,
eric