Skip to content

Commit 13a1acc

Browse files
committed
esp8266/scripts/webrepl: Add start_foreground() method.
Starts WebREPL server in foreground and waits for (single) connection.
1 parent c4587e2 commit 13a1acc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

esp8266/scripts/webrepl.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
client_s = None
1111

1212
def setup_conn(port, accept_handler):
13-
global listen_s, client_s
13+
global listen_s
1414
listen_s = socket.socket()
1515
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1616

@@ -19,11 +19,13 @@ def setup_conn(port, accept_handler):
1919

2020
listen_s.bind(addr)
2121
listen_s.listen(1)
22-
listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
22+
if accept_handler:
23+
listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
2324
for i in (network.AP_IF, network.STA_IF):
2425
iface = network.WLAN(i)
2526
if iface.active():
2627
print("WebREPL daemon started on ws://%s:%d" % (iface.ifconfig()[0], port))
28+
return listen_s
2729

2830

2931
def accept_conn(listen_sock):
@@ -65,3 +67,9 @@ def start(port=8266, password=None):
6567
_webrepl.password(password)
6668
setup_conn(port, accept_conn)
6769
print("Started webrepl in normal mode")
70+
71+
72+
def start_foreground(port=8266):
73+
stop()
74+
s = setup_conn(port, None)
75+
accept_conn(s)

0 commit comments

Comments
 (0)