Update GPS2.py

This commit is contained in:
Adolfo Delorenzo 2024-07-12 01:25:33 +00:00
parent 4cdd89a0fc
commit 9d8b7356a1

29
GPS2.py
View File

@ -43,14 +43,27 @@ def get_gps_position():
answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
if 1 == answer:
answer = 0
if ',,,,,,' not in rec_buff:
# Extract GPS information from rec_buff and store it in the database
gps_info = extract_gps_info(rec_buff) # Implement this function based on the format of rec_buff
store_gps_coordinates(gps_info)
return True
else:
print('GPS is not ready')
if ',,,,,,' in rec_buff:
print('GPS no está listo')
rec_null = False
time.sleep(1)
else:
# Extract GPS coordinates from the response
gps_data = rec_buff.split(',')
latitude = gps_data[2]
longitude = gps_data[3]
# Connect to the SQLite database
conn = sqlite3.connect('gps_coordinates.db')
c = conn.cursor()
# Insert the GPS coordinates into the database
c.execute("INSERT INTO gps_coordinates (latitude, longitude) VALUES (?, ?)", (latitude, longitude))
# Commit and close the connection
conn.commit()
conn.close()
else:
print('error %d'%answer)
rec_buff = ''
@ -58,6 +71,8 @@ def get_gps_position():
return False
time.sleep(1.5)
return True
def extract_gps_info(rec_buff):
# Implement this function based on the format of rec_buff
# Example: gps_info = rec_buff.split(',')[2]