Skip to content

Instantly share code, notes, and snippets.

@towynlin
Created April 18, 2014 07:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/11028739 to your computer and use it in GitHub Desktop.
Save towynlin/11028739 to your computer and use it in GitHub Desktop.
Exposing the IP and MAC address of a Spark Core using Spark.variable()
char ipString[16];
char macString[18];
void setup() {
Spark.variable("ip", ipString, STRING);
Spark.variable("mac", macString, STRING);
byte mac[6];
Network.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() {
IPAddress ip = Network.localIP();
sniprintf(ipString, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment