homecontrol-wsclient/main.py

29 lines
602 B
Python
Raw Normal View History

2020-02-27 13:02:23 +01:00
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()