How to get MAC Address?

Ok… After about an hour of messing around with the core, I solved the problem of getting the MAC Address of the core so I could enter it in my Router for MAC filtering… Anyways, here’s the suggested steps. If anyone has to go through this and finds a better way, let me know and I will update.

Goal: Get the MAC Address of the spark core to add it to router’s MAC Address filter list.

Steps:

  1. Assumes you have your core setup and talking to the online cloud. For the time being, turn off your MAC Address restrictions on your router and just get the spark connected.

  2. Go to the spark build and create a new sketch (sample below). The sketch will print the MAC Address to the serial window. Download it, and wait for the spark to restart. The blue LED should flash which should tell you the sketch is running.

  3. I am using Putty. Find the COM port that the spark is using (Device Manager on Win). Open Putty (or another Terminal app) and set to to connect to the spark COM port over Serial BUT DONT CONNECT JUST YET. (The default 9600,N,8,1 gobblygook should work).

  4. Now, click the reset button on your spark. It will go through the process to re-connect to your WiFi. Wait until it’s connected, then have Putty connect. If successful, the terminal window should come up and start showing the MAC Address (give it a few seconds to start).

Notes:

  • if Putty does not connect at first, try to connect again. You can’t connect while the spark is establishing it’s wifi connection. The LED should be slowly pulsing cyan in colour.
  • MAC Address: The response does not display leading 0’s. i.e. F:0:AA:35:48:33 is 0F:00…
  • When I first started doing this, I could not get Putty to connect to the spark when it was running. It said the COM port was already in use or some other error. Not sure what changed, but it works now.
  • Note that I did not go follow instructions in other posts to install the Windows USB driver manually. My spark installed a default driver the first time I plugged it in, and it works with that driver fine. it shows as “USB Serial (Communication Class, Abstract Control Model)” in Device Manager

//www.plastibots.com
byte mac[6]; // the MAC address of your Wifi shield
int LED = D7;

void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
Network.macAddress(mac);

}

void loop () {

Serial.print("MAC: ");

Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);

//blink an LED - this is just here as a validation that it’s working…

digitalWrite(LED, HIGH);
delay(250);
digitalWrite(LED, LOW);
delay(1000);

}

3 Likes