@Innocenzo The latter is easy, I have that in all of my espxxx's main.py:
wlan = network.WLAN(network.STA)
for _ in range(10):
if wlan.isconnected():
print('\nnetwork config:', wlan.ifconfig())
break
print('.', end='')
time.sleep(1)
else:
print("\nCould not connect")