Page 1 of 1

Nodemcu micropython wifi problems.

Posted: Mon Mar 12, 2018 9:21 pm
by Variomatic
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.connect('<NotMySSID>', '<NotMyPassword>')
while not sta_if.isconnected():
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 file, and not the file, does this have to be in boot or am I making some other mistake?

Re: Nodemcu micropython wifi problems.

Posted: Mon Mar 26, 2018 10:02 am
by crayfish
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.connect('<ssid>', '<password>')
....while not sta_if.isconnected():
....print('network config:', sta_if.ifconfig())


My sys.version prints as "3.4.0", I am using MicroPython 1.9.3-8.