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

Add example showing how to forward position as NMEA over UDP #171

Merged
merged 6 commits into from
Oct 13, 2024

Conversation

sindrehan
Copy link
Member

I'm not really familiar with the NMEA stuff, so would be great if you @aviggen or @haavardsyslak could take a look and see if everything makes sense.

Fixes #170

@sindrehan sindrehan added the documentation Improvements or additions to documentation label Oct 9, 2024
@sindrehan sindrehan self-assigned this Oct 9, 2024
examples/nmea_publisher.py Outdated Show resolved Hide resolved
examples/nmea_publisher.py Outdated Show resolved Hide resolved
Copy link
Contributor

@aviggen aviggen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to change the port, other that than it seems like it will work. Have you been able to test it at all?

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.77%. Comparing base (149ee93) to head (ae0557e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #171   +/-   ##
=======================================
  Coverage   73.77%   73.77%           
=======================================
  Files          11       11           
  Lines        1266     1266           
=======================================
  Hits          934      934           
  Misses        332      332           
Flag Coverage Δ
macos-latest_3.10 73.77% <ø> (ø)
macos-latest_3.11 73.77% <ø> (ø)
macos-latest_3.12 73.77% <ø> (ø)
macos-latest_3.9 73.75% <ø> (ø)
ubuntu-latest_3.10 73.77% <ø> (ø)
ubuntu-latest_3.11 73.77% <ø> (ø)
ubuntu-latest_3.12 73.77% <ø> (ø)
ubuntu-latest_3.9 73.75% <ø> (ø)
windows-latest_3.10 73.75% <ø> (ø)
windows-latest_3.11 73.75% <ø> (ø)
windows-latest_3.12 73.75% <ø> (ø)
windows-latest_3.9 73.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sindrehan
Copy link
Member Author

I don't have an actual device to test with, but I (CoPilot really) made a test script that uses an parser to check the validity and it seems to work fine with that.

import socket
import pynmea2

# UDP configuration
UDP_IP = "0.0.0.0"
UDP_PORT = 10111

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))

print(f"Listening for UDP packets on {UDP_IP}:{UDP_PORT}")


def validate_nmea_sentence(sentence: str) -> bool:
    """Validate the NMEA sentence using pynmea2."""
    try:
        parsed_sentence = pynmea2.parse(sentence)
        return isinstance(parsed_sentence, pynmea2.types.talker.GLL)
    except pynmea2.nmea.ChecksumError:
        print("Checksum error")
        return False
    except pynmea2.nmea.ParseError:
        print("Parse error")
        return False


try:
    while True:
        data, addr = sock.recvfrom(1024)  # Buffer size is 1024 bytes
        message = data.decode("utf-8").strip()
        print(f"Received message: {message} from {addr}")

        if validate_nmea_sentence(message):
            print("Valid NMEA sentence")
        else:
            print("Invalid NMEA sentence")

except KeyboardInterrupt:
    print("Exiting...")
finally:
    sock.close()

@sindrehan sindrehan merged commit 80ad30c into master Oct 13, 2024
16 checks passed
@sindrehan sindrehan deleted the add-nmea-publisher-example branch October 13, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example script forwarding drone position as NMEA over UDP
3 participants