I'm confused and I hope someone is able to help but please treat me gently, I am still learning!
I collect NMEA data and need to analyse it to select the correct record from the incoming stream. I've pasted a very small part below which fails to provide the expected result and it is driving me mad.
//NMEA String Parser test
char Sentence[90] = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M, 46.9, M, , *47";
char *p, *i;
char *latitude;
char *longtitude;
void setup()
{
Serial.begin(9600);
Serial.print("\nNMEA Sentence: ");
Serial.println(Sentence);
// Extract first element which is the type of NMEA Sentence
p = strtok_r(Sentence, ",", &i);
Serial.print("\nNMEAtype = ");
Serial.println(p);
if (p == "$GPGGA") {
Serial.println("$GPGGA found");
}
else {
Serial.println("\nIncorrect type");
while (1);
}
// then choose 3rd element which is Latitude
p = strtok_r(NULL, ", ", &i);
p = strtok_r(NULL, ", ", &i);
Serial.print("\nLatitude = ");
Serial.println(p);
// Finally 5tht element required which is Longtitude
p = strtok_r(NULL, ", ", &i);
p = strtok_r(NULL, ", ", &i);
Serial.print("\nLongtitude = ");
Serial.println(p);
}
void loop() {};
Despite the Sentence being of the correct type - $GPGGA - the test at the if fails and the sketch terminates at the while(1): as shown below in the serial monitor output.
NMEA Sentence: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M, 46.9, M, , *47
NMEAtype = $GPGGA
Incorrect type
Strings, strings and *pointers are a bit of dark magic in my current world and I need to understand why the test fails - is anyone able to help please.
Many thanks.