websocket doesn't work

This commit is contained in:
Mathieu Moran
2023-11-18 14:02:49 -05:00
parent 7a90b3768a
commit f5bbbc00af
9 changed files with 106 additions and 35 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16 -14
View File
@@ -1,11 +1,10 @@
import app_obd, app_car, app_account, time, app_events, threading
from flask import Flask, render_template, make_response, json
import app_obd, app_car, app_account, time, app_events
from app_events import socketio
app = Flask(__name__)
socketio.init_app(app)
app_obd.obd_connection()
port_number = 8000
app = Flask(__name__)
@app.route('/')
def index():
print("hello")
@@ -16,20 +15,23 @@ def dtc():
return render_template('dtc.html')
# not sure if im gonna use this
@app.route('/api/obd_speed/')
@app.route('/api/obd_speed')
def data():
data = app_obd.speed
response = make_response(json.dumps(data))
response.content_type = 'application/json'
return response
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Run the Flask application with a custom port."
)
parser.add_argument(
"--port", type=int, default=5000, help="Port number (default is 5000)"
)
args = parser.parse_args()
if __name__ == '__main__':
socketio.init_app(app)
app.run(debug=True, port=args.port)
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)
##
+12 -4
View File
@@ -4,6 +4,7 @@ import app_obd, app_account, time, threading
socketio = SocketIO()
uptime_lock = threading.Lock()
os_type = ["Linux","Windows"]
@socketio.on('connect')
def connect_event():
@@ -12,14 +13,15 @@ def connect_event():
uptime()
def uptime():
thread = Thread(target=loop_uptime)
thread = Thread(target=loop_uptime(os_type[1]))
thread.daemon = True
thread.start()
def loop_uptime():
uptime_lock.acquire()
try:
def loop_uptime(os):
loop = True
uptime_lock.acquire()
if os == "Linux":
try:
while loop == True:
boottime = time.clock_gettime(time.CLOCK_BOOTTIME)
# Convert to hours, minutes, and seconds
@@ -31,6 +33,12 @@ def loop_uptime():
socketio.emit("rpi_uptime", uptime)
finally:
uptime_lock.release()
elif os == "Windows":
while loop == True:
time.sleep(1)
socketio.emit("rpi_uptime", "1")
+11 -7
View File
@@ -6,6 +6,7 @@ from threading import Thread
status = None
speed = 0
rpm = 0
coonnection = None
class OBD:
def __init__(self):
@@ -19,13 +20,6 @@ obd_rpm_lock = 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():
global speed
date = datetime.now()
@@ -34,6 +28,14 @@ def get_speedtime():
return [str(time_now), speed]
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():
print(obd_status[1])
print("OBD connection established.")
@@ -77,6 +79,7 @@ def obd_state(status):
loop = True
try:
while loop == True:
print(obd_status[status])
socketio.emit('obd_status', obd_status[status])
time.sleep(2)
finally:
@@ -89,6 +92,7 @@ def obd_speed():
loop = True
try:
while loop == True:
print(obd_status[3])
socketio.emit('obd_status', obd_status[3])
global speed
speed = speed + 1
+57
View File
@@ -0,0 +1,57 @@
Babel==2.8.0
bidict==0.22.1
blinker==1.4
click==8.0.3
colorama==0.4.4
command-not-found==0.3
cryptography==3.4.8
dbus-python==1.2.18
distro==1.7.0
distro-info===1.1build1
Flask==2.0.1
Flask-SocketIO==5.3.6
h11==0.14.0
httplib2==0.20.2
importlib-metadata==4.6.4
itsdangerous==2.1.0
jeepney==0.7.1
Jinja2==3.0.3
keyring==23.5.0
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
lxml==4.9.3
MarkupSafe==2.0.1
more-itertools==8.10.0
netifaces==0.11.0
oauthlib==3.2.0
obd==0.7.2
Pint==0.20.1
pycairo==1.20.1
PyGObject==3.42.1
pyinotify==0.9.6
PyJWT==2.3.0
pyOpenSSL==21.0.0
pyparsing==2.4.7
pyserial==3.5
python-apt==2.4.0+ubuntu1
python-engineio==4.8.0
python-socketio==5.10.0
pytils==0.4.1
pytz==2022.1
PyYAML==5.4.1
SecretStorage==3.3.1
simple-websocket==1.0.0
simplejson==3.17.6
six==1.16.0
systemd-python==234
tools==0.1.9
tqdm==4.66.1
ubuntu-advantage-tools==8001
ufw==0.36.1
unattended-upgrades==0.1
wadllib==1.3.6
Werkzeug==2.0.2
wget==3.2
wsproto==1.2.0
zipp==1.0.0