@@ -122,16 +122,11 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
122122
123123 wifi_config_t conf_current;
124124 esp_wifi_get_config (WIFI_IF_AP, &conf_current);
125- if (softap_config_equal (conf, conf_current)) {
126- // DEBUGV("softap config unchanged");
127- return true ;
125+ if (!softap_config_equal (conf, conf_current) && esp_wifi_set_config (WIFI_IF_AP, &conf) != ESP_OK) {
126+ return false ;
128127 }
129128
130- bool ret;
131-
132- ret = esp_wifi_set_config (WIFI_IF_AP, &conf) == ESP_OK;
133-
134- return ret;
129+ return true ;
135130}
136131
137132
@@ -149,12 +144,25 @@ bool WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress
149144 return false ;
150145 }
151146
147+ esp_wifi_start ();
148+
152149 tcpip_adapter_ip_info_t info;
153150 info.ip .addr = static_cast <uint32_t >(local_ip);
154151 info.gw .addr = static_cast <uint32_t >(gateway);
155152 info.netmask .addr = static_cast <uint32_t >(subnet);
156153 tcpip_adapter_dhcps_stop (TCPIP_ADAPTER_IF_AP);
157154 if (tcpip_adapter_set_ip_info (TCPIP_ADAPTER_IF_AP, &info) == ESP_OK) {
155+ dhcps_lease_t lease;
156+ lease.enable = true ;
157+ lease.start_ip .addr = static_cast <uint32_t >(local_ip) + (1 << 24 );
158+ lease.end_ip .addr = static_cast <uint32_t >(local_ip) + (11 << 24 );
159+
160+ tcpip_adapter_dhcps_option (
161+ (tcpip_adapter_option_mode_t )TCPIP_ADAPTER_OP_SET,
162+ (tcpip_adapter_option_id_t )REQUESTED_IP_ADDRESS,
163+ (void *)&lease, sizeof (dhcps_lease_t )
164+ );
165+
158166 return tcpip_adapter_dhcps_start (TCPIP_ADAPTER_IF_AP) == ESP_OK;
159167 }
160168 return false ;
0 commit comments