Sim800L does not send SMS messages in a row

Hi

I created a project with sim800l that comes and stores 5 phone numbers in eeprom memory and then when a sensor is triggered, it sms all the numbers and then calls the first one. But the module does not send an SMS to everyone and only sends an SMS to the first number and then nothing else and then calls. The problem is not that the numbers are not read correctly, because when sending the text message, I said, show the number in the monitor series and it will show correctly. It is not a problem not to send a text message request because I also connected a usb to ttl module to the tx rx module and saw that it comes for all numbers and at sends the at command correctly.

Thanks if friends have experience in this area tell me.

Thanks in advance.

HINT : It would help to see your code

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here

Hi UKHeliBob. thanks for your reply

#include <EEPROM.h>
#include <SoftwareSerial.h>

#define SIM800RX 7 //D7 - SIM800L RX PIN
#define SIM800TX 8 //D8 - SIM800L TX PIN

#define SENSOR1SMSTEXT "Fire error" //Sensor 1 SMS Text
#define SENSOR2SMSTEXT "Theft error" //Sensor 2 SMS Text

SoftwareSerial SIM800(SIM800RX, SIM800TX);

String readSerial(String txt) {
  SIM800.flush();
  if (SIM800.readString() != "") {
    while (SIM800.readString() != "") {}
  }
  String text = "";
  if (txt != "") {
    SIM800.println(txt);
    int timeout = 0;
    while  (!SIM800.available() && timeout < 12000) {
      delay(1);
      timeout++;
    }
    if (SIM800.available()) {
      text = SIM800.readString();
    }
  }
  return text;
}

void readSerialOK(String txt) {
  while (readSerial(txt).indexOf("OK") == -1) {
    delay(700);
  }
}

void configSim800L() {
  readSerialOK("AT");
  delay(200);
  readSerialOK("AT+CMGF=1");
  delay(200);
  readSerialOK("AT+CNMI=1,2,0,0,0");
  delay(200);
  readSerialOK("AT+CMGDA=\"DEL ALL\"");
  delay(200);
  readSerialOK("AT+CSMP=17,167,0,0");
  delay(200);
}

void SendTextSMS(String num, String sms) {
  SIM800.print("AT+CMGS=\"");
  SIM800.print(num);
  SIM800.println("\"");
  delay(150);
  SIM800.print(sms);
  SIM800.write(26);
  delay(700);
  Serial.println("");
  Serial.print("Send SMS to:");
  Serial.print(num);
  Serial.print(":");
  Serial.println(sms);
}

bool checkPhone(String phone) {
  if (phone.substring(0, 2) == "09" && phone.length() == 11) {
    return true;
  } else {
    return false;
  }
}

void WriteEEPROM(byte part, String val) {
  int start_addw = part * 16;
  int w_len = val.length();
  EEPROM.write(start_addw, w_len + 1);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, int(val[len]));
    len++;
  }
  len = 0;
  EEPROM.commit();
}

String ReadEEPROM(byte part) {
  int start_addr = part * 16;
  String str;
  int ch;
  int r_len = EEPROM.read(start_addr);
  int end_r = start_addr + r_len;
  for (int i = start_addr + 1; i < end_r; i++) {
    ch = EEPROM.read(i);
    str += char(ch);
  }
  if (checkPhone(str) == false) {
    str = "";
  }
  return str;
}

void ClearEEPROM(byte part) {
  int start_addw = part * 16;
  int w_len = 11;
  EEPROM.write(start_addw, 0);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, 0);
    len++;
  }
  len = 0;
  EEPROM.commit();
}

void SendSMS(String sms) {
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    SendTextSMS(num1, sms);
  }
  if (num2 != "") {
    SendTextSMS(num2, sms);
  }
  if (num3 != "") {
    SendTextSMS(num3, sms);
  }
  if (num4 != "") {
    SendTextSMS(num4, sms);
  }
  if (num5 != "") {
    SendTextSMS(num5, sms);
  }
}

void Call() {
  String call = "";
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    call = num1;
  } else if (num2 != "") {
    call = num2;
  } else if (num3 != "") {
    call = num3;
  } else if (num4 != "") {
    call = num4;
  } else if (num5 != "") {
    call = num5;
  }
  Serial.println("");
  Serial.print("Call to:");
  Serial.print(call);
  if (call != "") {
    readSerialOK("ATD"+call+";");
    delay(300);
  }
}


void trigSensor1() {
  SendSMS(SENSOR1SMSTEXT);
  Call();
}

void trigSensor2() {
  SendSMS(SENSOR2SMSTEXT);
  Call();
}

void setup() {
  SIM800.begin(9600);
  Serial.begin(9600);
  EEPROM.begin(512);
  pinMode(IN1, INPUT_PULLUP);
  pinMode(IN2, INPUT);
  pinMode(SSS, OUTPUT);
  digitalWrite(SSS, LOW);
  while (readSerial("AT+COPS?").indexOf("+COPS: 0,0,\"") == -1) {
    delay(700);
  }
  configSim800L();
  digitalWrite(SSS, HIGH);
}

void loop() {
  if (digitalRead(IN1) == LOW) {
      trigSensor1();
  }
  if (digitalRead(IN2) == HIGH) {
      trigSensor2();
  }
}

Without going too much farther, if this is running on one of the smaller 8-bit Arduinos (UNU. 1280/2560 or other AVR based boards), you might lilke to look at converting from [u]S[/u]trings to [u]c-strings.[/u] In a high reliability application like this, you don't want the micro to lock up due to string-memory fragmentation.

In sendSMS() you'll find some benefits using arrays[] to store and process your multiple recipient numbers.

EEPROM.put() and .get() will help a lot too. When you dial out - when do you hang up (ATH) ?

Also if you have the opportunity to use a MEGA or 1284, you should look at [u]hardware[/u] serial, and finally, the shift to 4G/5G is well under way, the SIM800 (2G) is EOL in most regions, or will be within a year or two. Ive been using SIM5320 (3G) and SIM7600 (4G) modems for a a few years now.