Skip to content

Commit c857045

Browse files
committed
DNS server IP getter dnsIP()
1 parent 12c33f1 commit c857045

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

src/WiFi.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ IPAddress WiFiClass::gatewayIP()
266266
return ret;
267267
}
268268

269+
IPAddress WiFiClass::dnsIP(int n)
270+
{
271+
if (n > 1)
272+
return IPAddress(0,0,0,0);
273+
IPAddress dnsip0;
274+
IPAddress dnsip1;
275+
WiFiDrv::getDnsIP(dnsip0, dnsip1);
276+
return n ? dnsip1 : dnsip0;
277+
}
278+
269279
const char* WiFiClass::SSID()
270280
{
271281
return WiFiDrv::getCurrentSSID();

src/WiFi.h

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ class WiFiClass
178178
*/
179179
IPAddress gatewayIP();
180180

181+
/*
182+
* Get the DNS server IP address.
183+
* param n: index of the DNS server
184+
* return: DNS server IP address value
185+
* requires firmware version > 1.5.0
186+
*/
187+
IPAddress dnsIP(int n = 0);
188+
181189
/*
182190
* Return the current SSID associated with the network
183191
*

src/utility/wifi_drv.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,39 @@ void WiFiDrv::getIpAddress(IPAddress& ip)
418418
ip = _gatewayIp;
419419
}
420420

421+
void WiFiDrv::getDnsIP(IPAddress& dnsip0, IPAddress& dnsip1)
422+
{
423+
uint8_t ip0[WL_IPV4_LENGTH] = {0};
424+
uint8_t ip1[WL_IPV4_LENGTH] = {0};
425+
426+
tParam params[PARAM_NUMS_2] = { {0, (char*)ip0}, {0, (char*)ip1}};
427+
428+
WAIT_FOR_SLAVE_SELECT();
429+
430+
// Send Command
431+
SpiDrv::sendCmd(GET_DNS_IP_CMD, PARAM_NUMS_1);
432+
433+
uint8_t _dummy = DUMMY_DATA;
434+
SpiDrv::sendParam(&_dummy, sizeof(_dummy), LAST_PARAM);
435+
436+
// pad to multiple of 4
437+
SpiDrv::readChar();
438+
SpiDrv::readChar();
439+
440+
SpiDrv::spiSlaveDeselect();
441+
//Wait the reply elaboration
442+
SpiDrv::waitForSlaveReady();
443+
SpiDrv::spiSlaveSelect();
444+
445+
// Wait for reply
446+
SpiDrv::waitResponseParams(GET_DNS_IP_CMD, PARAM_NUMS_2, params);
447+
448+
SpiDrv::spiSlaveDeselect();
449+
450+
dnsip0 = ip0;
451+
dnsip1 = ip1;
452+
}
453+
421454
const char* WiFiDrv::getCurrentSSID()
422455
{
423456
WAIT_FOR_SLAVE_SELECT();

src/utility/wifi_drv.h

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ class WiFiDrv
181181
*/
182182
static void getGatewayIP(IPAddress& ip);
183183

184+
/*
185+
* Get the DNS servers IP addresses.
186+
*
187+
* return: copy the DNS servers IP addresses into IPAddress objects
188+
*/
189+
static void getDnsIP(IPAddress& dnsip0, IPAddress& dnsip1);
190+
184191
/*
185192
* Return the current SSID associated with the network
186193
*

src/utility/wifi_spi.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum {
5656
SET_AP_PASSPHRASE_CMD = 0x19,
5757
SET_DEBUG_CMD = 0x1A,
5858
GET_TEMPERATURE_CMD = 0x1B,
59+
GET_DNS_IP_CMD = 0x1E,
5960
GET_REASON_CODE_CMD = 0x1F,
6061

6162
GET_CONN_STATUS_CMD = 0x20,

0 commit comments

Comments
 (0)