char *msg;
...
if (pulseDuration > 1900 && pulseDuration < 2200)
{
const char *msg = "1";
p("Sending",1);
}
You have two different msg variables here you know. One with undefined contents (the first one) and a second one, which you don't use. This is likely to cause it to crash.