Introduction to the

Use FRP to NAT the PRIVATE IP address of raspberry PI to the cloud server of the public network. Use USB connection to connect raspberry PI to ESP8266 to implement remote control of ESP8266

Introduction to development Environment

Today’s hero looks like this:

webrepl.py
esptool

# install esptool
pip install esptool
# download bin fileWget HTTP: / / http://micropython.org/resources/firmware/esp8266-20191220-v1.12.binCopy the code

You’ll also need a developer machine, either on a MAC or Linux (as long as Terminal is open and the Internet is available), or raspberry, but it’s not as tough. Because raspberry has limited resources, I didn’t install Virtulenv. If the machine has more resources, I recommend using Venv and ZSH autoenv to improve efficiency.

Write Flash

Esp8266 manufacturers provide firmware, but I do not know C language. So I’m going to go ahead and clean up the original firmware and brush into the microPython-enabled firmware


# erase flash
esptool.py --port /dev/ttyUSB0 erase_flash
# write new flashEsptool. py --port /dev/ttyusb0 --baud 460800 write_flash --flash_size= detect-fm dio 0 ESP8266-20191220-v1.12.binCopy the code

/dev/tty* is the port corresponding to esp8266, which varies from machine to machine. The default value is /dev/ttyusb0 (raspberry) or /dev/cu.slab_usbtouart (MAC). Windows is usually COM*. Development of embedded systems are generally recommended to use Windows as the main machine, but I do not like Windows.

-FM dio needs to be added, and the specific reason is explained in the official document:

For some boards with a particular FlashROM configuration (e.g. some variants of a NodeMCU board) you may need to use the following command to deploy the firmware (note the -fm dio option)

Then the firmware is brushed.

WIFI Network connection

It’s fair to say that without the Internet, the ESP8266 would have nothing to play with. After brushing the microPython firmware, you need to press the RST key. You can then access the microPython REPL via a Screen connection (USB cable required)

# attach raspberrySSH -i ~/. SSH/id_rpi-oport =9434 [email protected]# attach microPython REPL
screen /dev/ttyUSB0 115200
Copy the code

Then enter microPythonREPL

MicroPython v112. on 2019- 12- 20; ESP module with ESP8266
Type "help()" for more information.
>>>
Copy the code

Open webREPL and upload files to the board

>>> import webrepl_setup
Copy the code

Just follow the instructions. Unsurprisingly, you’ve successfully opened WebREPL and set up your password.

Daemon started on ws://192.168.4.1:8266Copy the code

Ensure that the Esp8266 and Esp8266 are on the same LAN ~. If a jumper exists, the esp8266 can be accessed only if the jumper and ESP8266 are on the same LAN. The board will create a WIFI of its own with the name micropython-xxxxxx and password _micropythonN_ next clone the following repository to the board or local and start it

git clone [email protected]:micropython/webrepl.git
Copy the code

Then create the boot.py file locally. This file is automatically executed after the board starts working.

# -*- coding:utf-8 -*-
# 2020-02-13
# https://docs.micropython.org/en/latest/esp8266/quickref.html#networking

import network

def init_wifi_conn(wlan, ssid, pwd):
    wlan.active(True)
    wlan.connect(ssid, pwd)
    while not wlan.isconnected():
        pass
    print("network config:", wlan.ifconfig())


def do_connection(a):
    sta_if = network.WLAN(network.STA_IF)
    
    # remember modify ssid and pwd.
    ssid = "your_wifi_ssid"
    pwd = "your_wifi_pwd"
    if not sta_if.isconnected():
        init_wifi_conn(sta_if, ssid, pwd)


if __name__ == '__main__':
    import webrepl
    do_connection()
    webrepl.start()

Copy the code

Then execute the following command on the jumper to push the local file to ESP8266:

# cd webreplPy -p 1234 boot.py 192.168.4.1:/boot.py./webrepl_cli.py -p 1234 boot.py 192.168.4.1:/boot.pyCopy the code

Then press the reset button on the board and enter the microPython REPL again through screen. You will find that webREPL has an extra address, as shown in the following image:


WebREPL daemon started on ws://192.1684.1.:8266
WebREPL daemon started on ws://192.1681.2.:8266
Started webrepl in normal mode
Copy the code

192.168.1.2 is the IP address assigned by the router to the Esp8266. WebREPL is also available in the Web version, as follows:


# cd webrepl

python3 -m http.server

Copy the code

The local browser then accesses http://{jumper IP}:8000/webrepl.html, which can also connect to ESP8266

GPIO

Long press two seconds to identify the TWO-DIMENSIONAL code concerns ▼

Public account dialog box, reply keyword “bytedance internal push”
Get bytedance internal push code