From 9d8b7356a128781b8502f8182692ac9b5f76cb43 Mon Sep 17 00:00:00 2001 From: Adolfo Delorenzo Date: Fri, 12 Jul 2024 01:25:33 +0000 Subject: [PATCH] Update GPS2.py --- GPS2.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/GPS2.py b/GPS2.py index 46052c7..a9d57ac 100644 --- a/GPS2.py +++ b/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]