I've flashed Micropython onto my Nodemcu v3 and am trying to connect the thing to WiFi but I've come across a problem. This is the code I'm using to try and connect it to Wifi:
def do_connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('Connecting to network...')
sta_if.active(True)
sta_if.connect('<NotMySSID>', '<NotMyPassword>')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
When I upload it to the esp8266 it will get to the connecting to network print test and stop. It never seems to be able to connect to my WiFi network, I've checked that the SSID and password are correct. Currently has just been thrown into the main.py file, and not the boot.py file, does this have to be in boot or am I making some other mistake?
Nodemcu micropython wifi problems.
Re: Nodemcu micropython wifi problems.
Hi Variomatic
I tried your code and it works fine for me:
================================
import machine, network
def do_connect():
....sta_if = network.WLAN(network.STA_IF)
....if not sta_if.isconnected():
........print('Connecting to network...')
........sta_if.active(True)
........sta_if.connect('<ssid>', '<password>')
....while not sta_if.isconnected():
........pass
....print('network config:', sta_if.ifconfig())
do_connect()
================================
My sys.version prints as "3.4.0", I am using MicroPython 1.9.3-8.
I tried your code and it works fine for me:
================================
import machine, network
def do_connect():
....sta_if = network.WLAN(network.STA_IF)
....if not sta_if.isconnected():
........print('Connecting to network...')
........sta_if.active(True)
........sta_if.connect('<ssid>', '<password>')
....while not sta_if.isconnected():
........pass
....print('network config:', sta_if.ifconfig())
do_connect()
================================
My sys.version prints as "3.4.0", I am using MicroPython 1.9.3-8.