add raw to tsv, mangodb first commit, restructure
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
class Account:
|
||||
def __init__(self):
|
||||
self.name = "quoije"
|
||||
self.pp_image = None
|
||||
self.car = None
|
||||
@@ -0,0 +1,4 @@
|
||||
class Car:
|
||||
def __init__(self):
|
||||
self.model = "Yaris 2013"
|
||||
self.obd = None
|
||||
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import shutil
|
||||
from tqdm import tqdm
|
||||
|
||||
def mount_device(device, mount_point):
|
||||
os.system(f"sudo mount {device} {mount_point}")
|
||||
|
||||
def unmount_device(mount_point):
|
||||
os.system(f"sudo umount {mount_point}")
|
||||
|
||||
def copy_files(source_folder, destination_folder):
|
||||
if not os.path.exists(destination_folder):
|
||||
os.makedirs(destination_folder)
|
||||
|
||||
for root, dirs, files in os.walk(source_folder):
|
||||
for file in tqdm(files, desc="Copying files", unit="file"):
|
||||
source_path = os.path.join(root, file)
|
||||
destination_path = os.path.join(destination_folder, file)
|
||||
|
||||
# Check if the file already exists in the destination folder
|
||||
if not os.path.exists(destination_path):
|
||||
shutil.copy2(source_path, destination_folder)
|
||||
|
||||
if __name__ == "__main__":
|
||||
source_device = "/dev/sda"
|
||||
mount_point = "/mnt/dash"
|
||||
destination_folder = "~/yaris-obd/dash/videos"
|
||||
|
||||
try:
|
||||
# Mount the device
|
||||
mount_device(source_device, mount_point)
|
||||
|
||||
# Copy files from source to destination
|
||||
copy_files(os.path.join(mount_point, "DCIM"), os.path.expanduser(destination_folder))
|
||||
|
||||
finally:
|
||||
# Unmount the device (even if an exception occurs)
|
||||
unmount_device(mount_point)
|
||||
@@ -0,0 +1,23 @@
|
||||
from pymongo import MongoClient
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv("./creds.env")
|
||||
|
||||
mUser = os.getenv()
|
||||
mPass = os.getenv()
|
||||
mDB = os.getenv()
|
||||
|
||||
def get_database():
|
||||
|
||||
# Provide the mongodb atlas url to connect python to mongodb using pymongo
|
||||
CONNECTION_STRING = "mongodb+srv://"+ mUser + ":" + mPass + "@cluster.mongodb.net/" + mDB
|
||||
|
||||
# Create a connection using MongoClient. You can import MongoClient or use pymongo.MongoClient
|
||||
client = MongoClient(CONNECTION_STRING)
|
||||
|
||||
# This is added so that many files can reuse the function get_database()
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Get the database
|
||||
dbname = get_database()
|
||||
@@ -0,0 +1,37 @@
|
||||
from flask_socketio import SocketIO
|
||||
from threading import Thread
|
||||
import app_obd, time, threading
|
||||
|
||||
socketio = SocketIO()
|
||||
uptime_lock = threading.Lock()
|
||||
|
||||
@socketio.on('connect')
|
||||
def connect_event():
|
||||
print('Client connected')
|
||||
print('Getting OBD status...')
|
||||
app_obd.obd_connection()
|
||||
uptime()
|
||||
|
||||
def uptime():
|
||||
thread = Thread(target=loop_uptime)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
def loop_uptime():
|
||||
uptime_lock.acquire()
|
||||
try:
|
||||
loop = True
|
||||
while loop == True:
|
||||
boottime = time.clock_gettime(time.CLOCK_BOOTTIME)
|
||||
# Convert to hours, minutes, and seconds
|
||||
seconds = int(boottime)
|
||||
minutes, seconds = divmod(seconds, 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
time.sleep(1)
|
||||
uptime = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
|
||||
socketio.emit("rpi_uptime", uptime)
|
||||
finally:
|
||||
uptime_lock.release()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from app_events import socketio
|
||||
from threading import Thread
|
||||
|
||||
class GPS:
|
||||
def __init__(self):
|
||||
self.LocationX = None
|
||||
self.LocationY= None
|
||||
|
||||
@socketio.on('gps')
|
||||
def get_gps():
|
||||
global LocationX
|
||||
global LocationY
|
||||
|
||||
LocationX = "45.5202844"
|
||||
LocationY = "-73.5493208"
|
||||
Location = [LocationX, LocationY]
|
||||
|
||||
socketio.emit('gps_location', Location)
|
||||
|
||||
print("websocket should be sent now")
|
||||
|
||||
return print("socket.io emitted")
|
||||
@@ -0,0 +1,104 @@
|
||||
import obd, time, threading, app_gps
|
||||
from datetime import datetime
|
||||
from app_events import socketio
|
||||
from threading import Thread
|
||||
|
||||
status = None
|
||||
speed = 0
|
||||
rpm = None
|
||||
|
||||
class OBD:
|
||||
def __init__(self):
|
||||
self.status = status
|
||||
self.rpm = rpm
|
||||
self.speed = speed
|
||||
|
||||
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
|
||||
obd_speed_lock = threading.Lock()
|
||||
obd_rpm_lock = threading.Lock()
|
||||
|
||||
try:
|
||||
print(obd_status[2])
|
||||
connection = obd.OBD() # put linux /dev/rfi... something in () for the rpi bluetooth adpater
|
||||
|
||||
except Exception as e:
|
||||
print("An error occurred:", str(e))
|
||||
|
||||
def get_speedtime():
|
||||
global speed
|
||||
date = datetime.now()
|
||||
today = str(date.today())
|
||||
time_now = str(date.strftime("%H:%M:%S"))
|
||||
return [str(time_now), speed]
|
||||
|
||||
@socketio.on('obd')
|
||||
def obd_connection():
|
||||
if connection.is_connected():
|
||||
print(obd_status[1])
|
||||
socketio.emit('obd_status', obd_status[1])
|
||||
print("OBD connection established.")
|
||||
|
||||
else:
|
||||
print("OBD connection failed.")
|
||||
print(obd_status[0])
|
||||
|
||||
socketio.emit('obd_status', obd_status[0])
|
||||
socketio.emit('obd_speed', "-")
|
||||
socketio.emit('obm_error', "-")
|
||||
socketio.emit('obd_rpm', "-")
|
||||
|
||||
# debug speed for testing
|
||||
thread_speed = Thread(target=obd_speed)
|
||||
thread_speed.daemon = True
|
||||
thread_speed.start()
|
||||
|
||||
# debug rpm for testing
|
||||
thread_rpm = Thread(target=obd_rpm)
|
||||
thread_rpm.daemon = True
|
||||
thread_rpm.start()
|
||||
|
||||
def obd_speed():
|
||||
obd_speed_lock.acquire()
|
||||
cmd = obd.commands.SPEED # select an OBD command (sensor)
|
||||
response = connection.query(cmd) # send the command and parse the response
|
||||
loop = True
|
||||
try:
|
||||
while loop == True:
|
||||
global speed
|
||||
speed = speed + 1
|
||||
time.sleep(1)
|
||||
if response.is_null():
|
||||
print("No data received. #"+ str(get_speedtime()))
|
||||
print(app_gps.get_gps())
|
||||
socketio.emit('obd_speed', get_speedtime())
|
||||
else:
|
||||
print("Original value:", response.value)
|
||||
print("Value in kph:", response.value.to("kph"))
|
||||
socketio.emit('obd_speed', response.value.to("kph"))
|
||||
finally:
|
||||
obd_speed_lock.release()
|
||||
|
||||
def obd_rpm():
|
||||
obd_speed_lock.acquire()
|
||||
cmd = obd.commands.RPM # select an OBD command (sensor)
|
||||
response = connection.query(cmd) # send the command and parse the response
|
||||
loop = True
|
||||
try:
|
||||
while loop == True:
|
||||
global rpm
|
||||
speed = speed + 1
|
||||
time.sleep(1)
|
||||
if response.is_null():
|
||||
print("No data received. #"+ str(get_speedtime()))
|
||||
socketio.emit('obd_speed', get_speedtime())
|
||||
else:
|
||||
print("RPM:", response.value)
|
||||
socketio.emit('obd_speed', response.value.to("kph"))
|
||||
finally:
|
||||
obd_rpm_lock.release()
|
||||
|
||||
def kill_obd(obd_type):
|
||||
if obd_type == "speed":
|
||||
obd_speed.loop = False
|
||||
elif obd_type == "rpm":
|
||||
obd_rpm.loop = False
|
||||
@@ -0,0 +1,7 @@
|
||||
##
|
||||
## MangoDB server connection details
|
||||
##
|
||||
|
||||
mangosrv_user = ""
|
||||
mangosrv_pass = ""
|
||||
mangosrv_db = ""
|
||||
@@ -0,0 +1,4 @@
|
||||
## TSV File to MangoDB
|
||||
## VN_20240401_00_00_00.TSV
|
||||
##
|
||||
## VN NAME, DATE, TIME, GPS_X, GPS_Y, SPEED, ODOMETER
|
||||
|
Reference in New Issue
Block a user