Skip to content

Instantly share code, notes, and snippets.

@maxim75
Created February 15, 2022 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim75/f879cf78b4173d2a116be68587179c1d to your computer and use it in GitHub Desktop.
Save maxim75/f879cf78b4173d2a116be68587179c1d to your computer and use it in GitHub Desktop.
import serial
import datetime
ser = serial.Serial("/dev/cu.usbserial-0001", baudrate=9600)
ser.flushInput()
ser.flushOutput()
idx = 0
nmea_data = b""
# skip first line, since it could be incomplete
ser.readline()
while True:
idx += 1
nmea_sentence = ser.readline()
nmea_data += nmea_sentence
if idx % 100 == 0:
print(f"idx: {idx}")
if idx % 2000 == 0:
# save to file after 2000 sentences added
filename = datetime.datetime.utcnow().strftime("data/gps_data_%Y%m%d-%H%M%S.nmea")
f = open(filename, "ab")
f.write(nmea_data)
f.close()
nmea_data = b""
@maxim75
Copy link
Author

maxim75 commented Mar 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment