本站改版新增arduino频道

Micropython
Arduino

micropython esp32 支持多组ssid wifi连接


boot.py

import time
import machine
import micropython
import network
import esp
esp.osdebug(None)
import gc
gc.collect()

machine.freq(80000000)  # imposto la frequenza della CPU a 80MHz, la più bassa

reduce_WiFi_power = True    # if LOLIN C3 Mini is used

ssid = ['SSID1', 'NBWIFI', 'SSID3']  # add more if you want
password = ['PASS1', 'z7758521', 'PASS3']  # add more if you want


rosso = machine.Pin(12, machine.Pin.OUT)

station = network.WLAN(network.STA_IF)

station.active(True)
station.config(txpower=8.5)

connesso = False
count2 = 0

connected_ssid = None
connected_pw = None

while not connesso:
    if count2 > 0:
        rosso.value(1)
    
    for w in range(len(ssid)):
        if not connesso:
            station.disconnect()
            station.connect(ssid[w], password[w])
            print(ssid[w])
            print(password[w])

            count = 0
            while not station.isconnected():
                count = count + 1
                if count>50:
                    break
                time.sleep(.1)
            
            if station.isconnected():
                connected_ssid = ssid[w]
                connected_pw = password[w]
                connesso = True
                rosso.value(0)
                break
    
    count2 = count2 + 1
    

print('\n连接成功"' + connected_ssid + '" with IP address',station.ifconfig()[0],'\n')
station.active(False)
time.sleep(0.1)



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

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

执行时间: 0.0096089839935303 seconds