0

I have this data I'm getting through EEPROM "Emergency Contacts: +639*********, +639*********, +639*********;" Using this I want to send a message to these numbers.

I have this function but it only sends to the first number:

void sendSms(String text)
 {
  sim800.print("AT+CMGF=1\r");
  delay(1000);
  String contacts = EMERGENCY_CONTACTS;
  int commaPos;
  boolean allSent = true;
  do {
    commaPos = contacts.indexOf(',');
    String contact;
    if (commaPos != -1) {
      contact = contacts.substring(0, commaPos);
    } else {
      // If no comma found, it's the last contact
      contact = contacts;
    }
    contact.trim();  // Trim leading/trailing spaces
    contacts = contacts.substring(commaPos + 1);
    contacts.trim(); // Trim leading/trailing spaces and update contacts
    sim800.print("AT+CMGS=\"" + contact + "\"\r");
    delay(1000);
    sim800.print(text);
    delay(100);
    sim800.write(0x1A); 
    delay(1000);
    Serial.println("SMS Sent Successfully to " + contact);
    BTSerial.println("SMS Sent Successfully to " + contact);
    if (commaPos == -1) {
      allSent = false;  // Mark that it's the last contact
    }
  } while (commaPos != -1);
  return allSent;
}
5
  • please add a clear, answerable question to your post
    – jsotola
    Nov 16 at 15:57
  • How can i send a message to multiple numbers? Nov 16 at 16:03
  • loop through the list of numbers and send a message to each
    – jsotola
    Nov 16 at 16:12
  • can you give me and example? base on this data, im a beginner so i dont know how to make a loop for this data "Emergency Contacts: +639*********, +639*********, +639*********;" Nov 16 at 16:28
  • research the C++ for loop ... arduino.cc/reference/en/language/structure/control-structure/… ... modify your function to accept a phone number void sendSms(String text, String number)
    – jsotola
    Nov 16 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.