mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 00:02:21 +01:00
Add ESP8266 core v2.6.2 (#905)
* Add ESP8266 core v2.6.2 * Upstream ESP8266 Wifi fixes * Replace disable_interrupt with InterruptLock C++ class * Update code to use InterruptLock * Lint * Update dht.cpp * Improve InterruptLock docs, mark as ICACHE_RAM_ATTR * Fixes
This commit is contained in:
@@ -6,8 +6,16 @@
|
||||
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
extern "C" {
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/init.h" // LWIP_VERSION_
|
||||
#if LWIP_IPV6
|
||||
#include "lwip/netif.h" // struct netif
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
@@ -74,6 +82,19 @@ bool WiFiComponent::wifi_apply_power_save_() {
|
||||
}
|
||||
return wifi_set_sleep_type(power_save);
|
||||
}
|
||||
|
||||
#if LWIP_VERSION_MAJOR != 1
|
||||
/*
|
||||
lwip v2 needs to be notified of IP changes, see also
|
||||
https://github.com/d-a-v/Arduino/blob/0e7d21e17144cfc5f53c016191daca8723e89ee8/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L251
|
||||
*/
|
||||
#undef netif_set_addr // need to call lwIP-v1.4 netif_set_addr()
|
||||
extern "C" {
|
||||
struct netif *eagle_lwip_getif(int netif_index);
|
||||
void netif_set_addr(struct netif *netif, const ip4_addr_t *ip, const ip4_addr_t *netmask, const ip4_addr_t *gw);
|
||||
};
|
||||
#endif
|
||||
|
||||
bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
|
||||
// enable STA
|
||||
if (!this->wifi_mode_(true, {}))
|
||||
@@ -94,6 +115,13 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
|
||||
|
||||
bool ret = true;
|
||||
|
||||
#if LWIP_VERSION_MAJOR != 1
|
||||
// get current->previous IP address
|
||||
// (check below)
|
||||
ip_info previp{};
|
||||
wifi_get_ip_info(STATION_IF, &previp);
|
||||
#endif
|
||||
|
||||
struct ip_info info {};
|
||||
info.ip.addr = static_cast<uint32_t>(manual_ip->static_ip);
|
||||
info.gw.addr = static_cast<uint32_t>(manual_ip->gateway);
|
||||
@@ -122,6 +150,14 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
|
||||
dns_setserver(1, &dns);
|
||||
}
|
||||
|
||||
#if LWIP_VERSION_MAJOR != 1
|
||||
// trigger address change by calling lwIP-v1.4 api
|
||||
// only when ip is already set by other mean (generally dhcp)
|
||||
if (previp.ip.addr != 0 && previp.ip.addr != info.ip.addr) {
|
||||
netif_set_addr(eagle_lwip_getif(STATION_IF), reinterpret_cast<const ip4_addr_t *>(&info.ip),
|
||||
reinterpret_cast<const ip4_addr_t *>(&info.netmask), reinterpret_cast<const ip4_addr_t *>(&info.gw));
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -133,10 +169,31 @@ IPAddress WiFiComponent::wifi_sta_ip_() {
|
||||
return {ip.ip.addr};
|
||||
}
|
||||
bool WiFiComponent::wifi_apply_hostname_() {
|
||||
bool ret = wifi_station_set_hostname(const_cast<char *>(App.get_name().c_str()));
|
||||
const std::string &hostname = App.get_name();
|
||||
bool ret = wifi_station_set_hostname(const_cast<char *>(hostname.c_str()));
|
||||
if (!ret) {
|
||||
ESP_LOGV(TAG, "Setting WiFi Hostname failed!");
|
||||
}
|
||||
|
||||
// inform dhcp server of hostname change using dhcp_renew()
|
||||
for (netif *intf = netif_list; intf; intf = intf->next) {
|
||||
// unconditionally update all known interfaces
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
intf->hostname = (char *) wifi_station_get_hostname();
|
||||
#else
|
||||
intf->hostname = wifi_station_get_hostname();
|
||||
#endif
|
||||
if (netif_dhcp_data(intf) != nullptr) {
|
||||
// renew already started DHCP leases
|
||||
err_t lwipret = dhcp_renew(intf);
|
||||
if (lwipret != ERR_OK) {
|
||||
ESP_LOGW(TAG, "wifi_apply_hostname_(%s): lwIP error %d on interface %c%c (index %d)", intf->hostname,
|
||||
(int) lwipret, intf->name[0], intf->name[1], intf->num);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user