Pynmeagps showing "badly formed message" or "invalid checksum" from "read" function

129 views Asked by At

I am developing a Python program to read NMEA messages sent from a RTK device using the Pynmeagps and Pyserial libraries so I can check for every NMEA sentence the surveyor is providing to my computer. I use a while structure in loop to read continuously the data sent through a COM port and store latitude and longitude values in a .txt file. However, after some minutes, the program stops and a NMEAParseError message from Pynmeagps is shown saying "badly formed message" followed by a bunch of random numbers, letters and slashes, which seems to be some kind of buffer outputs. Another error message can be shown saying that a NMEAMessage got an invalid checksum that should be another value.

The weirdest thing is that both the characters in the message and the time taken until the error is shown are random. So I have no idea what is causing the problem because there is no pattern to help understand.

This is the program:

from pynmeagps import *    
import serial    
import sys    


# Defining serial port to a variable
serial_port = 'COM3'    
ser = serial.Serial(serial_port, 57600, timeout=3)    


while True:
    # Reading NMEA data
    msg = NMEAReader(ser)   
    (raw_data, parsed_data) = msg.read()
    pdict = parsed_data.__dict__


with open("NMEAOutputs_Rover1.txt", "a") as outputs:

    # Getting 'lat' and 'lon' accessed in parsed_data.__dict__
    if 'lat' in pdict:
        # Getting only lat and lon as GLL
        # '_msgID' stands for the type of message
        if pdict['_msgID'] == 'GLL':
            lat = pdict['lat']
            lon = pdict['lon']
            print(lat,";",lon,";", pdict['time'], file=outputs)

This is an example of the "invalid checksum" error messages:

Traceback (most recent call last): File "c:\Users\Maua\Documents\MauabusNav\Navigation\NMEANav_Rover1.py", line 16, in <module> (raw_data, parsed_data) = msg.read() File "C:\Users\Maua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pynmeagps\nmeareader.py", line 118, in read parsed_data = self.parse( File "C:\Users\Maua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pynmeagps\nmeareader.py", line 187, in parse raise nme.NMEAParseError( pynmeagps.exceptions.NMEAParseError: Message GLGSV$GNRMC invalid checksum 16 - should be 7B.

Unfortunately, I could not get a "badly formed message" example because it is less common to happen than the "invalid checksum" situation.

I recommend someone with experience in Pynmeagps, Pyserial and RTK devices such as the Sparkfun RTK Surveyor to try to help me solve this. But anyone is welcome!

I supposed it was something related with the transmission speed rate being too much for the reading capacity of the program, so I tried to increase the rate to 1000ms using another software. I used 1 second because it was the default transmission rate of a RTK device setup as BASE, which seemed to work decently before. But it didn't solve the problem.

Why can't I just put the device into BASE mode? That's because the program is supposed to receive data from a surveyor in ROVER mode. The BASE is only responsible for making the ROVER send precise geographic location.

0

There are 0 answers