summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-04-24 23:04:21 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-04-24 23:04:21 +0300
commit7c40b15a3f04e24dac5c5ebe7e24ce4463a4b63a (patch)
tree471129b9a9d2be0174f7deef8dd56be7d8c6051a /esp8266
parent0d10e5310a7e7caa33f2eabe144384ee8d63aed9 (diff)
downloadmicropython-7c40b15a3f04e24dac5c5ebe7e24ce4463a4b63a.tar.gz
micropython-7c40b15a3f04e24dac5c5ebe7e24ce4463a4b63a.zip
esp8266/scripts/webrepl: WebREPL based on C-level websocket object.
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/scripts/webrepl.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/esp8266/scripts/webrepl.py b/esp8266/scripts/webrepl.py
new file mode 100644
index 0000000000..37c98c6bc6
--- /dev/null
+++ b/esp8266/scripts/webrepl.py
@@ -0,0 +1,42 @@
+# This module should be imported from REPL, not run from command line.
+import socket
+import uos
+import websocket
+import websocket_helper
+
+listen_s = None
+client_s = None
+
+def wait_connection():
+ global listen_s, client_s
+ listen_s = socket.socket()
+ listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+ ai = socket.getaddrinfo("0.0.0.0", 8266)
+ print("Bind address info:", ai)
+ addr = ai[0][4]
+
+ listen_s.bind(addr)
+ listen_s.listen(1)
+ client_s, remote_addr = listen_s.accept()
+ print(client_s)
+ return client_s
+
+
+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()
+ 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")
+
+start()