通过arduino,sim 900a和NEO 6m通过短信发送链接谷歌地图GPS的麻烦

时间:2016-05-18 07:47:15

标签: arduino gps

我无法通过模块SIM 900aNEO 6m(GPS模块)和

通过短信发送链接的googlemap(GPS)

这是我的代码:

#include <SoftwareSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial serialgps (4,5);
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);

       }
     }
  }

}

void loop() {}
在拥有GPS之后,现在我将它由AT Comand带到短信

 void SendSMS(float latitude,float longitude )
 {
   delay (1000);
   Serial.print("AT\r");
   delay(1000);
   while (Serial.available()>0)
   { char inchar= (char)Serial.read();
   }
   Serial.println();
   Serial.println("AT+CMGF=1\r"); // 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("\r");

   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);


}

0 个答案:

没有答案