1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-17 07:15:48 +00:00

Merge branch 'wifi_manual_ip' into integration

# Conflicts:
#	esphome/components/wifi/wifi_component.h
This commit is contained in:
J. Nick Koston
2025-11-10 22:13:44 -06:00
8 changed files with 78 additions and 1 deletions

View File

@@ -425,6 +425,8 @@ async def to_code(config):
# Track if any network uses Enterprise authentication # Track if any network uses Enterprise authentication
has_eap = False has_eap = False
# Track if any network uses manual IP
has_manual_ip = False
# Initialize FixedVector with the count of networks # Initialize FixedVector with the count of networks
networks = config.get(CONF_NETWORKS, []) networks = config.get(CONF_NETWORKS, [])
@@ -438,11 +440,15 @@ async def to_code(config):
for network in networks: for network in networks:
if CONF_EAP in network: if CONF_EAP in network:
has_eap = True has_eap = True
if network.get(CONF_MANUAL_IP) or config.get(CONF_MANUAL_IP):
has_manual_ip = True
cg.with_local_variable(network[CONF_ID], WiFiAP(), add_sta, network) cg.with_local_variable(network[CONF_ID], WiFiAP(), add_sta, network)
if CONF_AP in config: if CONF_AP in config:
conf = config[CONF_AP] conf = config[CONF_AP]
ip_config = conf.get(CONF_MANUAL_IP) ip_config = conf.get(CONF_MANUAL_IP)
if ip_config:
has_manual_ip = True
cg.with_local_variable( cg.with_local_variable(
conf[CONF_ID], conf[CONF_ID],
WiFiAP(), WiFiAP(),
@@ -458,6 +464,10 @@ async def to_code(config):
if CORE.is_esp32: if CORE.is_esp32:
add_idf_sdkconfig_option("CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT", has_eap) add_idf_sdkconfig_option("CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT", has_eap)
# Only define USE_WIFI_MANUAL_IP if any AP uses manual IP
if has_manual_ip:
cg.add_define("USE_WIFI_MANUAL_IP")
cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))
cg.add(var.set_power_save_mode(config[CONF_POWER_SAVE_MODE])) cg.add(var.set_power_save_mode(config[CONF_POWER_SAVE_MODE]))
if CONF_MIN_AUTH_MODE in config: if CONF_MIN_AUTH_MODE in config:

View File

