本站改版新增arduino频道

Micropython
Arduino

micropython 实现wifi联网更新main代码


boot.py代码如下: 


# This file is executed on every boot (including wake-boot from deepsleep)

# 功能:联手机热点上网并获取gitee上最新文件替换esp32上的main.py

import network

import urequests

wlan = network.WLAN(network.STA_IF)

wlan.active(True)

def do_connect():

    if not wlan.isconnected():

        print('connecting to network...')

        wlan.connect('手机热点名', 'WIFI密码')

        while not wlan.isconnected():

            print('connecting to network failed...')

    print('network config:', wlan.ifconfig())

do_connect()

url="https://gitee.com/tianyudi/esp32/raw/master/webpush/main.py"

data=urequests.get(url,).content

if chr(data[9])=="1":

    # 如果main.py第十个字符为1,说明需要更新

    with open(r"main.py", "wb") as f:

        print("开始更新")

        f.write(data)

else:

    print("不更新") 



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号

执行时间: 0.0093259811401367 seconds