test inputs
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,36 +1,27 @@
|
|||||||
import app_obd, app_car, app_account, time, app_events, threading
|
|
||||||
from flask import Flask, render_template, make_response, json
|
from flask import Flask, render_template, make_response, json
|
||||||
|
import app_obd, app_car, app_account, time
|
||||||
from app_events import socketio
|
from app_events import socketio
|
||||||
|
|
||||||
port_number = 8000
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
socketio.init_app(app)
|
||||||
|
|
||||||
|
account = app_account.Account()
|
||||||
|
obd = app_obd.OBD()
|
||||||
|
car = app_car.Car()
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
print("hello")
|
print("hello "+account.name)
|
||||||
return render_template('index.html')
|
return render_template('index.html', account = account)
|
||||||
|
|
||||||
@app.route('/dtc')
|
@app.route('/dtc')
|
||||||
def dtc():
|
def dtc():
|
||||||
return render_template('dtc.html')
|
return render_template('dtc.html')
|
||||||
|
|
||||||
# not sure if im gonna use this
|
# not sure if im gonna use this
|
||||||
@app.route('/api/obd_speed')
|
@app.route('/api/obd_speed/')
|
||||||
def data():
|
def data():
|
||||||
data = app_obd.speed
|
data = app_obd.speed
|
||||||
response = make_response(json.dumps(data))
|
response = make_response(json.dumps(data))
|
||||||
response.content_type = 'application/json'
|
response.content_type = 'application/json'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
socketio.init_app(app)
|
|
||||||
p_obd_connection = threading.Thread(target=app_obd.obd_connection)
|
|
||||||
p_obd_connection.start()
|
|
||||||
|
|
||||||
print("allo?")
|
|
||||||
|
|
||||||
##
|
|
||||||
## only debug, remove in prod
|
|
||||||
##
|
|
||||||
app.run(host='localhost', port=port_number)
|
|
||||||
##
|
|
||||||
|
|||||||
+3
-16
@@ -1,18 +1,5 @@
|
|||||||
import app_car as Car
|
|
||||||
import threading, app_events
|
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
socketio = app_events.SocketIO()
|
|
||||||
account_name = "quoije"
|
|
||||||
account_pp_image = "static\img\image.png"
|
|
||||||
account_car = Car
|
|
||||||
account_car.model = "YARIS"
|
|
||||||
account_lock = threading.Lock()
|
|
||||||
|
|
||||||
class Account:
|
class Account:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = account_name
|
self.name = "quoije"
|
||||||
self.pp_image = account_pp_image
|
self.pp_image = None
|
||||||
self.car = account_car
|
self.car = None
|
||||||
def info():
|
|
||||||
return [name, pp_image, car.model]
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
class Car:
|
class Car:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.model = None
|
self.model = None
|
||||||
|
self.obd = None
|
||||||
+6
-15
@@ -1,28 +1,26 @@
|
|||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import app_obd, app_account, time, threading
|
import app_obd, time, threading
|
||||||
|
|
||||||
socketio = SocketIO()
|
socketio = SocketIO()
|
||||||
uptime_lock = threading.Lock()
|
uptime_lock = threading.Lock()
|
||||||
os_type = ["Linux","Windows"]
|
|
||||||
|
|
||||||
@socketio.on('connect')
|
@socketio.on('connect')
|
||||||
def connect_event():
|
def connect_event():
|
||||||
print('Client connected')
|
print('Client connected')
|
||||||
print('Getting OBD status...')
|
print('Getting OBD status...')
|
||||||
socketio.emit("connect", "connected with server")
|
app_obd.obd_connection()
|
||||||
# uptime()
|
uptime()
|
||||||
|
|
||||||
def uptime():
|
def uptime():
|
||||||
thread = Thread(target=loop_uptime(os_type[1]))
|
thread = Thread(target=loop_uptime)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def loop_uptime(os):
|
def loop_uptime():
|
||||||
loop = True
|
|
||||||
uptime_lock.acquire()
|
uptime_lock.acquire()
|
||||||
if os == "Linux":
|
|
||||||
try:
|
try:
|
||||||
|
loop = True
|
||||||
while loop == True:
|
while loop == True:
|
||||||
boottime = time.clock_gettime(time.CLOCK_BOOTTIME)
|
boottime = time.clock_gettime(time.CLOCK_BOOTTIME)
|
||||||
# Convert to hours, minutes, and seconds
|
# Convert to hours, minutes, and seconds
|
||||||
@@ -34,13 +32,6 @@ def loop_uptime(os):
|
|||||||
socketio.emit("rpi_uptime", uptime)
|
socketio.emit("rpi_uptime", uptime)
|
||||||
finally:
|
finally:
|
||||||
uptime_lock.release()
|
uptime_lock.release()
|
||||||
elif os == "Windows":
|
|
||||||
while loop == True:
|
|
||||||
time.sleep(1)
|
|
||||||
socketio.emit("rpi_uptime", "1")
|
|
||||||
print("[+] sent uptime windows (1) packet")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+21
-64
@@ -5,8 +5,7 @@ from threading import Thread
|
|||||||
|
|
||||||
status = None
|
status = None
|
||||||
speed = 0
|
speed = 0
|
||||||
rpm = 0
|
rpm = None
|
||||||
coonnection = None
|
|
||||||
|
|
||||||
class OBD:
|
class OBD:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -16,9 +15,14 @@ class OBD:
|
|||||||
|
|
||||||
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
|
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
|
||||||
obd_speed_lock = threading.Lock()
|
obd_speed_lock = threading.Lock()
|
||||||
obd_rpm_lock = threading.Lock()
|
obd_speed_rpm = threading.Lock()
|
||||||
obd_dtc_lock = threading.Lock()
|
|
||||||
obd_state_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():
|
def get_speedtime():
|
||||||
global speed
|
global speed
|
||||||
@@ -27,37 +31,21 @@ def get_speedtime():
|
|||||||
time_now = str(date.strftime("%H:%M:%S"))
|
time_now = str(date.strftime("%H:%M:%S"))
|
||||||
return [str(time_now), speed]
|
return [str(time_now), speed]
|
||||||
|
|
||||||
|
@socketio.on('obd')
|
||||||
def obd_connection():
|
def obd_connection():
|
||||||
global connection
|
|
||||||
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))
|
|
||||||
|
|
||||||
if connection.is_connected():
|
if connection.is_connected():
|
||||||
print(obd_status[1])
|
print(obd_status[1])
|
||||||
|
socketio.emit('obd_status', obd_status[1])
|
||||||
print("OBD connection established.")
|
print("OBD connection established.")
|
||||||
obd_events(1)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("OBD connection failed.")
|
print("OBD connection failed.")
|
||||||
print(obd_status[0])
|
print(obd_status[0])
|
||||||
obd_events(0)
|
|
||||||
|
|
||||||
@socketio.on('obd')
|
socketio.emit('obd_status', obd_status[0])
|
||||||
def obd_events(status):
|
socketio.emit('obd_speed', "-")
|
||||||
if status == 1:
|
socketio.emit('obm_error', "-")
|
||||||
thread_state = Thread(target=obd_state(1))
|
socketio.emit('obd_rpm', "-")
|
||||||
thread_state.daemon = True
|
|
||||||
thread_state.start()
|
|
||||||
|
|
||||||
# change status to 2 when done testing
|
|
||||||
elif status == 0:
|
|
||||||
thread_state = Thread(target=obd_state(2))
|
|
||||||
thread_state.daemon = True
|
|
||||||
thread_state.start()
|
|
||||||
|
|
||||||
# debug speed for testing
|
# debug speed for testing
|
||||||
thread_speed = Thread(target=obd_speed)
|
thread_speed = Thread(target=obd_speed)
|
||||||
@@ -69,20 +57,6 @@ def obd_events(status):
|
|||||||
thread_rpm.daemon = True
|
thread_rpm.daemon = True
|
||||||
thread_rpm.start()
|
thread_rpm.start()
|
||||||
|
|
||||||
else:
|
|
||||||
thread_speed = Thread(target=obd_state(0))
|
|
||||||
thread_speed.daemon = True
|
|
||||||
thread_speed.start()
|
|
||||||
|
|
||||||
|
|
||||||
def obd_state(status):
|
|
||||||
loop = True
|
|
||||||
while loop == True:
|
|
||||||
print(obd_status[status])
|
|
||||||
socketio.emit('obd_status', obd_status[status])
|
|
||||||
print("[+] websocket packet sent...")
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
def obd_speed():
|
def obd_speed():
|
||||||
obd_speed_lock.acquire()
|
obd_speed_lock.acquire()
|
||||||
cmd = obd.commands.SPEED # select an OBD command (sensor)
|
cmd = obd.commands.SPEED # select an OBD command (sensor)
|
||||||
@@ -90,13 +64,11 @@ def obd_speed():
|
|||||||
loop = True
|
loop = True
|
||||||
try:
|
try:
|
||||||
while loop == True:
|
while loop == True:
|
||||||
print(obd_status[3])
|
|
||||||
socketio.emit('obd_status', obd_status[3])
|
|
||||||
global speed
|
global speed
|
||||||
speed = speed + 1
|
speed = speed + 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if response.is_null():
|
if response.is_null():
|
||||||
print("TEST SPEED for DEBUG #"+ str(get_speedtime()))
|
print("No data received. #"+ str(get_speedtime()))
|
||||||
socketio.emit('obd_speed', get_speedtime())
|
socketio.emit('obd_speed', get_speedtime())
|
||||||
else:
|
else:
|
||||||
print("Original value:", response.value)
|
print("Original value:", response.value)
|
||||||
@@ -106,39 +78,24 @@ def obd_speed():
|
|||||||
obd_speed_lock.release()
|
obd_speed_lock.release()
|
||||||
|
|
||||||
def obd_rpm():
|
def obd_rpm():
|
||||||
obd_rpm_lock.acquire()
|
obd_speed_lock.acquire()
|
||||||
cmd = obd.commands.RPM # select an OBD command (sensor)
|
cmd = obd.commands.RPM # select an OBD command (sensor)
|
||||||
response = connection.query(cmd) # send the command and parse the response
|
response = connection.query(cmd) # send the command and parse the response
|
||||||
loop = True
|
loop = True
|
||||||
try:
|
try:
|
||||||
while loop == True:
|
while loop == True:
|
||||||
global rpm
|
global rpm
|
||||||
rpm = rpm + 1
|
speed = speed + 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if response.is_null():
|
if response.is_null():
|
||||||
print("No data received. #"+"RPM :"+str(rpm))
|
print("No data received. #"+ str(get_speedtime()))
|
||||||
socketio.emit('obd_rpm', rpm)
|
socketio.emit('obd_speed', get_speedtime())
|
||||||
else:
|
else:
|
||||||
print("RPM:", response.value)
|
print("RPM:", response.value)
|
||||||
socketio.emit('obd_rpm', response.value.to("kph"))
|
socketio.emit('obd_speed', response.value.to("kph"))
|
||||||
finally:
|
finally:
|
||||||
obd_rpm_lock.release()
|
obd_rpm_lock.release()
|
||||||
|
|
||||||
def obd_dtc():
|
|
||||||
obd_dtc_lock.acquire()
|
|
||||||
cmd = obd.commands.GET_DTC # select an OBD command (sensor)
|
|
||||||
response = connection.query(cmd) # send the command and parse the response
|
|
||||||
try:
|
|
||||||
if response.is_null():
|
|
||||||
error_txt = "No data received."
|
|
||||||
print(error_txt)
|
|
||||||
socketio.emit('obd_dtc', error_txt)
|
|
||||||
else:
|
|
||||||
print(response.value)
|
|
||||||
socketio.emit('obd_dtc', response.value)
|
|
||||||
finally:
|
|
||||||
obd_dtc_lock.release()
|
|
||||||
|
|
||||||
def kill_obd(obd_type):
|
def kill_obd(obd_type):
|
||||||
if obd_type == "speed":
|
if obd_type == "speed":
|
||||||
obd_speed.loop = False
|
obd_speed.loop = False
|
||||||
|
|||||||
@@ -32,24 +32,12 @@ chart = new Chart(ctx, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// account
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// websockets
|
// websockets
|
||||||
|
|
||||||
socket.on('connect', function(data) {
|
socket.on('connect', function(data) {
|
||||||
console.log('socket.io is connected')
|
console.log('socket.io is connected')
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('account_info', function(data) {
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
// car model
|
|
||||||
const car_model = document.getElementById('index-car-model');
|
|
||||||
car_model.innerHTML = data;
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('obd_status', function(data) {
|
socket.on('obd_status', function(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
const status = document.getElementById('obd-status');
|
const status = document.getElementById('obd-status');
|
||||||
@@ -87,12 +75,6 @@ socket.on('obd_rpm', function(data) {
|
|||||||
status.innerHTML = data;
|
status.innerHTML = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('obd_dtc', function(data) {
|
|
||||||
console.log("obd dtc "+data);
|
|
||||||
const status = document.getElementById('obd-dtc');
|
|
||||||
status.innerHTML = data;
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('obd_error', function(data) {
|
socket.on('obd_error', function(data) {
|
||||||
console.log("obd errors "+data);
|
console.log("obd errors "+data);
|
||||||
const status = document.getElementById('obd-error');
|
const status = document.getElementById('obd-error');
|
||||||
|
|||||||
+2
-4
@@ -15,7 +15,7 @@
|
|||||||
<nav class="navbar align-items-start sidebar sidebar-dark accordion bg-gradient-primary p-0 navbar-dark" style="color: var(--bs-accordion-btn-focus-border-color);background: rgb(0,0,0);filter: blur(0px);backdrop-filter: blur(0px) hue-rotate(0deg);">
|
<nav class="navbar align-items-start sidebar sidebar-dark accordion bg-gradient-primary p-0 navbar-dark" style="color: var(--bs-accordion-btn-focus-border-color);background: rgb(0,0,0);filter: blur(0px);backdrop-filter: blur(0px) hue-rotate(0deg);">
|
||||||
<div class="container-fluid d-flex flex-column p-0"><a class="navbar-brand d-flex justify-content-center align-items-center sidebar-brand m-0" href="#">
|
<div class="container-fluid d-flex flex-column p-0"><a class="navbar-brand d-flex justify-content-center align-items-center sidebar-brand m-0" href="#">
|
||||||
<div class="sidebar-brand-icon rotate-n-15"><i class="fas fa-car"></i></div>
|
<div class="sidebar-brand-icon rotate-n-15"><i class="fas fa-car"></i></div>
|
||||||
<div id="index-car-model" class="sidebar-brand-text mx-3"><span>CAR MODEL</span></div>
|
<div class="sidebar-brand-text mx-3"><span>yaris </span></div>
|
||||||
</a>
|
</a>
|
||||||
<hr class="sidebar-divider my-0">
|
<hr class="sidebar-divider my-0">
|
||||||
<ul class="navbar-nav text-light" id="accordionSidebar">
|
<ul class="navbar-nav text-light" id="accordionSidebar">
|
||||||
@@ -58,9 +58,7 @@
|
|||||||
<div class="card-header py-3">
|
<div class="card-header py-3">
|
||||||
<p class="text-primary m-0 fw-bold">Output</p>
|
<p class="text-primary m-0 fw-bold">Output</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body"></div>
|
||||||
<p id="obd-dtc"></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user