Update GPS2.py
This commit is contained in:
parent
4cdd89a0fc
commit
9d8b7356a1
31
GPS2.py
31
GPS2.py
@ -43,21 +43,36 @@ 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)
|
||||
print('error %d'%answer)
|
||||
rec_buff = ''
|
||||
send_at('AT+CGPS=0','OK',1)
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user