@@ -569,6 +569,7 @@ void WiFiComponent::setup_ap_config_() {
" IP Address: %s", " IP Address: %s",
this->ap_.get_ssid().c_str(), this->ap_.get_password().c_str(), ip_address.c_str()); this->ap_.get_ssid().c_str(), this->ap_.get_password().c_str(), ip_address.c_str());
#ifdef USE_WIFI_MANUAL_IP
auto manual_ip = this->ap_.get_manual_ip(); auto manual_ip = this->ap_.get_manual_ip();
if (manual_ip.has_value()) { if (manual_ip.has_value()) {
ESP_LOGCONFIG(TAG, ESP_LOGCONFIG(TAG,
@@ -578,6 +579,7 @@ void WiFiComponent::setup_ap_config_() {
manual_ip->static_ip.str().c_str(), manual_ip->gateway.str().c_str(), manual_ip->static_ip.str().c_str(), manual_ip->gateway.str().c_str(),
manual_ip->subnet.str().c_str()); manual_ip->subnet.str().c_str());
} }
#endif
if (!this->has_sta()) { if (!this->has_sta()) {
this->state_ = WIFI_COMPONENT_STATE_AP; this->state_ = WIFI_COMPONENT_STATE_AP;
@@ -716,11 +718,14 @@ void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
} else { } else {
ESP_LOGV(TAG, " Channel not set"); ESP_LOGV(TAG, " Channel not set");
} }
#ifdef USE_WIFI_MANUAL_IP
if (ap.get_manual_ip().has_value()) { if (ap.get_manual_ip().has_value()) {
ManualIP m = *ap.get_manual_ip(); ManualIP m = *ap.get_manual_ip();
ESP_LOGV(TAG, " Manual IP: Static IP=%s Gateway=%s Subnet=%s DNS1=%s DNS2=%s", m.static_ip.str().c_str(), ESP_LOGV(TAG, " Manual IP: Static IP=%s Gateway=%s Subnet=%s DNS1=%s DNS2=%s", m.static_ip.str().c_str(),
m.gateway.str().c_str(), m.subnet.str().c_str(), m.dns1.str().c_str(), m.dns2.str().c_str()); m.gateway.str().c_str(), m.subnet.str().c_str(), m.dns1.str().c_str(), m.dns2.str().c_str());
} else { } else
#endif
{
ESP_LOGV(TAG, " Using DHCP IP"); ESP_LOGV(TAG, " Using DHCP IP");
} }
ESP_LOGV(TAG, " Hidden: %s", YESNO(ap.get_hidden())); ESP_LOGV(TAG, " Hidden: %s", YESNO(ap.get_hidden()));
@@ -1555,7 +1560,9 @@ void WiFiAP::set_password(const std::string &password) { this->password_ = passw
void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = std::move(eap_auth); } void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = std::move(eap_auth); }
#endif #endif
void WiFiAP::set_channel(optional<uint8_t> channel) { this->channel_ = channel; } void WiFiAP::set_channel(optional<uint8_t> channel) { this->channel_ = channel; }
#ifdef USE_WIFI_MANUAL_IP
void WiFiAP::set_manual_ip(optional<ManualIP> manual_ip) { this->manual_ip_ = manual_ip; } void WiFiAP::set_manual_ip(optional<ManualIP> manual_ip) { this->manual_ip_ = manual_ip; }
#endif
void WiFiAP::set_hidden(bool hidden) { this->hidden_ = hidden; } void WiFiAP::set_hidden(bool hidden) { this->hidden_ = hidden; }
const std::string &WiFiAP::get_ssid() const { return this->ssid_; } const std::string &WiFiAP::get_ssid() const { return this->ssid_; }
const optional<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; } const optional<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; }
@@ -1564,7 +1571,9 @@ const std::string &WiFiAP::get_password() const { return this->password_; }
const optional<EAPAuth> &WiFiAP::get_eap() const { return this->eap_; } const optional<EAPAuth> &WiFiAP::get_eap() const { return this->eap_; }
#endif #endif
const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; } const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; }
#ifdef USE_WIFI_MANUAL_IP
const optional<ManualIP> &WiFiAP::get_manual_ip() const { return this->manual_ip_; } const optional<ManualIP> &WiFiAP::get_manual_ip() const { return this->manual_ip_; }
#endif
bool WiFiAP::get_hidden() const { return this->hidden_; } bool WiFiAP::get_hidden() const { return this->hidden_; }
WiFiScanResult::WiFiScanResult(const bssid_t &bssid, std::string ssid, uint8_t channel, int8_t rssi, bool with_auth, WiFiScanResult::WiFiScanResult(const bssid_t &bssid, std::string ssid, uint8_t channel, int8_t rssi, bool with_auth,

View File

@@ -158,7 +158,9 @@ class WiFiAP {
#endif // USE_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
void set_channel(optional<uint8_t> channel); void set_channel(optional<uint8_t> channel);
void set_priority(int8_t priority) { priority_ = priority; } void set_priority(int8_t priority) { priority_ = priority; }
#ifdef USE_WIFI_MANUAL_IP
void set_manual_ip(optional<ManualIP> manual_ip); void set_manual_ip(optional<ManualIP> manual_ip);
#endif
void set_hidden(bool hidden); void set_hidden(bool hidden);
const std::string &get_ssid() const; const std::string &get_ssid() const;
const optional<bssid_t> &get_bssid() const; const optional<bssid_t> &get_bssid() const;
@@ -168,7 +170,9 @@ class WiFiAP {
#endif // USE_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
const optional<uint8_t> &get_channel() const; const optional<uint8_t> &get_channel() const;
int8_t get_priority() const { return priority_; } int8_t get_priority() const { return priority_; }
#ifdef USE_WIFI_MANUAL_IP
const optional<ManualIP> &get_manual_ip() const; const optional<ManualIP> &get_manual_ip() const;
#endif
bool get_hidden() const; bool get_hidden() const;
protected: protected:
@@ -178,7 +182,9 @@ class WiFiAP {
#ifdef USE_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
optional<EAPAuth> eap_; optional<EAPAuth> eap_;
#endif // USE_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
#ifdef USE_WIFI_MANUAL_IP
optional<ManualIP> manual_ip_; optional<ManualIP> manual_ip_;
#endif
optional<uint8_t> channel_; optional<uint8_t> channel_;
int8_t priority_{0}; int8_t priority_{0};
bool hidden_{false}; bool hidden_{false};

View File

@@ -282,9 +282,15 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
return false; return false;
} }
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) { if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) {
return false; return false;
} }
#else
if (!this->wifi_sta_ip_config_({})) {
return false;
}
#endif
// setup enterprise authentication if required // setup enterprise authentication if required
#ifdef USE_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
@@ -832,10 +838,17 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
return false; return false;
} }
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) { if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed"); ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false; return false;
} }
#else
if (!this->wifi_ap_ip_config_({})) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false;
}
#endif
return true; return true;
} }

