-
Notifications
You must be signed in to change notification settings - Fork 1
/
gps_final.py
42 lines (38 loc) · 1.59 KB
/
gps_final.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import serial
from time import sleep
import sys
import webbrowser
ser = serial.Serial ("/dev/ttyS0")
gpgga_info = "$GPGGA,"
GPGGA_buffer = 0
NMEA_buff = 0
def convert_to_degrees(raw_value):
decimal_value = raw_value/100.00
degrees = int(decimal_value)
mm_mmmm = (decimal_value-int(decimal_value))/0.6
position = degrees + mm_mmmm
position = "%.4f" %(position)
return position
try:
while True:
received_data = (str)(ser.readline()) #read NMEA string received
GPGGA_data_available = received_data.find(gpgga_info) #check for NMEA GPGGA string
if (GPGGA_data_available>0):
GPGGA_buffer = received_data.split("$GPGGA,",1)[1] #store data coming after “$GPGGA,” string
NMEA_buff = (GPGGA_buffer.split(','))
nmea_time = []
nmea_latitude = []
nmea_longitude = []
nmea_time = NMEA_buff[0] #extract time from GPGGA string
nmea_latitude = NMEA_buff[1] #extract latitude from GPGGA string
nmea_longitude = NMEA_buff[3] #extract longitude from GPGGA string
print("NMEA Time: ", nmea_time,'\n')
lat = (float)(nmea_latitude)
lat = convert_to_degrees(lat)
longi = (float)(nmea_longitude)
longi = convert_to_degrees(longi)
print ("NMEA Latitude:", lat,"NMEA Longitude:", '-'+longi,'\n')
#map_link='http://maps.google.com/?q='+lat+','+longi
#webbrowser.open(map_link)
except KeyboardInterrupt:
sys.exit(0)