Page 1 of 1

cannot get mac address?

Posted: Mon May 09, 2016 10:06 pm
by victorclaessen
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):

Re: cannot get mac address?

Posted: Mon May 09, 2016 10:28 pm
by deshipu
It was moved to

Code: Select all

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

Re: cannot get mac address?

Posted: Mon May 09, 2016 11:27 pm
by victorclaessen
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)