diff --git a/src/WiFi.cpp b/src/WiFi.cpp index 264194e..77e4ede 100644 --- a/src/WiFi.cpp +++ b/src/WiFi.cpp @@ -266,6 +266,16 @@ IPAddress WiFiClass::gatewayIP() return ret; } +IPAddress WiFiClass::dnsIP(int n) +{ + if (n > 1) + return IPAddress(0,0,0,0); + IPAddress dnsip0; + IPAddress dnsip1; + WiFiDrv::getDNS(dnsip0, dnsip1); + return n ? dnsip1 : dnsip0; +} + const char* WiFiClass::SSID() { return WiFiDrv::getCurrentSSID(); diff --git a/src/WiFi.h b/src/WiFi.h index b4518df..e6a16c1 100644 --- a/src/WiFi.h +++ b/src/WiFi.h @@ -178,6 +178,14 @@ class WiFiClass */ IPAddress gatewayIP(); + /* + * Get the DNS server IP address. + * param n: index of the DNS server + * return: DNS server IP address value + * requires firmware version > 1.5.0 + */ + IPAddress dnsIP(int n = 0); + /* * Return the current SSID associated with the network * diff --git a/src/utility/wifi_drv.cpp b/src/utility/wifi_drv.cpp index a092007..c16656f 100644 --- a/src/utility/wifi_drv.cpp +++ b/src/utility/wifi_drv.cpp @@ -418,6 +418,39 @@ void WiFiDrv::getIpAddress(IPAddress& ip) ip = _gatewayIp; } + void WiFiDrv::getDNS(IPAddress& dnsip0, IPAddress& dnsip1) + { + uint8_t ip0[WL_IPV4_LENGTH] = {0}; + uint8_t ip1[WL_IPV4_LENGTH] = {0}; + + tParam params[PARAM_NUMS_2] = { {0, (char*)ip0}, {0, (char*)ip1}}; + + WAIT_FOR_SLAVE_SELECT(); + + // Send Command + SpiDrv::sendCmd(GET_DNS_CONFIG_CMD, PARAM_NUMS_1); + + uint8_t _dummy = DUMMY_DATA; + SpiDrv::sendParam(&_dummy, sizeof(_dummy), LAST_PARAM); + + // pad to multiple of 4 + SpiDrv::readChar(); + SpiDrv::readChar(); + + SpiDrv::spiSlaveDeselect(); + //Wait the reply elaboration + SpiDrv::waitForSlaveReady(); + SpiDrv::spiSlaveSelect(); + + // Wait for reply + SpiDrv::waitResponseParams(GET_DNS_CONFIG_CMD, PARAM_NUMS_2, params); + + SpiDrv::spiSlaveDeselect(); + + dnsip0 = ip0; + dnsip1 = ip1; + } + const char* WiFiDrv::getCurrentSSID() { WAIT_FOR_SLAVE_SELECT(); diff --git a/src/utility/wifi_drv.h b/src/utility/wifi_drv.h index c20db43..2d1872f 100644 --- a/src/utility/wifi_drv.h +++ b/src/utility/wifi_drv.h @@ -181,6 +181,13 @@ class WiFiDrv */ static void getGatewayIP(IPAddress& ip); + /* + * Get the DNS servers IP addresses. + * + * return: copy the DNS servers IP addresses into IPAddress objects + */ + static void getDNS(IPAddress& dnsip0, IPAddress& dnsip1); + /* * Return the current SSID associated with the network * diff --git a/src/utility/wifi_spi.h b/src/utility/wifi_spi.h index a11f145..96aa00b 100644 --- a/src/utility/wifi_spi.h +++ b/src/utility/wifi_spi.h @@ -56,6 +56,7 @@ enum { SET_AP_PASSPHRASE_CMD = 0x19, SET_DEBUG_CMD = 0x1A, GET_TEMPERATURE_CMD = 0x1B, + GET_DNS_CONFIG_CMD = 0x1E, GET_REASON_CODE_CMD = 0x1F, GET_CONN_STATUS_CMD = 0x20,