I'm not able to receive GPS data.
The jumpers are placed in the top position (A)
AT commands return the following:
>>> ser = serial.Serial("/dev/ttyUSB2",115200)
>>> ser.write(('AT+CGPS=1,1'+ '\r\n' ).encode())
13
>>>
>>> ser.write(('AT+CGPS?'+ '\r\n' ).encode())
10
>>> ser.write(('AT+CGPSINFO'+ '\r\n' ).encode())
13
python code ####################################### '''
import RPi.GPIO as GPIO
import serial
import time
import pynmea2
ser_send = serial.Serial('/dev/ttyUSB2',115200,timeout=1)
ser_receive = serial.Serial('/dev/ttyUSB1',115200,timeout=1)
ser_S0 = serial.Serial('/dev/ttyS0',115200,timeout=1)
def parseGPS(string):
if 'GGA' in string:
msg = pynmea2.parse(string)
print(str(msg))
print("Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units))
else:
print(f' doesnt contain GGA: {string}')
def check_conn(conn):
return conn.name, conn.is_open
def send_at(command,expected_result,timeout):
name, state = check_conn(ser_send)
print(f'{name} is {state}')
rec_buff = ''
if state:
ser_send.write((command+'\r\n').encode())
time.sleep(timeout)
if ser_send.inWaiting(): #something was received in the buffer
time.sleep(0.01 )
rec_buff = ser_send.read(ser_send.inWaiting()) # read the buffer
if rec_buff != '':
if expected_result not in rec_buff.decode():
print(command + ' ERROR')
print(command + ' returned:\t' + rec_buff.decode())
return False
else:
print(f'---------- response from AT command: {rec_buff.decode()}')
return True
else:
print('GPS is not ready, returned nothing')
return False
def get_gps_position():
rec_null = True
answer = False
gps_started = False
print('Start GPS session...')
while not gps_started:
rec_buff = ''
send_at('AT+CGPS=1,1','OK',1)
time.sleep(2)
gps_status= send_at('AT+CGPS','OK',1)
if gps_status:
gps_started = True
while 1:
answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
#readings = list()
print('######################## USB1 ')
while ser_receive.inWaiting() >0:
readings = ser_receive.readline().decode()
parseGPS(readings)
#readings.append(ser_receive.readline())
# testing another port
print('######################## S0 ')
while ser_S0.inWaiting() >0:
readings = ser_S0.readline().decode()
parseGPS(readings)
if answer:
answer = False
rec_buff = ser_send.read(ser_send.inWaiting()).decode()
if ',,,,,,' in rec_buff:
print('GPS is not ready')
#rec_null = False
print(f'{ser_receive.name} received {readings}')
time.sleep(2)
else:
print(f'{ser_receive.name} received {readings}')
time.sleep(2)
else:
print('error %d'%answer)
rec_buff = ''
send_at('AT+CGPS=0','OK',1)
return False
time.sleep(1.5)
'''
#######################################
All I see is this:
/dev/ttyUSB2 is True AT+CGPS ERROR AT+CGPS returned: AT+CGPS ERROR
OK
end of response ######################## USB1
doesnt contain GGA: $GNGNS,,,,,,NNN,,,,,,*1D
doesnt contain GGA: $GPVTG,,T,,M,,N,,K,N*2C
doesnt contain GGA: $GPGSA,A,1,,,,,,,,,,,,,,,*1E
doesnt contain GGA: $GNGSA,A,1,,,,,,,,,,,,,,,*00
doesnt contain GGA: $BDGSA,A,1,,,,,,,,,,,,,,,*0F
– Newbie_dude Jan 22 '21 at 15:29