This does compile and run. And when a message is received it doesn't overflow like you mentioned so a step in the right direction. It even outputs a 0, although it should be outputting a 1.
Below is copy pasted from the serial monitor output. The custom function is being executed between the lines "sending awake status" and "hold up" as you can see there is a 0 there, but interestingly the entire rest of the message is printed when I read the serial monitor later in the program. It seems to me that the function is only analyzing one or a few characters of the message, unlike my previous approach.
16:49:27.922 -> sending awake status
16:49:27.922 -> 0
16:49:28.446 -> hold up
16:49:28.446 -> A
16:49:33.460 -> T+QMTPUBEX=1,0,0,0,"motorbeta/heartbeat","{"pulse":1,"secondary":2}"
16:49:33.460 -> OK
16:49:33.460 ->
16:49:33.460 -> +QMTPUB: 1,0,0
Below is the exact place in the code where I am calling our custom function "atreceivebasic"
Serial.println("sending awake status");
//send awake status
atreceivebasic("AT+QMTPUBEX=1,0,0,0,\"motorbeta/heartbeat\",\"{\"pulse\":1,\"secondary\":2}\"\r\n",60000,5000);
delay(500);
Serial.println("hold up");
char subscription = Serial2.read();
Serial.println(subscription);
with my previous code which could only read serial monitor and not assign shutdown to an integer value I was seeing:
15:45:17.907 -> AT+QMTPUBEX=1,0,0,0,"motorbeta/heartbeat","{"pulse":1,"secondary":2}"
15:45:17.907 -> OK
15:45:17.907 ->
15:45:17.907 -> +QMTPUB: 1,0,0
15:45:17.907 ->
15:45:17.907 -> +QMTRECV: 1,0,"motorbeta/shutdown","shutdown=1"
For reference this was the function I was using to read my serial monitor
void atsendbasic(String command, int fallout3, int fallout4){
unsigned long initialtime4 = millis();
Serial2.print(command);
Serial2.flush(); // Wait until it is all sent
while ((!Serial2.available() && millis() - initialtime4 <= fallout3) || millis() - initialtime4 <= fallout4) continue;
while ((Serial2.available()&& millis() - initialtime4 <= fallout3) || millis() - initialtime4 <= fallout4) {
char feedback = Serial2.read();
Serial.print(feedback);
}
}