From feb56614db05f04269dff0376175bd22babe9399 Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Sat, 26 Mar 2016 13:53:39 +0100 Subject: [PATCH] Implemented gatwayIP() and subnetMask() --- src/WiFiEsp.cpp | 15 +++++++++++++++ src/utility/EspDrv.cpp | 26 ++++++++++++++++++++++++++ src/utility/EspDrv.h | 25 ++++++++++++++++++++----- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/WiFiEsp.cpp b/src/WiFiEsp.cpp index d5a1376..52b1957 100644 --- a/src/WiFiEsp.cpp +++ b/src/WiFiEsp.cpp @@ -114,6 +114,21 @@ IPAddress WiFiEspClass::localIP() return ret; } +IPAddress WiFiEspClass::subnetMask() +{ + IPAddress mask; + if(espMode==1) + EspDrv::getNetmask(mask); + return mask; +} + +IPAddress WiFiEspClass::gatewayIP() +{ + IPAddress gw; + if(espMode==1) + EspDrv::getGateway(gw); + return gw; +} char* WiFiEspClass::SSID() diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index f2b862d..eb84883 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -494,6 +494,32 @@ uint8_t EspDrv::getScanNetworks() return ssidListNum; } +bool EspDrv::getNetmask(IPAddress& mask) { + LOGDEBUG(F("> getNetmask")); + + char buf[20]; + if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:netmask:\""), F("\""), buf, sizeof(buf))) + { + mask.fromString (buf); + return true; + } + + return false; +} + +bool EspDrv::getGateway(IPAddress& gw) { + LOGDEBUG(F("> getGateway")); + + char buf[20]; + if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:gateway:\""), F("\""), buf, sizeof(buf))) + { + gw.fromString (buf); + return true; + } + + return false; +} + char* EspDrv::getSSIDNetoworks(uint8_t networkItem) { if (networkItem >= WL_NETWORKS_LIST_MAXNUM) diff --git a/src/utility/EspDrv.h b/src/utility/EspDrv.h index f4e71d3..e2d68ab 100644 --- a/src/utility/EspDrv.h +++ b/src/utility/EspDrv.h @@ -178,6 +178,21 @@ class EspDrv static void getIpAddressAP(IPAddress& ip); + /* + * Get the interface IP netmask. + * This can be used to retrieve settings configured through DHCP. + * + * return: true if successful + */ + static bool getNetmask(IPAddress& mask); + + /* + * Get the interface IP gateway. + * This can be used to retrieve settings configured through DHCP. + * + * return: true if successful + */ + static bool getGateway(IPAddress& mask); /* * Return the current SSID associated with the network @@ -235,8 +250,8 @@ class EspDrv * return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list */ static uint8_t getEncTypeNetowrks(uint8_t networkItem); - - + + /* * Get the firmware version */ @@ -275,10 +290,10 @@ class EspDrv static long _bufPos; static uint8_t _connId; - + static uint16_t _remotePort; static uint8_t _remoteIp[WL_IPV4_LENGTH]; - + // firmware version string static char fwVersion[WL_FW_VER_LENGTH]; @@ -287,7 +302,7 @@ class EspDrv static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH]; static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM]; static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM]; - + // settings of current selected network static char _ssid[WL_SSID_MAX_LENGTH];