diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc deleted file mode 100644 index 26d4e5f..0000000 Binary files a/__pycache__/app.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/app_account.cpython-310.pyc b/__pycache__/app_account.cpython-310.pyc deleted file mode 100644 index 305bffa..0000000 Binary files a/__pycache__/app_account.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/app_car.cpython-310.pyc b/__pycache__/app_car.cpython-310.pyc deleted file mode 100644 index 6575be2..0000000 Binary files a/__pycache__/app_car.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/app_events.cpython-310.pyc b/__pycache__/app_events.cpython-310.pyc deleted file mode 100644 index f648fd7..0000000 Binary files a/__pycache__/app_events.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/app_obd.cpython-310.pyc b/__pycache__/app_obd.cpython-310.pyc deleted file mode 100644 index cac1e9c..0000000 Binary files a/__pycache__/app_obd.cpython-310.pyc and /dev/null differ diff --git a/app.py b/app.py index 929fd0a..c7dbfaf 100644 --- a/app.py +++ b/app.py @@ -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) \ No newline at end of file + 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) + ## diff --git a/app_events.py b/app_events.py index ac98017..d1d731b 100644 --- a/app_events.py +++ b/app_events.py @@ -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,25 +13,32 @@ 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(): +def loop_uptime(os): + loop = True uptime_lock.acquire() - try: - loop = True + if os == "Linux": + try: + 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() + elif os == "Windows": 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() + socketio.emit("rpi_uptime", "1") + + diff --git a/app_obd.py b/app_obd.py index 23370de..e18b8c2 100644 --- a/app_obd.py +++ b/app_obd.py @@ -6,7 +6,8 @@ from threading import Thread status = None speed = 0 rpm = 0 - +coonnection = None + class OBD: def __init__(self): self.status = status @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f183cb9 --- /dev/null +++ b/requirements.txt @@ -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