View File

@@ -380,9 +380,15 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
return false; return false;
} }
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) { if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) {
return false; return false;
} }
#else
if (!this->wifi_sta_ip_config_({})) {
return false;
}
#endif
// setup enterprise authentication if required // setup enterprise authentication if required
#ifdef USE_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
@@ -994,10 +1000,17 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
return false; return false;
} }
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) { if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) {
ESP_LOGE(TAG, "wifi_ap_ip_config_ failed:"); ESP_LOGE(TAG, "wifi_ap_ip_config_ failed:");
return false; return false;
} }
#else
if (!this->wifi_ap_ip_config_({})) {
ESP_LOGE(TAG, "wifi_ap_ip_config_ failed:");
return false;
}
#endif
return true; return true;
} }

View File

@@ -112,9 +112,15 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
WiFi.disconnect(); WiFi.disconnect();
} }
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) { if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) {
return false; return false;
} }
#else
if (!this->wifi_sta_ip_config_({})) {
return false;
}
#endif
this->wifi_apply_hostname_(); this->wifi_apply_hostname_();
@@ -445,10 +451,17 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
if (!this->wifi_mode_({}, true)) if (!this->wifi_mode_({}, true))
return false; return false;
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) { if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed"); ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false; return false;
} }
#else
if (!this->wifi_ap_ip_config_({})) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false;
}
#endif
yield(); yield();

View File

@@ -55,8 +55,13 @@ bool WiFiComponent::wifi_apply_power_save_() {
bool WiFiComponent::wifi_apply_output_power_(float output_power) { return true; } bool WiFiComponent::wifi_apply_output_power_(float output_power) { return true; }
bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_sta_ip_config_(ap.get_manual_ip())) if (!this->wifi_sta_ip_config_(ap.get_manual_ip()))
return false; return false;
#else
if (!this->wifi_sta_ip_config_({}))
return false;
#endif
auto ret = WiFi.begin(ap.get_ssid().c_str(), ap.get_password().c_str()); auto ret = WiFi.begin(ap.get_ssid().c_str(), ap.get_password().c_str());
if (ret != WL_CONNECTED) if (ret != WL_CONNECTED)
@@ -161,10 +166,17 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
if (!this->wifi_mode_({}, true)) if (!this->wifi_mode_({}, true))
return false; return false;
#ifdef USE_WIFI_MANUAL_IP
if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) { if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed"); ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false; return false;
} }
#else
if (!this->wifi_ap_ip_config_({})) {
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed");
return false;
}
#endif
WiFi.beginAP(ap.get_ssid().c_str(), ap.get_password().c_str(), ap.get_channel().value_or(1)); WiFi.beginAP(ap.get_ssid().c_str(), ap.get_password().c_str(), ap.get_channel().value_or(1));

View File

@@ -144,6 +144,7 @@
#define USE_TIME_TIMEZONE #define USE_TIME_TIMEZONE
#define USE_WIFI #define USE_WIFI
#define USE_WIFI_AP #define USE_WIFI_AP
#define USE_WIFI_MANUAL_IP
#define USE_WIREGUARD #define USE_WIREGUARD
#endif #endif