Skip to content

How to get value  #110

Description

@Leweyy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions