Skip to content

Commit

Permalink
DNS server IP getter dnsIP()
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Sep 18, 2023
1 parent 12c33f1 commit cd0210f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
33 changes: 33 additions & 0 deletions src/utility/wifi_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/utility/wifi_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions src/utility/wifi_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cd0210f

Please sign in to comment.