Skip to content

Add "Get Global IPv6 Address" and update the example. #7065

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 3 additions & 1 deletion libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ void WiFiEvent(WiFiEvent_t event){
WiFi.enableIpV6();
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
Serial.print("STA IPv6: ");
Serial.print("STA Local IPv6: ");
Serial.println(WiFi.localIPv6());
Serial.print("STA Global IPv6: ");
Serial.println(WiFi.globalIPv6());
break;
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
Serial.print("AP IPv6: ");
Expand Down
18 changes: 17 additions & 1 deletion libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ bool WiFiSTAClass::enableIpV6()
}

/**
* Get the station interface IPv6 address.
* Get the station interface local link IPv6 address.
* @return IPv6Address
*/
IPv6Address WiFiSTAClass::localIPv6()
Expand All @@ -832,6 +832,22 @@ IPv6Address WiFiSTAClass::localIPv6()
return IPv6Address(addr.addr);
}

/**
* Get the station interface global IPv6 address.
* @return IPv6Address
*/
IPv6Address WiFiSTAClass::globalIPv6()
{
esp_ip6_addr_t addr;
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return IPv6Address();
}
if(esp_netif_get_ip6_global(get_esp_interface_netif(ESP_IF_WIFI_STA), &addr)) {
return IPv6Address();
}
return IPv6Address(addr.addr);
}


bool WiFiSTAClass::_smartConfigStarted = false;
bool WiFiSTAClass::_smartConfigDone = false;
Expand Down
1 change: 1 addition & 0 deletions libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class WiFiSTAClass

bool enableIpV6();
IPv6Address localIPv6();
IPv6Address globalIPv6();

// STA WiFi info
static wl_status_t status();
Expand Down