Get Spark Core MAC address any of several ways
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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