gpsd-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending NMEA to other device from my APP via Serial


From: Pinnacle Systems Group
Subject: Re: Sending NMEA to other device from my APP via Serial
Date: Sun, 17 Mar 2024 20:10:20 -0400

Greetings Hans-- 

To feed NMEA sentences from your Raspberry Pi (running gpsd for GPS data acquisition) to another device via RS232/V.24, you can use a straightforward method by piping the NMEA sentences directly from gpsd to one of the Raspberry Pi’s serial /dev/tty devices.

Here’s one way to approach to doing this:

  1. Identify the Serial Port: First, make sure you have identified the correct serial port (/dev/tty*) on your Raspberry Pi that corresponds to your RS232/V.24 connection. This could be something like /dev/ttyAMA0 or /dev/ttyUSB0, depending on how the RS232 interface is connected to your Raspberry Pi (directly to the GPIO pins or via a USB-to-serial adapter).

  2. Configure gpsd for Shared Memory: Since you’re already using gpsd with its shared memory interface in your C++ application, check that gpsd is correctly configured and running, acquiring GPS data from your ublox GPS device.

  3. Pipe NMEA Sentences to the Serial Port: The simplest method to pipe NMEA sentences is to use a short script or program that reads NMEA sentences from gpsd and writes them to the specified serial device. You can do this s a using Python, which is commonly available on Raspberry Pi:

import gps
import serial
import time

# Set up serial port. Replace '/dev/ttyUSB0' with your serial port
serial_port = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)

# Listen on localhost port 2947 (gpsd) using the gps module
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

try:
    while True:
        report = session.next()
        # Check if the report's class is 'TPV' (Time Position Velocity) for valid GPS data
        if report['class'] == 'TPV':
            if hasattr(report, 'lat') and hasattr(report, 'lon'):
                # Create NMEA sentence or use any valid NMEA sentence from gpsd
                nmea_sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\r\n"
                serial_port.write(nmea_sentence.encode())
        time.sleep(1)
except KeyboardInterrupt:
    # Gracefully close the serial port and terminate
    serial_port.close()

This Python script uses a hardcoded NMEA sentence for demonstration. In practice, you should modify the script to use the actual data from gpsd. Libraries like gps (for interfacing with gpsd) and serial (for serial communication) make it straightforward to extract GPS data and transmit it over serial ports.

Remember, the baud rate and serial port in the example (9600 and /dev/ttyUSB0) should be adjusted based on your specific RS232 device’s requirements and the Raspberry Pi’s serial port configuration.

Make sure your user has the necessary permissions to access both the GPS device and the serial port on the Raspberry Pi. You might need to add your user to groups like dialout or tty.

Also when working with physical connections like RS232, be sure to check the electrical specifications and ensure compatibility to avoid damaging your devices.


On Sun, Mar 17, 2024, 1:19 AM Hans Kurscheidt <lve0200@gmail.com> wrote:
Hi there,
just assume Raspberry Pi under Linux Debian and ublox GPS via USB. I'm running gpsd in my APP, using the shared mem i/f under C++. All fine! But there's another device which I have to feed w/ NMEA from my RPI via RS232/V.24. Can't get my head around, what would be the easiest way, doing it. Off course, I would prefer just piping NMEA sentences directly from the device to one of my /dev/tty devices. Any suggestion?
Thank you in advance.
hk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]