strcpy / strcat crashing on ESP 12E

I do not have stack trace decoder working so I’ll paste the stack.

The full sketch is attached.

Here is a function, it crashes between serial prints of “declares” and “StatusReport event1”.

char *event1 = "0 ";
char *event2 = "0 ";
char *event3 = "0 ";
char *event4 = "0 ";
char *event5 = "0 ";
char *cAddMsg;
void statusReport() {
  Serial.print("StatusReport");
  char *cBiProfile, *cLastIssue, *cNode5Ping, *cNode7Ping, *cKeyIn, *cLastKitchenMotion;
 Serial.print("declares");
  strcpy(cAddMsg, "Last 5 Events:");
  strcat(cAddMsg, event1);
  Serial.print("StatusReport event1");
  strcat(cAddMsg, " / ");
  strcat(cAddMsg, event2);
  strcat(cAddMsg, " / ");
  strcat(cAddMsg, event3);
  strcat(cAddMsg, " / ");
  strcat(cAddMsg, event4);
  strcat(cAddMsg, " / ");
  strcat(cAddMsg, event5);
  strcat(cAddMsg, ". \n ");
Serial.print("Last 5");

  itoa(biProfile, cBiProfile, 10);
  strcat(cAddMsg, "BI Profile: ");
  strcat(cAddMsg, cBiProfile);
  strcat(cAddMsg, ". \n");
  strcat(cAddMsg, northDoorOpen);
  strcat(cAddMsg, northDoorLocked);
  strcat(cAddMsg, ". \n");
Serial.print("BI Profile...");

  cKeyIn = reinterpret_cast<char * const>((millis() - keyinMS / 60000));
  cLastKitchenMotion = reinterpret_cast<char * const>((millis() - lastKitchenMotion / 60000));
  cNode5Ping = reinterpret_cast<char * const>((millis() - timer5));
  cNode7Ping = reinterpret_cast<char * const>((millis() - timer7));
  cLastIssue = reinterpret_cast<char * const>((millis() - lastIssueMS / 60000));
  strcat(cAddMsg, "Node 5 Pinged ");
  strcat(cAddMsg, cNode5Ping);
  strcat(cAddMsg, "ms ago. ");
  strcat(cAddMsg, "Kitchen Motion ");
  strcat(cAddMsg, cLastKitchenMotion);
  strcat(cAddMsg, " ms ago. \n");
  strcat(cAddMsg, southDoorOpen);
  strcat(cAddMsg, ". ");
  strcat(cAddMsg, southDoorLocked);
  strcat(cAddMsg, ". \n");
  Serial.print("south door locked");
  
  strcat(cAddMsg, "Last key-in ");
  strcat(cAddMsg, cKeyIn);
  strcat(cAddMsg, " mins ago. \n");
  strcat(cAddMsg, "Node7 Pinged ");
  strcat(cAddMsg, cNode7Ping);
  strcat(cAddMsg, " ms ago. \n");
  strcat(cAddMsg, "Last issue: ");
  strcat(cAddMsg, lastIssue);
  strcat(cAddMsg, " was ");
  strcat(cAddMsg, cLastIssue);
  strcat(cAddMsg, "mins ago.");
Serial.print("last issue");
  //Send to SMS webhooks app
  char* address;
  address = "https://maker.ifttt.com/trigger/Domestat/with/key/jAKx5y33Bp2wtLHBINCuBXFkvL3BjMUJBK63INT-pdc?value1=";
  address = strcat(address, cAddMsg);
  Serial.println(address);
  http.begin(client, address);
  http.GET();
  http.end();
}

Here is stack:

>>>stack>>>
04:51:50.149 -> 
04:51:50.149 -> ctx: cont
04:51:50.149 -> sp: 3ffffd50 end: 3fffffc0 offset: 01a0
04:51:50.149 -> 3ffffef0:  000022b8 4020f0b0 00000040 4020279f  
04:51:50.149 -> 3fffff00:  3ffe8737 3ffeeb7c 3fff1cec 40204af7  
04:51:50.149 -> 3fffff10:  3ffe8776 00000004 3fff1cec 3fff1cec  
04:51:50.149 -> 3fffff20:  402077f0 00000000 3fff0c9c 3ffe8754  
04:51:50.149 -> 3fffff30:  3ffe84e0 3fff0bd8 3fff0c9c 40202cf8  
04:51:50.182 -> 3fffff40:  402077f0 8b01a8c0 402077f0 fe01a8c0  
04:51:50.182 -> 3fffff50:  402077f0 00ffffff 402077f0 fe01a8c0  
04:51:50.182 -> 3fffff60:  402077f0 8b01a8c0 402077f0 00ffffff  
04:51:50.182 -> 3fffff70:  402077f0 fe01a8c0 402077f0 fe01a8c0  
04:51:50.182 -> 3fffff80:  402077f0 8b01a8c0 feefeffe feefeffe  
04:51:50.182 -> 3fffff90:  feefeffe feefeffe feefeffe 3fff0d04  
04:51:50.182 -> 3fffffa0:  3fffdad0 00000000 3fff0cd4 40206fe8  
04:51:50.216 -> 3fffffb0:  feefeffe feefeffe 3ffe8524 40100a59  
04:51:50.216 -> <<<stack<<<

node9-9.ino (13.8 KB)

cAddMsg is a pointer but you haven't given it any memory to point to. It's global, so the compiler will initialize it to zero (NULL).

Your code uses strcpy and strcat extensively to copy strings to the memory cAddMsg points to. Which basically means that it will stomp all over your RAM with unexpected results, as you observe.