I have the Arduino GSM shield and I have a class with name SimpleGSM to send SMSs. The SimpleGSM class inherits SoftwareSerial.
I have the following method:
bool
SimpleGSM::sendSMS (const String phoneNumber, const String message)
{
const byte CONTROL_Z_HEX_CODE = 0x1A;
const unsigned long SERIAL_DELAY_TIME = 500;
this->flush();
this->print(F("AT+CMGS=\""));
this->print(phoneNumber);
this->print(F("\"\r"));
delay(SERIAL_DELAY_TIME);
this->flushInput();
this->print(message);
this->write(CONTROL_Z_HEX_CODE);
delay(SERIAL_DELAY_TIME);
this->flushInput();
}
The above method successfully sends the SMS but I do not check the response of the AT command.
I have some other methods for disabling the ECHO and setting the Modem to SMS Text mode:
bool
SimpleGSM::setEcho (const bool state)
{
this->flush();
this->print(F("ATE"));
this->print(state);
this->print(F("\r"));
return this->find(OK_RESPONSE_FORMAT);
}
bool
SimpleGSM::setSMSMode (const byte mode)
{
this->flush();
this->print(F("AT+CMGF="));
this->print(mode);
this->print(F("\r"));
return this->find(OK_RESPONSE_FORMAT);
}
The above two methods successfully handle the response of the AT command.
My problem is that I want to handle the response of the AT command of the sendSMS method like that:
bool
SimpleGSM::sendSMS (const String phoneNumber, const String message)
{
const byte CONTROL_Z_HEX_CODE = 0x1A;
this->flush();
this->print(F("AT+CMGS=\""));
this->print(phoneNumber);
this->print(F("\"\r"));
if (!this->find("\r\n> "))
{
return false;
}
this->print(message);
this->write(CONTROL_Z_HEX_CODE);
return this->find(OK_RESPONSE_FORMAT);
}
However, for some reason this does not work. The 'this->find("\r\n> ")' always returns false.
Please, take account also that OK_RESPONSE_FORMAT is:
char * SimpleGSM::OK_RESPONSE_FORMAT = "\r\nOK\r\n";
AT command responses are usually sent by the module via the same connection. I.e if you're connection to the module serially then you send to the transmission pin, and read from the receive pin (tx vs. rx).