Hello,
I am looking for any tips or pointers on my program which I am working on for college.
Basically, my brief was to create a program that could receive an sms message and send back a gps location in return.
To do this I am using a Sim800L GSM Module and a NEO6M GPS Module along with an Arduino mega for testing and eventually a PCB I have made myself at college.
My current program is as follows:
#include <TinyGPS++.h>
TinyGPSPlus gps;
double latitude, longitude;
static const uint32_t GPSBaud = 9600;
#include <SoftwareSerial.h>
SoftwareSerial SIM800L(10, 11); // The serial connection to the GSM device
String response;
int lastStringLength = response.length();
String link;
void setup()
{
Serial.begin(9600);
Serial.println("GPS Dog Collar");
SIM800L.begin(9600);
SIM800L.println("AT+CMGF=1");
Serial.println("SIM800L started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM800L is Ready!");
SIM800L.println("AT+CNMI=2,2,0,0,0");
}
void loop()
{
if (SIM800L.available()>0)
{
response = SIM800L.readStringUntil('\n');
}
if(lastStringLength != response.length())
{
GPS();
//Perintah ON
if(response.indexOf("ON") == 4)
{
SIM800L.println("AT+CREG=1"); //CONNECTS TO NETWORK
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CREG?"); //SHOWS CONNECTION
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CSMS=1"); //ENTERS SMS MODE
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGS=\"+447717095234\"\r");
delay(1000);
SIM800L.println(link); // The SMS text you want to send
delay(100);
SIM800L.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
}
}
void GPS()
{
if (Serial.available())
{
gps.encode(Serial.read());
}
if(gps.location.isUpdated())
{
latitude = gps.location.lat();
longitude = gps.location.lng();
link = "www.google.com/maps/place/" + String(latitude, 6) + "," + String(longitude, 6) ;
Serial.println(link);
}
}
It is fairly simple, I am getting it all good as far as the link being displayed on the serial monitor, it is when I am sending the message containing "ON" and expecting the link to be sent back that nothing is happening. No returned message.
Can anyone see any obvious error in the program? Or have any pointers for it?
Thank you!!