How to determine wlan connected ESSID ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
devnull
Posts: 142
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

How to determine wlan connected ESSID ?

Post by devnull » Mon Feb 27, 2017 7:09 am

I am trying to get the connected ssid, however this is failing:

Code: Select all

>>> from network import WLAN,STA_IF
>>> sta = WLAN(STA_IF)
>>> print(sta.config('essid'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: AP required
I don't understand the error AP required ?

Also, is it possible to get the dbm signal strength without doing a scan of all the networks ?

blavery
Posts: 2
Joined: Thu Oct 12, 2017 12:56 pm

Re: How to determine wlan connected ESSID ?

Post by blavery » Thu Oct 12, 2017 1:45 pm

Agree. Something is missing. The only STA config parameter retrievable seems to be
print(sta.config('mac'))

(And incidentally, is the AP mac really the same as STA mac???)

There really needs to be in STA mode a 'ssid' read also, otherwise when the 8266 auto-reconnects using flash-stored wifi credentials, how do we determine just what router it managed to connect to. My house has 3 wifi points!

As a truly awful way of rescuing such data, how about reading the top flash sectors like this:
[code]
import esp
from flashbdev import bdev
sector_size = bdev.SEC_SIZE
flash_size = esp.flash_size()
sector = int(flash_size / sector_size-2 )
data = bytearray(esp.flash_read((sector * sector_size)+16, 20))
for j in range(0,20):
if data[j]==0:
break
print(chr(data[j]),end="")
print("")
[/code]
##### AWW, [ code ] SEEMS TO BE OFF: SUPPLY YOUR OWN INDENTING. SORRY.

I'm not sure that is the right flash address, but it is currently giving me my ssid. (Is it what I am currently logged to, even by auto-reconnect? Or is it merely a stored credential, possibly one of several?)

But this is the wrong solution, isn't it. If nodemcu-lua can easily tell me what AP I'm connected to, then surely micropython ought be able also?

Post Reply