Code: Select all
#!/usr/bin/python
import serial
import pynmea2
import time
# Enable Serial Communication
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
# Transmitting AT Commands to the Modem
# '\r\n' indicates the Enter key
port.write('AT'+'\r\n')
rcv = port.read(100)
print rcv
time.sleep(.1)
port.write('AT+CGNSPWR=1'+'\r\n') # to power the GPS
rcv = port.read(100)
print rcv
time.sleep(5)
port.write('AT+CGNSIPR=9600'+'\r\n') # Set the baud rate of GPS
rcv = port.read(100)
print rcv
time.sleep(.1)
port.write('AT+CGNSTST=1'+'\r\n') # Send data received to UART
rcv = port.read(100)
print rcv
time.sleep(5)
port.write('AT+CGNSINF'+'\r\n') # Print the GPS information
rcv = port.read(200)
print rcv
time.sleep(5)
ser = serial.Serial('/dev/ttyS0',9600)
while 1:
data = ser.readline()
if (data.startswith("$GPGGA")):
msg = pynmea2.parse(data)
print repr(msg)
Any tips?