Setup WebREPL
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:
1. Enable webREPL
After connecting the device, enter import webrepl_setup
in the shell interface, and input according to the prompt information:
Enable it running on boot: E
Set password for it: your own password(e.g. 1234)
Repeat the password to confirm
Reboot the ESP8266: y
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FxOQxyR9dz3o2SCJ9E7e8%252FenableREPL.png%3Falt%3Dmedia%26token%3D0c945a86-5fec-4f01-a8f4-6e11a8291d03&width=768&dpr=4&quality=100&sign=14d3e1a7&sv=1)
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.
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.
Remember this IP address (automatically assigned by router DHCP), useful when configuring WebREPL.
3. Configure the WebREPL service
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.
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252F0djXQuelCMJ3TzY3wbBR%252FTHONNYREPL.png%3Falt%3Dmedia%26token%3D7b5d604d-1537-4a12-bd72-48f0d02dfa6b&width=768&dpr=4&quality=100&sign=4645a139&sv=1)
Then we fill in the IP address, port and password of WebREPL, and click OK.
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252F0Tcybo06DAotdmAE5KuT%252FThonnyIPConfig.png%3Falt%3Dmedia%26token%3Dbfc5759a-5513-4bcf-a4bc-c1bd94ca203d&width=768&dpr=4&quality=100&sign=883792a0&sv=1)
When WebREPL Connected
is displayed, the connection is successful.
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FrPjWKK8IFJeDy3gWIldu%252FwebSuccess.png%3Falt%3Dmedia%26token%3D823c64e9-d7d5-4496-97b0-a64407bef1b6&width=768&dpr=4&quality=100&sign=f4bf5664&sv=1)
We can try some simple scripts, such as blink.py
.
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.
4. Separate the serial port from the debugger
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๏ผ
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FjVszwcDINurv2QGf0J8d%252FdebugInfo.png%3Falt%3Dmedia%26token%3D1fa987d6-33b6-40bc-bf09-3e476ec4aaa4&width=768&dpr=4&quality=100&sign=f0f0de29&sv=1)
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.py
on 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.
![](https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FOTWO1tWtYo0p1TZLhjnZ%252FdisableSerialDebug.png%3Falt%3Dmedia%26token%3D87108ca8-eb6c-4e86-b698-fe2a70af0021&width=768&dpr=4&quality=100&sign=f0ec381d&sv=1)
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.
Last updated