Python - Convertion of GPS time to UTC

1.8k Views Asked by At

I have been researching everywhere for a solution to this problem. Any help would be much appreciated.

I would like to take the time from the GPS data and need to convert that to a human readable format, may be like YYYY-MM-DD HH:MM:SS.

Following is the GPS dataformat:

$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A

Here, 123519 is fix taken at 12:35:19 UTC and 230394 is the date - 23rd of March 1994

Thanks.

2

There are 2 best solutions below

0
On BEST ANSWER

You can use something like

for line in data.split('\n') :
    if line.startswith( '$GPRMC' ) :
        lat, _, lon = line.strip().split(',')[2:5]

to manually bring the string to a suitable format. Then pass this to datetime.strptime:

from datetime import datetime
datetime_object = datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')

Or use a library like

pynmea2

micropyGPS

1
On

use gpsd service daemon and then use code gpsd.utc