esp8266/scripts/webrepl: Convert to persistent daemon.
This commit is contained in:
parent
7c40b15a3f
commit
8db4f363e9
|
@ -7,7 +7,7 @@ import websocket_helper
|
|||
listen_s = None
|
||||
client_s = None
|
||||
|
||||
def wait_connection():
|
||||
def setup_conn():
|
||||
global listen_s, client_s
|
||||
listen_s = socket.socket()
|
||||
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
|
@ -18,25 +18,35 @@ def wait_connection():
|
|||
|
||||
listen_s.bind(addr)
|
||||
listen_s.listen(1)
|
||||
client_s, remote_addr = listen_s.accept()
|
||||
print(client_s)
|
||||
return client_s
|
||||
listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_conn)
|
||||
print("WebREPL daemon started on port 8266")
|
||||
|
||||
|
||||
def start():
|
||||
global listen_s, client_s
|
||||
uos.dupterm(None)
|
||||
if client_s:
|
||||
client_s.close()
|
||||
if listen_s:
|
||||
listen_s.close()
|
||||
cl = wait_connection()
|
||||
def accept_conn(listen_sock):
|
||||
global client_s
|
||||
cl, remote_addr = listen_sock.accept()
|
||||
client_s = cl
|
||||
websocket_helper.server_handshake(cl)
|
||||
ws = websocket.websocket(cl, True)
|
||||
cl.setblocking(False)
|
||||
# notify REPL on socket incoming data
|
||||
cl.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify)
|
||||
uos.dupterm(ws)
|
||||
print("Connected")
|
||||
print("WebREPL connected\n>>> ", end="")
|
||||
|
||||
|
||||
def stop():
|
||||
global listen_s, client_s
|
||||
uos.dupterm(None)
|
||||
if client_s:
|
||||
client_s.close()
|
||||
if listen_s:
|
||||
listen_s.close()
|
||||
|
||||
|
||||
def start():
|
||||
stop()
|
||||
setup_conn()
|
||||
|
||||
|
||||
start()
|
||||
|
|
Loading…
Reference in New Issue