I am not getting the output for the following code when I am trying to implement the below code to find and send an SMS to a particular phone number my location in url format:
#include <SoftwareSerial.h>
SoftwareSerial ec200uSerial(10, 11); // RX, TX for EC200U module
void setup() {
Serial.begin(9600);
ec200uSerial.begin(9600);Serial.println(“Initializing EC200U…”);
delay(1000);
ec200uSerial.println(“AT”);
waitForResponse();ec200uSerial.println(“AT+CMGF=1”); // Set SMS mode to text
waitForResponse();
}void loop() {
String location = getLocation();
if (location.length() > 0) {
String message = "Location: " + location;
sendSMS(message);
}
delay(60000); // Wait for 1 minute before sending next SMS
}String getLocation() {
ec200uSerial.println(“AT+QGPS=1”); // Turn on GPS
if (waitForResponse()) {
delay(2000); // Wait for the GPS to get a fix
ec200uSerial.println(“AT+QGPSLOC?”); // Request GPS location
if (waitForResponse()) {
String response = ec200uSerial.readString();
int latStart = response.indexOf(“:”) + 2;
int latEnd = response.indexOf(“,”, latStart);
String latitude = response.substring(latStart, latEnd);int lngStart = response.indexOf(",", latEnd + 1) + 1; int lngEnd = response.indexOf(",", lngStart); String longitude = response.substring(lngStart, lngEnd); return "https://maps.google.com/?q=" + latitude + "," + longitude; }
}
return “”;
}void sendSMS(String message) {
ec200uSerial.println(“AT+CMGS="+1234567890"”); // Replace with your mobile number
delay(1000);
ec200uSerial.print(message);
delay(1000);
ec200uSerial.write(26); // ASCII code for CTRL+Z to send the message
delay(1000);
Serial.println("SMS sent: " + message);
}bool waitForResponse() {
long timeout = millis() + 5000; // 5 seconds timeout
while (millis() < timeout) {
if (ec200uSerial.available()) {
String response = ec200uSerial.readString();
Serial.println(response);
if (response.indexOf(“OK”) != -1) {
return true;
}
}
}
return false;
}
I am getting the output as this:
Initializing EC200U
AT
OK
AT+CMGF=1?OK
AT+QGPS=1?+CMS ERROR: 504
AT+QGPS=1
+CMS ERROR: 504
AT+QGPS=1
+CMS ERROR: 504