I don't have the hardware with me but I understood both of your suggestions and will test it later after lunch. Thank you very much.
My attention was mainly on the InitModem function, as occasionally I'm getting "ERROR" on the Serial Monitor after issuing a command. However, everything works in the end, so maybe it's the delays causing trouble regarding when data is displayed not so much regarding it being accepted.
At some point I was trying this but I was never able to catch the "OK" not the end LED with turn on.
void InitModem()
{
mySerial.print("AT+CMGD=1,4\n\r");
ReadChar();
if (val.indexOf("+OK") > -1)
{
mySerial.print("AT+CMGF=1\n\r");
ReadChar();
if (val.indexOf("+OK") > -1)
{
mySerial.print("AT+CSCS=\"GSM\"\r");
ReadChar();
if (val.indexOf("+OK") > -1)
{
mySerial.print("AT+CNMI=2,2,0,0,0\n\r");
while (mySerial.available())
ReadChar();
if (val.indexOf("+OK") > -1)
{digitalWrite(greenLED, HIGH); // signal InitModem finished, modem ready to receive SMS
sms(String("Module Active"), String(master));
delay(2000);
startup_sequence = false;
}
}
}
}
}
void ReadChar()
{
while (mySerial.available())
{
ch = mySerial.read();
val += char(ch);
delay(50);
}
}