-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathred.py
15 lines (14 loc) · 949 Bytes
/
red.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# FUNCIÓN PARA ESTABLECER LA CONEXIÓN WIFI (STATION)
import network # importa el módulo network
import ujson # importa módulo para json
def conectarwifi():
with open("configwifi.json") as configFile:
wifiConfig = ujson.load(configFile)
sta_if = network.WLAN(network.STA_IF) # instancia el objeto -sta_if- para realizar la conexión en modo STA
if not sta_if.isconnected(): # si no existe conexión...
sta_if.active(True) # activa el interfaz STA del ESP32
sta_if.connect(wifiConfig["ssid"], wifiConfig["pwd"]) # inicia la conexión con el AP
print('Conectando a la red', wifiConfig["ssid"] +"...")
while not sta_if.isconnected(): # ...si no se ha establecido la conexión...
pass # ...repite el bucle...
print('Configuración de red (IP/netmask/gw/DNS):', sta_if.ifconfig())