/
main.py
64 lines (48 loc) · 1.93 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import asyncio
import websockets
@asyncio.coroutine
def hello():
websocket = yield from websockets.connect('ws://192.168.1.106:81/')
ws = yield from websockets.connect('ws://192.168.1.107:81/')
while True:
try:
option = input("What Do you want to do? ")
if option == "Led on":
yield from websocket.send(option)
print("> {}".format(option))
greeting = yield from websocket.recv()
print("< {}".format(greeting))
elif option == "Led off":
yield from websocket.send(option)
print("> {}".format(option))
greeting = yield from websocket.recv()
print("< {}".format(greeting))
elif option == "Lamp on":
yield from websocket.send(option)
print("> {}".format(option))
greeting = yield from websocket.recv()
print("< {}".format(greeting))
elif option == "Lamp off":
yield from websocket.send(option)
print("> {}".format(option))
greeting = yield from websocket.recv()
print("< {}".format(greeting))
elif option == "Computer on":
yield from ws.send(option)
print("> {}".format(option))
greeting = yield from ws.recv()
print("< {}".format(greeting))
elif option == "Computer off":
yield from ws.send(option)
print("> {}".format(option))
greeting = yield from ws.recv()
print("< {}".format(greeting))
elif option == "Exit" or option == "quit":
break
else:
print("Invalid option")
finally:
print("")
yield from websocket.close()
yield from ws.close()
asyncio.get_event_loop().run_until_complete(hello())