Skip to content

DNS server IP getter handler #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arduino/libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ uint32_t WiFiClass::gatewayIP()
return _ipInfo.gw.addr;
}

uint32_t WiFiClass::dnsIP(int n)
{
return dns_getserver(n).u_addr.ip4.addr;
}

char* WiFiClass::SSID()
{
return (char*)_apRecord.ssid;
Expand Down
1 change: 1 addition & 0 deletions arduino/libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class WiFiClass
uint32_t localIP();
uint32_t subnetMask();
uint32_t gatewayIP();
uint32_t dnsIP(int n = 0);
char* SSID();
int32_t RSSI();
uint8_t encryptionType();
Expand Down
18 changes: 17 additions & 1 deletion main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ int getTemperature(const uint8_t command[], uint8_t response[])
return 9;
}

int getDNSconfig(const uint8_t command[], uint8_t response[])
{
uint32_t dnsip0 = WiFi.dnsIP();
uint32_t dnsip1 = WiFi.dnsIP(1);

response[2] = 2; // number of parameters

response[3] = 4; // parameter 1 length
memcpy(&response[4], &dnsip0, sizeof(dnsip0));

response[8] = 4; // parameter 2 length
memcpy(&response[9], &dnsip1, sizeof(dnsip1));

return 14;
}

int getReasonCode(const uint8_t command[], uint8_t response[])
{
uint8_t reasonCode = WiFi.reasonCode();
Expand Down Expand Up @@ -2061,7 +2077,7 @@ const CommandHandlerType commandHandlers[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

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

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