But I really like that I can use WebREPL for that.
I just did toggle builtin LED of remote ESP01s by toggling a button on local ESP01s:
https://www.youtube.com/watch?v=tQHDQqGaous
The interesting feature of current solution is, that no modules need to be installed on remote ESP01s, only WebREPL needs to be enabled on it. The local ESP01s executes the needed MicroPython commands on remote ESP01s, so code for local and remote ESP01s is in one script running on local ESP01s, here "as is":
Code: Select all
import network
import uwebsockets.client
import time
from machine import Pin
but = Pin(0, Pin.IN, Pin.PULL_UP)
led = Pin(2, Pin.OUT)
led.value(0)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("MicroPython-b7e5c8", "12345678")
while not(sta_if.isconnected()):
led.value(1-led.value())
time.sleep(0.2)
led.value(1)
websocket = uwebsockets.client.connect('ws://'+sta_if.ifconfig()[2]+':8266/')
def wait_for_prompt():
resp = ""
while not(">>> " in resp):
resp = websocket.recv()
print("< {}".format(resp))
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)")
do("led.value(1)")
while True:
if but.value() == 0:
led.value(0)
do("led.value(0)")
time.sleep(0.1)
while but.value() == 0:
time.sleep(0.1)
led.value(1)
do("led.value(1)")
time.sleep(0.1)