     
     gpsS.begin(9600);
 
-    next_aprs = millis() + 5000l;
+    next_aprs = 0;
 }
 
 void loop() {
-  if (gps.available(gpsS)) {
+  while (gps.available(gpsS)) {
     fix = gps.read();
-    gpsUpdates++;
-  }
+    next_aprs++;
 
-  if (millis() >= next_aprs && gpsUpdates >= 2) {
-    gpsUpdates = 0;
+    if (next_aprs >= 5) {
+      next_aprs = 0;
 
-    fix = gps.read();
-    char latitude[9];
-    snprintf(latitude, 9, "%02d%02d.%02u%c", fix.latitudeDMS.degrees, fix.latitudeDMS.minutes, truncate(fix.latitudeDMS.seconds_whole, 2), fix.latitudeDMS.NS() );
+      char latitude[9];
+      char longitude[10];
+      char datetime[7];
+      if(fix.valid.location) {
+        snprintf(latitude, 9, "%02d%02d.%02u%c", fix.latitudeDMS.degrees, fix.latitudeDMS.minutes, truncate(fix.latitudeDMS.seconds_whole, 2), fix.latitudeDMS.NS() );
+        snprintf(longitude, 10, "%03d%02d.%02u%c", fix.longitudeDMS.degrees, fix.longitudeDMS.minutes, truncate(fix.longitudeDMS.seconds_whole, 2), fix.longitudeDMS.EW() );
+      }
 
-    char longitude[10];
-    snprintf(longitude, 10, "%03d%02d.%02u%c", fix.longitudeDMS.degrees, fix.longitudeDMS.minutes, truncate(fix.longitudeDMS.seconds_whole, 2), fix.longitudeDMS.EW() );
 
-    char datetime[7];
-    snprintf(datetime, 7, "%02d%02d%02d", fix.dateTime.hours, fix.dateTime.minutes, fix.dateTime.seconds);
-  
-    //Check pressure the flight day in http://weather.noaa.gov/weather/current/LEMD.html
-    //We take the value between parenthesis. If pressure is 1013 write in readAltitude
-    //this value multiplied by 100
-    APRSPacket packet(datetime,
-                      bmp.readAltitude(101900),
-                      fix.speed(),
-                      fix.heading(),
-                      bmp.readTemperature(),
-                      bmp.readPressure());
+      snprintf(datetime, 7, "%02d%02d%02d", fix.dateTime.hours, fix.dateTime.minutes, fix.dateTime.seconds);
 
-    packet.setLatitude(latitude);
-    packet.setLongitude(longitude);
-    packet.setLatitudeF(fix.latitude());
-    packet.setLongitudeF(fix.longitude());
-  
-    packet.aprs_send();
-  
-    while (afsk_flush()) {
-      power_save();
+    
+      //Check pressure the flight day in http://weather.noaa.gov/weather/current/LEMD.html
+      //We take the value between parenthesis. If pressure is 1013 write in readAltitude
+      //this value multiplied by 100
+      APRSPacket packet(datetime,
+                        bmp.readAltitude(101900),
+                        fix.speed(),
+                        fix.heading(),
+                        bmp.readTemperature(),
+                        bmp.readPressure());
+
+      packet.setLatitude(latitude);
+      packet.setLongitude(longitude);
+      if(fix.valid.location){
+        packet.setLatitudeF(fix.latitude());
+        packet.setLongitudeF(fix.longitude());
+      }
+    
+      packet.aprs_send();
+    
+      while (afsk_flush()) {
+        power_save();
+      }
     }
-  
-    next_aprs = millis() + 5000l;
   }
 }
 


Adafruit_BMP085 bmp;

unsigned long next_aprs = 0;

void setup() {
    pinMode(LED_PIN, OUTPUT);

#include <NMEAGPS.h>
#include <NeoSWSerial.h>

static NMEAGPS gps;  // The parsing object
static gps_fix fix;  // GPS fields are stored here as they are parsed

static NeoSWSerial gpsS(RXPIN, TXPIN);

//Internal Temp sensor
#include <Wire.h>
