Hi guys, how can I get the phone number of the sender that is received by the GSM module and use it for sending a reply to that number instead of manually setting the phone number on the code? I am working with this code as of now.
#include <TinyGPS.h>
#define GPRS Serial1
#define GPS Serial2
TinyGPS Neo6m;
String TextMessage;
String AlarmStatus = "off";
String PhoneNumber = "+63**********";
int aled = 4;
int bled = 5;
void setup() {
pinMode(aled, OUTPUT);
pinMode(bled, OUTPUT);
Serial.begin(9600);
delay(500);
GPRS.begin(9600);
delay(500);
GPS.begin(9600);
delay(5000);
Serial.print("SYSTEM IS READY!");
GPRS.print("AT+CMGF=1\r");
delay(100);
GPRS.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
}
void loop() {
if (GPRS.available() > 0) {
TextMessage = GPRS.readString();
Serial.print(TextMessage);
delay(10);
TextMessage.toUpperCase();
}
if (TextMessage.indexOf("RING") >= 0) {
digitalWrite(aled, HIGH);
digitalWrite(bled, HIGH);
AlarmStatus = "on";
Serial.println("Command: Alarm set to ON!");
TextMessage = "";
}
if (TextMessage.indexOf("STOP") >= 0) {
// Turn off relay and save current state
digitalWrite(aled, LOW);
digitalWrite(bled, LOW);
AlarmStatus = "off";
Serial.println("Command: Alarm set to OFF!");
TextMessage = "";
}
if (TextMessage.indexOf("STATE") >= 0) {
String AlarmStatusMessage = "Alarm is " + AlarmStatus;
AlarmStatusSMS(AlarmStatusMessage);
Serial.println("Command: Alarm status request!");
TextMessage = "";
}
while (GPS.available()) {
if (Neo6m.encode(GPS.read())) {
if (TextMessage.indexOf("LOCATION") >= 0) {
float latitude, longitude;
Neo6m.f_get_position(&latitude, &longitude);
float lat = latitude;
float lng = longitude;
String meslat = String(lat, 6);
String meslon = String(lng, 6);
String com = ",";
String link = "https://www.google.com/maps/?q=";
String CoordinateMessage = link + meslat + com + meslon;
Serial.println(CoordinateMessage);
delay(500);
GPRS.print("\r");
delay(500);
GPRS.print("AT+CMGF=1\r");
delay(500);
GPRS.print("AT+CMGS=\"");
GPRS.print(PhoneNumber);
GPRS.print("\"\r");
delay(500);
GPRS.print(CoordinateMessage);
delay(500);
GPRS.write(0x1A);
delay(500);
Serial.println("Command: Coordinates request!");
TextMessage = "";
}
}
}
}
void AlarmStatusSMS(String AlarmStatusMessage) {
GPRS.print("AT+CMGF=1\r");
delay(100);
GPRS.print("AT+CMGS=\"");
GPRS.print(PhoneNumber);
GPRS.print("\"\r");
delay(100);
GPRS.print(AlarmStatusMessage);
delay(100);
GPRS.print((char)26);
delay(100);
}
Thanks in advance.