add fist admin config
This commit is contained in:
parent
6f7140b87d
commit
a3a11a5078
36
recever.py
36
recever.py
@ -3,12 +3,42 @@
|
||||
import asyncio
|
||||
from websockets.server import serve
|
||||
|
||||
async def echo(ws, path):
|
||||
pin = "1234"
|
||||
boats = ["999", "999", "999", "999"]
|
||||
|
||||
def onCMD(data):
|
||||
global boats, pin
|
||||
print("command:" + str(data))
|
||||
if (len(data) != 4):
|
||||
return
|
||||
if (data[1] != pin):
|
||||
return
|
||||
boot = int(data[2])
|
||||
if (boot >= 0 and boot <= 3):
|
||||
boats[boot] = data[3]
|
||||
print(boats)
|
||||
|
||||
def sendData(data):
|
||||
global boats
|
||||
print("data to send: " + str(data))
|
||||
|
||||
def onMessage(message):
|
||||
global boats
|
||||
data = message.split(':')
|
||||
if(data[0] == "cmd"):
|
||||
onCMD(message)
|
||||
else:
|
||||
for boat in boats:
|
||||
if(data[0] == boat):
|
||||
sendData(data)
|
||||
break
|
||||
|
||||
async def run(ws, path):
|
||||
async for message in ws:
|
||||
print(message)
|
||||
onMessage(message)
|
||||
|
||||
async def main():
|
||||
async with serve(echo, "0.0.0.0", 8080):
|
||||
async with serve(run, "0.0.0.0", 8080):
|
||||
await asyncio.Future()
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user