Skip to content

Commit

Permalink
Update SparkFunESP8266WiFi.cpp
Browse files Browse the repository at this point in the history
Adding localMac function to get MAC address...
  • Loading branch information
kepeter committed Oct 19, 2015
1 parent 1c5cd04 commit 39db72f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/SparkFunESP8266WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,29 @@ IPAddress ESP8266Class::localIP()
return rsp;
}

int16_t ESP8266Class::localMAC(char * mac)
{
sendCommand(ESP8266_GET_STA_MAC, ESP8266_CMD_QUERY); // Send "AT+CIPSTAMAC?"

int16_t rsp = readForResponse(RESPONSE_OK, COMMAND_RESPONSE_TIMEOUT);

if (rsp > 0)
{
// Look for "+CIPSTAMAC"
char * p = strstr(esp8266RxBuffer, ESP8266_GET_STA_MAC);
if (p != NULL)
{
p += strlen(ESP8266_GET_STA_MAC) + 2;
char * q = strchr(p, '"');
if (q == NULL) return ESP8266_RSP_UNKNOWN;
strncpy(mac, p, q - p); // Copy string to temp char array:
return 1;
}
}

return rsp;
}

/////////////////////
// TCP/IP Commands //
/////////////////////
Expand Down Expand Up @@ -772,4 +795,4 @@ char * ESP8266Class::searchBuffer(const char * test)
}
}

ESP8266Class esp8266;
ESP8266Class esp8266;

0 comments on commit 39db72f

Please sign in to comment.