we're trying to read data from a digital yacht AISnet base station on a Pi. From what I've read, Digital Yacht has drivers for both osx and windows (but not linux for this unit) and their job is to create a virtual com port so that the device can send an NMEA 1083 stream as if it's doing RS-232 serial communication. We are OK with parsing the NMEA data ourselves, but I don't know much about drivers. Wondering if anyone has any experience getting NMEA data from a digital yacht or similar device in to the Pi?
Well, I'm answering my question because it was easier than I thought. The linux "gpsd" project provided everything we need, because GPS units use the same protocol, NMEA 1083. I found all docs I needed on the gpsd site:
You can install the gpsd daemon, and then connect to it with client code or with telnet and see all the AIS messages it picks up, already parsed to json messages. Fantastic!
Getting GPS's Data: GPS receives data from output NMEA0183, tcp: // 2947, class: TPV & amp; tag: GPGGA.
Next is the step in the terminal to access GPS data:
- Install: gpsd, gpsd-clients. (Note: install both use apt-get install)
- Reboot (sudo reboot or sudo init 6)
- Sudo dpkg-reconfigure gpsd (Note: configuration baudrate = 9600, 8 N 1 data format).
- Serial tests with the command: gpspipe -r or cat /dev/ttyS* or /dev/ttyUSB* (Note: the * sign matches the read, use command ls /dev/ttyS*, /ttyS*, /ttyAMA* or /ttyUSB* or others).
If point 3 fails, stop and disable socket 2947 for a while. Try to type with the command & then reboot Raspberry Pi immadiately:
$ sudo systemctl stop gpsd.socket
$ sudo systemctl disables gpsd.socket
Then start and enable gpsd socket with command:
$ sudo systemctl start gpsd.socket
$ sudo systemctl enables gpsd.socket
Start daemon using command:
$ sudo gpsd /dev/ttyS0 –F /var/run/gpsd.sock
For live straming:
$ cgps –s or $ cgps or gpsmon
In practice way to get stream data GPS from NMEA Output, you can also use a simple command:
$ timeout 10s gpspipe -w -n 10 | grep -m 1 speed
$ timeout 10s gpspipe -w -n 10 | grep -m 1 speed | jq
Using json query / jq for pretty printing.
In python script:
def getGPS(): gpspipe= "timeout 10s gpspipe -w -n 10 | grep -m 1 speed" p = subprocess.Popen(gpspipe, stdout = subprocess.PIPE, shell = True)