#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define SerialMon Serial 

double gpslong                = 0;
double gpslat                 = 0;
static const int RXPin = 4, TXPin = 15;
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);                          // Activate GPS
bool gpsStatus = false;

void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);
}

void loop()
{
  SerialMon.println("Waiting for GPS ");
  long timenow = millis() + 5000;
  while (timenow > millis()) {
    handleGPS ();
  }
  gpslong = gps.location.lng();
  gpslat  = gps.location.lat();
  SerialMon.print("LONG: ");
  SerialMon.print(gpslong, 6);
  SerialMon.print(", LAT: ");
  SerialMon.println(gpslat, 6);
  SerialMon.println();
}

void handleGPS () {
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      if (millis() > 5000 && gps.charsProcessed() < 10)
      {
        Serial.println(F("No GPS detected: check wiring."));
        while (true);
      } else {
        gpsStatus = true;
      }
}
