Skip to content

Commit

Permalink
Merge pull request #4 from kepeter/master
Browse files Browse the repository at this point in the history
localMAC method
  • Loading branch information
Jim Lindblom committed Oct 20, 2015
2 parents 297458e + 39db72f commit ffe5ccd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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;
3 changes: 2 additions & 1 deletion src/SparkFunESP8266WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class ESP8266Class : public Stream
int16_t connect(const char * ssid);
int16_t connect(const char * ssid, const char * pwd);
int16_t getAP(char * ssid);
int16_t localMAC(char * mac);
int16_t disconnect();
IPAddress localIP();

Expand Down Expand Up @@ -216,4 +217,4 @@ class ESP8266Class : public Stream

extern ESP8266Class esp8266;

#endif
#endif
3 changes: 2 additions & 1 deletion src/util/ESP8266_AT.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const char ESP8266_DISCONNECT[] = "+CWQAP"; // Disconnect from AP
//!const char ESP8266_DHCP_EN[] = "+CWDHCP"; // Enable/disable DHCP
//!const char ESP8266_AUTO_CONNECT[] = "+CWAUTOCONN"; // Connect to AP automatically
//!const char ESP8266_SET_STA_MAC[] = "+CIPSTAMAC"; // Set MAC address of station
const char ESP8266_GET_STA_MAC[] = "+CIPSTAMAC"; // Get MAC address of station
//!const char ESP8266_SET_AP_MAC[] = "+CIPAPMAC"; // Set MAC address of softAP
//!const char ESP8266_SET_STA_IP[] = "+CIPSTA"; // Set IP address of ESP8266 station
//!const char ESP8266_SET_AP_IP[] = "+CIPAP"; // Set IP address of ESP8266 softAP
Expand All @@ -73,4 +74,4 @@ const char ESP8266_PING[] = "+PING"; // Function PING
//////////////////////////
const char ESP8266_PINMODE[] = "+PINMODE"; // Set GPIO mode (input/output)
const char ESP8266_PINWRITE[] = "+PINWRITE"; // Write GPIO (high/low)
const char ESP8266_PINREAD[] = "+PINREAD"; // Read GPIO digital value
const char ESP8266_PINREAD[] = "+PINREAD"; // Read GPIO digital value

0 comments on commit ffe5ccd

Please sign in to comment.