May-10-2021, 06:48 PM
Hi,
I'm trying to read the outputs from a GPS device. The only data I'm interested in is the one between the words '$GPGGA' and '$GPGSA'.
The code below works but at times I get extra characters coming from outside my search and I cannot seem to find the culpit.
I appreciate some help.
TIA
but at times I get
I'm trying to read the outputs from a GPS device. The only data I'm interested in is the one between the words '$GPGGA' and '$GPGSA'.
The code below works but at times I get extra characters coming from outside my search and I cannot seem to find the culpit.
I appreciate some help.
TIA
rxData = b'$GPRMC,111956.00,A,4030.32925,N,00353.76292,W,0.208,,100521,,,A*61\r\n$GPVTG,,T,,M,0.208,N,0.384,K,A*26\r\n$GPGGA,111956.00,4030.32925,N,00353.76292,W,1,05,1.55,718.1,M,50.2,M,,*4C\r\n$GPGSA,A,3,31,29,25,26,18,,,,,,,,3.81,1.55,3.48*05\r\n$GPGSV,3,1,11,04,08,319,,0' def readData(): try: data = re.search("GPGGA,(.*)\r\n", rxData.decode("utf-8")) if data: data = data.group(1) print('data: {}'.format(data)) #split string by, into array arry = data.split(',') # print(arry[0]) time.sleep(1) except Exception as e: print(str(e)) readData()The output should be
data: 111956.00,4030.32925,N,00353.76292,W,1,05,1.55,718.1,M,50.2,M,,*4C
but at times I get
data: 111956.00,4030.32925,N,00353.76292,W,1,05,1.55,718.1,M,50.2,M,,*4C$GPGSA,A,3,31,29,25,26,18,,,,,,,,3.81,1.55,3.48*05