In boot.py I have following code that connects ESP32 NodeMCU to WiFi network.
import network
import ujson
from time import sleep
from machine import Pin
def read_networks_from_config():
with open('config.json', 'r') as file:
data = ujson.load(file)
return data['Networks']
networks = read_networks_from_config()
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
print('Scanning network...')
discovered_networks = sta_if.scan()
for network in discovered_networks:
n_ssid = network[0].decode('utf-8')
print('Checking network {}'.format(n_ssid))
net_info = list(filter(lambda x: x['SSID'] == n_ssid, networks))
if net_info:
net_info = net_info[0]
sta_if.connect(net_info['SSID'], net_info['Password'])
if sta_if.isconnected():
led = Pin(2, Pin.OUT)
led.value(True)
print('Connected...')
break
else:
print('Failed to connect...')
If device successfully connected to WiFi network then onboard led should turn on, but for some reason if sta_if.isconnected(): statement always returns False even though microcontroller is visible in network and is pingable. Weird thing I noticed that when connecting to device using rshell utility like this:
$ rshell --buffer-size=30 -p /dev/ttyUSB0
if sta_if.isconnected(): does not return False value and led turns on. Also in repl isconnected returns True too.
Firmware information:
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.10.0', version='v1.10-298-g47e76b527 on 2019-04-18', machine='ESP32 module with ESP32')
In
boot.pyI have following code that connects ESP32 NodeMCU to WiFi network.If device successfully connected to WiFi network then onboard led should turn on, but for some reason
if sta_if.isconnected():statement always returnsFalseeven though microcontroller is visible in network and is pingable. Weird thing I noticed that when connecting to device usingrshellutility like this:if sta_if.isconnected():does not returnFalsevalue and led turns on. Also inreplisconnectedreturnsTruetoo.Firmware information: