1. Prerequisite

This post is continuation of my earlier post on How to flash MicroPython firmware onto an ESP8266 ESP-12E chip using esptool.

 

2. Setup WebREPL

  1. Connect ESP8266 to the computer using USB to Serial converter.

  2. Connect to REPL prompt over USB serial UART using any terminal program (e.g. picocom on Linux, screen on MAC and TeraTerm on Windows).

    For example
     screen /dev/tty.wchusbserial1410 115200
    
  3. Run import webrepl_setup in the prompt. Follow on-screen instructions to enable WebREPL daemon and to set a desired password.

     MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
    Type "help()" for more information.
    >>> import webrepl_setup
    WebREPL daemon auto-start status: disabled
    
    Would you like to (E)nable or (D)isable it running on boot?
    (Empty line to quit)
    > E
    To enable WebREPL, you must set password for it
    New password: srccodes
    Confirm password: srccodes
    Changes will be activated after reboot
    Would you like to reboot now? (y/n) y
    
    import webrepl_setup
  4. Once rebooted, WebREPL daemon will be started on boot. Note down the WebREPL url (e.g. ws://192.168.4.1:8266).

    MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
    Type "help()" for more information.
    >>> import webrepl_setup
    WebREPL daemon auto-start status: enabled
    
    Would you like to (E)nable or (D)isable it running on boot?
    (Empty line to quit)
    > 
    No further action required
    >>> 
    
    WebREPL daemon auto-start

 

3. Note WIFI Access Point (AP) name

Run following micropython commands and note the WIFI access point (AP) name (e.g. MicroPython-xxxxxx). Default password is micropythoN.

MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
Type "help()" for more information.
>>> import network;
>>> ap = network.WLAN(network.AP_IF);
>>> print(ap.config('essid'));
MicroPython-d0fa00
>>> 

How to change Access Point (AP) name and password?

 MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
Type "help()" for more information.
>>> import network;
>>> ap = network.WLAN(network.AP_IF);
>>> ap.active(True);
>>> ap.config(essid='MyESP8266', authmode=network.AUTH_WPA_WPA2_PSK, password='mypassword');
>>> print(ap.config('essid'));
MyESP8266
>>> 

 

4. Install WebREPL client and run program over WIFI

  1. Download the WebREPL client from https://github.com/micropython/webrepl/archive/master.zip and unzip the same.

  2. Disconnect USB to Serial converter from computer.

  3. Connect computer to the WIFI access point of ESP8266.

    Connect the computer to the WIFI access point
  4. Open webrepl.html using Chrome or Firefox browser.

    webrepl.html
  5. Enter WebREPL url and click ?Connect? button.

    Open webrepl.html using Chrome or Firefox browser
  6. Use the password set during webrepl_setup. Run print('Hello World!'); command in WebREPL remotely. It'll print Hello World! in the console.

    Welcome to MicroPython! 
    Password:
    WebREPL connected
    >>> print('Hello World!'); 
    Hello World!   
    
    Enter WebREPL url and click ?Connect? button. Use the password set during webrepl_setup.

 

References