i have a question right now i can get the NMEA string given by the gps antenna every seconds. Now my question is all i want is to get the $GPRMC using infinite while loop in python. Below is the sample output of antenna.

b'$GPGGA,083439.000,1437.9128,N,12100.2349,E,1,08,1.2,21.1,M,39.1,M,,0000*66\r\n' b'$GPRMC,083439.000,A,1437.9128,N,12100.2349,E,0.47,24.55,140117,,,A*51\r\n' b'$GPGGA,083440.000,1437.9128,N,12100.2350,E,1,08,1.2,21.0,M,39.1,M,,0000*61\r\n' b'$GPRMC,083440.000,A,1437.9128,N,12100.2350,E,0.43,24.55,140117,,,A*53\r\n' b'$GPGGA,083441.000,1437.9127,N,12100.2353,E,1,08,1.2,21.1,M,39.1,M,,0000*6D\r\n' b'$GPRMC,083441.000,A,1437.9127,N,12100.2353,E,0.29,24.55,140117,,,A*52\r\n' b'$GPGGA,083442.000,1437.9126,N,12100.2350,E,1,08,1.2,20.9,M,39.1,M,,0000*65\r\n' b'$GPRMC,083442.000,A,1437.9126,N,12100.2350,E,0.29,24.55,140117,,,A*53\r\n' b'$GPGGA,083443.000,1437.9123,N,12100.2348,E,1,08,1.2,20.9,M,39.1,M,,0000*68\r\n' b'$GPRMC,083443.000,A,1437.9123,N,12100.2348,E,0.71,24.55,140117,,,A*53\r\n' b'$GPGGA,083444.000,1437.9123,N,12100.2351,E,1,08,1.2,21.0,M,39.1,M,,0000*6F\r\n' b'$GPRMC,083444.000,A,1437.9123,N,12100.2351,E,0.41,24.55,140117,,,A*5F\r\n' b'$GPGGA,083445.000,1437.9122,N,12100.2354,E,1,08,1.2,21.1,M,39.1,M,,0000*6B\r\n' b'$GPRMC,083445.000,A,1437.9122,N,12100.2354,E,0.49,24.55,140117,,,A*52\r\n' b'$GPGGA,083446.000,1437.9122,N,12100.2360,E,1,08,1.2,21.2,M,39.1,M,,0000*6C\r\n' b'$GPRMC,083446.000,A,1437.9122,N,12100.2360,E,0.75,24.55,140117,,,A*59\r\n' b'$GPGGA,083447.000,1437.9121,N,12100.2366,E,1,08,1.2,21.4,M,39.1,M,,0000*6E\r\n' b'$GPRMC,083447.000,A,1437.9121,N,12100.2366,E,0.85,24.55,140117,,,A*52\r\n' b'$GPGGA,083448.000,1437.9118,N,12100.2371,E,1,08,1.2,21.6,M,39.1,M,,0000*6F\r\n' b'$GPRMC,083448.000,A,1437.9118,N,12100.2371,E,0.85,24.55,140117,,,A*51\r\n'

  • try something like this: if you have each line in a variable called data then you can do sub = data[9:19] to get the numeric value from that field Jan 14, 2017 at 9:34
  • @SteveRobillard I would avoid slices here, you get such a nice and well behaving separator , why not use that? But then again I don't think that's much Pi specific either.
    – Ghanima
    Jan 14, 2017 at 10:04
  • @Ghanima first and simplest idea Jan 14, 2017 at 10:07
  • @SteveRobillard I was just wondering if NMEA string parts are of guaranteed and definite length.
    – Ghanima
    Jan 14, 2017 at 10:09
  • @Ghanima IIRC they are, but the answer is a better solution and why I only posted a comment Jan 14, 2017 at 10:13

1 Answer 1


Assuming you already have said loop to fetch those strings and you only want the GPRMC and not GPGGA bit of it. Then, in python3, something like

s = [long string goes here]
parts = bytes.decode(s).split(',')
if parts[0] == '$GPRMC':
    print(parts[1]) #or whatever you want to do with it.
    asFloat = float(parts[1]) # convert to a float

would get you said string / numeric.

  • thankis Mr @tobyd it works in me on what i really want to get :)
    – CeciliA
    Jan 17, 2017 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.