Skip to content

Instantly share code, notes, and snippets.

@maxim75
Created February 15, 2022 21:15
Show Gist options
  • Save maxim75/bc712d4f003c8abee63bb8e75d48dce9 to your computer and use it in GitHub Desktop.
Save maxim75/bc712d4f003c8abee63bb8e75d48dce9 to your computer and use it in GitHub Desktop.
import pynmea2
nmea_data = open("data/gps_data_20220215-070028.nmea", "rb")
for message_bytes in nmea_data.readlines()[:10]: # read first 10 messages from file
try:
message = message_bytes.decode("utf-8").replace("\n", "").replace("\r", "")
parsed_message = pynmea2.parse(message)
except:
# skip invalid messages
continue
print(f"message: {message}")
for field in parsed_message.fields:
value = getattr(parsed_message, field[1])
print(f"{field[0]:40} {field[1]:20} {value}")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment