Python-NEO-6M-GPS-Raspberry-Pi icon indicating copy to clipboard operation
Python-NEO-6M-GPS-Raspberry-Pi copied to clipboard

Type Error on Neo-6m-GPS.py

Open OrbisTerrarumProLiberi opened this issue 5 years ago • 3 comments

TypeError: argument should be integer or bytes-like object, not 'str'

OrbisTerrarumProLiberi avatar Feb 26 '20 16:02 OrbisTerrarumProLiberi

Hi,

You are getting this error message because the parse method from the pynmea2 library expects a string as argument but you are passing bytes.

To solve that issue you need to convert the byte message into string before passing it to the parser as follows:

import serial
import pynmea2



def parseGPS(str_conv):

    if str_conv.find('GGA'): #now you can search for string characters
        msg = pynmea2.parse(str_conv) #if found use parser
        print("Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.l$

 
while True:

    serialPort = serial.Serial("/dev/serial0", 9600, timeout=0.5)
    str = serialPort.readline()
    str_conv = str.decode('utf-8').strip() #convert bytes to string

    try:

        parseGPS2(str_conv)

    except:

        continue

Hope it helps!

Regards,

YannickLecroart avatar Aug 21 '20 14:08 YannickLecroart

Hi, I forked the project because I wanted to work on the Python part of the repo. In particular, my plan is to remove the dependency to pynmea2. Unfortunately, at the moment I have not too much to work on that but I will definitely fix it on a long run. I will let you guys know when I'm ready for a pull request ;-)

maximilianwank avatar Aug 25 '20 08:08 maximilianwank

yes please let me know. This repo is just a collection of useful code for the Neo-6m because I didn't find as many useful information.

FranzTscharf avatar Jan 11 '21 14:01 FranzTscharf