diff --git a/gps_data_raspberrypi.csv b/gps_data_raspberrypi.csv index 5ee1c59..75b6b74 100644 --- a/gps_data_raspberrypi.csv +++ b/gps_data_raspberrypi.csv @@ -6491,3 +6491,43 @@ Timestamp,Latitude,Longitude 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 +2024-07-26 22:06:36,9.939901,-84.104904 +2024-07-26 22:06:51,9.939901,-84.104904 +2024-07-26 22:07:06,9.939902,-84.104906 +2024-07-26 22:07:21,9.939902,-84.104905 +2024-07-26 22:07:36,9.939902,-84.104905 +2024-07-26 22:07:51,9.939903,-84.104906 +2024-07-26 22:08:06,9.939903,-84.104906 +2024-07-26 22:08:21,9.939903,-84.104906 +2024-07-26 22:08:36,9.939904,-84.104906 +2024-07-26 22:08:51,9.939903,-84.104905 +2024-07-26 22:09:06,9.939903,-84.104905 +2024-07-26 22:09:21,9.939903,-84.104905 +2024-07-26 22:09:36,9.939902,-84.104904 +2024-07-26 22:09:52,9.939903,-84.104905 +2024-07-26 22:10:07,9.939903,-84.104905 +2024-07-26 22:10:22,9.939903,-84.104905 +2024-07-26 22:10:37,9.939903,-84.104905 +2024-07-26 22:10:52,9.939903,-84.104905 +2024-07-26 22:11:07,9.939903,-84.104905 +2024-07-26 22:11:22,9.939904,-84.104905 +2024-07-26 22:11:37,9.939903,-84.104905 +2024-07-26 22:11:52,9.939904,-84.104905 +2024-07-26 22:12:07,9.939903,-84.104904 +2024-07-26 22:12:22,9.939903,-84.104904 +2024-07-26 22:12:37,9.939904,-84.104904 +2024-07-26 22:12:52,9.939904,-84.104904 +2024-07-26 22:13:07,9.939903,-84.104903 +2024-07-26 22:13:22,9.939903,-84.104903 +2024-07-26 22:13:37,9.939903,-84.104903 +2024-07-26 22:13:52,9.939904,-84.104903 +2024-07-26 22:14:07,9.939904,-84.104902 +2024-07-26 22:14:22,9.939905,-84.104902 +2024-07-26 22:14:37,9.939905,-84.104902 +2024-07-26 22:15:37,9.939905,-84.104901 +2024-07-26 22:15:52,9.939904,-84.104900 +2024-07-26 22:16:07,9.939904,-84.104899 +2024-07-26 22:16:22,9.939904,-84.104899 +2024-07-26 22:16:37,9.939904,-84.104898 +2024-07-26 22:16:52,9.939904,-84.104898 +2024-07-26 22:17:07,9.939904,-84.104897 diff --git a/gpsinflux01.py b/gpsinflux01.py deleted file mode 100644 index 172fba9..0000000 --- a/gpsinflux01.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/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 lat, lon - -def write_to_influxdb(lat, lon): - timestamp = int(time.time() * 1000000000) # nanosecond precision - - lat_point = Point("latitude") \ - .tag("host", myhost) \ - .field("_value", lat) \ - .time(timestamp) - - lon_point = Point("longitude") \ - .tag("host", myhost) \ - .field("_value", lon) \ - .time(timestamp) - - 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(14) # Wait for 14 seconds before the next reading - -ser.close() -GPIO.cleanup() -client.close() -print("GPS tracking stopped. Goodbye!") diff --git a/gpsinfluxdb.py b/gpsinfluxdb.py deleted file mode 100644 index aa537d1..0000000 --- a/gpsinfluxdb.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/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 deleted file mode 100644 index 3d26710..0000000 --- a/gpsinfluxdb01.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/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 deleted file mode 100644 index 14636ab..0000000 --- a/gpsinfluxdb02.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/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 deleted file mode 100644 index 7a825bb..0000000 --- a/gpsinfluxdb03.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/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!")