Where am I going wrong here?
Using delay.
Here is a NeoGPS version of your sketch:
#include <ESP8266WiFi.h>
#include <NMEAGPS.h>
#include <SoftwareSerial.h>
NMEAGPS gps; // the parser
gps_fix fix; // the results of the parser, all GPS fields
uint16_t fixCount = 0;
static const int RXPin = 4;
static const int TXPin = 5;
SoftwareSerial gpsPort (RXPin,TXPin);
const char* ssid = "Ryan's iPhone";
const char* password = "ryanwifi";
unsigned long age = 0;
//WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
gpsPort.begin(9600);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("\nAttempting to Connect..");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void checkGPS()
{
static bool warningPrinted = false;
if (not warningPrinted and (millis() > 5000) and (gps.statistics.chars < 10))
{
Serial.println(F("No GPS detected: check wiring."));
warningPrinted = true;
}
}
void loop()
{
// Check for and parse any available GPS characters
if (gps.available( gpsPort )) {
// Once per second, a complete structure of GPS fields is ready.
fix = gps.read();
// Remember how many fixes we have received. This can be
// used for a 1Hz "clock".
fixCount++;
Serial.println("\n\n\nTest: ");
Serial.println( fixCount );
Serial.println("\nNumber of satellies: ");
if (fix.valid.satellites)
Serial.println( fix.satellites );
Serial.println("\nLatitude: ");
if (fix.valid.location)
Serial.println( fix.latitude(), 6 );
Serial.println("\nLongitude: ");
if (fix.valid.location)
Serial.println( fix.longitude(), 6 );
}
checkGPS();
}
Note how it only prints when a new GPS fix has arrived, after all sentences have arrived (RMC+GGA+ etc.). Other libraries do not work that way... you will get one update for each sentence (RMC, then GGA, etc.).
Because the sketch never sits at a delay, doing nothing, the sketch can do other things will each GPS gradually arrives. 9600 is really sloooow when your processor is running at 16MHz (or faster!). Don't make the processor twiddle its thumbs with delay. ![]()