diff --git a/modules/__pycache__/app_account.cpython-310.pyc b/modules/__pycache__/app_account.cpython-310.pyc deleted file mode 100644 index 3807aa7..0000000 Binary files a/modules/__pycache__/app_account.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_account.cpython-311.pyc b/modules/__pycache__/app_account.cpython-311.pyc deleted file mode 100644 index 94983e6..0000000 Binary files a/modules/__pycache__/app_account.cpython-311.pyc and /dev/null differ diff --git a/modules/__pycache__/app_car.cpython-310.pyc b/modules/__pycache__/app_car.cpython-310.pyc deleted file mode 100644 index 115f545..0000000 Binary files a/modules/__pycache__/app_car.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_car.cpython-311.pyc b/modules/__pycache__/app_car.cpython-311.pyc deleted file mode 100644 index 007728e..0000000 Binary files a/modules/__pycache__/app_car.cpython-311.pyc and /dev/null differ diff --git a/modules/__pycache__/app_events.cpython-310.pyc b/modules/__pycache__/app_events.cpython-310.pyc deleted file mode 100644 index 0879636..0000000 Binary files a/modules/__pycache__/app_events.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_events.cpython-311.pyc b/modules/__pycache__/app_events.cpython-311.pyc deleted file mode 100644 index 12fa951..0000000 Binary files a/modules/__pycache__/app_events.cpython-311.pyc and /dev/null differ diff --git a/modules/__pycache__/app_gps.cpython-310.pyc b/modules/__pycache__/app_gps.cpython-310.pyc deleted file mode 100644 index 4a768b3..0000000 Binary files a/modules/__pycache__/app_gps.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_gps.cpython-311.pyc b/modules/__pycache__/app_gps.cpython-311.pyc deleted file mode 100644 index 1a437ec..0000000 Binary files a/modules/__pycache__/app_gps.cpython-311.pyc and /dev/null differ diff --git a/modules/__pycache__/app_obd.cpython-310.pyc b/modules/__pycache__/app_obd.cpython-310.pyc deleted file mode 100644 index 96e1981..0000000 Binary files a/modules/__pycache__/app_obd.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_obd.cpython-311.pyc b/modules/__pycache__/app_obd.cpython-311.pyc deleted file mode 100644 index f4f9cce..0000000 Binary files a/modules/__pycache__/app_obd.cpython-311.pyc and /dev/null differ diff --git a/modules/__pycache__/app_sql.cpython-310.pyc b/modules/__pycache__/app_sql.cpython-310.pyc deleted file mode 100644 index 4edeedd..0000000 Binary files a/modules/__pycache__/app_sql.cpython-310.pyc and /dev/null differ diff --git a/modules/__pycache__/app_sql.cpython-311.pyc b/modules/__pycache__/app_sql.cpython-311.pyc deleted file mode 100644 index 4bd7e1d..0000000 Binary files a/modules/__pycache__/app_sql.cpython-311.pyc and /dev/null differ diff --git a/modules/app_events.py b/modules/app_events.py index eba78d2..175df7b 100644 --- a/modules/app_events.py +++ b/modules/app_events.py @@ -5,6 +5,7 @@ import time, threading socketio = SocketIO() uptime_lock = threading.Lock() +thread_uptime = None @socketio.on('connect') def connect_event(): @@ -14,9 +15,15 @@ def connect_event(): uptime() def uptime(): - thread = Thread(target=loop_uptime) - thread.daemon = True - thread.start() + global thread_uptime + + if thread_uptime is None or not thread_uptime.is_alive(): + thread_uptime = Thread(target=loop_uptime) + thread_uptime.daemon = True + thread_uptime.start() + print(f"Uptime thread started, alive: {thread_uptime.is_alive()}") + else: + print(f"Uptime thread already running, alive: {thread_uptime.is_alive()}") def loop_uptime(): uptime_lock.acquire() diff --git a/modules/app_obd.py b/modules/app_obd.py index 213ca95..fa3b8db 100644 --- a/modules/app_obd.py +++ b/modules/app_obd.py @@ -16,6 +16,8 @@ class OBD: obd_status = ["Disconnected", "Connected", "Connection...", "wtf"] obd_speed_lock = threading.Lock() obd_rpm_lock = threading.Lock() +thread_speed = None +thread_rpm = None try: print(obd_status[2]) @@ -31,12 +33,14 @@ def get_speedtime(): time_now = str(date.strftime("%H:%M:%S")) return [str(time_now), speed] -def obd_connection(): + +def obd_connection(): + global thread_speed, thread_rpm + if connection.is_connected(): print(obd_status[1]) app_events.socketio.emit('obd_status', obd_status[1]) print("OBD connection established.") - else: print("OBD connection failed.") print(obd_status[0]) @@ -46,16 +50,18 @@ def obd_connection(): app_events.socketio.emit('obm_error', "-") app_events.socketio.emit('obd_rpm', "-") - # debug speed for testing - thread_speed = Thread(target=obd_speed) - thread_speed.daemon = True - thread_speed.start() + if thread_speed is None or not thread_speed.is_alive(): + thread_speed = Thread(target=obd_speed) + print(f'thread_speed alive? {thread_speed.is_alive()}') + thread_speed.daemon = True + thread_speed.start() + + if thread_rpm is None or not thread_rpm.is_alive(): + thread_rpm = Thread(target=obd_rpm) + print(f'thread_rpm alive? {thread_rpm.is_alive()}') + thread_rpm.daemon = True + thread_rpm.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) @@ -65,7 +71,7 @@ def obd_speed(): while loop == True: global speed speed = speed + 1 - time.sleep(10) + time.sleep(2) if response.is_null(): print("No data received. #"+ str(get_speedtime())) print(app_gps.get_gps())