Comment on page
Realize remote debugging and upload script
The previous tutorial realized the function of the robot to perform sequence actions by editing Python code offline. But this is very inconvenient. Whenever we need to modify the code, we need to unplug the WiFi module for modification, and we cannot flexibly pause and modify parameters during execution. The reason is that ESP8266 only has one serial port, and we need to use it to communicate with NyBoard. Fortunately, MicroPython uses the WiFi function provided by ESP to realize remote wireless Python debugging - WebREPL.
On the basis of official documents, combined with the characteristics of ESP8266, we wrote the following tutorials:
After connecting the device, enter
import webrepl_setupin the shell interface, and input according to the prompt information:
- 1.Enable it running on boot: E
- 2.Set password for it: your own password(e.g. 1234)
- 3.Repeat the password to confirm
- 4.Reboot the ESP8266: y
2. The script to setup webREPL
We use the demo script below, to replace the SSID and password with the network information your own around you.
# WiFi SSID and Password
wifi_ssid = "YOUR SSID" # YOUR WiFi SSID
wifi_password = "YOUR PASSWORD" # YOUR WiFi PASSWORD
# Wireless config : Station mode
station = network.WLAN(network.STA_IF)
# Continually try to connect to WiFi access point
while not station.isconnected():
# Try to connect to WiFi access point
# Display connection details
print("My IP Address:", station.ifconfig())
if __name__ == "__main__":
After running the script, it will keep trying to connect to the WiFi network. Once connected, it will automatically start the WebREPL service of the device.
My IP Address: 192.168.xxx.xxx
WebREPL daemon started on ws://192.168.xxx.xxx:8266
Started webrepl in normal mode
Remember this IP address (automatically assigned by router DHCP), useful when configuring WebREPL.
We are now debugging the Python script through WebREPL, and the previous serial port is used to communicate with NyBoard. So in the options, change the previous USB-COMx interface to WebREPL.
Then we fill in the IP address, port and password of WebREPL, and click OK.
WebREPL Connectedis displayed, the connection is successful.
We can try some simple scripts, such as
WebREPL saves serial ports and supports wireless debugging. The disadvantage is that the speed is slow (because of network delay), and the waiting time for software reset is relatively long.
Now we can use webREPL to debug the script, but when we open the serial port monitor, we will find that whenever we run the script, the serial port will send out a series of debugging content: These massive strings will cause the NyBoard to be too late to process and crash. As shown below：
We hope that when debugging the program, the serial port only outputs the commands we want to output, not the Debug information. Open the
boot.pyon the device, uncomment the line of code
uos.dupterm(None, 1)and save it , and unbind the serial port and REPL debug. Restart the module, and the serial port debugging assistant will no longer print the debug information.
As a supplement, we can output debug information through the
print()statement, which will be displayed in the Shell through WiFi.
So far, you can easily use the ESP8266 to debug robot through webREPL to edit action sequences based on MicroPython.