Hello
on my de vice there is a sensor that read data all the time
I want to create a web socket , that when someone enter it he will get the data everytime it change
(I did it in the past in JAVA)
this is what I have doen:
it's seem that it only read the data after I open web socket to him
what did I do wrong ?
I want the main will be the reading of the sensor
Thanks ,
on my de vice there is a sensor that read data all the time
I want to create a web socket , that when someone enter it he will get the data everytime it change
(I did it in the past in JAVA)
this is what I have doen:
import os import time import websockets import asyncio async def DataServer(websocket , path): message = bus.recv() # print (message) PID = message.arbitration_id dlc= message.dlc MyData = message.data MSG_Time = message.timestamp #print(str(MyData)) New_Data = (bytes(MyData).hex()).upper() New_Data = ' '.join(New_Data[i:i+2] for i in range(0,len(New_Data),2)) #print(New_Data) PID_Hex = str(hex(PID)) print (str(MSG_Time) + ' Hex PID is - ' + PID_Hex) if PID_Hex == hex(0x48c): print('this is Door 1') print ('I need bytes 1 , bit 2,1') door1 = New_Data[0:2] print(door1) elif PID_Hex == hex(0x48d): print('this is Door 2') print ('I need bytes 1 , bit 2,1') door2 = New_Data[0:2] print(door2) result = getBinarybits(door2,0,2) print('you need this ' + result) else: print("I don't know this PID!") print ('done') SendData = (door1 + "!" + door2) await websocket.send(SendData) start_server = websockets.serve(DataServer, '10.0.0.100', 8765) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever() print ('WebSocket Server Start!') # I don;t see this messagebut it doesn't read my the data all the time
it's seem that it only read the data after I open web socket to him
what did I do wrong ?
I want the main will be the reading of the sensor
Thanks ,