ESP8266 connects to WiFi (MicroPython firmware version)

ESP8266 connect to WiFi

1. Use uPyLoader to debug ESP8266 running MicroPython

*Development environment
Windows 10 x64
Python 3.5.1
uPyLoader ( download link : https://github.com/BetaRavener/uPyLoader/releases )

*Start uPyLoader 1.
uPyLoader itself also supports Web connection. If you can't find the serial port configuration after startup, you can click the refresh button behind "Connection".
2. Click "Connect" on the far right to connect.
3. Next, the menu bar -> "File" -> "Init transfer files". Initialize the transmission file. After the initialization is successful, two files, __upload.py and __download.py, will be added on the MCU side.
4. In the menu bar -> "View", you can open the terminal (Terminal) and editor (Code Editor) to facilitate debugging and code writing.
5. Create a new main.py file in the uPyLoader directory, and write code in this file.
6. If you need to transfer a file, just double-click the corresponding py file, and then click "Transfer" after the "MCU name". After the pop-up window is over, the file will be downloaded to ESP8266.
Insert picture description here

2. Connect to WIFI

The code in main.py:

import network  # 导入network包
import time

SSID="WIFI名称"  #  WIFI名称
PASSWORD="WIFI密码"  #  WIFI密码

def connectWifi(ssid,passwd):
	global wlan
	wlan=network.WLAN(network.STA_IF)  #  生成wlan对象
	wlan.active(True)  #  开启wlan
	wlan.disconnect()
	wlan.connect(ssid,passwd)  #  连接wlan
	while(wlan.ifconfig()[0]=='0.0.0.0'):
		time.sleep(1)

connectWifi(SSID,PASSWORD)

Open the terminal (Terminal) under the menu bar -> "View",
select Remote (main.py under the MCU) and click Execute below
Insert picture description here

3. Verify that it is connected

The following content appears successfully in Terminal
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_25886111/article/details/106215795