SIm800L send multiple text

I have a sim800L V2 connected to a mega. The idea is to send a text to a gps tracker and handle the response by uploding the data to a google sheets. It also writes the data as backup to an SD card.

This works for one text and one tracker, but I would like to add a whole lot more and this doesn't seem to be as easy as one would think :slight_smile:

This is the code I use for sending a text message (I'm using software serial):

void sendTxt(String txtNo){
  sim800.print("AT+CMGS=\"" + txtNo + "\"\r");
  delay(500);
  sim800.print("G123456#");
  delay(500);
  sim800.print((char)26);
  delay(500);
  sim800.println();
}

For sending to multiple numbers I've created an array (currently 3 items) and tried to loop it and call the sendTxt function, but for some reason I can't quite understand it only send's to the first item. If i add a delay of 3000 it sends to two numbers, but only the first and the last, never the second number.

Here's the loop part:

      for (int i = 0; i < 3; i++) {
        sendTxt(phoneNumbers[i]);
        delay(3000);
      }

Any tips on how to make it more robust is more than welcome. The entire script is rather long, but the broad strokes are that it listens to incoming text (using receive with end markers example) from sim800 and if it matches the pattern from the trackers the data is split into peices, written to the SD card and finally uploaded to google sheets as well.

You need to read the response, not insert an arbitrary delay()....

Thank you - I'll look into it. This is the only place I use delays really as I couldn't figure out how to do it properly when the loop might fire again if there's no delay and it just moves along and trigger another AT command (updating signal strength for instance).

That sort of did the trick, however it tends to get messed up when there's an incoming text as well, but that might very well be some of hte limitations of the setup itself.