loopy loop, doesn't work, too many loops

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