Hello I'm new in python and raspberry, today I try to run a script take in 'https://www.rhydolabz.com/wiki/?p=18639#comment-47045' But I don't have a valid data in my status code. The code :
#Code pour reconnaissance GPS :
import serial
import time
from decimal import *
from subprocess import call
def find(str, ch):
for i, ltr in enumerate(str):
if ltr == ch:
yield i
# initialisation des commandes AT
port = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=1)
print('test')
port.write('AT\n'.encode('utf8')); #on fait repartir le système à 0
rcv = port.read(100)
print(rcv)
print('fin test')
time.sleep(.1)
port.write('AT+CGNSPWR=1\n'.encode('utf8')) # on allume le GPS
rcv = port.read(100)
print(rcv)
time.sleep(.1)
port.write('AT+CGNSIPR=115200\n'.encode('utf8')) # baud rate de UART2
rcv = port.read(100)
print(rcv)
time.sleep(.1)
port.write('AT+CGNSTST=1\n'.encode('utf8')) #on envoie les donées à l'UART
rcv = port.read(100)
print(rcv)
time.sleep(.1)
port.write('AT+CGNSINF\n'.encode('utf8')) #transphorme les infos GPS
rcv = port.read(200) # en phrases NMEA
print(rcv)
time.sleep(.1)
ck=1
while ck==1:
print("test 2")
fd = port.read(200)
print(fd) #envoie les données GPS à l'UART
time.sleep(.5)
if '$GNRMC'.encode('utf8') in fd:
print("test 3") #on relève la lattitude et longitude
ps=fd.find('$GNRMC'.encode('utf8'))
print(ps)
dif=len(fd)-ps
print(dif)
if dif > 50 :
print("test 4")
data=fd[ps:(ps+50)]
print(data)
ds=data.find('A'.encode('utf8')) #on regarde juste si le GPS marche bien.
if ds > 0 and ds < 20:
print("test 5")
p=list(find(data, ","))
lat=data[(p[2]+1):p[3]]
lon=data[(p[4]+1):p[5]]
#calcul des données du GPS
s1=lat[2:len(lat)]
s1=Decimal(s1)
s1=s1/60
s11=int(lat[0:2])
s1 = s11+s1
s2=lon[3:len(lon)]
s2=Decimal(s2)
s2=s2/60
s22=int(lon[0:3])
s2 = s22+s2
print(s1)
print(s2)
the probleme is on the line :
ds=data.find('A'.encode('utf8')) #on regarde juste si le GPS marche bien.
if ds > 0 and ds < 20:
I don't have any 'A' !!! I just have a "V" for "data is void". I can give you some words of my shell :
test
b'AT\r\nOK\r\n$GNGGA,022839.094,,,,,0,0,,,M,,M,,*59\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GLGSA,A,1,,,,,,,,,,,,,'
fin test
b',,*02\r\n$GPGSV,1,1,00*79\r\n$GLGSV,1,1,00*65\r\n$GNRMC,022839.094,V,,,,,0.00,0.00,060180,,,N*53\r\n$GNVTG,0'
b'.00,T,,M,0.00,N,0.00,K,N*2C\r\nAT+CGNSPWR=1\r\nOK\r\nAT+CGNSIPR=115200\r\nOK\r\n$GNGGA,022840.094,,,,,0,0,,,M,'
b',M,,*57\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GLGSA,A,1,,,,,,,,,,,,,,,*02\r\n$GPGSV,1,1,00*79\r\n$GLGSV,1,1,00'
b'*65\r\n$GNRMC,022840.094,V,,,,,0.00,0.00,060180,,,N*5D\r\n$GNVTG,0.00,T,,M,0.00,N,0.00,K,N*2C\r\nAT+CGNSTST=1\r\nOK\r\nAT+CGNSINF\r\n+CGNSINF: 0,,,,,,,,,,,,,,,,,,,,\r\n\r\nOK\r\n$GNGGA,022841.094,,,,,0,0,,,M,,M,,*56\r\n$'
test 2
b'GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GLGSA,A,1,,,,,,,,,,,,,,,*02\r\n$GPGSV,1,1,00*79\r\n$GLGSV,1,1,00*65\r\n$GNRMC,022841.094,V,,,,,0.00,0.00,060180,,,N*5C\r\n$GNVTG,0.00,T,,M,0.00,N,0.00,K,N*2C\r\n$GNGGA,022842.094,,'
test 3
95
105
test 4
b'$GNRMC,022841.094,V,,,,,0.00,0.00,060180,,,N*5C\r\n$'
The problem is from this line :
test 4
b'$GNRMC,022841.094,V,,,,,0.00,0.00,060180,,,N*5C\r\n$'
Have you got an idee for what can I do ? Thank you !!