A6 GSM Modemmit Nano - SMS Senden

Also, es handelt sich um einen Arduino Uno

#include <SoftwareSerial.h>

const byte rxPin = 10;        // Wire this to Tx Pin of A6GSM
const byte txPin = 11;        // Wire this to Rx Pin of A6GSM
bool ini = true;
// We'll use a software serial interface to connect to A6GSM
SoftwareSerial A6GSM (rxPin, txPin);

void setup() {
  Serial.begin(9600);
  A6GSM.begin(9600);                                    // Change this to the baudrate used by A6GSM
  delay(3000);                                            // Let the module self-initialize
  Serial.println("SETUP: SoftwareSerial.begin()");
  A6GSM.listen();
  Serial.println("SETUP: SoftwareSerial.listen()");
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                                                  FUNCTION - Start/Restart
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bool CheckModule(void) {
  String inData;
  Serial.print("******************************** START **************************************\n");
  A6GSM.println("AT&F");
  Serial.println("SND> AT&F");
  delay(500);
  for (int timer = 0; timer < 5; timer++) {
    inData = A6GSM.readStringUntil('\n');
    Serial.print(">");
    Serial.print(inData);
    Serial.print("<");
    if (inData.startsWith("OK")) {
      Serial.println(" => Startup response OK");
      return false;
    }
  }
  Serial.print("\n");
  return true;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                                                  FUNCTION - SndMsg
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int SndMsg (String MsgTxt, char PhoneNo[])
{

  Serial.print("******************************** SEND NOW **************************************\n");
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  int timer = 0;

  A6GSM.println("AT+CMGF=1");
  Serial.println("SND> AT+CMGF=1");
  delay(500);
  for (timer = 0; timer < 15; timer++) {               //the inside of the for loop is just for viewing if the A6 has any feedback and how long will my delay needs to be
    delay(10);
    String inData = A6GSM.readStringUntil('\n');          //reads the  feedback
    Serial.println("0 Got response from AT [10ms]: " + inData);    //displays gibberish, but won't affect any RX-TX "chatting"
    if (inData.startsWith("OK") ) {
      break;
    }
    else if (inData.startsWith("ERROR") ) {
      return 0;
    }
  }
  if (timer == 15) {
    return 0;
  }
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // SEND Number
  A6GSM.print("AT+CMGS=\"");
  A6GSM.print(PhoneNo);
  A6GSM.write(0x22);
  A6GSM.write(0x0D);  // hex equivalent of Carraige return
  A6GSM.write(0x0A);  // hex equivalent of newline
  Serial.print("SND> AT+CMGS=\"");
  Serial.println("<phone number>");
  delay(500);

  // Wait for Feedback
  for (int timer = 0; timer < 20; timer++) {              //the inside of the for loop is just for viewing if the A6 has any feedback and how long will my delay needs to be
    delay(10);
    String inData = A6GSM.readStringUntil('\n');          //reads the  feedback
    Serial.println("1 Got response from AT [10ms] - Send Number: " + inData);    //displays gibberish, but won't affect any RX-TX "chatting"
    if (inData.startsWith(">") ) {
      break;
    }
    else if (inData.startsWith("ERROR") ) {
      return 0;
    }

  }
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  A6GSM.print(MsgTxt);
  A6GSM.println (char(26));//the ASCII code of the ctrl+z is 26
  Serial.print("SND> \"<Msg Text>");
  Serial.println("ctrl+z");
  delay(200);

  for (int timer = 0; timer < 20; timer++) {              //the inside of the for loop is just for viewing if the A6 has any feedback and how long will my delay needs to be
    delay(10);
    String inData = A6GSM.readStringUntil('\n');          //reads the  feedback
    Serial.println("2 Got response from AT[10ms]: " + inData);    //displays gibberish, but won't affect any RX-TX "chatting"
    if (inData.startsWith("OK") ) {
      return 1;
    }
    else if (inData.startsWith("+CMS ERROR") ) {
      return 0;
    }
  }
  return 0;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                                                  FUNCTION - RcvMsg
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

String RcvMsg(void) {
  Serial.print("****************************** RECEIVE NOW ************************************\n");

  for (int timer = 0; timer < 8; timer++) {               //the inside of the for loop is just for viewing if the A6 has any feedback and how long will my delay needs to be
    delay(10);
    String inData = A6GSM.readStringUntil('\n');          //reads the  feedback
    Serial.println("  Received: " + inData);    //displays gibberish, but won't affect any RX-TX "chatting"

    // Compare with known text messages
    if (inData.equals("Test\n"))
    {
      return inData;
    }
  }
  return ("No Message");
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                                                  LOOP
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void loop() {

  bool SndOrder = false;
  char phone_no[] = "0..............84";
  String MsgSndTxt = "Test";
  String MsgRcvTxt = "No Message";
  int state;


  MsgRcvTxt = "No Message";


  // ------------------------------- Restart -> set default parameters --------------------------------------
  if (ini) {
    delay(500);
    ini = CheckModule();
    if (ini) {
      return;
    }
    delay(500);
  }
  // ---------------------------- Receive Msg from Phone - Später interrupt ---------------------------------
  if  (A6GSM.available()>0){
     MsgRcvTxt = RcvMsg();
  
   }

  // -------------------------------------- Send Msg to PhoneNumber ------------------------------------------
  if (SndOrder){
    state = (SndMsg(MsgSndTxt, phone_no));
    if (state == 0) {
      ini = true;
    }
  }
}