From b29a31418585a9e7da8e56a9cbae4cf8de06f9f0 Mon Sep 17 00:00:00 2001 From: habi Date: Sat, 21 Jul 2018 23:38:16 +0300 Subject: [PATCH 1/3] added ability to change mac address --- README.md | 10 ++-- examples/ChangeMac/ChangeMac.ino | 33 +++++++++++ keywords.txt | 3 +- src/WiFiEsp.cpp | 21 ++++++- src/WiFiEsp.h | 15 ++++- src/utility/EspDrv.cpp | 94 ++++++++++++++++++++++--------- src/utility/EspDrv.h | 14 +++++ src/utility/EspDrv.h.gch | Bin 0 -> 13564 bytes 8 files changed, 156 insertions(+), 34 deletions(-) create mode 100644 examples/ChangeMac/ChangeMac.ino create mode 100644 src/utility/EspDrv.h.gch diff --git a/README.md b/README.md index b3cc5fd..de2fae9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ With an ESP8266 board, WiFiEsp library allows an Arduino board to connect to the internet. It can serve as either a server accepting incoming connections or a client making outgoing ones. -The WiFiEsp library is very similar to the Arduino [WiFi](http://www.arduino.cc/en/Reference/WiFi) and [Ethernet](http://www.arduino.cc/en/Reference/Ethernet) libraries, and many of the function calls are the same. +The WiFiEsp library is very similar to the Arduino [WiFi](http://www.arduino.cc/en/Reference/WiFi) and [Ethernet](http://www.arduino.cc/en/Reference/Ethernet) libraries, and many of the function calls are the same. Supports ESP SDK version 1.1.1 and above (AT version 0.25 and above). @@ -23,13 +23,13 @@ It is a cheap version of the Arduino WiFi shield that uses an ESP-01 module to p ## Examples - [ConnectWPA](https://github.com/bportaluri/WiFiEsp/blob/master/examples/ConnectWPA/ConnectWPA.ino) - Demonstrates how to connect to a network that is encrypted with WPA2 Personal -- [WebClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClient/WebClient.ino) - Connect to a remote webserver -- [WebClientRepeating](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientRepeating/WebClientRepeating.ino) - Make repeated HTTP calls to a webserver -- [WebServer](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServer/WebServer.ino) - Serve a webpage from the WiFi shield +- [WebClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClient/WebClient.ino) - Connect to a remote webserver +- [WebClientRepeating](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientRepeating/WebClientRepeating.ino) - Make repeated HTTP calls to a webserver +- [WebServer](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServer/WebServer.ino) - Serve a webpage from the WiFi shield - [WebServerAP](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerAP/WebServerAP.ino) - Serve a webpage from the WiFi shield starting a local Access Point - [WebServerLed](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerLed/WebServerLed.ino) - Turn on and off a led from a webpage - [UdpNTPClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/UdpNTPClient/UdpNTPClient.ino) - Query a Network Time Protocol (NTP) server using UDP - +- [ChangeMac](https://github.com/habi3000/WiFiEsp/blob/master/examples/ChangeMac/ChangeMac.ino) - Change MAC address temporary ## Supported APIs diff --git a/examples/ChangeMac/ChangeMac.ino b/examples/ChangeMac/ChangeMac.ino new file mode 100644 index 0000000..d80cd25 --- /dev/null +++ b/examples/ChangeMac/ChangeMac.ino @@ -0,0 +1,33 @@ +#include "WiFiEsp.h" +int status = WL_IDLE_STATUS; // the Wifi radio's status + +void setup() { + // initialize serial for debugging + Serial.begin(115200); + // initialize serial for ESP module "for boards that like uno with only one serial interface, use software serial" + Serial1.begin(115200); + // initialize ESP module + WiFi.init(&Serial1); + delay(1000); + WiFi.SetSTAmacAddressTMP("18:fe:35:98:d3:7a"); + printWifiData(); + } + +void loop() {} + +void printWifiData() +{ + // print your WiFi shield's IP address + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print your MAC address + byte mac[6]; + WiFi.macAddress(mac); + char buf[20]; + sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]); + Serial.print("MAC address: "); + Serial.println(buf); +} + diff --git a/keywords.txt b/keywords.txt index 3270a71..16c1de8 100644 --- a/keywords.txt +++ b/keywords.txt @@ -51,7 +51,8 @@ endPacket KEYWORD2 parsePacket KEYWORD2 remoteIP KEYWORD2 remotePort KEYWORD2 - +setSTAmacAddressPER KEYWORD2 +SetSTAmacAddressTMP KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/WiFiEsp.cpp b/src/WiFiEsp.cpp index 76073f5..b8a2df9 100644 --- a/src/WiFiEsp.cpp +++ b/src/WiFiEsp.cpp @@ -55,13 +55,14 @@ int WiFiEspClass::begin(const char* ssid, const char* passphrase) } + int WiFiEspClass::beginAP(const char* ssid, uint8_t channel, const char* pwd, uint8_t enc, bool apOnly) { if(apOnly) espMode = 2; else espMode = 3; - + if (EspDrv::wifiStartAP(ssid, pwd, channel, enc, espMode)) return WL_CONNECTED; @@ -104,6 +105,24 @@ uint8_t* WiFiEspClass::macAddress(uint8_t* mac) return mac; } +static bool WiFiEspClass::setSTAmacAddressPER(const char* mac){ + espMode=1; + if(EspDrv::setMacAddressSTA_PER(mac)) + return true; + else + return false; +} + + +static bool WiFiEspClass::SetSTAmacAddressTMP(const char* mac){ + espMode=1; + if(EspDrv::SetMacAddressSTA_TMP(mac)) + return true; + else + return false; +} + + IPAddress WiFiEspClass::localIP() { IPAddress ret; diff --git a/src/WiFiEsp.h b/src/WiFiEsp.h index 0ad0984..3eb8285 100644 --- a/src/WiFiEsp.h +++ b/src/WiFiEsp.h @@ -111,7 +111,20 @@ class WiFiEspClass * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH */ uint8_t* macAddress(uint8_t* mac); - + + /* + * Set the station MAC address configration saved in flash. + * + * param mac: Pointer to the mac string. + */ + static bool setSTAmacAddressPER(const char* mac); + + /* + * Set the station MAC address configration not saved in flash. + * + * param mac: Pointer to the mac string. + */ + static bool SetSTAmacAddressTMP(const char* mac); /** * Get the interface IP address. * diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index 76b1a61..bb7c4c6 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -19,8 +19,8 @@ along with The Arduino WiFiEsp library. If not, see #include #include -#include "utility/EspDrv.h" -#include "utility/debug.h" +#include "EspDrv.h" +#include "debug.h" #define NUMESPTAGS 5 @@ -74,7 +74,7 @@ void EspDrv::wifiDriverInit(Stream *espSerial) EspDrv::espSerial = espSerial; bool initOK = false; - + for(int i=0; i<5; i++) { if (sendCmd(F("AT")) == TAG_OK) @@ -131,7 +131,7 @@ void EspDrv::reset() // Show remote IP and port with "+IPD" sendCmd(F("AT+CIPDINFO=1")); - + // Disable autoconnect // Automatic connection can create problems during initialization phase at next boot sendCmd(F("AT+CWAUTOCONN=0")); @@ -194,7 +194,7 @@ bool EspDrv::wifiStartAP(const char* ssid, const char* pwd, uint8_t channel, uin LOGWARN1(F("Failed to start AP"), ssid); return false; } - + if (espMode==2) sendCmd(F("AT+CWDHCP_CUR=0,1")); // enable DHCP for AP mode if (espMode==3) @@ -225,10 +225,10 @@ void EspDrv::config(IPAddress ip) // disable station DHCP sendCmd(F("AT+CWDHCP_CUR=1,0")); - + // it seems we need to wait here... delay(500); - + char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); @@ -244,15 +244,15 @@ void EspDrv::config(IPAddress ip) void EspDrv::configAP(IPAddress ip) { LOGDEBUG(F("> config")); - + sendCmd(F("AT+CWMODE_CUR=2")); - + // disable station DHCP sendCmd(F("AT+CWDHCP_CUR=2,0")); - + // it seems we need to wait here... delay(500); - + char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); @@ -353,6 +353,48 @@ uint8_t* EspDrv::getMacAddress() return _mac; } +static bool EspDrv::setMacAddressSTA_PER(const char* mac) +{ + + LOGDEBUG(F("> setMacAddressSTA_PER")); + + int ret = sendCmd(F("AT+CIPSTAMAC_DEF=\"%s\""), 20000, mac); + + if (ret==TAG_OK) + { + LOGINFO1(F("Changed mac to "), mac); + return true; + } + + LOGWARN1(F("Failed changing mac to"), mac); + + // clean additional messages logged after the FAIL tag + delay(1000); + espEmptyBuf(false); + + return false; +} + +static bool EspDrv::SetMacAddressSTA_TMP(const char* mac) +{ + LOGDEBUG(F("> SetMacAddressSTA_TMP")); + + int ret = sendCmd(F("AT+CIPSTAMAC_CUR=\"%s\""), 20000, mac); + + if (ret==TAG_OK) + { + LOGINFO1(F("Changed mac to "), mac); + return true; + } + + LOGWARN1(F("Failed changing mac to"), mac); + + // clean additional messages logged after the FAIL tag + delay(1000); + espEmptyBuf(false); + + return false; +} void EspDrv::getIpAddress(IPAddress& ip) { @@ -459,23 +501,23 @@ uint8_t EspDrv::getScanNetworks() uint8_t ssidListNum = 0; int idx; bool ret = false; - + espEmptyBuf(); LOGDEBUG(F("----------------------------------------------")); LOGDEBUG(F(">> AT+CWLAP")); - + espSerial->println(F("AT+CWLAP")); char buf[100]; - + idx = readUntil(10000, "+CWLAP:("); - + while (idx == NUMESPTAGS) { _networkEncr[ssidListNum] = espSerial->parseInt(); - + // discard , and " characters readUntil(1000, "\""); @@ -485,12 +527,12 @@ uint8_t EspDrv::getScanNetworks() memset(_networkSsid[ssidListNum], 0, WL_SSID_MAX_LENGTH ); ringBuf.getStrN(_networkSsid[ssidListNum], 1, WL_SSID_MAX_LENGTH-1); } - + // discard , character readUntil(1000, ","); - + _networkRssi[ssidListNum] = espSerial->parseInt(); - + idx = readUntil(1000, "+CWLAP:("); if(ssidListNum==WL_NETWORKS_LIST_MAXNUM-1) @@ -498,7 +540,7 @@ uint8_t EspDrv::getScanNetworks() ssidListNum++; } - + if (idx==-1) return -1; @@ -576,7 +618,7 @@ bool EspDrv::ping(const char *host) LOGDEBUG(F("> ping")); int ret = sendCmd(F("AT+PING=\"%s\""), 8000, host); - + if (ret==TAG_OK) return true; @@ -599,7 +641,7 @@ bool EspDrv::startServer(uint16_t port, uint8_t sock) bool EspDrv::startClient(const char* host, uint16_t port, uint8_t sock, uint8_t protMode) { LOGDEBUG2(F("> startClient"), host, port); - + // TCP // AT+CIPSTART=,"TCP",, @@ -685,7 +727,7 @@ uint16_t EspDrv::availData(uint8_t connId) espSerial->read(); // " espSerial->read(); // , _remotePort = espSerial->parseInt(); // - + espSerial->read(); // : LOGDEBUG(); @@ -762,7 +804,7 @@ bool EspDrv::getData(uint8_t connId, uint8_t *data, bool peek, bool* connClose) _bufPos = 0; _connId = 0; *data = 0; - + return false; } @@ -778,14 +820,14 @@ int EspDrv::getDataBuf(uint8_t connId, uint8_t *buf, uint16_t bufSize) if(_bufPos)qzaqS*?U*&zb;2GI&9u0YFLoN1^JRndYA%OsdWtw9@q%dT$8%Jz34T3Vq z|KLyYSNYK|ezpDLdowaCvkGjP%{gq6$f~T!h#NO7SpPzd!jz|MJrO`NCc&SG#{-zIe>j<1{g!xa;|W z-25#w_KW7H`BBe|>ptOU{NSbe*W7A8b))ZTNjmzF*8K&x@cZn&2#~Xb8ZaqV9 zIlUP5Rj>c!)o5OJqCdsRALyHh<7F7-`nE7I1|&rsr5OEndxbVmb;6S{>n24KcY{2N zqCD#cS&`;hoOa_3A4Ewv&8y=$AJTT2|E%9vqq48M-9q)J7qfAB*@-^IaNG7=Ex($T zu>E0szj?E*t~*z6*E>$aWx#i%e=Mg%H5^ZS%RIn!Vah3fO%K8YTzLQ0)luiF^Vw&e zF&+LJdaQrmo2%2&61U`>>NoYLbeb$%y!AWyRD!Y4H@qGVmgl_Xk1-$t0{tDw_1^sYf1ufy%YD{xvg|GEGti73BaPub^7jp+?KTT9QTa3n2{h0DN z><$Ls#RZIyQViXB@5@pxzMAxP@Otx7^(F(gc-@<+uoFJ}+UO&$O*-Ka&zGn(GX~{k zI=?U&yng@i^=&bnPGNdo>a+VR(OZ(Zd2p%=a)Om<0;BK$Tx& z=%QSnPX`#)D3FvPPQKo3*Sl}jEr@uxzGcpbagZ>$at$Ux@Y)X`O1`5lpkbc%z$GZc zt$-JCGU1k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3%=c+w_O w Date: Sat, 28 Jul 2018 00:11:18 +0300 Subject: [PATCH 2/3] using temp flag instead of two functions --- README.md | 8 ++++---- examples/ChangeMac/ChangeMac.ino | 17 +++++++++++++++-- keywords.txt | 3 +-- src/WiFiEsp.cpp | 29 +++++++++++------------------ src/WiFiEsp.h | 15 +++++---------- src/utility/EspDrv.cpp | 6 +++--- src/utility/EspDrv.h | 2 +- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index de2fae9..218abac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ With an ESP8266 board, WiFiEsp library allows an Arduino board to connect to the internet. It can serve as either a server accepting incoming connections or a client making outgoing ones. -The WiFiEsp library is very similar to the Arduino [WiFi](http://www.arduino.cc/en/Reference/WiFi) and [Ethernet](http://www.arduino.cc/en/Reference/Ethernet) libraries, and many of the function calls are the same. +The WiFiEsp library is very similar to the Arduino [WiFi](http://www.arduino.cc/en/Reference/WiFi) and [Ethernet](http://www.arduino.cc/en/Reference/Ethernet) libraries, and many of the function calls are the same. Supports ESP SDK version 1.1.1 and above (AT version 0.25 and above). @@ -23,9 +23,9 @@ It is a cheap version of the Arduino WiFi shield that uses an ESP-01 module to p ## Examples - [ConnectWPA](https://github.com/bportaluri/WiFiEsp/blob/master/examples/ConnectWPA/ConnectWPA.ino) - Demonstrates how to connect to a network that is encrypted with WPA2 Personal -- [WebClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClient/WebClient.ino) - Connect to a remote webserver -- [WebClientRepeating](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientRepeating/WebClientRepeating.ino) - Make repeated HTTP calls to a webserver -- [WebServer](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServer/WebServer.ino) - Serve a webpage from the WiFi shield +- [WebClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClient/WebClient.ino) - Connect to a remote webserver +- [WebClientRepeating](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientRepeating/WebClientRepeating.ino) - Make repeated HTTP calls to a webserver +- [WebServer](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServer/WebServer.ino) - Serve a webpage from the WiFi shield - [WebServerAP](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerAP/WebServerAP.ino) - Serve a webpage from the WiFi shield starting a local Access Point - [WebServerLed](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerLed/WebServerLed.ino) - Turn on and off a led from a webpage - [UdpNTPClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/UdpNTPClient/UdpNTPClient.ino) - Query a Network Time Protocol (NTP) server using UDP diff --git a/examples/ChangeMac/ChangeMac.ino b/examples/ChangeMac/ChangeMac.ino index d80cd25..886015d 100644 --- a/examples/ChangeMac/ChangeMac.ino +++ b/examples/ChangeMac/ChangeMac.ino @@ -1,4 +1,5 @@ -#include "WiFiEsp.h" +#include "src/WiFiEsp.h" +#include "SoftwareSerial.h" int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { @@ -9,7 +10,19 @@ void setup() { // initialize ESP module WiFi.init(&Serial1); delay(1000); - WiFi.SetSTAmacAddressTMP("18:fe:35:98:d3:7a"); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7a",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7b",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7c",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7d",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7e",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:7f",true); + printWifiData(); + WiFi.setSTAmacAddress("18:fe:35:98:d3:70",true); printWifiData(); } diff --git a/keywords.txt b/keywords.txt index 16c1de8..e97dc98 100644 --- a/keywords.txt +++ b/keywords.txt @@ -51,8 +51,7 @@ endPacket KEYWORD2 parsePacket KEYWORD2 remoteIP KEYWORD2 remotePort KEYWORD2 -setSTAmacAddressPER KEYWORD2 -SetSTAmacAddressTMP KEYWORD2 +setSTAmacAddress KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/WiFiEsp.cpp b/src/WiFiEsp.cpp index b8a2df9..8ebc9c8 100644 --- a/src/WiFiEsp.cpp +++ b/src/WiFiEsp.cpp @@ -55,14 +55,13 @@ int WiFiEspClass::begin(const char* ssid, const char* passphrase) } - int WiFiEspClass::beginAP(const char* ssid, uint8_t channel, const char* pwd, uint8_t enc, bool apOnly) { if(apOnly) espMode = 2; else espMode = 3; - + if (EspDrv::wifiStartAP(ssid, pwd, channel, enc, espMode)) return WL_CONNECTED; @@ -105,24 +104,18 @@ uint8_t* WiFiEspClass::macAddress(uint8_t* mac) return mac; } -static bool WiFiEspClass::setSTAmacAddressPER(const char* mac){ - espMode=1; - if(EspDrv::setMacAddressSTA_PER(mac)) - return true; - else - return false; -} - - -static bool WiFiEspClass::SetSTAmacAddressTMP(const char* mac){ - espMode=1; - if(EspDrv::SetMacAddressSTA_TMP(mac)) - return true; - else - return false; +static bool WiFiEspClass::setSTAmacAddress(const char* mac,bool temp){ + espMode=1; + if(temp) + if(EspDrv::setMacAddressSTA_TMP(mac)) + return true; + else + return false; + if(EspDrv::setMacAddressSTA_PER(mac)) + return true; + return false; } - IPAddress WiFiEspClass::localIP() { IPAddress ret; diff --git a/src/WiFiEsp.h b/src/WiFiEsp.h index 3eb8285..ef1c9e9 100644 --- a/src/WiFiEsp.h +++ b/src/WiFiEsp.h @@ -112,20 +112,15 @@ class WiFiEspClass */ uint8_t* macAddress(uint8_t* mac); - /* + /** * Set the station MAC address configration saved in flash. * * param mac: Pointer to the mac string. + * param temp: Boolean value indicates if the change should be permanent or not */ - static bool setSTAmacAddressPER(const char* mac); + static bool setSTAmacAddress(const char* mac, bool temp); - /* - * Set the station MAC address configration not saved in flash. - * - * param mac: Pointer to the mac string. - */ - static bool SetSTAmacAddressTMP(const char* mac); - /** + /** * Get the interface IP address. * * return: Ip address value @@ -145,7 +140,7 @@ class WiFiEspClass * * return: gateway ip address value */ - IPAddress gatewayIP(); + IPAddress gatewayIP(); /** * Return the current SSID associated with the network diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index bb7c4c6..279d101 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -19,8 +19,8 @@ along with The Arduino WiFiEsp library. If not, see #include #include -#include "EspDrv.h" -#include "debug.h" +#include "utility/EspDrv.h" +#include "utility/debug.h" #define NUMESPTAGS 5 @@ -375,7 +375,7 @@ static bool EspDrv::setMacAddressSTA_PER(const char* mac) return false; } -static bool EspDrv::SetMacAddressSTA_TMP(const char* mac) +static bool EspDrv::setMacAddressSTA_TMP(const char* mac) { LOGDEBUG(F("> SetMacAddressSTA_TMP")); diff --git a/src/utility/EspDrv.h b/src/utility/EspDrv.h index eec702f..e766907 100644 --- a/src/utility/EspDrv.h +++ b/src/utility/EspDrv.h @@ -181,7 +181,7 @@ class EspDrv * * param mac: Pointer to the mac string. */ - static bool SetMacAddressSTA_TMP(const char* mac); + static bool setMacAddressSTA_TMP(const char* mac); /* * Get the interface IP address. From 825dc0368e87ed1fa72f6bbdcc7bdf4d7dcd8102 Mon Sep 17 00:00:00 2001 From: mohamed ahmed Date: Sat, 28 Jul 2018 00:14:27 +0300 Subject: [PATCH 3/3] Update ChangeMac.ino --- examples/ChangeMac/ChangeMac.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ChangeMac/ChangeMac.ino b/examples/ChangeMac/ChangeMac.ino index 886015d..1c478da 100644 --- a/examples/ChangeMac/ChangeMac.ino +++ b/examples/ChangeMac/ChangeMac.ino @@ -1,4 +1,4 @@ -#include "src/WiFiEsp.h" +#include "WiFiEsp.h" #include "SoftwareSerial.h" int status = WL_IDLE_STATUS; // the Wifi radio's status