Skip to content

Instantly share code, notes, and snippets.

@towynlin
Created March 27, 2015 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/147337f20f70d7a0247d to your computer and use it in GitHub Desktop.
Save towynlin/147337f20f70d7a0247d to your computer and use it in GitHub Desktop.
Get Spark Core MAC address any of several ways
static char macString[18];
static int t = 0;
static bool printed = false;
void setup() {
Spark.variable("mac", macString, STRING);
Serial.begin(115200);
byte mac[6];
WiFi.macAddress(mac);
sniprintf(macString, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
}
void loop() {
int delta = millis() - t;
if (delta > 10000) {
Spark.publish("mac", macString, 0, PRIVATE);
printed = false;
t = millis();
} else if (delta > 5000 && !printed) {
Serial.println(macString);
printed = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment