WebREPL daemon auto-start is disabled by default in MycroPython on ESP8266 for security reason. Here, we'll enable the same, connect to the REPL over WIFI using locally installed WebREPL client and run a "Hello World" program remotely on the chip.
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
a. Connect ESP8266 to the computer using USB to Serial converter.
b. Connect to REPL prompt over USB serial UART using any terminal program (e.g. picocom on Linux, screen on MAC and TeraTerm on Windows).
screen /dev/tty.wchusbserial1410 115200
c. 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
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')); MyESP8
4. Install WebREPL client and run program over WIFI
a. Download the WebREPL client from https://github.com/micropython/webrepl/archive/master.zip and unzip the same.
b. Disconnect USB to Serial converter from computer.
c. Connect computer to the WIFI access point of ESP8266.
d. Open webrepl.html using Chrome or Firefox browser.
e. Enter WebREPL url and click 'Connect' button.
f. 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!