Skip to content

Commit feca160

Browse files
authored
Merge pull request #87 from JAndrassy/dns_ip
Add a new command to return the DNS IP.
2 parents c84aa34 + 7a5695d commit feca160

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: arduino/libraries/WiFi/src/WiFi.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ uint32_t WiFiClass::gatewayIP()
464464
return _ipInfo.gw.addr;
465465
}
466466

467+
uint32_t WiFiClass::dnsIP(int n)
468+
{
469+
return dns_getserver(n).u_addr.ip4.addr;
470+
}
471+
467472
char* WiFiClass::SSID()
468473
{
469474
return (char*)_apRecord.ssid;

Diff for: arduino/libraries/WiFi/src/WiFi.h

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class WiFiClass
7676
uint32_t localIP();
7777
uint32_t subnetMask();
7878
uint32_t gatewayIP();
79+
uint32_t dnsIP(int n = 0);
7980
char* SSID();
8081
int32_t RSSI();
8182
uint8_t encryptionType();

Diff for: main/CommandHandler.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ int getTemperature(const uint8_t command[], uint8_t response[])
256256
return 9;
257257
}
258258

259+
int getDNSconfig(const uint8_t command[], uint8_t response[])
260+
{
261+
uint32_t dnsip0 = WiFi.dnsIP();
262+
uint32_t dnsip1 = WiFi.dnsIP(1);
263+
264+
response[2] = 2; // number of parameters
265+
266+
response[3] = 4; // parameter 1 length
267+
memcpy(&response[4], &dnsip0, sizeof(dnsip0));
268+
269+
response[8] = 4; // parameter 2 length
270+
memcpy(&response[9], &dnsip1, sizeof(dnsip1));
271+
272+
return 14;
273+
}
274+
259275
int getReasonCode(const uint8_t command[], uint8_t response[])
260276
{
261277
uint8_t reasonCode = WiFi.reasonCode();
@@ -2061,7 +2077,7 @@ const CommandHandlerType commandHandlers[] = {
20612077
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
20622078

20632079
// 0x10 -> 0x1f
2064-
setNet, setPassPhrase, setKey, NULL, setIPconfig, setDNSconfig, setHostname, setPowerMode, setApNet, setApPassPhrase, setDebug, getTemperature, NULL, NULL, NULL, getReasonCode,
2080+
setNet, setPassPhrase, setKey, NULL, setIPconfig, setDNSconfig, setHostname, setPowerMode, setApNet, setApPassPhrase, setDebug, getTemperature, NULL, NULL, getDNSconfig, getReasonCode,
20652081

20662082
// 0x20 -> 0x2f
20672083
getConnStatus, getIPaddr, getMACaddr, getCurrSSID, getCurrBSSID, getCurrRSSI, getCurrEnct, scanNetworks, startServerTcp, getStateTcp, dataSentTcp, availDataTcp, getDataTcp, startClientTcp, stopClientTcp, getClientStateTcp,

0 commit comments

Comments
 (0)