Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using re.search()
#2
If I had to do this myself, I would first split on newlines, then split on commas. You can then ignore any lines that don't have the $GPGGA as the message.

rxData = b'$GPRMC,111956.00,A,4030.32925,N,00353.76292,W,0.208,,100521,,,A*61\r\n$GPVTG,,T,,M,0.208,N,0.384,K,A*26\r\n$GPGGA,111956.00,4030.32925,N,00353.76292,W,1,05,1.55,718.1,M,50.2,M,,*4C\r\n$GPGSA,A,3,31,29,25,26,18,,,,,,,,3.81,1.55,3.48*05\r\n$GPGSV,3,1,11,04,08,319,,0'

rxData = rxData.decode()
for line in rxData.splitlines():
    data = line.split(",")
    if data[0] == "$GPGGA":
        print(data)
Output:
['$GPGGA', '111956.00', '4030.32925', 'N', '00353.76292', 'W', '1', '05', '1.55', '718.1', 'M', '50.2', 'M', '', '*4C']
But there are modules out there that can read your stream directly and parse the NMEA sentences. I don't have your raw stream, so I can't demonstrate that. But I can use pynmeagps to parse that line.

from pynmeagps import NMEAReader

rxData = b'$GPRMC,111956.00,A,4030.32925,N,00353.76292,W,0.208,,100521,,,A*61\r\n$GPVTG,,T,,M,0.208,N,0.384,K,A*26\r\n$GPGGA,111956.00,4030.32925,N,00353.76292,W,1,05,1.55,718.1,M,50.2,M,,*4C\r\n$GPGSA,A,3,31,29,25,26,18,,,,,,,,3.81,1.55,3.48*05\r\n$GPGSV,3,1,11,04,08,319,,0'

rxData = rxData.decode()
for line in rxData.splitlines():
    data = line.split(",")
    if data[0] == "$GPGGA":
        print(NMEAReader.parse(line))
Output:
<NMEA(GPGGA, time=11:19:56, lat=40.505488, NS=N, lon=-3.896049, EW=W, quality=1, numSV=5, HDOP=1.55, alt=718.1, altUnit=M, sep=50.2, sepUnit=M, diffAge=, diffStation=)>
ebolisa likes this post
Reply


Messages In This Thread
using re.search() - by ebolisa - May-10-2021, 06:48 PM
RE: using re.search() - by bowlofred - May-10-2021, 07:30 PM
RE: using re.search() - by ebolisa - May-10-2021, 08:12 PM
RE: using re.search() - by bowlofred - May-10-2021, 09:43 PM
RE: using re.search() - by nilamo - May-10-2021, 08:37 PM
RE: using re.search() - by Gribouillis - May-11-2021, 06:06 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020