mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
[wifi] Fix some access point bugs related to esp-idf 4.4.7 (#6928)
* Set dhcp server range to only 10 IPs * Change log level to errors to make it clearer * We want to stop the dhcp server, not client
This commit is contained in:
parent
5dec62bf1e
commit
d27e7b3b70
3 changed files with 21 additions and 21 deletions
|
@ -694,15 +694,15 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
info.netmask = network::IPAddress(255, 255, 255, 0);
|
||||
}
|
||||
|
||||
err = esp_netif_dhcpc_stop(s_ap_netif);
|
||||
err = esp_netif_dhcps_stop(s_ap_netif);
|
||||
if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcpc_stop failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_stop failed: %s", esp_err_to_name(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
err = esp_netif_set_ip_info(s_ap_netif, &info);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_set_ip_info failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_set_ip_info failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -712,20 +712,20 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
start_address += 99;
|
||||
lease.start_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease start: %s", start_address.str().c_str());
|
||||
start_address += 100;
|
||||
start_address += 10;
|
||||
lease.end_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.str().c_str());
|
||||
err = esp_netif_dhcps_option(s_ap_netif, ESP_NETIF_OP_SET, ESP_NETIF_REQUESTED_IP_ADDRESS, &lease, sizeof(lease));
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcps_option failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_option failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
err = esp_netif_dhcps_start(s_ap_netif);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcps_start failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_start failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -716,12 +716,12 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
|
||||
if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
||||
if (!wifi_softap_dhcps_stop()) {
|
||||
ESP_LOGV(TAG, "Stopping DHCP server failed!");
|
||||
ESP_LOGW(TAG, "Stopping DHCP server failed!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!wifi_set_ip_info(SOFTAP_IF, &info)) {
|
||||
ESP_LOGV(TAG, "Setting SoftAP info failed!");
|
||||
ESP_LOGE(TAG, "Setting SoftAP info failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -735,17 +735,17 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
start_address += 99;
|
||||
lease.start_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease start: %s", start_address.str().c_str());
|
||||
start_address += 100;
|
||||
start_address += 10;
|
||||
lease.end_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.str().c_str());
|
||||
if (!wifi_softap_set_dhcps_lease(&lease)) {
|
||||
ESP_LOGV(TAG, "Setting SoftAP DHCP lease failed!");
|
||||
ESP_LOGE(TAG, "Setting SoftAP DHCP lease failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// lease time 1440 minutes (=24 hours)
|
||||
if (!wifi_softap_set_dhcps_lease_time(1440)) {
|
||||
ESP_LOGV(TAG, "Setting SoftAP DHCP lease time failed!");
|
||||
ESP_LOGE(TAG, "Setting SoftAP DHCP lease time failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -755,13 +755,13 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
uint8_t mode = 1;
|
||||
// bit0, 1 enables router information from ESP8266 SoftAP DHCP server.
|
||||
if (!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) {
|
||||
ESP_LOGV(TAG, "wifi_softap_set_dhcps_offer_option failed!");
|
||||
ESP_LOGE(TAG, "wifi_softap_set_dhcps_offer_option failed!");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!wifi_softap_dhcps_start()) {
|
||||
ESP_LOGV(TAG, "Starting SoftAP DHCPS failed!");
|
||||
ESP_LOGE(TAG, "Starting SoftAP DHCPS failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -823,15 +823,15 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
info.netmask = network::IPAddress(255, 255, 255, 0);
|
||||
}
|
||||
|
||||
err = esp_netif_dhcpc_stop(s_ap_netif);
|
||||
err = esp_netif_dhcps_stop(s_ap_netif);
|
||||
if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcpc_stop failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_stop failed: %s", esp_err_to_name(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
err = esp_netif_set_ip_info(s_ap_netif, &info);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_set_ip_info failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_set_ip_info failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -841,20 +841,20 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
|||
start_address += 99;
|
||||
lease.start_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease start: %s", start_address.str().c_str());
|
||||
start_address += 100;
|
||||
start_address += 10;
|
||||
lease.end_ip = start_address;
|
||||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.str().c_str());
|
||||
err = esp_netif_dhcps_option(s_ap_netif, ESP_NETIF_OP_SET, ESP_NETIF_REQUESTED_IP_ADDRESS, &lease, sizeof(lease));
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcps_option failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_option failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
err = esp_netif_dhcps_start(s_ap_netif);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_netif_dhcps_start failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_netif_dhcps_start failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -887,12 +887,12 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
|
|||
|
||||
esp_err_t err = esp_wifi_set_config(WIFI_IF_AP, &conf);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGV(TAG, "esp_wifi_set_config failed! %d", err);
|
||||
ESP_LOGE(TAG, "esp_wifi_set_config failed! %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->wifi_ap_ip_config_(ap.get_manual_ip())) {
|
||||
ESP_LOGV(TAG, "wifi_ap_ip_config_ failed!");
|
||||
ESP_LOGE(TAG, "wifi_ap_ip_config_ failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue