Nodemcu micropython wifi problems.

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Variomatic
Posts: 2
Joined: Mon Mar 12, 2018 9:08 pm

Nodemcu micropython wifi problems.

Post by Variomatic » Mon Mar 12, 2018 9:21 pm

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?

crayfish
Posts: 4
Joined: Fri Jan 20, 2017 9:49 am

Re: Nodemcu micropython wifi problems.

Post by crayfish » Mon Mar 26, 2018 10:02 am

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.

Post Reply