Hi guys,
i need some advice or help.
my project is about gps tracker. Im using GSM (SIM800L EVB) , GPS SKYLAB SKM53 and Arduino UNO.
Ok, i have no problem with my first coding. Which is i request from serial monitor like "GPS LOCATION" . After serial find GPS LOCATION . i will SUCCESS receive sms with the latitude and longitude.
BUT i have problem with my second coding. When i request the GPS LOCATION from my handphone it will show my number and the "GPS LOCATION" in serial monitor. BUT i did not get any SMS.
What is my mistake?
Here is my coding.
My first coding..
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
char number[]="01********";
char message[40];
char value_str[12];
char message1[40];
char value_str1[12];
char message2[40];
char value_str2[12];
int temp=0,i;
unsigned long fix_age;
AltSoftSerial GPS (8,9);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup(){
GPS.begin(9600);
Serial.begin(9600);
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
}
void loop()
{
serialEvent();
if(temp)
{
getGPS();
sendLocation();
}
}
void serialEvent()
{
while(Serial.available())
{
if(Serial.find("GPS LOCATION"))
{
temp=1;
break;
}
else
temp=0;
}
}
void sendLocation(){
GPS.listen();
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
// retrieves +/- lat/long in 100000ths of a degree
getGPS();
gps.get_position(&lat, &lon, &fix_age);
int latitude=LAT/100000;
int longitude=LON/100000;
Serial.print("Latitude : ");
Serial.print(LAT/1000000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/1000000,7);
Serial.println("Sending message");
//Sending the latitude and longitude
if(started){
//start to build up message
message[0]='\0';
strcat(message,"The current location is ");
strcat(message1,"\n Latitude= ");
itoa(latitude,value_str1,10);
strcat(message2,"\n Longitude= " );
itoa(longitude,value_str2,10);
strcat(message,value_str);
strcat(message1,value_str1);
strcat(message2,value_str2);
strcat(message1,message2);
strcat(message,message1);
sms.SendSMS(number,message);
Serial.println("\nSMS sent OK");
delay (30000);
}}
void getGPS(){
bool newdata = false;
unsigned long start = millis();
// Every 1 seconds we print an update
while (millis() - start < 1000)
{
if (feedgps ()){
newdata = true;
}
}
if (newdata)
{
gpsdump(gps);
}
}
bool feedgps(){
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
//byte month, day, hour, minute, second, hundredths;
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
}
}
My second coding which is i'm in trouble
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
char number[]="01*******";
char message[40];
char value_str[4];
char message2[40];
char value_str2[4];
unsigned long fix_age;
AltSoftSerial GPS (8,9);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
char sms1[20];
int temp=0,i;
char location;
char c = location;
void setup(){
GPS.begin(9600);
Serial.begin(9600);
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
}
void loop()
{
strcat(sms1,"gps location");
serialEvent();
if(smsbuffer == sms1)
{
getGPS();
sendLocation();
}
}
void serialEvent()
{
//Read if there are messages on SIM card and print them.
Serial.println("Awaiting Message:");
if(gsm.readSMS(smsbuffer, 160, n, 20))
{
Serial.println(n);
Serial.println(smsbuffer);
}
}
void sendLocation(){
GPS.listen();
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
// retrieves +/- lat/long in 100000ths of a degree
getGPS();
gps.get_position(&lat, &lon, &fix_age);
int latitude=LAT/100000;
int longitude=LON/100000;
Serial.print("Latitude : ");
Serial.print(LAT/1000000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/1000000,7);
delay(5000);
GPS.end();
Serial.println("Sending message");
//Sending the latitude and longitude
if(started){
//start to build up message
message[0]='\0';
strcat(message,"Latitude= ");
itoa(latitude,value_str,10);
strcat(message2,"\n Longitude= ");
itoa(longitude,value_str2,10);
strcat(message,value_str);
strcat(message2,value_str2);
strcat(message,message2);
sms.SendSMS(number,message);
Serial.println("\nSMS sent OK");
delay (30000);
}
}
void getGPS(){
bool newdata = false;
unsigned long start = millis();
// Every 1 seconds we print an update
while (millis() - start < 1000)
{
if (feedgps ()){
newdata = true;
}
}
if (newdata)
{
gpsdump(gps);
}
}
bool feedgps(){
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
//byte month, day, hour, minute, second, hundredths;
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
}
}
Thank You for the help =)