Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get value #110

Open
Leweyy opened this issue Jun 7, 2020 · 0 comments
Open

How to get value #110

Leweyy opened this issue Jun 7, 2020 · 0 comments

Comments

@Leweyy
Copy link

Leweyy commented Jun 7, 2020

Im not sure how to get the GGA message from msg variable, the message var seems to contain all or the parsed messages


import pynmea2
import serial


ser = serial.Serial('/dev/ttyS1', 9600, timeout=5.0)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))

while 1:
    try:
        line = sio.readline()
        msg = pynmea2.parse(line)
        print(repr(msg))
    except serial.SerialException as e:
        print('Device error: {}'.format(e))
        break
    except pynmea2.ParseError as e:
        print('Parse error: {}'.format(e))
        continue

This is my current code

_ser = serial.Serial(GPS_PORT, 19200, timeout=1.0)
_gps = io.TextIOWrapper(io.BufferedRWPair(_ser, _ser))

def get_gps_data_v2 ():
    while 1:
        try:
            data = _gps.readline()
            prefix = data[0:6]
            if prefix == "$GPGGA":
                msg = pynmea2.parse(data)
                location = {}
                location["latitude"] = msg.latitude
                location["longitude"] = msg.longitude
                location["altitude"] = msg.altitude
                return json.dumps(location)

        except serial.SerialException as e:
            print('Device error: {}'.format(e))
            break
        except pynmea2.ParseError as e:
            print('Parse error: {}'.format(e))
            continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant