Gps data parsing from $GPGGA

If you are asking a question, please follow this template:

  1. My goal is: I want lattitude, Longitude, time etc from nmea string GPGGA string.
  2. My actions are:I set the gps nmea sentance to give only $GPGGA , but when I compare the data.p with sscanf function. I get nothing at variables.
    //sscanf(data.p, “$GPGGA,%f,%f,%c,%f,%c,%f,%f,%d,%f,%f”,
    // &time, &lat, &ns, &lon, &ew, &hdop, &alt, &fix, &course, &speed);

when I tried to log ( data.p ) directly .
I can see Disturbed output on console . I can see GPGGA over there too. but there are some charaters from previous cmds and iterations.Same like garbage. but with visible GPGGA.

  1. How can I compare only GPGGA from this disturbed string in data.p?

This is fuction getting called after sequence of command…

bool gnsinf_cb(void *cb_arg, bool ok, struct mg_str data)
  LOG(LL_INFO, ("What is ok %d", ok));
   sscanf(data.p, "$GPGGA,%f,%f,%c,%f,%c,%f,%f,%d,%f,%f",
   &time, &lat, &ns, &lon, &ew, &hdop, &alt, &fix, &course, &speed);

Any comment on this will be helpful, Thank you…

Try to declare variables as double and use %lf in sscanf specifiers.

You have to check if the string is a valid GGA sentence.

I have checked GPGGA is valid sentence. Major issue is garbage values in data.p with this GPGGA string.

What does LOG(LL_INFO, ("[%.*s]", data.len, data.p)); show?

My u-blox NEO-6M returns


when there is no fix and


where xx is the latitude and yyy is the longitude (in degrees).
According to this, GN means the talker ID is mixed GPS and GLONASS data.

It shows recent GPGGA values and, previous uart data mixed with it. data.p does not parsed recent uart string.

I am here using Gps only, so GPGGA is valid sentence, major issue is to read uart string from data.p, Its more of a garbage mixed with recent GPGGA values.

You need to insure that the string you pass to gnsinf_cb is a valid GGA sentence, i.e. it starts with $GPGGA, ends with <CR><LF>, contains 14 comma separated fields and the CRC is ok.

Yes, it is valid sentence. it shows garbage in data.p logging.

When we use serial terminal, it shows proper clean string.