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;
}
for loop
... arduino.cc/reference/en/language/structure/control-structure/… ... modify your function to accept a phone numbervoid sendSms(String text, String number)