Update gps00.py
This commit is contained in:
parent
5d709fbe8f
commit
3a2beffb41
31
gps00.py
31
gps00.py
@ -18,6 +18,31 @@ ser.flushInput()
|
||||
rec_buff = ''
|
||||
time_count = 0
|
||||
|
||||
def convert_to_decimal(coord, direction):
|
||||
# Split the coordinate into degrees and minutes
|
||||
parts = coord.split('.')
|
||||
degrees = float(parts[0][:-2])
|
||||
minutes = float(parts[0][-2:] + '.' + parts[1])
|
||||
|
||||
# Convert to decimal degrees
|
||||
decimal = degrees + (minutes / 60)
|
||||
|
||||
# Make negative if South or West
|
||||
if direction in ['S', 'W']:
|
||||
decimal = -decimal
|
||||
|
||||
return decimal
|
||||
|
||||
def parse_gps_data(gps_string):
|
||||
parts = gps_string.split(',')
|
||||
if len(parts) < 6:
|
||||
return "Invalid GPS data"
|
||||
|
||||
lat = convert_to_decimal(parts[0], parts[1])
|
||||
lon = convert_to_decimal(parts[2], parts[3])
|
||||
|
||||
return f"{lat:.6f}, {lon:.6f}"
|
||||
|
||||
def send_at(command,back,timeout):
|
||||
rec_buff = ''
|
||||
ser.write((command+'\r\n').encode())
|
||||
@ -33,8 +58,10 @@ def send_at(command,back,timeout):
|
||||
else:
|
||||
# gps_data = rec_buff.decode()[25:-36]
|
||||
gps_data = rec_buff.decode()[13:-36]
|
||||
print(gps_data)
|
||||
client.publish("iiot/"+ myhost +"/gps", gps_data)
|
||||
print("Raw GPS data:", gps_data)
|
||||
converted_gps = parse_gps_data(gps_data)
|
||||
print("Converted GPS data for Google Maps:", converted_gps)
|
||||
# client.publish("iiot/"+ myhost +"/gps", gps_data)
|
||||
return 1
|
||||
else:
|
||||
print('GPS no está listo')
|
||||
|
Loading…
Reference in New Issue
Block a user