I looked into webrepl_cli.py, and that looks much more difficult for connecting a module's WebREPL than using Danni's uwebsockets lib with examples. While working on
mp.py yesterday, a step inbetween was a nice demo of uwebsocket module. Running in unix port MicroPython print() can be used (in unix_demo.py). This is the output it generates:
Code: Select all
$ ./micropython unix_demo.py
WebREPL connected
>>> import machine
>>> led = machine.Pin(1, machine.Pin.OUT)
>>> led.value(0)
>>> led.value(1)
>>> led.value(0)
>>> led.value(1)
>>> led.value(0)
>>> ^CTraceback (most recent call last):
File "unix_demo.py", line 28, in <module>
File "unix_demo.py", line 14, in do
File "unix_demo.py", line 9, in wait_for_prompt
File "/home/stammw/micropython/ports/unix/uwebsockets/protocol.py", line 172, in recv
File "/home/stammw/micropython/ports/unix/uwebsockets/protocol.py", line 168, in recv
File "/home/stammw/micropython/ports/unix/uwebsockets/protocol.py", line 80, in read_frame
KeyboardInterrupt:
$
And this is unix_demo.py showing how easy it is to execute commands remotely via WebREPL. Only the while loop and delays run in unix port micropython, the other commands are executed on ESP-01s via WebREPL and do blink:
Code: Select all
import uwebsockets.client
import utime
websocket = uwebsockets.client.connect('ws://192.168.4.1:8266/')
def wait_for_prompt():
resp = ""
while not(">>> " in resp):
resp = websocket.recv()
print(resp,end='')
def do(cmd):
websocket.send(cmd+"\r\n")
wait_for_prompt()
resp = websocket.recv()
assert resp == "Password: ", resp
do("abcd")
do("import machine")
do("led = machine.Pin(1, machine.Pin.OUT)")
while True:
do("led.value(0)")
utime.sleep(0.5)
do("led.value(1)")
utime.sleep(1.5)