Well, I've managed to do on a different way, thanks a lot for your help. Here is the code:
#import wifisetup
#wifisetup.auto_connect()
import network
from m5stack import *
from m5ui import *
from m5_pin import *
from m5mqtt import M5mqtt
from time import strftime, ticks_ms, ticks_diff, sleep_ms
import utime
import _thread
def connect(ssid,auth,timeout=6000):
from network import WLAN, STA_IF, AP_IF
global uplink
uplink = WLAN(STA_IF)
uplink.active(True)
uplink.connect(ssid, auth)
started= ticks_ms()
while True:
if uplink.isconnected():
return True
else:
if ticks_diff(ticks_ms(), started) < timeout:
sleep_ms(100)
continue
else:
return False
wlan = network.WLAN(network.AP_IF)
while True:
if connect('Wifi1', 'password1'):
red='Wifi1'
break
elif connect('Wifi2', 'password2'):
red='Wifi2'
break
print('connected to: ',red)
...