• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP8266 as “access point can’t set AP config”

Q&A Forum › Category: ESP8266 › ESP8266 as “access point can’t set AP config”
0 Vote Up Vote Down
Enzo Pontone asked 4 years ago

Hi Rui,
I’m trying to set up an ESP8266 for AP as you tell in:
https://randomnerdtutorials.com/micropython-esp32-esp8266-access-point-ap/
I keep it the simplest for now:

SSID = "mynet"
pw = "1234"
import network
def createOpenWifiNet(SSID, pw):
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid=SSID, password=pw)
    while ap.active() == false:
        print("AP not active!")

createOpenWifiNet(SSID, pw)

It throws an error:
File “<stdin>”, line 27, in createOpenWifiNet
OSError: can’t set AP config

line 27 is this one:

ap.config(essid=SSID, password=pw)

Please can you tell me where am I wrong?
Thanks.

Question Tags: AP, MicroPython, wifi
8 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Enzo.
Did you try the original code?
I’ve just run the code and it is working as expected.
I recommend reflash your board with micropython firmware and try again.
Regards,
Sara

0 Vote Up Vote Down
Enzo Pontone answered 4 years ago

Hi Sara,
thanks, I’ll try to reflash but if I set it up as a station (client) it works fine and so for all other code I’m writing so I don’t think it’s a firmware issue.
However I need to write some different code so I need to understand what’s the issue about this.
I’ve a station setup in my boot code: maybe this is the problem? I tried setting

station.active(False) 

before setting

network.WLAN(network.AP_IF)

but it gave the same error.

0 Vote Up Vote Down
Enzo Pontone answered 4 years ago

UPDATE: I made some tries and this is what I got:
when I flash the ESP with fresh new MicroPython 1.13 it has only a basic boot in it:

# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import uos, machine
#uos.dupterm(None, 1) # disable REPL on UART(0)
import gc
#import webrepl
#webrepl.start()
gc.collect()

but neverthless it starts a wifi network “MicroPython-c64376” and pw unknown (???). Do you know why and what’s the default password it sets?
However my fault seems to be that I tried to re-assign the same variable name to the network.WLAN instance: if Iset the active ap instance to False and create  a new one with a different name it works.
I need further experimenting to be sure of this. I’ll let you know what I find!

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Current releases of MicroPython have the access point interface enabled by default. The default password for this connection is micropythoN.
Regards,
Sara

0 Vote Up Vote Down
Enzo Pontone answered 4 years ago

Hi Sara,
this code at first sets up the ESP as an AP and after sets it up as a client of the home wifi net:

def createAP(ssid, pw):
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid=ssid, password=pw)
    while ap.active() == False:
        pass
    return(ap)
def connect_to_wifi(SSID, PW):
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print("Connecting to network...")
        wlan.connect(SSID, PW)
        while not wlan.isconnected():
            pass
    print('Connection successful')
    mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
    return(wlan.ifconfig())
ap = createAP(ssid, pw)
print(ap.ifconfig())
a = input("Close AP?")
client_config = connect_to_wifi(SSID, PW)
print(client_config)
ap.active(False)

Do you know why it sends this output:

bcn 0
del if1
pm open,type:2 0
mode : sta(8c:aa:b5:c6:43:76)

after I set the AP to false because I don’t need it anymore?
Thanks.
Best regards.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Unfortunately, I don’t know what it means.
Do you want to set access point and station at the same time?
Can you tell me why do you need access point at first? Just to better understand what you are trying to achieve.
Regards,
Sara

0 Vote Up Vote Down
Enzo Pontone answered 4 years ago

Hi Sara,
I need to make my ESP an AP at first and then a station. I achieved it this way (sample code):

def createWifiAP(ssid, pw):
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid=ssid, password=pw)
    while ap.active() == False:
        pass
    return(ap)

def connectToWifi(SSID, PW):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print(“Connecting to network…”)
wlan.connect(SSID, PW)
while not wlan.isconnected():
pass
print(‘Connection successful’)
mac = ubinascii.hexlify(network.WLAN().config(‘mac’),’:’).decode()
return(wlan.ifconfig())

ap = createWifiAP(ssid, pw)
print(ap.ifconfig())
a = input(“Close AP?”)
client_config = connectToWifi(SSID, PW)
print(client_config)
ap.active(False)

it works, I don’t understand why after setting inactive the AP instance it outputs this:

bcn 0
del if1
pm open,type:2 0
mode : sta(8c:aa:b5:c6:43:76)

 

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Enzo.
Thanks for sharing your code.
I also don’t know what that output means. I think it is some information about the wi-fi station.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.