I’m trying to set up an ESP8266 for AP as you tell in:
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:
Please can you tell me where am I wrong?
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.
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
but it gave the same error.
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 uos, machine
#uos.dupterm(None, 1) # disable REPL on UART(0)
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!
Current releases of MicroPython have the access point interface enabled by default. The default password for this connection is micropythoN.
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?
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.