*** RESOLVED ***
The reason it was crashing the Mega was the char html[550] was being overfilled. I put in a check to see when it got nearly full to dump it into another c string.
void handleSchedule() {
char html0[550] = { 0 }, html0b[550] = { 0 }, html1[100] = { 0 }, html2[100] = { 0 }, html3[100] = { 0 }, html4[100] = { 0 };
char scheduleHHA[4] = { 0 };
char scheduleMMA[4] = { 0 };
char scheduleTempA[4] = { 0 };
int scheduleHHi, scheduleMMi, scheduleTempi;
char buff[10] = { 0 };
currentBlock = 'A';
char *pCurrentBlock = ¤tBlock;
strcpy(html0, "<!DOCTYPE html><html><head><title>Thermostat Schedule</title></head><body><hr>");
strcpy(html1, "<table><tr><th> Time </th > <th> Temp. </th> <tr><td><a href=AHHUp> + </a>");
strcat(html0, html1);
for (int i = 0; i < 4; i++) {
Serial.print("currentBlock:");
Serial.println(currentBlock);
scheduleHHi = scheduleArray(currentBlock, 'r', "timeHH", 0);
scheduleMMi = scheduleArray(currentBlock, 'r', "timeMM", 0);
scheduleTempi = scheduleArray(currentBlock, 'r', "temperature", 0);
Serial.print("ScheduleTempi:"); Serial.println(scheduleTempi);
itoa(scheduleHHi, buff, 10);
strcpy(scheduleHHA, buff);
itoa(scheduleMMi, buff, 10);
strcpy(scheduleMMA, buff);
itoa(scheduleTempi, buff, 10);
strcpy(scheduleTempA, buff);
Serial.print("ScheduleTempA:"); Serial.println(scheduleTempA);
strcpy(html2, "<a href=");
strcat(html2, pCurrentBlock);
strcat(html2, "HHDown> - </a>");
strcat(html2, scheduleHHA);
strcat(html2, "<a href=");
strcat(html2, pCurrentBlock);
strcat(html2, "HHUp> + </a>");
strcat(html2, ": <a href=");
strcat(html2, pCurrentBlock);
strcat(html2, "MMDown> - </a>");
strcat(html2, scheduleMMA);
strcat(html2,"<a href=");
strcat(html2, pCurrentBlock);
strcat(html2, "MMUp> + </a>");
strcat(html2, " </td> <td>");
strcat(html3, "<a href=");
strcat(html3, pCurrentBlock);
strcat(html3, "TempDown> - </a>");
strcat(html3, scheduleTempA);
strcat(html3, "<a href=");
strcat(html3, pCurrentBlock);
strcat(html3, "TempUp> + </a>");
strcat(html3, " </td></tr><tr><td>");
int len0 = strlen(html0);
int len0b = strlen(html0b);
if (len0 > 430) { //When html0 is near overflow, start on html0b
strcat(html0b, html2);
strcat(html0b, html3);
} else {
strcat(html0, html2);
strcat(html0, html3);
}
Serial.print("html0 length: "); Serial.print(len0);
Serial.print("html0b length: "); Serial.print(len0b);
currentBlock++;
}
strcpy(html4, " </table> </body> </html> ");
strcat(html0b, html4);
Serial.println(html0);
Serial.println(html0b);
}
For some reason this reboots the Mega. It compiles without warnings on More warnings setting. I do get quite a few ALL warnings, but nothing fatal to suggest it would crash the Mega. The line that crashes is the Serial.print(htmlAll);. If I comment it out, it runs ok.
I'm begining to think the board is toast. What do YOU think?
void handleSchedule() {
//This prints to WWW the schedule
char html0[82] = { 0 }, html0b[100] = { 0 }, html1[100] = { 0 }, html2[100] = { 0 }, html3[400] = { 0 }, html4[100] = { 0 }, html5[200] = { 0 };
currentBlock = 'A';
strcpy(html0, "<!DOCTYPE html><html><head><title>Thermostat Schedule</title></head><body><hr>");
strcpy(html1, "<table><tr><th> Time </th > <th> Temp. </th> <tr><td>");
for (int i = 0; i < 8; i++) {
currentBlock = currentBlock + i;
Serial.print("currentBlock:");
Serial.println(currentBlock);
scheduleHH = scheduleArray(currentBlock, 'r', "timeHH", 0);
scheduleMM = scheduleArray(currentBlock, 'r', "timeMM", 0);
scheduleTemp = scheduleArray(currentBlock, 'r', "temperature", 0);
strcpy(html2, scheduleHH);
strcat(html2, ':');
strcat(html2, scheduleMM);
strcat(html2, " < / td > <td>");
strcpy(html3, scheduleTemp);
strcat(html3, " </td> <tr>");
}
strcpy(html4, " </table> </body> < / html > ");
strcat(html0, html1);
strcat(html0, html2);
strcat(html0, html3);
strcat(html0, html4);
Serial.println(html0);
}