I'm trying to learn and use the correct Serial.print line-by-line method of sending serial data, to a SIM7670NA 4GLTE module, as used in [this post #8 code here] (Purpose of delay in sim800l at commands - #8 by johnwasser.._gaODc2Mzk4NjM3LjE3MzY5MTI1MDU._ga_NEXN8H46L5MTczNjkxMjUwNC4xLjAuMTczNjkxMjUwNC4wLjAuNjgxOTk4MDIz).
Specifically the method used in the SendSMSMessage function as below.
// by John Wasser, Aug 2022
#include <SoftwareSerial.h>
SoftwareSerial ATCommandStream(2, 3);
unsigned long ATComandBaudRate = 19200;
const char * DestinationNumber = "+639NNNNN1057";
const char * SMSMessage = "New Message";
void setup()
{
// start th serial communication with the host computer
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.println("Sketch started.");
ATCommandStream.begin(ATComandBaudRate);
Serial.print("ATCommandStream started at baud rate ");
Serial.println(ATComandBaudRate);
// Turn on verbose messages
SendShortCommand("AT+CMEE");
// Set character set to GSM:
SendShortCommand("AT+CSCS=\"GSM\"");
// Set the SMS output to text mode
SendShortCommand("AT+CMGF=1");
// Check the phone number type
SendShortCommand("AT+CSTA?");
Serial.println("Note: 129=Unknown, 161=National, 145=International, 177=Network Specific");
// Test for CMGS command support:
SendShortCommand("AT+CMGS=?");
SendSMSMessage(DestinationNumber, SMSMessage);
SendShortCommand("AT"); // Just checking that it responds with OK
}
void loop() {}
bool WaitForResponse()
{
unsigned long startTime = millis();
while (millis() - startTime < 5000)
{
String reply = ATCommandStream.readStringUntil('\n');
if (reply.length() > 0)
{
Serial.print("Received: \"");
Serial.print(reply);
Serial.println("\"");
if (reply.startsWith("OK"))
return true;
if (reply.startsWith("ERROR"))
return false;
}
}
Serial.println("Did not receive OK.");
return false;
}
bool SendShortCommand(String command)
{
Serial.print("Sending command: \"");
Serial.print(command);
Serial.println("\"");
ATCommandStream.print(command);
ATCommandStream.print("\r\n");
return WaitForResponse();
}
void SendSMSMessage(const char *number, const char *message)
{
Serial.println("Sending SMS text");
Serial.print("Sending: ");
Serial.print("AT+CMGS=\"");
Serial.print(number);
Serial.println("\"(CR)");
Serial.print(message); // The SMS text you want to send
Serial.println("(EM)");
ATCommandStream.print("AT+CMGS=\""); // Send SMS
ATCommandStream.print(number);
ATCommandStream.print("\"\r"); // NOTE: Command ends with CR, not CRLF
ATCommandStream.print(message); // The SMS text you want to send
ATCommandStream.write(26); // ASCII EndMessage (EM) CTRL+Z character
WaitForResponse();
}
This sketch is working as designed with single commands, I'm asking because when I test this sketch, it actually sends an SMS that includes a couple AT commands, instead of the "Test Message" only.
Any help appreciated.
I can not see why the AT commands are added above the SMS message text.
