From c1d1c562f3a1e4922711f0584e99ef074c5ce0f1 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 30 Apr 2016 20:41:09 +0300 Subject: esp8266/scripts/webrepl: Add "first connection" mode to setup password. If there's no port_config.py file, or it lacks WEBREPL_PASS variable, "initial setup mode" will be entered on first WebREPLconnection. User will be asked for password, which will be written to port_config.WEBREPL_PASS, and system restarted to work in normal mode with password active. --- esp8266/scripts/webrepl.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'esp8266/scripts/webrepl.py') diff --git a/esp8266/scripts/webrepl.py b/esp8266/scripts/webrepl.py index 18c991287..1a2c82277 100644 --- a/esp8266/scripts/webrepl.py +++ b/esp8266/scripts/webrepl.py @@ -9,7 +9,7 @@ import _webrepl listen_s = None client_s = None -def setup_conn(port): +def setup_conn(port, accept_handler): global listen_s, client_s listen_s = socket.socket() listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -19,7 +19,7 @@ def setup_conn(port): listen_s.bind(addr) listen_s.listen(1) - listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_conn) + listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler) for i in (network.AP_IF, network.STA_IF): iface = network.WLAN(i) if iface.active(): @@ -51,4 +51,12 @@ def stop(): def start(port=8266): stop() - setup_conn(port) + try: + import port_config + _webrepl.password(port_config.WEBREPL_PASS) + setup_conn(port, accept_conn) + print("Started webrepl in normal mode") + except: + import webrepl_setup + setup_conn(port, webrepl_setup.handle_conn) + print("Started webrepl in setup mode") -- cgit v1.2.3