-
Notifications
You must be signed in to change notification settings - Fork 0
/
singlegps.py
27 lines (26 loc) · 868 Bytes
/
singlegps.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
import os
import serial
def get_present_gps():
ser=serial.Serial('/dev/ttyAMA0',9600)
ser.open()
# open a file to write gps data
f = open('/home/pi/Desktop/gps1', 'w')
data=ser.read(512) # read 1024 bytes
f.write(data) #write data into file
f.flush() #flush from buffer into os buffer
#ensure to write from os buffers(internal) into disk
f = open('/home/pi/Desktop/gps1', 'r')# fetch the required file
for line in f.read().split('\n'):
if line.startswith('$GPGGA'):
lat, _, lon= line.split(',')[2:5]
try:
lat=float(lat)
lon=float(lon)
print lat
print lon
a=[lat,lon]
print a[0]
print a
except:
pass
get_present_gps()