#include <WiFi.h>
// GSM module pin definitions
#define GSM_TX 17
#define GSM_RX 16
#define GSM_RESET 5
SoftwareSerial GSM_serial(GSM_RX, GSM_TX); // RX, TX
void setup() {
Serial.begin(115200);
GSM_serial.begin(115200); // Correct baud rate
Serial.println("GSM Test");
// Initialize GSM modem
while (!GSM_serial) {
delay(10);
}
Serial.println("GSM Serial initialized");
}
void loop() {
// Example: Send an SMS
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
Serial.println("Command received: " + command);
if (command.equals("SMS")) {
// Replace with your SMS message
String message = "Hello from ESP32!";
Serial.println("Sending SMS...");
sendSMS(message, "555-1234"); // Replace with your recipient's number
Serial.println("SMS sent!");
}
}
}
void sendSMS(const String& message, const String& number) {
Serial.println("Sending AT commands...");
GSM_serial.println("AT+CMGF=1"); // Set SMS message format to text
delay(1000);
GSM_serial.println("AT+CMGS=\"" + number + "\"");
delay(1000);
GSM_serial.print(message);
GSM_serial.println((char)26); // Ctrl-Z to send the message
}