adafruit / Adafruit_CircuitPython_GPS

GPS parsing module for CircuitPython. Meant to parse NMEA data from serial GPS modules.
MIT License
75 stars 58 forks source link

Lag in receiving gps lat long values #78

Open nayanagg opened 2 years ago

nayanagg commented 2 years ago

Hi, I'm getting data lag in receiving data from GPS when using threading in the python script.

BAUD_RATE SETTING = 115200 UPDATE_RATE SETTING= 100 milisecond

caternuson commented 2 years ago

Can you clarify what you mean by lag. What device are you running the code on? Is it only happening when using threading?

nayanagg commented 2 years ago

lag as in when using threading starts in python code the GPS timestamp starts lagging behind from actual time and keeps on increasing.

DEVICE = RASPBERRY PI 3B Is it only happening when using threading? : YES

caternuson commented 2 years ago

lag as in when using threading starts in python code the GPS timestamp starts lagging behind from actual time

By how much? How are you determining this?

nayanagg commented 2 years ago

by comparing with the gps timestamp with raspberry pi timestamp

caternuson commented 2 years ago

Are the two time stamps acquired at the same time in the same thread? Or in separate threads?

Is the difference milliseconds? Minutes? Days? Weeks?

Can you provide example code that demonstrates the issue?

nayanagg commented 2 years ago

Both timestamp collections running in the same thread. the difference in timestamp is shown in the image, GPS time is in UTC, and python DateTime is in IST.

Screenshot 2022-04-01 at 20 59 26
nayanagg commented 2 years ago

code :

def gps_int(): global gps,latitude,longitude,speed,accuracy,progSock, client_sock, client_info, state,BUFF_SIZE uart = serial.Serial("/dev/ttyUSB0", baudrate=9600,timeout=10) gps = adafruit_gps.GPS(uart,debug=False) gps.send_command(b"PMTK251,115200") uart = serial.Serial("/dev/ttyUSB0", baudrate=115200,timeout=10) gps = adafruit_gps.GPS(uart,debug=False) gps.send_command(b"PMTK220,100") gps.send_command(b"PMTK300,100") gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") while True: gps.update() if gps.has_fix: print("=" * 40) print("Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(gps.timestamp_utc.tm_mon,gps.timestamp_utc.tm_mday,gps.timestamp_utc.tm_year,gps.timestamp_utc.tm_hour,gps.timestamp_utc.tm_min,gps.timestamp_utc.tm_sec,)) print(datetime.now()) if gps.speed_knots is not None:

print("Speed: {} Km/Hr".format(int((gps.speed_knots) * 1.852)))

            speed = int(gps.speed_knots*1.852)
        if gps.horizontal_dilution is not None:
            #print("Horizontal dilution: {}".format(gps.horizontal_dilution))
            accuracy = gps.horizontal_dilution
        latitude = ("{0:.6f}".format(gps.latitude))
        longitude = ("{0:.6f}".format(gps.longitude))
    else:
        print("Waiting for fix...")
        latitude = 0.0
        longitude = 0.0
        speed = 0.0
        accuracy = 0.0
        time.sleep(1)
ladyada commented 2 years ago

the date time we get from the GPS is whatever is emitted, there's nothing in the library that manipuates it. so maybe its threading or maybe your raspi has a timing offset. either way, we recommend not using threading, none of the examples use it and its the fastest way to solve your problem as we have no plans to research your threading issue