Re: Finding localMAC on SparkFun WiFi Shield/Arduino
Posted: Sat Jun 03, 2017 6:31 pm
I have extracted the following pieces of code from the libraries:
I did play with C for a while but C++ is vague to me. I hope this code clarifies the problem.
Code: Select all
// From SparkFunESP8266.h
=========================
int16_t localMAC(char * mac);
// From SparkFunESP8266,cpp
===========================
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;
}
I did play with C for a while but C++ is vague to me. I hope this code clarifies the problem.