SHARE
TWEET

Untitled

a guest Jan 20th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. static const int RXPin = 2, TXPin = 3;
  5. static const uint32_t GPSBaud = 9600;
  6.  
  7. // The TinyGPS++ object
  8. TinyGPSPlus gps;
  9.  
  10. // The serial connection to the GPS device
  11. SoftwareSerial ss(RXPin, TXPin);
  12.  
  13. SoftwareSerial SIM800L(7,6);
  14.  
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(9600);
  19.   ss.begin(GPSBaud);
  20.  
  21.   Serial.println(F("DeviceExample.ino"));
  22.   Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  23.   Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  24.   Serial.println(F("by Mikal Hart"));
  25.   Serial.println();
  26. }
  27.  
  28. void loop()
  29. {
  30.   // This sketch displays information every time a new sentence is correctly encoded.
  31.   while (ss.available() > 0)
  32.     if (gps.encode(ss.read()))
  33.       displayInfo();
  34.  
  35.   if (millis() > 5000 && gps.charsProcessed() < 10)
  36.   {
  37.     Serial.println(F("No GPS detected: check wiring."));
  38.     delay(10000);
  39.   }
  40. }
  41.  
  42. void displayInfo()
  43. {
  44.   Serial.print(F("Location: "));
  45.   if (gps.location.isValid())
  46.   {
  47.     Serial.print(gps.location.lat(), 6);
  48.     Serial.print(F(","));
  49.     Serial.print(gps.location.lng(), 6);
  50.  
  51.     static uint32_t prevmillis;
  52.     if(millis() - prevmillis > 10000){
  53.         SIM800L.println("AT+CMGF=1");
  54.         SIM800L.println("AT+CMGS=\"xxxxxxxxxxxx\"");
  55.         delay(500);
  56.         SIM800L.println("www.google.com/maps/place/" + String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6));// The SMS text you want to send
  57.         delay(100);
  58.     SIM800L.write(13);
  59.     SIM800L.write(26);
  60.     prevmillis = millis();
  61.  
  62.     }
  63.   }
  64.   else
  65.   {
  66.     Serial.print(F("INVALID"));
  67.   }
  68.   Serial.println();
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top