Hi, I've spent last week struggling with this so I decided to ask here. I am building a GPS tracker that sends current location in google maps iOS url via GSM when asked by SMS.
Here is my code:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
char latitude[12];
char longitude[12];
char textnav[180];
char number[]="123123123";
char message[180]="123";
char pos;
char *p;
static const int RXPin = 7, TXPin = 8;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
if (gsm.begin(2400))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
}
void loop()
{
pos=sms.IsSMSPresent(SMS_UNREAD);
Serial.println((int)pos);
if((int)pos>0&&(int)pos<=20){
Serial.print("Incomming message, POS=");
Serial.println((int)pos);
message[0]='\0';
sms.GetSMS((int)pos,number,message,180);
p=strstr(message,"PASSWORD");
if(p){
Serial.println("Success");
while (ss.available() > 0)
gps.encode(ss.read());
if (gps.location.isUpdated())
{
strcpy(textnav, "comgooglemaps://?q=");
dtostrf(gps.location.lat(), 1, 6, latitude);
strcat(textnav,latitude);
strcat(textnav,",");
dtostrf(gps.location.lng(), 1, 6, longitude);
strcat(textnav,longitude);
Serial.println(textnav);
sms.SendSMS(number, textnav);
delay(1000);
}
}
}
sms.DeleteSMS((int)pos);
delay(2000);
}
It should check for incomming messages. When text message arrives it checks if it contains PASSWORD. If it does, GPS location is saved in comgooglemaps url to textnav variable and sent back by SMS.
I have SIM800L module (not a shield) connected to pins 2, 3 of NANO, and GPS connected to pins 7, 8. Modules are connected properly with voltage dividers and voltage is OK. The problem is somewhere in the code. I am not a programmer and it is hard for me to find what is wrong. I think there might be a problem with SoftwareSerial library.
I will appreciate any help