29 lines
602 B
Python
29 lines
602 B
Python
|
import ujson
|
||
|
import utime as time
|
||
|
from uwebsockets import client
|
||
|
|
||
|
HOST="ws://10.64.12.20:8100"
|
||
|
NODEID="esp8266-1234"
|
||
|
NAME="esp8266-1234"
|
||
|
|
||
|
def register(ws):
|
||
|
ret = { "command": "register", "nodeid": NODEID, "name": NAME, "ts": time.time()}
|
||
|
ws.send(ujson.dumps(ret))
|
||
|
|
||
|
def listen(ws):
|
||
|
while (True):
|
||
|
msg = ws.recv()
|
||
|
if msg:
|
||
|
print("< {}".format(msg))
|
||
|
|
||
|
def main():
|
||
|
ws = client.connect(HOST)
|
||
|
while (True):
|
||
|
print("register...")
|
||
|
register(ws)
|
||
|
print("listen...")
|
||
|
listen(ws)
|
||
|
time.sleep(5)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|