From bdf6bb477bd187040e575209f9738b0662b3f960 Mon Sep 17 00:00:00 2001 From: quoije Date: Sun, 17 Mar 2024 22:37:25 -0400 Subject: [PATCH] add gps function --- __pycache__/app_car.cpython-311.pyc | Bin 546 -> 558 bytes __pycache__/app_events.cpython-311.pyc | Bin 2205 -> 2205 bytes __pycache__/app_gps.cpython-311.pyc | Bin 0 -> 1190 bytes __pycache__/app_obd.cpython-311.pyc | Bin 6113 -> 6236 bytes app.py | 14 +++-- app_car.py | 2 +- app_gps.py | 22 +++++++ app_obd.py | 5 +- requirements.txt | 60 +----------------- static/js/yaris.js | 18 ++++++ templates/dash.html | 83 +++++++++++++++++++++++++ templates/dtc.html | 15 +++-- templates/index.html | 20 +++--- 13 files changed, 157 insertions(+), 82 deletions(-) create mode 100644 __pycache__/app_gps.cpython-311.pyc create mode 100644 app_gps.py create mode 100644 templates/dash.html diff --git a/__pycache__/app_car.cpython-311.pyc b/__pycache__/app_car.cpython-311.pyc index 85fce9f20bb75b4a378cbf9b6df3429824a57bb4..1925477967b48c4097881592872ae32fdf2f1803 100644 GIT binary patch delta 50 zcmZ3)vW|s!IWI340}xzj{+=2?k#`~^plnLRsP!}3vStKC9DloANj2;O9$G8G1Qvp=69SMCFIl^B! z#uW&QcHs!k<1hf_C>vV`DfXL3B;v*_qxx30H3RMF%Pmt?SarA=jqs?!BszznLYXiq z3ygH3EHVL)5?yii#d&9eR(=}U` z+bINB2tD2?i{GRJ{pp!~dT^~jmF1s(dGag)3K|L>ZMMOT*d47)H!~-<2i9|s{D8xoD z6njVnfST|D>>&{Vwt1~DOx%M}+7PhgVHP;4u)7zexs<&`DI8a{)J_za3QG&~3(Lh~ zJ304Yv9MHJSzMT3c2jr_xqd#$c6LYI3<#F9wv1Mt%jJ|!yI-{>gMS>iLMD1-!V^;Dt_P^jL=YxNB7WEh F`5&XV0vrGU literal 0 HcmV?d00001 diff --git a/__pycache__/app_obd.cpython-311.pyc b/__pycache__/app_obd.cpython-311.pyc index 59459878b7da647a7ca2447e37bf3b0e2e13c469..1cda88895202de46034a9eb0a318b3ea978e2fb7 100644 GIT binary patch delta 795 zcmb79O-NKx6u#&E%#8E?X6C&&(|h6{O^Q0EffP)nIZYW7k*n}U4CWn->5UH00SiJ~ zxah~l*x6cGi-MvMT(wjPTofqGLL{OVu7a>dMZ4}xCUe>0p6`6$cfQ5BpSwTwD9;ro zOjyk<{>-m0C>B%}+M2I|%R4+Jlyilm;0Qn%=UuTFZ~}k0;Bv*F6J#8m5GA8^6h^}w z86;GkBQ)@gBjhFPy>g^+LW57ikvWp*3JNYu@sOkL3)#`?2$PY#Ohfohv;$0#g5(En zCpyt~nB-$g;x#$CpQ3dPjl7N@qm8X2{t5aOeIm3sr(v4h_7!>iLblFPO{y<2%VV@T?c3Lt5 zq}=k48O0ycAjGgwZkJ*;e@Vx8a&POwU~Nf-+fX$Hn_+n6nEnPJi(iZmafta8Z8Hn?m^0(T zDW4J|W;e14Q;Zv`w$_RjF_jiu6D{VTsCba9hgv&JYuuz|TWAkO zJoHc$O6sScM64G<@D%Xgg6Oe=hf);uuCy1=I#W?Eg2T)+-_JYq4)d}9%Q5YRrpbg2 zXpIIdtC|bTtKHtwSSU0EUjRZ06~cH!^u@h69>yAyFR>W>1SR813gfBOMc0rg2~9i) zUx|?*R#&kT^4-~t@6GgM=hEY%rv)L?YmuiDeCtYUYtjl~0?RWNLfC`Q|y<(MBCve3%m&r#S7Y{OQr{<=jV4U7+PU1Ib z#Msuj!R$;B?AhS)ObMzumDyL~mjYX}YmB=B0Bn)Y&Hqh&o4K!>g;wgJ{@(OHnBH9t kZ)9H@78G~MAM~J`>&rS`xkT1WVkIxE4>=V_*l>9K6XJrWO8@`> diff --git a/app.py b/app.py index 02ffd8c..4e174ee 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, make_response, json -import app_obd, app_car, app_account, time +import app_obd, app_car, app_account, app_gps, time from app_events import socketio from gevent.pywsgi import WSGIServer @@ -9,15 +9,21 @@ socketio.init_app(app) account = app_account.Account() obd = app_obd.OBD() car = app_car.Car() +gps = app_gps.get_gps() @app.route('/') def index(): - print("hello "+account.name) - return render_template('index.html', account = account) + print("hello "+ account.name) + print("you're car model is:" + car.model) + return render_template('index.html', account = account, car = car) @app.route('/dtc') def dtc(): - return render_template('dtc.html') + return render_template('dtc.html', account = account, car = car) + +@app.route('/dash') +def dash(): + return render_template('dash.html', account = account, car = car) # not sure if im gonna use this @app.route('/api/obd_speed/') diff --git a/app_car.py b/app_car.py index 72e47b9..c5da2cf 100644 --- a/app_car.py +++ b/app_car.py @@ -1,4 +1,4 @@ class Car: def __init__(self): - self.model = None + self.model = "Yaris 2013" self.obd = None \ No newline at end of file diff --git a/app_gps.py b/app_gps.py new file mode 100644 index 0000000..e797c4c --- /dev/null +++ b/app_gps.py @@ -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") \ No newline at end of file diff --git a/app_obd.py b/app_obd.py index 29a0fe6..a45d7f3 100644 --- a/app_obd.py +++ b/app_obd.py @@ -1,4 +1,4 @@ -import obd, time, threading +import obd, time, threading, app_gps from datetime import datetime from app_events import socketio from threading import Thread @@ -15,7 +15,7 @@ class OBD: obd_status = ["Disconnected", "Connected", "Connection...", "wtf"] obd_speed_lock = threading.Lock() -obd_speed_rpm = threading.Lock() +obd_rpm_lock = threading.Lock() try: print(obd_status[2]) @@ -69,6 +69,7 @@ def obd_speed(): 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) diff --git a/requirements.txt b/requirements.txt index f183cb9..7ec2998 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,57 +1,3 @@ -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 +Flask +Flask-SocketIO +gevent \ No newline at end of file diff --git a/static/js/yaris.js b/static/js/yaris.js index 50feb9e..e39d19c 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -1,4 +1,13 @@ const socket = io(); +// map + +var map = L.map('map').setView([48.505, -0.09], 13); + L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(map); + L.marker([51.5, -0.09]).addTo(map) + .bindPopup('your car... soon(tm)') + .openPopup(); // charts @@ -84,4 +93,13 @@ socket.on('obd_error', function(data) { socket.on('rpi_uptime', function(data) { const status = document.getElementById('rpi-uptime'); status.innerHTML = data; +}); + +socket.on('gps_location', function(data) { + console.log("location received") + const LocationX = document.getElementById('gpsLocationX'); + const LocationY = document.getElementById('gpsLocationY'); + LocationX.innerHTML = data[0]; + LocationY.innerHTML = data[1]; + }); \ No newline at end of file diff --git a/templates/dash.html b/templates/dash.html new file mode 100644 index 0000000..cf9c0b1 --- /dev/null +++ b/templates/dash.html @@ -0,0 +1,83 @@ + + + + + + + Dashboard - yaris vroom vroom de course + + + + + + + + +
+ +
+
+ +
+

DTC Codes

+
+
+

Output

+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/templates/dtc.html b/templates/dtc.html index ba74135..02614d0 100644 --- a/templates/dtc.html +++ b/templates/dtc.html @@ -4,10 +4,12 @@ - Table - yaris vroom vroom de course + Dashboard - yaris vroom vroom de course + - + + @@ -15,12 +17,14 @@