Skip to content

Commit

Permalink
Soft-AP: get subnet mask (espressif#8358)
Browse files Browse the repository at this point in the history
In WiFiSTA you can ask for the subnet mask, but not in WiFiAP.
Only the CIDR is reported.
Therefor the missing method is added to have the same features in softAP as well.
  • Loading branch information
rstephan authored Jul 17, 2023
1 parent 289c2a1 commit 7a37684
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 9 additions & 0 deletions docs/source/api/wifi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ Get the softAP subnet CIDR.
uint8_t softAPSubnetCIDR();
softAPSubnetMask
****************

Get the softAP subnet mask.

.. code-block:: arduino
IPAddress softAPSubnetMask();
softAPenableIpV6
****************

Expand Down
23 changes: 16 additions & 7 deletions libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,29 @@ IPAddress WiFiAPClass::softAPNetworkID()
}

/**
* Get the softAP subnet CIDR.
* @return uint8_t softAP subnetCIDR
* Get the softAP subnet mask.
* @return IPAddress subnetMask
*/
uint8_t WiFiAPClass::softAPSubnetCIDR()
IPAddress WiFiAPClass::softAPSubnetMask()
{
esp_netif_ip_info_t ip;
esp_netif_ip_info_t ip;
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return IPAddress();
}
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_AP), &ip) != ESP_OK){
log_e("Netif Get IP Failed!");
return IPAddress();
log_e("Netif Get IP Failed!");
return IPAddress();
}
return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr));
return IPAddress(ip.netmask.addr);
}

/**
* Get the softAP subnet CIDR.
* @return uint8_t softAP subnetCIDR
*/
uint8_t WiFiAPClass::softAPSubnetCIDR()
{
return WiFiGenericClass::calculateSubnetCIDR(softAPSubnetMask());
}

/**
Expand Down
1 change: 1 addition & 0 deletions libraries/WiFi/src/WiFiAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WiFiAPClass

IPAddress softAPBroadcastIP();
IPAddress softAPNetworkID();
IPAddress softAPSubnetMask();
uint8_t softAPSubnetCIDR();

bool softAPenableIpV6();
Expand Down

0 comments on commit 7a37684

Please sign in to comment.