2024-07-26 -

This commit is contained in:
Adolfo Delorenzo 2024-07-26 22:28:58 -06:00
parent 31ae945885
commit fa6fa1390b
6 changed files with 40 additions and 512 deletions

View File

@ -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

1 Timestamp Latitude Longitude
6491 2024-07-26 22:05:51 9.939901 -84.104903
6492 2024-07-26 22:06:06 9.939902 -84.104903
6493 2024-07-26 22:06:21 9.939901 -84.104904
6494 2024-07-26 22:06:36 9.939901 -84.104904
6495 2024-07-26 22:06:51 9.939901 -84.104904
6496 2024-07-26 22:07:06 9.939902 -84.104906
6497 2024-07-26 22:07:21 9.939902 -84.104905
6498 2024-07-26 22:07:36 9.939902 -84.104905
6499 2024-07-26 22:07:51 9.939903 -84.104906
6500 2024-07-26 22:08:06 9.939903 -84.104906
6501 2024-07-26 22:08:21 9.939903 -84.104906
6502 2024-07-26 22:08:36 9.939904 -84.104906
6503 2024-07-26 22:08:51 9.939903 -84.104905
6504 2024-07-26 22:09:06 9.939903 -84.104905
6505 2024-07-26 22:09:21 9.939903 -84.104905
6506 2024-07-26 22:09:36 9.939902 -84.104904
6507 2024-07-26 22:09:52 9.939903 -84.104905
6508 2024-07-26 22:10:07 9.939903 -84.104905
6509 2024-07-26 22:10:22 9.939903 -84.104905
6510 2024-07-26 22:10:37 9.939903 -84.104905
6511 2024-07-26 22:10:52 9.939903 -84.104905
6512 2024-07-26 22:11:07 9.939903 -84.104905
6513 2024-07-26 22:11:22 9.939904 -84.104905
6514 2024-07-26 22:11:37 9.939903 -84.104905
6515 2024-07-26 22:11:52 9.939904 -84.104905
6516 2024-07-26 22:12:07 9.939903 -84.104904
6517 2024-07-26 22:12:22 9.939903 -84.104904
6518 2024-07-26 22:12:37 9.939904 -84.104904
6519 2024-07-26 22:12:52 9.939904 -84.104904
6520 2024-07-26 22:13:07 9.939903 -84.104903
6521 2024-07-26 22:13:22 9.939903 -84.104903
6522 2024-07-26 22:13:37 9.939903 -84.104903
6523 2024-07-26 22:13:52 9.939904 -84.104903
6524 2024-07-26 22:14:07 9.939904 -84.104902
6525 2024-07-26 22:14:22 9.939905 -84.104902
6526 2024-07-26 22:14:37 9.939905 -84.104902
6527 2024-07-26 22:15:37 9.939905 -84.104901
6528 2024-07-26 22:15:52 9.939904 -84.104900
6529 2024-07-26 22:16:07 9.939904 -84.104899
6530 2024-07-26 22:16:22 9.939904 -84.104899
6531 2024-07-26 22:16:37 9.939904 -84.104898
6532 2024-07-26 22:16:52 9.939904 -84.104898
6533 2024-07-26 22:17:07 9.939904 -84.104897

View File

@ -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!")

View File

@ -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!")

View File

@ -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!")

View File

@ -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!")

View File

@ -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!")