8000 stm32/modules: Add various modules useful for networking. · micropython/micropython@87a9e99 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87a9e99

Browse files
committed
stm32/modules: Add various modules useful for networking.
1 parent f2a1c22 commit 87a9e99

File tree

9 files changed

+81
-0
lines changed

9 files changed

+81
-0
lines changed

ports/stm32/modules/ntptime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../esp8266/modules/ntptime.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../micropython-lib/uasyncio/uasyncio/__init__.py

ports/stm32/modules/uasyncio/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../micropython-lib/uasyncio.core/uasyncio/core.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../micropython-lib/uasyncio.queues/uasyncio/queues.py

ports/stm32/modules/upip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../tools/upip.py

ports/stm32/modules/upip_utarfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../tools/upip_utarfile.py

ports/stm32/modules/urequests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../micropython-lib/urequests/urequests.py

ports/stm32/modules/webrepl.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This module should be imported from REPL, not run from command line.
2+
import socket
3+
import uos
4+
import network
5+
import uwebsocket
6+
import websocket_helper
7+
import _webrepl
8+
9+
listen_s = None
10+
client_s = None
11+
12+
13+
def setup_conn(port, accept_handler):
14+
global listen_s
15+
listen_s = socket.socket()
16+
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
17+
18+
ai = socket.getaddrinfo("0.0.0.0", port)
19+
addr = ai[0][4]
20+
21+
listen_s.bind(addr)
22+
listen_s.listen(1)
23+
if accept_handler:
24+
listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
25+
for i in (0, 1):
26+
iface = network.WLAN(i)
27+
if iface.active():
28+
print("WebREPL daemon started on ws://%s:%d" % (iface.ifconfig()[0], port))
29+
return listen_s
30+
31+
32+
def accept_conn(listen_sock):
33+
global client_s
34+
cl, remote_addr = listen_sock.accept()
35+
prev = uos.dupterm(None)
36+
uos.dupterm(prev)
37+
if prev:
38+
print("\nConcurrent WebREPL connection from", remote_addr, "rejected")
39+
cl.close()
40+
return
41+
print("\nWebREPL connection from:", remote_addr)
42+
client_s = cl
43+
websocket_helper.server_handshake(cl)
44+
ws = uwebsocket.websocket(cl, True)
45+
ws = _webrepl._webrepl(ws)
46+
cl.setblocking(False)
47+
# notify REPL on socket incoming data
48+
#cl.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify)
49+
uos.dupterm(ws)
50+
51+
52+
def stop():
53+
global listen_s, client_s
54+
uos.dupterm(None)
55+
if client_s:
56+
client_s.close()
57+
if listen_s:
58+
listen_s.close()
59+
60+
61+
def start(port=8266, password=None):
62+
stop()
63+
if password is None:
64+
print('Using default password "mp"')
65+
password = 'mp'
66+
_webrepl.password(password)
67+
setup_conn(port, accept_conn)
68+
69+
70+
def start_foreground(port=8266):
71+
stop()
72+
s = setup_conn(port, None)
73+
accept_conn(s)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../esp8266/modules/websocket_helper.py

0 commit comments

Comments
 (0)
0