Get ssid of currently connected wifi network?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
larsks
Posts: 22
Joined: Mon Feb 13, 2017 5:27 pm

Get ssid of currently connected wifi network?

Post by larsks » Sat Apr 07, 2018 5:33 pm

Is there any way of getting the ssid of the wifi network to which the esp8266 is currently connected? I was hoping for:

Code: Select all

sta = network.WLAN(network.STA_IF)
sta.config('ssid')
...but that reports "unknown config param".

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: Get ssid of currently connected wifi network?

Post by devnull » Sat Apr 07, 2018 11:56 pm

How to determine wlan connected ESSID ?

larsks
Posts: 22
Joined: Mon Feb 13, 2017 5:27 pm

Re: Get ssid of currently connected wifi network?

Post by larsks » Mon Apr 09, 2018 2:55 am

That is...pretty much exactly what I am asking, yes.

I took a look at the sources and it seems as if this would be a reasonably easy feature to add, except that I am unsure where the various MP_QSTR_ constants come from (like MP_QSTR_essid). They get generated as part of the build process, but I'm not sure from what.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Get ssid of currently connected wifi network?

Post by dhylands » Mon Apr 09, 2018 5:10 pm

The MP_QSTR constants are generated by scanning the source code and looking for use in the source code.

So if the source code uses MP_QSTR_foobar, then the scanner will generate a qstr for foobar.

larsks
Posts: 22
Joined: Mon Feb 13, 2017 5:27 pm

Re: Get ssid of currently connected wifi network?

Post by larsks » Mon Apr 09, 2018 7:38 pm

Dave,

Thanks for the pointer. That's magical! :)

Anway, I've posted https://github.com/micropython/micropython/pull/3705 which allows one to ask for the essid of both Station and AP network interfaces:

Code: Select all

>>> import network
>>> sta = network.WLAN(network.STA_IF)
>>> ap = network.WLAN(network.AP_IF)
>>> ap.config('essid')
'MicroPython-66e36c'
>>> sta.config('essid')
'mynetwork'

Post Reply