@@ -14,9 +14,9 @@ extern flash_settings_t flashSettings;
14
14
15
15
// Internals
16
16
wifi_handle_t * wifiHandle = NULL ;
17
- uint32_t wifiTick = 0 ;
18
- uint32_t APFallbackTick = 0 ; // Tick set at init before falling in AP mode in case of unsuccessfull client mode
19
-
17
+ uint32_t wifiTick = WIFI_CHECK_PERIOD; // Init with its value to avoid an execution on the first run of wifi_main()
18
+ uint32_t APFallbackTick = 0 ; // Tick set at init before falling in AP mode in case of unsuccessfull client mode
19
+ bool isAPConfigToDo;
20
20
/* *
21
21
* We need some compiler tricks here
22
22
* See: https://pcbartists.com/firmware/esp32-firmware/designator-outside-aggregate-initializer-solved/
@@ -80,10 +80,16 @@ static void wifi_fallback_as_ap(void)
80
80
static int wifi_ap_init (void )
81
81
{
82
82
WiFi.mode (WIFI_AP);
83
+
83
84
WiFi.softAP (wifiHandle->ap .ssid , wifiHandle->ap .password , wifiHandle->ap .channel , wifiHandle->ap .isHidden , wifiHandle->ap .maxConnection );
85
+
84
86
/* * This line does magic, keep it here */
85
87
WiFi.persistent (false );
86
- WiFi.softAPConfig (wifiHandle->ap .ip , wifiHandle->ap .gateway , wifiHandle->ap .subnet );
88
+
89
+ // We have to wait at least 100ms after WiFi.softAP() before calling WiFi.softAPConfig()
90
+ // so we moved this call into the main function with the flag isAPConfigToDo
91
+ // More info : https://github.com/espressif/arduino-esp32/issues/985#issuecomment-359157428
92
+ isAPConfigToDo = true ;
87
93
return 0 ;
88
94
}
89
95
@@ -108,7 +114,7 @@ static int wifi_client_init(void)
108
114
*
109
115
* @return boolean
110
116
*/
111
- static bool wifi_is_handle_valid (wifi_handle_t * pWifiHandle, String &reason)
117
+ static bool wifi_is_handle_valid (wifi_handle_t * pWifiHandle, String & reason)
112
118
{
113
119
if (pWifiHandle->userMode >= MODE_MAX) {
114
120
reason = " Mauvais mode wifi" ;
@@ -159,13 +165,13 @@ wifi_handle_t * wifi_get_handle(void)
159
165
* @brief Use new settings for wifi module
160
166
* @details Store them in flash after validation check
161
167
*/
162
- int32_t wifi_use_new_settings (wifi_handle_t * pWifiHandle, String &reason)
168
+ int32_t wifi_use_new_settings (wifi_handle_t * pWifiHandle, String & reason)
163
169
{
164
170
if (wifi_is_handle_valid (pWifiHandle, reason)) {
165
171
// Copy new data to handle
166
172
memcpy (wifiHandle, pWifiHandle, sizeof (wifi_handle_t ));
167
173
wifiHandle->forcedMode = MODE_NONE;
168
- wifiHandle->mode = MODE_NONE;
174
+ wifiHandle->mode = MODE_NONE;
169
175
170
176
// Save handle to flash
171
177
return flash_write ();
@@ -211,7 +217,7 @@ int wifi_init(void)
211
217
ret = wifi_ap_init ();
212
218
213
219
// In AP, we are ready to print now
214
- wifi_print ();
220
+ // wifi_print();
215
221
} else if (wifiHandle->mode == MODE_CLIENT) {
216
222
ret = wifi_client_init ();
217
223
wifi_print ();
@@ -239,6 +245,13 @@ void wifi_main(void)
239
245
wifiTick = tick + WIFI_CHECK_PERIOD;
240
246
241
247
if (wifiHandle->mode == MODE_AP) {
248
+ // We have to wait a bit before calling WiFi.softAPConfig()
249
+ // so do it here 1 time after one WIFI_CHECK_PERIOD
250
+ if (isAPConfigToDo) {
251
+ isAPConfigToDo = false ;
252
+ WiFi.softAPConfig (wifiHandle->ap .ip , wifiHandle->ap .gateway , wifiHandle->ap .subnet );
253
+ }
254
+
242
255
if (WiFi.softAPgetStationNum () <= 0 ) {
243
256
_unset (STATUS_WIFI, STATUS_WIFI_DEVICE_CO);
244
257
} else {
0 commit comments