Gps data parsing from $GPGGA

#1

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…

#2

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

#3

You have to check if the string is a valid GGA sentence.
https://gpsd.gitlab.io/gpsd/NMEA.html#_gga_global_positioning_system_fix_data

#4

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

#5

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

#6

My u-blox NEO-6M returns

$GNGGA,173322.00,,,,,0,00,99.99,,,,,,*7E

when there is no fix and

$GNGGA,174134.00,xx23.30293,N,yyy06.75219,E,1,06,2.35,95.6,M,34.9,M,,*70

otherwise.
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.

#7

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

#8

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.

#9

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.

#10

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

#11

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