Skip to content

Commit 23880b4

Browse files
committed
DNS server IP getter handler
1 parent c84aa34 commit 23880b4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

arduino/libraries/WiFi/src/WiFi.cpp

Lines changed: 5 additions & 0 deletions
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;

arduino/libraries/WiFi/src/WiFi.h

Lines changed: 1 addition & 0 deletions
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();

main/CommandHandler.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ int getTemperature(const uint8_t command[], uint8_t response[])
256256
return 9;
257257
}
258258

259+
int getDnsIP(const uint8_t command[], uint8_t response[])
260+
{
261+
uint32_t dnsip0 = WiFi.dnsIP();
262+
uint32_t dnsip1 = WiFi.dnsIP(1);
263+
264+
ets_printf("test %d", dnsip0);
265+
266+
response[2] = 2; // number of parameters
267+
268+
response[3] = 4; // parameter 1 length
269+
memcpy(&response[4], &dnsip0, sizeof(dnsip0));
270+
271+
response[8] = 4; // parameter 2 length
272+
memcpy(&response[9], &dnsip1, sizeof(dnsip1));
273+
274+
return 14;
275+
}
276+
259277
int getReasonCode(const uint8_t command[], uint8_t response[])
260278
{
261279
uint8_t reasonCode = WiFi.reasonCode();
@@ -2061,7 +2079,7 @@ const CommandHandlerType commandHandlers[] = {
20612079
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
20622080

20632081
// 0x10 -> 0x1f
2064-
setNet, setPassPhrase, setKey, NULL, setIPconfig, setDNSconfig, setHostname, setPowerMode, setApNet, setApPassPhrase, setDebug, getTemperature, NULL, NULL, NULL, getReasonCode,
2082+
setNet, setPassPhrase, setKey, NULL, setIPconfig, setDNSconfig, setHostname, setPowerMode, setApNet, setApPassPhrase, setDebug, getTemperature, NULL, NULL, getDnsIP, getReasonCode,
20652083

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

0 commit comments

Comments
 (0)