向esp32、pico等单片机传输二进制文件

对于一些特殊文件比如图片、二进制程序等等,无法通过thonny等开发环境传输到esp32、树莓派pico等单片机,但micropython官方提供了一种方案,具体如下:

在esp32中运行以下代码建立wifi热点并取esp32的ip地址

import network,time
wlan = network.WLAN(network.STA_IF) # 创建一个WLAN实例  create station interface
wlan.active(True)       # 激活实例 activate the interface
wlan.scan()             # 扫描WIFI  scan for access points
wlan.isconnected()      # 判断WIFI连接否, 返回布尔值  check if the station is connected to an AP
wlan.connect('HUAWEI-WULIAN', 'onlychina') # 连接WIFI  connect to an AP
wlan.config('mac')      # 获取实例的MAC地址 get the interface's MAC address
wlan.ifconfig()         # 获取实例的网络信息  get the interface's IP/netmask/gw/DNS addresses
ap = network.WLAN(network.AP_IF) # 创建一个AP实例 create access-point interface
ap.active(True)         # 激活实例 activate the interface
ap.config(max_clients=10) # 设定多少个客户端可以连接它 set how many clients can connect to the network
ap.config(essid='ESP-AP') #  配置实例的essid参数 set the ESSID of the access point
time.sleep(3)
import webrepl
webrepl.start()

输入

import webrepl_setup

配置好相关参数后,打开链接:http://micropython.org/webrepl/

(此时主机需要连接到热点:ESP-AP,或在同一无线局域网内使用webrepl分配的局域网地址),此时就可以将相关文件传输给esp32了

sudo pip install esptool adafruit-ampy pyserial