09-21-2022, 05:27 AM
This demo source code, you just replace with your 10 phone numbers, then will send one SMS to 10 mobile phone, you can also send to many many mobile phone number in loop() function.
// make sure set your Serial2 pins in your "HardwareSerial.cpp" for ESP32 as follows:
//#define RX2 15
//#define TX2 13
// make sure set your Serial2 pins in your "HardwareSerial.cpp" for ESP32 as follows:
//#define RX2 15
//#define TX2 13
Code:
//code use for KC868-A8S board
int data;
String message;
unsigned long int last;
void setup()
{
String phone1,phone2,phone3,phone4,phone5,phone6,phone7,phone8,phone9,phone10;
Serial.begin(115200);
Serial2.begin(115200);
Serial.print("start test");
phone1="15381100000";
phone2="15381100001";
phone3="15381100002";
phone4="15381100003";
phone5="15381100004";
phone6="15381100005";
phone7="15381100006";
phone8="15381100007";
phone9="15381100008";
phone10="15381100009";
send_sms("Test message from KinCony KC868-A8S",phone1);
send_sms("Test message from KinCony KC868-A8S",phone2);
send_sms("Test message from KinCony KC868-A8S",phone3);
send_sms("Test message from KinCony KC868-A8S",phone4);
send_sms("Test message from KinCony KC868-A8S",phone5);
send_sms("Test message from KinCony KC868-A8S",phone6);
send_sms("Test message from KinCony KC868-A8S",phone7);
send_sms("Test message from KinCony KC868-A8S",phone8);
send_sms("Test message from KinCony KC868-A8S",phone9);
send_sms("Test message from KinCony KC868-A8S",phone10);
}
void loop()
{
check_sms_responce();
}
void send_sms ( String sms, String number)
{
Serial2.print("AT+CMGF=1\r"); //Set text mode
delay(1000);
Serial2.print("AT+CMGS=\""+ number +"\"\r"); //Send message
delay(1000);
Serial2.print(sms);//Text message
Serial2.println((char)0x1A); //Ctrl+Z
}
void check_sms_responce()
{
if(Serial2.available()>0)
{
delay(60);
message="";
while(Serial2.available())
{
message+=(char)Serial2.read();
}
Serial.print(message);
}
}