mySerial syntax, convert Dynanic Allocation lines to Line-by-line

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.

For debugging assign each and every character to String-variables.

Then call your "send characters to sim800" functions

inside these functions do it the same way as in this function:

bool SendShortCommand(String command)
{
  Serial.print("Sending command: \"");
  Serial.print(command); // print the content of the String-variable to serial monitor
  Serial.println("\"");

  ATCommandStream.print(command); // // print the content of the String-variable to sim module
  ATCommandStream.print("\r\n");

Is it in the SMS you get or in the Serial monitor ?

Some module have echo on which means they repeat the command you sent back at you before the answer. You send ATE1 to activate echo, ATE0 to deactivate it.

The AT commands are actually showing up in the SMS message received by the recipient device. See screenshot.

Without restarting the module, I can load and run another simple test sketch, send an sms message, and only the actual message text is sent/received.

Your code shows that you send

and your screen grab shows
image

➜ this does not make sense...
Can you post the exact code that was used to create what you see? That could be useful if you want us to help you...

Also, share what you see in the Serial monitor?

Sorry, I corrected the SMS message content.
I had a couple different test scripts going.

post a script and the resulting transmission so that we have reliable information.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.