30/09/2018, 21:04

GPS send link GG map qua sms arduino,sim900a,neo 6m

// bác nào fix giúp e vs.thanks nhiều

#include <SoftwareSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial serialgps (4,5);//mo cong giao tiep GPS 

int year;
byte month,day,hour,minute,second,hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
float latitude;
float longitude;


void setup()
{
Serial.begin(19200);
serialgps.begin(9600);

 while(serialgps.available())
   {
    int c = serialgps.read();
     int count=c;
     for( count=0; count<5;count++)
     {
    if (gps.encode(c))
    {

      gps.f_get_position(&latitude, &longitude);
      Serial.print("Lat/Long: ");
      Serial.print(latitude, 5);
      Serial.print(", ");
      Serial.println(longitude, 5);
      gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths);
      Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
      Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
      Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
      Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
      Serial.print("."); Serial.println(hundredths, DEC);
      Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
      Serial.print("Course (degrees): "); Serial.println(gps.f_course());
      Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
      Serial.print("Satellites: "); Serial.println(gps.satellites());
      Serial.println();
      SendSMS(latitude,longitude);
      gps.stats(&chars, &sentences, &failed_checksum);
   
    }
  }
   }
  // put your setup code here, to run once:
}

void loop() {
 

}
void SendSMS(float latitude,float longitude  )
{
  delay (1000);
  Serial.print("AT
");
  delay(1000);
  while (Serial.available()>0)
     { char inchar= (char)Serial.read();
     }
    Serial.println();
    Serial.println("AT+CMGF=1
"); // sets the SMS mode to text
    delay(100);
    delay(1200);


    Serial.print("AT+CMGS=""); // send the SMS number
    Serial.print("01682740718");
    Serial.println(""");
    delay(1000);
  Serial.print("Localtion:"); // noi dung SMS

  Serial.print("www.google.com.vn/maps/place/");

  Serial.print(latitude, 5);

  Serial.print(",");

  Serial.print(longitude, 5);
  
  Serial.print("
");

  delay(500);
  
  Serial.println((char)26);//o código ASCII do ctrl + z é 26
 
    delay(500);

    Serial.write(0x1A);
    Serial.write(0x0D);
    Serial.write(0x0A);
 
    

    


}
Bài liên quan
0