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 9, 2023
1 parent fa6526a commit 84b7c44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void WiFiClass::handleEvent(uint8_t u8MsgType, void *pvMsg)
_localip = 0;
_submask = 0;
_gateway = 0;
_dnsip = 0;
}
// Close sockets to clean state
// Clients will need to reconnect once the physical link will be re-established
Expand All @@ -110,6 +111,7 @@ void WiFiClass::handleEvent(uint8_t u8MsgType, void *pvMsg)
_localip = pstrIPCfg->u32StaticIP;
_submask = pstrIPCfg->u32SubnetMask;
_gateway = pstrIPCfg->u32Gateway;
_dnsip = pstrIPCfg->u32DNS;

_status = WL_CONNECTED;

Expand Down Expand Up @@ -150,6 +152,7 @@ void WiFiClass::handleEvent(uint8_t u8MsgType, void *pvMsg)
_localip = 0;
_submask = 0;
_gateway = 0;
_dnsip = 0;
m2m_wifi_connect((char *)pstrProvInfo->au8SSID, strlen((char *)pstrProvInfo->au8SSID),
pstrProvInfo->u8SecType, pstrProvInfo->au8Password, M2M_WIFI_CH_ALL);
} else {
Expand Down Expand Up @@ -306,6 +309,7 @@ int WiFiClass::init()
_localip = 0;
_submask = 0;
_gateway = 0;
_dnsip = 0;
_dhcp = 1;
_resolve = 0;
_remoteMacAddress = 0;
Expand Down Expand Up @@ -369,6 +373,7 @@ uint8_t WiFiClass::begin()
_localip = 0;
_submask = 0;
_gateway = 0;
_dnsip = 0;
}
if (m2m_wifi_default_connect() < 0) {
_status = WL_CONNECT_FAILED;
Expand Down Expand Up @@ -431,6 +436,7 @@ uint8_t WiFiClass::startConnect(const char *ssid, uint8_t u8SecType, const void
_localip = 0;
_submask = 0;
_gateway = 0;
_dnsip = 0;
}
if (m2m_wifi_connect((char*)ssid, strlen(ssid), u8SecType, (void*)pvAuthInfo, M2M_WIFI_CH_ALL) < 0) {
_status = WL_CONNECT_FAILED;
Expand Down Expand Up @@ -553,6 +559,7 @@ uint8_t WiFiClass::startAP(const char *ssid, uint8_t u8SecType, const void *pvAu
m2m_memcpy((uint8 *)&_localip, (uint8 *)&strM2MAPConfig.au8DHCPServerIP[0], 4);
_submask = 0x00FFFFFF;
_gateway = _localip;
_dnsip = _localip;

#ifdef CONF_PERIPH
// WiFi led ON (rev A then rev B).
Expand Down Expand Up @@ -619,6 +626,7 @@ uint8_t WiFiClass::startProvision(const char *ssid, const char *url, uint8_t cha
m2m_memcpy((uint8 *)&_localip, (uint8 *)&strM2MAPConfig.au8DHCPServerIP[0], 4);
_submask = 0x00FFFFFF;
_gateway = _localip;
_dnsip = _localip;

#ifdef CONF_PERIPH
// WiFi led ON (rev A then rev B).
Expand Down Expand Up @@ -674,6 +682,7 @@ void WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gatew
_localip = conf.u32StaticIP;
_submask = conf.u32SubnetMask;
_gateway = conf.u32Gateway;
_dnsip = conf.u32DNS;
}

void WiFiClass::hostname(const char* name)
Expand Down Expand Up @@ -763,6 +772,11 @@ uint32_t WiFiClass::gatewayIP()
return _gateway;
}

IPAddress WiFiClass::dnsIP()
{
return _dnsip;
}

char* WiFiClass::SSID()
{
if (_status == WL_CONNECTED || _status == WL_AP_LISTENING || _status == WL_AP_CONNECTED) {
Expand Down
2 changes: 2 additions & 0 deletions src/WiFi101.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class WiFiClass
uint32_t localIP();
uint32_t subnetMask();
uint32_t gatewayIP();
IPAddress dnsIP();
char* SSID();
int32_t RSSI();
uint8_t encryptionType();
Expand Down Expand Up @@ -174,6 +175,7 @@ class WiFiClass
uint32_t _localip;
uint32_t _submask;
uint32_t _gateway;
uint32_t _dnsip;
int _dhcp;
uint32_t _resolve;
byte *_remoteMacAddress;
Expand Down

0 comments on commit 84b7c44

Please sign in to comment.