Hi community!
I spend some time accessing NMEA from my R+ with Python.
As I couldn’t find any related post, I thought I’d share my experience.
-
Hardware Setup
R+ with stable satellite connection and WiFi access to the same network as the PC. -
Software Setup
Python with pynmeagps module: pynmeagps · PyPI
(complete code attached below) -
Output
<NMEA(GNGGA, time=16:08:27, lat=50.xxxxxxxx, NS=N, lon=6.xxxxxxxxx, EW=E, quality=5, numSV=14, HDOP=1.3, alt=91.441, altUnit=M, sep=46.329, sepUnit=M, diffAge=1.0, diffStation=2975)> -
Code
import datetime
import socket
from pynmeagps import NMEAReader
if __name__ == '__main__':
host_ip = 'xxx.xxx.xxx.xx' # Reach IP
port = 9001 # Reach TCP Port
try:
stream = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket successfully created")
except socket.error as err:
print ("socket creation failed with error %s" %(err))
print('Connecting: ' + str(host_ip) + ' : ' + str(port))
stream.connect((host_ip, port))
nmr = NMEAReader(stream)
print('Listening...')
for (raw_data, parsed_data) in nmr.iterate():
if parsed_data:
t = '' # to be filled with time data
try:
t = parsed_data.time.strftime('%H:%M:%S,%f')
# print(parsed_data.time)
except:
pass
print(parsed_data)
print('System \t\t\t\t GPS' )
print(str(datetime.datetime.now()) + ' \t ' + str(t) + '\n')
else:
pass