0

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 problem 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 !!

3
  • I don't know how I can active my status code !!! can anyone help me ? Apr 17, 2019 at 11:45
  • maybe it's because my GPS can't find any fix but I don't know how can I resolve this problem !! Apr 17, 2019 at 13:39
  • Take it outside for fifteen minutes (powered up). It should be able to see four satellites in that time and get an initial fix. Once it's got that it should be OK no more than ~40 cm from the window. Also try using gpsd which is a zero code way of driving any GPS receiver.
    – Dougie
    Sep 1, 2023 at 19:30

2 Answers 2

0

I find the solution, my GPS can't work beacause he don't do the "fix". I just make it during 5 minutes with the antenna projected to clear sky for GPS initialization.

0

Sadly, the tutorial I used is not realy complete. I changed the code:

#Code pour reconnaissance GPS :
import re
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\r'.encode())   #on fait repartir le système à 0
rcv = port.read(100)
#print(rcv)
time.sleep(.1) 

port.write(b'AT+CGNSPWR=1'+'\r'.encode())        # on allume le GPS
rcv = port.read(100)

#print(rcv)
time.sleep(.1)

port.write(b'AT+CGNSIPR=115200'+'\r'.encode()) # baud rate de UART2
rcv = port.read(100)
#print(rcv)
time.sleep(.1)

port.write(b'AT+CGNSTST=1'+'\r'.encode())   #on envoie les donées à l'UART
rcv = port.read(100)
#print(rcv)
time.sleep(.1)

port.write(b'AT+CGNSINF'+'\r'.encode())      #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() in fd:
        #print("test 3")       #on relève la lattitude et longitude
        ps=fd.find('$GNRMC'.encode())
        #print(ps)
        dif=len(fd)-ps
        #print(dif)
        if dif > 50 :
            #print("test 4")
            data=fd[ps:(ps+74)]
            #print(data)
            ds=data.find('A'.encode()) #on regarde juste si le GPS marche bien.
            if ds > 0 and ds < 20:
                #print("test 5")
                #p=list(find(data, ","))
                pos2=data.find(",N,".encode())
                pos1=pos2-11
                lat=data[pos1:pos2]
                pos11=pos2+3
                pos22=pos11+12
                lon=data[pos11:pos22]
                #print(lat)
                #print(lon)


#calcul des données du GPS

                s1=lat[2:11]
                s1=s1.decode()
                s1=s1.replace('.','')
                s1=Decimal(s1)
                s1=s1/60
                #print(s1)
                s1=str(s1)
                s1=s1[0:5]
                #print(s1)
                s11=int(lat[0:2])
                s11=str(s11)
                s1=str(s1)
                s111="latitude="+s11+","+s1




                s2=lon[3:12]
                s2=s2.decode()
                s2=s2.replace(".","")
                s2=Decimal(s2)
                s2=s2/60
                #print(s2)
                s2=str(s2)
                s2=s2[0:5]
                #print(s2)
                s22=int(lon[0:3])
                s2=str(s2)
                s22=str(s22)
                s222="longitude="+s22+","+s2

                print(s111)
                print(s222)

More than that, the tutorial don't explain a lot of specifications so if anyone need help....

1
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Jan 21, 2020 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.