Setup Wifi and WebREPL for ESP8266 running MicroPython

This is a step-by-step instruction for setting up Wifi connection and WebREPL ESP8266 that runs MicroPython. After the setup, you will be able to use the MP Explorer app to program the ESP8266.

This post assumes that you have an ESP8266 running MicroPython. If you need to make your ESP8266 run MicroPython, you should read this guideline from MicroPython first.

Step 1: Use the REPL via serial

Connect the ESP8266 to your computer.

If you use a Linux machine or a Mac, you can use screen to communicate with the ESP8266. So start the terminal on your machine first.

Then, we check the name of the serial port of the ESP8266. On Linux, the name is usually something like /dev/ttyUSB0. So we can use the following command to find the name:

ls /dev/tty*

On Mac, the name is usually something like /dev/cu.something. So we can use the following command the find the name:

ls /dev/cu.*

Note down the name once you get it.

Then, we use screen to get into the REPL. The format is screen /dev/yourSerialPortName 115200. The baud rate 115200 should not be change. For instance, on my Linux machine, the name of the serial port is /dev/ttyUSB0. So I should type:

screen /dev/ttyUSB0 115200

Once it's entered, you should be in the REPL environment now. (Press the hard reset button on your board if you cannot see anything.)

On Windows, the name of the serial port is something like 'COMx', where x is a number. We can use the device manager to check this. Press Win + R on the keyboard, and type devmgmt.msc.

In the 'Port' section, you should be able to find the name of the serial port of your ESP8266.

Next, make sure that you have putty installed on Windows. Once putty is launched, change the connection type to Serial, enter the port name of the ESP8266, and change the speed to 115200. After clicking 'Open', you should be in the REPL environment now. (Press the hard reset button on your board if you cannot see anything.)

Step 2: Connect to the Wifi network

Then enter the following Python codes line by line. A detailed explanation of what these codes do can be found on the MicroPython documentation.

import network
sta_if = network.WLAN(network.STA_IF)  
sta_if.active(True)  
sta_if.connect('YOURWIFISSID', 'YOURPASSWORD')  
sta_if.ifconfig()

The first IP address shown is the IP address of your ESP8266 (in the above figure, 192.168.0.12). You will need this when you use the MP Explorer app.

Step 3: Start the WebREPL

To start the WebREPL, enter the following code:

import webrepl_setup

You will see the following question. Enter 'E' to enable WebREPL.

Then the program will ask you to setup a password for WebREPL. Enter whatever you like and note it down. You will need this when you use the MP Explorer app.

WebREPL is now on. So you can use MP Explorer, MicroPython's WebREPL interface or mpfshell to program ESP8266 wirelessly.