loopy loop, doesn't work, too many loops

This commit is contained in:
Mathieu Moran
2023-11-28 23:04:06 -05:00
parent 82f0c92e6c
commit 00e14db023
11 changed files with 19 additions and 20 deletions
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 -2
View File
@@ -3,8 +3,8 @@ from flask import Flask, render_template, make_response, json
from app_events import socketio from app_events import socketio
port_number = 8000 port_number = 8000
app = Flask(__name__) app = Flask(__name__)
@app.route('/') @app.route('/')
def index(): def index():
print("hello") print("hello")
@@ -24,7 +24,6 @@ def data():
if __name__ == '__main__': if __name__ == '__main__':
socketio.init_app(app) socketio.init_app(app)
p_obd_connection = threading.Thread(target=app_obd.obd_connection) p_obd_connection = threading.Thread(target=app_obd.obd_connection)
p_obd_connection.start() p_obd_connection.start()
+3 -1
View File
@@ -10,7 +10,8 @@ os_type = ["Linux","Windows"]
def connect_event(): def connect_event():
print('Client connected') print('Client connected')
print('Getting OBD status...') print('Getting OBD status...')
uptime() socketio.emit("connect", "connected with server")
# uptime()
def uptime(): def uptime():
thread = Thread(target=loop_uptime(os_type[1])) thread = Thread(target=loop_uptime(os_type[1]))
@@ -37,6 +38,7 @@ def loop_uptime(os):
while loop == True: while loop == True:
time.sleep(1) time.sleep(1)
socketio.emit("rpi_uptime", "1") socketio.emit("rpi_uptime", "1")
print("[+] sent uptime windows (1) packet")
+11 -13
View File
@@ -44,19 +44,20 @@ def obd_connection():
else: else:
print("OBD connection failed.") print("OBD connection failed.")
print(obd_status[0]) print(obd_status[0])
obd_events(2) obd_events(0)
@socketio.on('obd') @socketio.on('obd')
def obd_events(status): def obd_events(status):
if status == 1: if status == 1:
thread_speed = Thread(target=obd_state(1)) thread_state = Thread(target=obd_state(1))
thread_speed.daemon = True thread_state.daemon = True
thread_speed.start() thread_state.start()
elif status == 2: # change status to 2 when done testing
thread_speed = Thread(target=obd_state(2)) elif status == 0:
thread_speed.daemon = True thread_state = Thread(target=obd_state(2))
thread_speed.start() 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)
@@ -75,15 +76,12 @@ def obd_events(status):
def obd_state(status): def obd_state(status):
obd_state_lock.acquire()
loop = True loop = True
try:
while loop == True: while loop == True:
print(obd_status[status]) print(obd_status[status])
socketio.emit('obd_status', obd_status[status]) socketio.emit('obd_status', obd_status[status])
print("[+] websocket packet sent...")
time.sleep(2) time.sleep(2)
finally:
obd_state_lock.release()
def obd_speed(): def obd_speed():
obd_speed_lock.acquire() obd_speed_lock.acquire()
@@ -98,7 +96,7 @@ def obd_speed():
speed = speed + 1 speed = speed + 1
time.sleep(1) time.sleep(1)
if response.is_null(): if response.is_null():
print("No data received. #"+ str(get_speedtime())) print("TEST SPEED for DEBUG #"+ 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)