diff --git a/gps_data_raspberrypi.csv b/gps_data_raspberrypi.csv index ab9b68f..5ee1c59 100644 --- a/gps_data_raspberrypi.csv +++ b/gps_data_raspberrypi.csv @@ -6309,3 +6309,185 @@ Timestamp,Latitude,Longitude 2024-07-26 21:14:01,9.939956,-84.104910 2024-07-26 21:14:16,9.939956,-84.104909 2024-07-26 21:14:31,9.939956,-84.104909 +2024-07-26 21:14:46,9.939955,-84.104907 +2024-07-26 21:15:01,9.939955,-84.104907 +2024-07-26 21:15:16,9.939955,-84.104908 +2024-07-26 21:15:31,9.939955,-84.104907 +2024-07-26 21:15:46,9.939956,-84.104907 +2024-07-26 21:16:01,9.939954,-84.104907 +2024-07-26 21:16:16,9.939954,-84.104907 +2024-07-26 21:16:31,9.939954,-84.104907 +2024-07-26 21:16:46,9.939953,-84.104908 +2024-07-26 21:17:01,9.939952,-84.104908 +2024-07-26 21:17:16,9.939951,-84.104907 +2024-07-26 21:17:31,9.939949,-84.104907 +2024-07-26 21:17:46,9.939947,-84.104905 +2024-07-26 21:18:01,9.939947,-84.104904 +2024-07-26 21:18:16,9.939945,-84.104903 +2024-07-26 21:18:31,9.939944,-84.104902 +2024-07-26 21:18:46,9.939942,-84.104902 +2024-07-26 21:19:01,9.939942,-84.104902 +2024-07-26 21:19:16,9.939940,-84.104901 +2024-07-26 21:19:31,9.939939,-84.104900 +2024-07-26 21:19:46,9.939938,-84.104899 +2024-07-26 21:20:01,9.939937,-84.104898 +2024-07-26 21:20:16,9.939936,-84.104897 +2024-07-26 21:20:31,9.939934,-84.104896 +2024-07-26 21:20:46,9.939935,-84.104897 +2024-07-26 21:21:01,9.939935,-84.104898 +2024-07-26 21:21:16,9.939935,-84.104898 +2024-07-26 21:21:31,9.939934,-84.104897 +2024-07-26 21:21:46,9.939933,-84.104895 +2024-07-26 21:22:01,9.939932,-84.104895 +2024-07-26 21:22:16,9.939931,-84.104894 +2024-07-26 21:22:31,9.939931,-84.104894 +2024-07-26 21:22:46,9.939930,-84.104894 +2024-07-26 21:23:01,9.939930,-84.104894 +2024-07-26 21:23:16,9.939929,-84.104894 +2024-07-26 21:23:31,9.939929,-84.104893 +2024-07-26 21:23:47,9.939927,-84.104890 +2024-07-26 21:24:02,9.939926,-84.104889 +2024-07-26 21:24:17,9.939926,-84.104888 +2024-07-26 21:24:32,9.939926,-84.104889 +2024-07-26 21:24:47,9.939926,-84.104888 +2024-07-26 21:25:02,9.939925,-84.104887 +2024-07-26 21:25:17,9.939925,-84.104886 +2024-07-26 21:25:32,9.939924,-84.104885 +2024-07-26 21:25:47,9.939923,-84.104885 +2024-07-26 21:26:02,9.939923,-84.104885 +2024-07-26 21:26:17,9.939924,-84.104885 +2024-07-26 21:26:47,9.939924,-84.104885 +2024-07-26 21:27:02,9.939924,-84.104885 +2024-07-26 21:27:32,9.939923,-84.104884 +2024-07-26 21:27:47,9.939923,-84.104884 +2024-07-26 21:28:02,9.939923,-84.104883 +2024-07-26 21:28:17,9.939922,-84.104883 +2024-07-26 21:28:32,9.939923,-84.104884 +2024-07-26 21:28:47,9.939923,-84.104884 +2024-07-26 21:29:02,9.939923,-84.104884 +2024-07-26 21:29:17,9.939923,-84.104884 +2024-07-26 21:29:32,9.939923,-84.104884 +2024-07-26 21:29:47,9.939923,-84.104886 +2024-07-26 21:30:02,9.939923,-84.104885 +2024-07-26 21:30:17,9.939923,-84.104885 +2024-07-26 21:30:32,9.939923,-84.104885 +2024-07-26 21:31:02,9.939923,-84.104884 +2024-07-26 21:31:17,9.939923,-84.104883 +2024-07-26 21:31:32,9.939923,-84.104883 +2024-07-26 21:31:47,9.939923,-84.104883 +2024-07-26 21:32:02,9.939922,-84.104883 +2024-07-26 21:32:17,9.939921,-84.104882 +2024-07-26 21:32:32,9.939921,-84.104883 +2024-07-26 21:32:47,9.939921,-84.104883 +2024-07-26 21:33:02,9.939921,-84.104883 +2024-07-26 21:33:17,9.939921,-84.104882 +2024-07-26 21:33:32,9.939909,-84.104869 +2024-07-26 21:33:47,9.939903,-84.104863 +2024-07-26 21:34:02,9.939900,-84.104859 +2024-07-26 21:34:17,9.939899,-84.104857 +2024-07-26 21:34:32,9.939899,-84.104857 +2024-07-26 21:34:47,9.939899,-84.104857 +2024-07-26 21:35:03,9.939899,-84.104857 +2024-07-26 21:35:18,9.939899,-84.104858 +2024-07-26 21:35:33,9.939899,-84.104858 +2024-07-26 21:35:48,9.939899,-84.104858 +2024-07-26 21:36:03,9.939898,-84.104857 +2024-07-26 21:36:18,9.939897,-84.104857 +2024-07-26 21:36:33,9.939896,-84.104857 +2024-07-26 21:36:49,9.939896,-84.104857 +2024-07-26 21:37:04,9.939895,-84.104857 +2024-07-26 21:37:19,9.939895,-84.104857 +2024-07-26 21:37:49,9.939894,-84.104858 +2024-07-26 21:38:04,9.939894,-84.104857 +2024-07-26 21:38:34,9.939894,-84.104857 +2024-07-26 21:39:04,9.939894,-84.104857 +2024-07-26 21:39:19,9.939893,-84.104856 +2024-07-26 21:39:34,9.939892,-84.104856 +2024-07-26 21:39:49,9.939892,-84.104856 +2024-07-26 21:40:19,9.939892,-84.104857 +2024-07-26 21:40:49,9.939892,-84.104858 +2024-07-26 21:41:19,9.939891,-84.104857 +2024-07-26 21:41:34,9.939890,-84.104857 +2024-07-26 21:42:04,9.939890,-84.104858 +2024-07-26 21:42:19,9.939890,-84.104858 +2024-07-26 21:42:34,9.939889,-84.104858 +2024-07-26 21:43:04,9.939890,-84.104859 +2024-07-26 21:43:19,9.939890,-84.104860 +2024-07-26 21:43:34,9.939890,-84.104860 +2024-07-26 21:43:49,9.939890,-84.104861 +2024-07-26 21:44:04,9.939889,-84.104862 +2024-07-26 21:44:19,9.939890,-84.104863 +2024-07-26 21:44:34,9.939890,-84.104863 +2024-07-26 21:45:04,9.939890,-84.104864 +2024-07-26 21:45:34,9.939890,-84.104865 +2024-07-26 21:45:49,9.939889,-84.104865 +2024-07-26 21:46:04,9.939889,-84.104866 +2024-07-26 21:46:19,9.939889,-84.104867 +2024-07-26 21:46:34,9.939889,-84.104867 +2024-07-26 21:46:49,9.939888,-84.104867 +2024-07-26 21:47:04,9.939888,-84.104867 +2024-07-26 21:47:20,9.939888,-84.104867 +2024-07-26 21:47:35,9.939888,-84.104868 +2024-07-26 21:47:50,9.939888,-84.104869 +2024-07-26 21:48:05,9.939888,-84.104869 +2024-07-26 21:48:20,9.939888,-84.104870 +2024-07-26 21:48:35,9.939888,-84.104870 +2024-07-26 21:48:50,9.939888,-84.104871 +2024-07-26 21:49:05,9.939888,-84.104872 +2024-07-26 21:49:20,9.939888,-84.104873 +2024-07-26 21:49:35,9.939889,-84.104873 +2024-07-26 21:49:50,9.939889,-84.104874 +2024-07-26 21:50:05,9.939890,-84.104875 +2024-07-26 21:50:20,9.939890,-84.104875 +2024-07-26 21:50:35,9.939891,-84.104876 +2024-07-26 21:50:50,9.939891,-84.104877 +2024-07-26 21:51:05,9.939891,-84.104877 +2024-07-26 21:51:20,9.939891,-84.104877 +2024-07-26 21:51:35,9.939891,-84.104878 +2024-07-26 21:51:50,9.939891,-84.104879 +2024-07-26 21:52:05,9.939891,-84.104879 +2024-07-26 21:52:20,9.939891,-84.104880 +2024-07-26 21:52:35,9.939891,-84.104880 +2024-07-26 21:52:50,9.939891,-84.104881 +2024-07-26 21:53:05,9.939891,-84.104882 +2024-07-26 21:53:35,9.939891,-84.104883 +2024-07-26 21:54:05,9.939891,-84.104884 +2024-07-26 21:54:35,9.939891,-84.104885 +2024-07-26 21:55:05,9.939892,-84.104887 +2024-07-26 21:55:20,9.939892,-84.104887 +2024-07-26 21:55:35,9.939892,-84.104888 +2024-07-26 21:55:50,9.939893,-84.104889 +2024-07-26 21:56:20,9.939893,-84.104890 +2024-07-26 21:56:35,9.939893,-84.104890 +2024-07-26 21:56:50,9.939893,-84.104890 +2024-07-26 21:57:05,9.939893,-84.104890 +2024-07-26 21:57:35,9.939893,-84.104891 +2024-07-26 21:57:50,9.939893,-84.104892 +2024-07-26 21:58:05,9.939893,-84.104892 +2024-07-26 21:58:21,9.939893,-84.104893 +2024-07-26 21:58:51,9.939893,-84.104893 +2024-07-26 21:59:21,9.939893,-84.104893 +2024-07-26 21:59:36,9.939893,-84.104893 +2024-07-26 21:59:51,9.939893,-84.104893 +2024-07-26 22:00:06,9.939894,-84.104894 +2024-07-26 22:00:21,9.939894,-84.104894 +2024-07-26 22:00:51,9.939894,-84.104895 +2024-07-26 22:01:06,9.939894,-84.104895 +2024-07-26 22:01:21,9.939895,-84.104896 +2024-07-26 22:01:51,9.939896,-84.104897 +2024-07-26 22:02:21,9.939897,-84.104898 +2024-07-26 22:02:51,9.939898,-84.104899 +2024-07-26 22:03:06,9.939899,-84.104900 +2024-07-26 22:03:21,9.939900,-84.104901 +2024-07-26 22:03:36,9.939900,-84.104901 +2024-07-26 22:03:51,9.939900,-84.104902 +2024-07-26 22:04:06,9.939901,-84.104903 +2024-07-26 22:04:21,9.939901,-84.104903 +2024-07-26 22:04:36,9.939901,-84.104904 +2024-07-26 22:04:51,9.939902,-84.104904 +2024-07-26 22:05:06,9.939902,-84.104905 +2024-07-26 22:05:21,9.939903,-84.104906 +2024-07-26 22:05:36,9.939903,-84.104906 +2024-07-26 22:05:51,9.939901,-84.104903 +2024-07-26 22:06:06,9.939902,-84.104903 +2024-07-26 22:06:21,9.939901,-84.104904 diff --git a/gpsinfluxdb.py b/gpsinfluxdb.py new file mode 100644 index 0000000..aa537d1 --- /dev/null +++ b/gpsinfluxdb.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- +import RPi.GPIO as GPIO +import serial +import time +from datetime import datetime +import os +import signal +from influxdb_client import InfluxDBClient, Point +from influxdb_client.client.write_api import SYNCHRONOUS + +# GPIO configuration +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +ser = serial.Serial('/dev/ttyUSB3', 115200) +ser.flushInput() + +myhost = os.uname()[1] + +# InfluxDB settings +INFLUXDB_URL = "http://100.64.0.24:8086" +INFLUXDB_TOKEN = "IPtqPXbaXuuMHvx_tUOt1cmIZfLHucd-9DcepXTVpQc-fNKBhp6pkhyTsq_XnoGXdxwILy5AFFgZ_QUZCE5Jhg==" +INFLUXDB_ORG = "juandiego" # Replace with your organization name +INFLUXDB_BUCKET = "gps_data" + +# Initialize InfluxDB client +client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG) +write_api = client.write_api(write_options=SYNCHRONOUS) + +# Global flag for graceful exit +running = True + +def signal_handler(sig, frame): + global running + print('You pressed Ctrl+C! Stopping GPS tracking...') + running = False + +signal.signal(signal.SIGINT, signal_handler) + +def parse_gps_data(gps_string): + parts = gps_string.split(',') + if len(parts) < 4: + return None + + lat = float(parts[0][:2]) + float(parts[0][2:]) / 60 + if parts[1] == 'S': + lat = -lat + + lon = float(parts[2][:3]) + float(parts[2][3:]) / 60 + if parts[3] == 'W': + lon = -lon + + return f"{lat:.6f}", f"{lon:.6f}" + +def write_to_influxdb(lat, lon): + lat_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "latitude") \ + .field("value", float(lat)) + + lon_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "longitude") \ + .field("value", float(lon)) + + write_api.write(bucket=INFLUXDB_BUCKET, record=[lat_point, lon_point]) + +def send_at(command, back, timeout): + ser.write((command + '\r\n').encode()) + time.sleep(timeout) + if ser.inWaiting(): + time.sleep(0.01) + rec_buff = ser.read(ser.inWaiting()).decode() + if back in rec_buff: + gps_data = rec_buff.split('+CGPSINFO: ')[1].split('\r\n')[0] + parsed_data = parse_gps_data(gps_data) + if parsed_data: + lat, lon = parsed_data + print(f"GPS: Lat: {lat}, Lon: {lon}") + write_to_influxdb(lat, lon) + return 1 + return 0 + +def get_gps_position(): + send_at('AT+CGPSINFO', '+CGPSINFO:', 1) + +def initialize_gps(): + print('Starting GPS') + send_at('AT+CGPS=1', 'OK', 1) + time.sleep(2) + +initialize_gps() +print("Starting continuous GPS tracking. Press Ctrl+C to stop.") + +while running: + get_gps_position() + time.sleep(14) # Wait for 14 seconds before the next reading + +ser.close() +GPIO.cleanup() +client.close() +print("GPS tracking stopped. Goodbye!") diff --git a/gpsinfluxdb01.py b/gpsinfluxdb01.py new file mode 100644 index 0000000..3d26710 --- /dev/null +++ b/gpsinfluxdb01.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- +import RPi.GPIO as GPIO +import serial +import time +from datetime import datetime +import os +import signal +from influxdb_client import InfluxDBClient, Point +from influxdb_client.client.write_api import SYNCHRONOUS + +# GPIO configuration +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +ser = serial.Serial('/dev/ttyUSB3', 115200) +ser.flushInput() + +myhost = os.uname()[1] + +# InfluxDB settings +INFLUXDB_URL = "http://100.64.0.24:8086" +INFLUXDB_TOKEN = "IPtqPXbaXuuMHvx_tUOt1cmIZfLHucd-9DcepXTVpQc-fNKBhp6pkhyTsq_XnoGXdxwILy5AFFgZ_QUZCE5Jhg==" +INFLUXDB_ORG = "juandiego" # Replace with your organization name +INFLUXDB_BUCKET = "gpsdata" + +# Initialize InfluxDB client +client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG) +write_api = client.write_api(write_options=SYNCHRONOUS) + +# Global flag for graceful exit +running = True + +def signal_handler(sig, frame): + global running + print('You pressed Ctrl+C! Stopping GPS tracking...') + running = False + +signal.signal(signal.SIGINT, signal_handler) + +def parse_gps_data(gps_string): + parts = gps_string.split(',') + if len(parts) < 4: + return lat, lon + + lat = float(parts[0][:2]) + float(parts[0][2:]) / 60 + if parts[1] == 'S': + lat = -lat + + lon = float(parts[2][:3]) + float(parts[2][3:]) / 60 + if parts[3] == 'W': + lon = -lon + + return f"{lat:.6f}", f"{lon:.6f}" + +def write_to_influxdb(lat, lon): + lat_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "latitude") \ + .field("value", round(lat, 6)) + + lon_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "longitude") \ + .field("value", round(lon, 6)) + + write_api.write(bucket=INFLUXDB_BUCKET, record=[lat_point, lon_point]) + +def send_at(command, back, timeout): + ser.write((command + '\r\n').encode()) + time.sleep(timeout) + if ser.inWaiting(): + time.sleep(0.01) + rec_buff = ser.read(ser.inWaiting()).decode() + if back in rec_buff: + gps_data = rec_buff.split('+CGPSINFO: ')[1].split('\r\n')[0] + parsed_data = parse_gps_data(gps_data) + if parsed_data: + lat, lon = parsed_data + print(f"GPS: Lat: {lat:.6f}, Lon: {lon:.6f}") + write_to_influxdb(lat, lon) + return 1 + return 0 + +def get_gps_position(): + send_at('AT+CGPSINFO', '+CGPSINFO:', 1) + +def initialize_gps(): + print('Starting GPS') + send_at('AT+CGPS=1', 'OK', 1) + time.sleep(2) + +initialize_gps() +print("Starting continuous GPS tracking. Press Ctrl+C to stop.") + +while running: + get_gps_position() + time.sleep(2) # Wait for 14 seconds before the next reading + +ser.close() +GPIO.cleanup() +client.close() +print("GPS tracking stopped. Goodbye!") diff --git a/gpsinfluxdb02.py b/gpsinfluxdb02.py new file mode 100644 index 0000000..14636ab --- /dev/null +++ b/gpsinfluxdb02.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- +import RPi.GPIO as GPIO +import serial +import time +from datetime import datetime +import os +import signal +from influxdb_client import InfluxDBClient, Point +from influxdb_client.client.write_api import SYNCHRONOUS + +# GPIO configuration +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +ser = serial.Serial('/dev/ttyUSB3', 115200) +ser.flushInput() + +myhost = os.uname()[1] + +# InfluxDB settings +INFLUXDB_URL = "http://100.64.0.24:8086" +INFLUXDB_TOKEN = "IPtqPXbaXuuMHvx_tUOt1cmIZfLHucd-9DcepXTVpQc-fNKBhp6pkhyTsq_XnoGXdxwILy5AFFgZ_QUZCE5Jhg==" +INFLUXDB_ORG = "juandiego" # Replace with your organization name +INFLUXDB_BUCKET = "gpsdata" + +# Initialize InfluxDB client +client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG) +write_api = client.write_api(write_options=SYNCHRONOUS) + +# Global flag for graceful exit +running = True + +def signal_handler(sig, frame): + global running + print('You pressed Ctrl+C! Stopping GPS tracking...') + running = False + +signal.signal(signal.SIGINT, signal_handler) + +def parse_gps_data(gps_string): + parts = gps_string.split(',') + if len(parts) < 4: + return None + + lat = float(parts[0][:2]) + float(parts[0][2:]) / 60 + if parts[1] == 'S': + lat = -lat + + lon = float(parts[2][:3]) + float(parts[2][3:]) / 60 + if parts[3] == 'W': + lon = -lon + + return lat, lon # Return as float values, not strings + +def write_to_influxdb(lat, lon): + lat_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "latitude") \ + .field("value", round(lat, 6)) # Round to 6 decimal places + + lon_point = Point("gps_location") \ + .tag("host", myhost) \ + .tag("coordinate", "longitude") \ + .field("value", round(lon, 6)) # Round to 6 decimal places + + write_api.write(bucket=INFLUXDB_BUCKET, record=[lat_point, lon_point]) + +def send_at(command, back, timeout): + ser.write((command + '\r\n').encode()) + time.sleep(timeout) + if ser.inWaiting(): + time.sleep(0.01) + rec_buff = ser.read(ser.inWaiting()).decode() + if back in rec_buff: + gps_data = rec_buff.split('+CGPSINFO: ')[1].split('\r\n')[0] + parsed_data = parse_gps_data(gps_data) + if parsed_data: + lat, lon = parsed_data + print(f"GPS: Lat: {lat:.6f}, Lon: {lon:.6f}") # Print with 6 decimal places + write_to_influxdb(lat, lon) + return 1 + return 0 + +def get_gps_position(): + send_at('AT+CGPSINFO', '+CGPSINFO:', 1) + +def initialize_gps(): + print('Starting GPS') + send_at('AT+CGPS=1', 'OK', 1) + time.sleep(2) + +initialize_gps() +print("Starting continuous GPS tracking. Press Ctrl+C to stop.") + +while running: + get_gps_position() + time.sleep(14) # Wait for 14 seconds before the next reading + +ser.close() +GPIO.cleanup() +client.close() +print("GPS tracking stopped. Goodbye!") diff --git a/gpsinfluxdb03.py b/gpsinfluxdb03.py new file mode 100644 index 0000000..7a825bb --- /dev/null +++ b/gpsinfluxdb03.py @@ -0,0 +1,98 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- +import RPi.GPIO as GPIO +import serial +import time +from datetime import datetime +import os +import signal +from influxdb_client import InfluxDBClient, Point +from influxdb_client.client.write_api import SYNCHRONOUS + +# GPIO configuration +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +ser = serial.Serial('/dev/ttyUSB3', 115200) +ser.flushInput() + +myhost = os.uname()[1] + +# InfluxDB settings +INFLUXDB_URL = "http://100.64.0.24:8086" +INFLUXDB_TOKEN = "IPtqPXbaXuuMHvx_tUOt1cmIZfLHucd-9DcepXTVpQc-fNKBhp6pkhyTsq_XnoGXdxwILy5AFFgZ_QUZCE5Jhg==" +INFLUXDB_ORG = "juandiego" # Replace with your organization name +INFLUXDB_BUCKET = "gpsdata" + +# Initialize InfluxDB client +client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG) +write_api = client.write_api(write_options=SYNCHRONOUS) + +# Global flag for graceful exit +running = True + +def signal_handler(sig, frame): + global running + print('You pressed Ctrl+C! Stopping GPS tracking...') + running = False + +signal.signal(signal.SIGINT, signal_handler) + +def parse_gps_data(gps_string): + parts = gps_string.split(',') + if len(parts) < 4: + return None + + lat = float(parts[0][:2]) + float(parts[0][2:]) / 60 + if parts[1] == 'S': + lat = -lat + + lon = float(parts[2][:3]) + float(parts[2][3:]) / 60 + if parts[3] == 'W': + lon = -lon + + return lat, lon + +def write_to_influxdb(lat, lon): + point = Point("gps_location") \ + .tag("host", myhost) \ + .field("latitude", round(lat, 6)) \ + .field("longitude", round(lon, 6)) + + write_api.write(bucket=INFLUXDB_BUCKET, record=point) + +def send_at(command, back, timeout): + ser.write((command + '\r\n').encode()) + time.sleep(timeout) + if ser.inWaiting(): + time.sleep(0.01) + rec_buff = ser.read(ser.inWaiting()).decode() + if back in rec_buff: + gps_data = rec_buff.split('+CGPSINFO: ')[1].split('\r\n')[0] + parsed_data = parse_gps_data(gps_data) + if parsed_data: + lat, lon = parsed_data + print(f"GPS: Lat: {lat:.6f}, Lon: {lon:.6f}") + write_to_influxdb(lat, lon) + return 1 + return 0 + +def get_gps_position(): + send_at('AT+CGPSINFO', '+CGPSINFO:', 1) + +def initialize_gps(): + print('Starting GPS') + send_at('AT+CGPS=1', 'OK', 1) + time.sleep(2) + +initialize_gps() +print("Starting continuous GPS tracking. Press Ctrl+C to stop.") + +while running: + get_gps_position() + time.sleep(3) # Wait for 14 seconds before the next reading + +ser.close() +GPIO.cleanup() +client.close() +print("GPS tracking stopped. Goodbye!")