mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
Enable IPv6 for ESP8266 and Raspberry pi pico w (RP2040) (#4759)
This commit is contained in:
parent
fc354eec0e
commit
dadbc1aefa
9 changed files with 41 additions and 34 deletions
|
@ -19,4 +19,4 @@ async def to_code(config):
|
|||
cg.add_library("esphome/AsyncTCP-esphome", "2.0.1")
|
||||
elif CORE.is_esp8266:
|
||||
# https://github.com/esphome/ESPAsyncTCP
|
||||
cg.add_library("esphome/ESPAsyncTCP-esphome", "1.2.3")
|
||||
cg.add_library("esphome/ESPAsyncTCP-esphome", "2.0.0")
|
||||
|
|
|
@ -13,8 +13,7 @@ namespace mdns {
|
|||
void MDNSComponent::setup() {
|
||||
this->compile_records_();
|
||||
|
||||
network::IPAddress addr = network::get_ip_address();
|
||||
MDNS.begin(this->hostname_.c_str(), (uint32_t) addr);
|
||||
MDNS.begin(this->hostname_.c_str());
|
||||
|
||||
for (const auto &service : this->services_) {
|
||||
// Strip the leading underscore from the proto and service_type. While it is
|
||||
|
|
|
@ -273,8 +273,8 @@ async def to_code(config):
|
|||
await cg.register_component(var, config)
|
||||
# Add required libraries for ESP8266
|
||||
if CORE.is_esp8266:
|
||||
# https://github.com/OttoWinter/async-mqtt-client/blob/master/library.json
|
||||
cg.add_library("ottowinter/AsyncMqttClient-esphome", "0.8.6")
|
||||
# https://github.com/heman/async-mqtt-client/blob/master/library.json
|
||||
cg.add_library("heman/AsyncMqttClient-esphome", "1.0.0")
|
||||
|
||||
cg.add_define("USE_MQTT")
|
||||
cg.add_global(mqtt_ns.using)
|
||||
|
|
|
@ -168,15 +168,10 @@ void MQTTClientComponent::start_dnslookup_() {
|
|||
case ERR_OK: {
|
||||
// Got IP immediately
|
||||
this->dns_resolved_ = true;
|
||||
#ifdef USE_ESP32
|
||||
#if LWIP_IPV6
|
||||
this->ip_ = addr.u_addr.ip4.addr;
|
||||
#else
|
||||
this->ip_ = addr.addr;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_ESP8266
|
||||
this->ip_ = addr.addr;
|
||||
#endif
|
||||
this->start_connect_();
|
||||
return;
|
||||
|
@ -228,15 +223,10 @@ void MQTTClientComponent::dns_found_callback(const char *name, const ip_addr_t *
|
|||
if (ipaddr == nullptr) {
|
||||
a_this->dns_resolve_error_ = true;
|
||||
} else {
|
||||
#ifdef USE_ESP32
|
||||
#if LWIP_IPV6
|
||||
a_this->ip_ = ipaddr->u_addr.ip4.addr;
|
||||
#else
|
||||
a_this->ip_ = ipaddr->addr;
|
||||
#endif
|
||||
#endif // USE_ESP32
|
||||
#ifdef USE_ESP8266
|
||||
a_this->ip_ = ipaddr->addr;
|
||||
#endif
|
||||
a_this->dns_resolved_ = true;
|
||||
}
|
||||
|
|
|
@ -15,15 +15,12 @@ IPAddress = network_ns.class_("IPAddress")
|
|||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.SplitDefault(CONF_ENABLE_IPV6, esp32=False): cv.All(
|
||||
cv.only_on_esp32, cv.boolean
|
||||
),
|
||||
cv.Optional(CONF_ENABLE_IPV6, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
if CONF_ENABLE_IPV6 in config:
|
||||
cg.add_define("ENABLE_IPV6", config[CONF_ENABLE_IPV6])
|
||||
if CORE.using_esp_idf:
|
||||
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", config[CONF_ENABLE_IPV6])
|
||||
|
@ -34,3 +31,7 @@ async def to_code(config):
|
|||
if config[CONF_ENABLE_IPV6]:
|
||||
cg.add_build_flag("-DCONFIG_LWIP_IPV6")
|
||||
cg.add_build_flag("-DCONFIG_LWIP_IPV6_AUTOCONFIG")
|
||||
if CORE.is_rp2040:
|
||||
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_ENABLE_IPV6")
|
||||
if CORE.is_esp8266:
|
||||
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY")
|
||||
|
|
|
@ -60,7 +60,7 @@ socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t po
|
|||
memset(server, 0, sizeof(sockaddr_in6));
|
||||
server->sin6_family = AF_INET6;
|
||||
server->sin6_port = htons(port);
|
||||
server->sin6_addr = in6addr_any;
|
||||
server->sin6_addr = IN6ADDR_ANY_INIT;
|
||||
return sizeof(sockaddr_in6);
|
||||
#else
|
||||
if (addrlen < sizeof(sockaddr_in)) {
|
||||
|
|
|
@ -19,6 +19,7 @@ extern "C" {
|
|||
#include "lwip/apps/sntp.h"
|
||||
#if LWIP_IPV6
|
||||
#include "lwip/netif.h" // struct netif
|
||||
#include <AddrList.h>
|
||||
#endif
|
||||
#if USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0)
|
||||
#include "LwipDhcpServer.h"
|
||||
|
@ -164,11 +165,11 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
|
|||
|
||||
ip_addr_t dns;
|
||||
if (uint32_t(manual_ip->dns1) != 0) {
|
||||
dns.addr = static_cast<uint32_t>(manual_ip->dns1);
|
||||
ip_addr_set_ip4_u32_val(dns, static_cast<uint32_t>(manual_ip->dns1));
|
||||
dns_setserver(0, &dns);
|
||||
}
|
||||
if (uint32_t(manual_ip->dns2) != 0) {
|
||||
dns.addr = static_cast<uint32_t>(manual_ip->dns2);
|
||||
ip_addr_set_ip4_u32_val(dns, static_cast<uint32_t>(manual_ip->dns2));
|
||||
dns_setserver(1, &dns);
|
||||
}
|
||||
|
||||
|
@ -325,6 +326,18 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
|
|||
return false;
|
||||
}
|
||||
|
||||
#if ENABLE_IPV6
|
||||
for (bool configured = false; !configured;) {
|
||||
for (auto addr : addrList) {
|
||||
ESP_LOGV(TAG, "Address %s", addr.toString().c_str());
|
||||
if ((configured = !addr.isLocal() && addr.isV6())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
delay(500); // NOLINT
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ap.get_channel().has_value()) {
|
||||
ret = wifi_set_channel(*ap.get_channel());
|
||||
if (!ret) {
|
||||
|
|
|
@ -175,7 +175,11 @@ network::IPAddress WiFiComponent::wifi_subnet_mask_() { return {WiFi.subnetMask(
|
|||
network::IPAddress WiFiComponent::wifi_gateway_ip_() { return {WiFi.gatewayIP()}; }
|
||||
network::IPAddress WiFiComponent::wifi_dns_ip_(int num) {
|
||||
const ip_addr_t *dns_ip = dns_getserver(num);
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_IPV6
|
||||
return {dns_ip->u_addr.ip4.addr};
|
||||
#else
|
||||
return {dns_ip->addr};
|
||||
#endif
|
||||
}
|
||||
|
||||
void WiFiComponent::wifi_loop_() {
|
||||
|
|
|
@ -57,6 +57,7 @@ lib_deps =
|
|||
${common.lib_deps}
|
||||
SPI ; spi (Arduino built-in)
|
||||
Wire ; i2c (Arduino built-int)
|
||||
heman/AsyncMqttClient-esphome@1.0.0 ; mqtt
|
||||
esphome/ESPAsyncWebServer-esphome@2.1.0 ; web_server_base
|
||||
fastled/FastLED@3.3.2 ; fastled_base
|
||||
mikalhart/TinyGPSPlus@1.0.2 ; gps
|
||||
|
@ -88,8 +89,7 @@ lib_deps =
|
|||
${common:arduino.lib_deps}
|
||||
ESP8266WiFi ; wifi (Arduino built-in)
|
||||
Update ; ota (Arduino built-in)
|
||||
ottowinter/AsyncMqttClient-esphome@0.8.6 ; mqtt
|
||||
esphome/ESPAsyncTCP-esphome@1.2.3 ; async_tcp
|
||||
esphome/ESPAsyncTCP-esphome@2.0.0 ; async_tcp
|
||||
ESP8266HTTPClient ; http_request (Arduino built-in)
|
||||
ESP8266mDNS ; mdns (Arduino built-in)
|
||||
DNSServer ; captive_portal (Arduino built-in)
|
||||
|
|
Loading…
Reference in a new issue