Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b24b5fc

Browse files
committed
WIP, from 2/5/23
1 parent f7681e4 commit b24b5fc

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

backend/app.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import eventlet
44
import socketio
55
from datetime import datetime
6-
import time
6+
import time, threading
7+
8+
79

810
sio = socketio.Server(cors_allowed_origins=["http://localhost:3000"])
911
app = socketio.WSGIApp(sio)
@@ -16,11 +18,6 @@
1618
@sio.event
1719
def connect(sid, environ):
1820
print('connect ', sid)
19-
val = ser.read(100).decode('utf-8')
20-
current_date = datetime.now()
21-
timestamp = current_date.isoformat()
22-
sio.emit("pedal_value", {"timestamp": timestamp, "number": val})
23-
print("MESSAGE ID "+str(random.randint(1,20))+ " RECIEVED! VALUE IS: "+str(val))
2421

2522

2623
@sio.event
@@ -31,6 +28,32 @@ def my_message(sid, data):
3128
def disconnect(sid):
3229
print('disconnect ', sid)
3330

31+
def action() :
32+
val = ser.read(100).decode('utf-8')
33+
current_date = datetime.now()
34+
timestamp = current_date.isoformat()
35+
sio.emit("pedal_value", {"timestamp": timestamp, "number": val})
36+
print("MESSAGE ID "+str(random.randint(1,20))+ " RECIEVED! VALUE IS: "+str(val))
37+
38+
39+
class setInterval :
40+
def __init__(self,interval,action) :
41+
self.interval=interval
42+
self.action=action
43+
self.stopEvent=threading.Event()
44+
thread=threading.Thread(target=self.__setInterval)
45+
thread.start()
46+
47+
def __setInterval(self) :
48+
nextTime=time.time()+self.interval
49+
while not self.stopEvent.wait(nextTime-time.time()) :
50+
nextTime+=self.interval
51+
self.action()
52+
53+
inter=setInterval(1,action)
54+
55+
sio.start_background_task(action())
56+
3457
if __name__ == '__main__':
3558
eventlet.wsgi.server(eventlet.listen(('', 5050)), app)
3659

frontend/src/pages/InteractivePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const InteractivePage = () => {
7070

7171
Object.keys(stringData).forEach((name) => {
7272
socket.on(name, (update: StringUpdate) => {
73+
console.log(update)
7374
setStringData((oldData) => {
7475
const updatedData = {
7576
...oldData,

0 commit comments

Comments
 (0)