esp32 刷Micropython固件并连接 wifi

进入http://www.micropython.org/download/esp32/   下载

esp32-idf3-20191220-v1.12.bin

先管理员进入powerShell,安装esptool,pip3 install esptool   如果esptool命令无效,在下列地址找到esptool安装目录:

C:\Users\战鹰Ryan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

将esptool.py拷贝到工作目录win10borad文件夹

然后擦除芯片

esptool --chip esp32 --port COM10 erase_flash   (设置自己的COM口)

记得要摁板子上的boot键,才能开始擦除

PS C:\Users\战鹰Ryan\win10board> esptool --chip esp32 --port COM10 erase_flash
esptool.py v2.8
Serial port COM10
Connecting........_____....._____.....___
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 8c:aa:b5:84:de:fc
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.8s
Hard resetting via RTS pin...
PS C:\Users\战鹰Ryan\win10board>

刷入固件:

将固件文件,esp32-idf3-20191220-v1.12.bin,放在win10broad目录下

PS C:\Users\战鹰Ryan\win10board> esptool --chip esp32 --port COM10 --baud 460800 write_flash -z 0x1000 esp32-idf3-20191220-v1.12.bin
esptool.py v2.8
Serial port COM10
Connecting........_
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 8c:aa:b5:84:de:fc
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1247280 bytes to 787794...
Wrote 1247280 bytes (787794 compressed) at 0x00001000 in 90.3 seconds (effective 110.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
PS C:\Users\战鹰Ryan\win10board>

设置工作目录:C:\Users\战鹰Ryan\win10board


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2020/8/23     17:30        1247280 esp32-idf3-20191220-v1.12.bin
-a----        2020/8/24      0:05              0 main.py
-a----        2020/8/29      4:35           1949 mic.py
-a----        2020/8/23     23:19         106424 rshell.exe
-a----        2020/8/26     17:16            225 socket_client.py
-a----        2020/8/25      0:46            752 socket_srv.py
-a----        2020/8/29      2:53             27 wave.py
-a----        2020/8/25      1:15            391 wifiConnect.py

将rshell.exe放入该文件夹,然后执行
PS C:\Users\战鹰Ryan\win10board> .\rshell --buffer-size 512 --editor C:\Windows\system32\notepad.exe -p COM10
Using buffer-size of 512
Connecting to COM10 (buffer-size 512)...
Trying to connect to REPL  connected
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/
Setting time ... Sep 02, 2020 18:56:08
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use the exit command to exit rshell.
C:\Users\战鹰Ryan\win10board>    

 

 

记得要按重启键

 

连接wifi

import network
import machine

import urequests
import utime
import gc
gc.enable()
import ujson
import _thread

"""
连接到wifi;
"""
def wifiConnect(ssid:str, password:str):
    # http://docs.micropython.org/en/v1.9.3/esp8266/esp8266/tutorial/network_basics.html
    # 创建wifi连接实例: 使用账号密码连接无线路由使用: STA_IF; 如果板子本身当路由使用:AP_IF;
    wifi = network.WLAN(network.STA_IF)
    # 判断是否已经连接, wifi.isconnected()是False;
    if not wifi.isconnected() :
        print("will connect to wifi Route")
        # 激活WIFI, 才会开始扫描周围的SSID;
        wifi.active(True)
        # 连接指定的Wifi;
        wifi.connect(ssid, password)
        # 如果连接失败的话,会一直尝试重新连接,
        while not wifi.isconnected():
            utime.sleep(1)
    
#wifiConnect("wifi账号", "wifi密码")

wifiConnect("wifi账号", "wifi密码")

''''''
云同步本地时间;
"""
def setTime() -> None:
    for i in range(2):
        try:
            ### 用自带 ntptime联网获取;
            # 查看本地时间;
            #print("local time is: {t}".format(t=utime.localtime()))
            # 连网查看现实时间;
            #print("net time is: {t}".format(t=ntptime.time()))
            # 使用网上获取的时间设置本地时间;
            # ntptime.settime()
            # 查看时间是否已正确
            #print("now localtime is: {t}".format(t=utime.localtime()))

            ### 自己动手丰衣足食;datetime.datetime.now().strftime('[%Y,%m,%d,%w,%H,%M,%S,%f]');
            rtc = machine.RTC()
            # 能获取到我uwsgi处定制的: [2019,06,28,5,10,42,13,909417]
            response = urequests.get("https://www.gamefunc.top/getCtime")
            rtc.init(tuple(ujson.loads(response.text)))
            print(utime.localtime())
            del response
            break
        except:
            utime.sleep(5)
            
# 执行: setTime; 
# _thread.start_new_thread(setTime, ())
setTime()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值