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)
|
answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
|
||||||
if 1 == answer:
|
if 1 == answer:
|
||||||
answer = 0
|
answer = 0
|
||||||
if ',,,,,,' not in rec_buff:
|
if ',,,,,,' in rec_buff:
|
||||||
# Extract GPS information from rec_buff and store it in the database
|
print('GPS no está listo')
|
||||||
gps_info = extract_gps_info(rec_buff) # Implement this function based on the format of rec_buff
|
rec_null = False
|
||||||
store_gps_coordinates(gps_info)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
print('GPS is not ready')
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
print('error %d' % answer)
|
# 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 = ''
|
rec_buff = ''
|
||||||
send_at('AT+CGPS=0','OK',1)
|
send_at('AT+CGPS=0','OK',1)
|
||||||
return False
|
return False
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def extract_gps_info(rec_buff):
|
def extract_gps_info(rec_buff):
|
||||||
# Implement this function based on the format of rec_buff
|
# Implement this function based on the format of rec_buff
|
||||||
# Example: gps_info = rec_buff.split(',')[2]
|
# Example: gps_info = rec_buff.split(',')[2]
|
||||||
|
Loading…
Reference in New Issue
Block a user