cannot get mac address?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
victorclaessen
Posts: 7
Joined: Wed May 04, 2016 2:18 pm

cannot get mac address?

Post by victorclaessen » Mon May 09, 2016 10:06 pm

Hi, the following code does not work on my board:

Code: Select all

>>> import network
>>> wlan=network.WLAN()
>>> wlan.mac()              # get the interface's MAC adddress
Traceback (most recent call last):
  File "<stdin">, line 1, in <module>
AttributeError: 'WLAN' object has no attribute 'mac'
>>> dir(wlan)
['active',  'connect', 'disconnect',  'status', 'scan', 'isconnected', 'config', 'ifconfig']
>>>
But in the Quick Reference (http://docs.micropython.org/en/latest/e ... rd-control) it says that the function mac() should be available. Any thoughts? I am actually looking for a way to uniquely identify individual boards, since I have a bunch of them. I thought the MAC address to be a pretty good candidate.

(Witty Cloud ESP-12, micropython, firmware built with latest commit 65402ab1ec05fd552ceae63e2dcac69095ab1338):

User avatar
deshipu
Posts: 1348
Joined: Thu May 28, 2015 5:54 pm

Re: cannot get mac address?

Post by deshipu » Mon May 09, 2016 10:28 pm

It was moved to

Code: Select all

wlan.config('mac')
. I guess the quickref is not updated yet.

victorclaessen
Posts: 7
Joined: Wed May 04, 2016 2:18 pm

Re: cannot get mac address?

Post by victorclaessen » Mon May 09, 2016 11:27 pm

Right, check, thanks!

For the next person to come along: to format the MAC address in a way you may recognise, try:

Code: Select all

import network
import ubinascii
mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
print mac
output will look like (fictional value):

Code: Select all

01:23:45:67:89:ab
(edit: made code more concise)

Post Reply