13
13
14
14
Built by Khoi Hoang https://github.com/khoih-prog/ESPAsync_WiFiManager
15
15
Licensed under MIT license
16
- Version: 1.3 .0
16
+ Version: 1.4 .0
17
17
18
18
Version Modified By Date Comments
19
19
------- ----------- ---------- -----------
24
24
1.1.2 K Hoang 17/09/2020 Fix bug in examples.
25
25
1.2.0 K Hoang 15/10/2020 Restore cpp code besides Impl.h code to use if linker error. Fix bug.
26
26
1.3.0 K Hoang 04/12/2020 Add LittleFS support to ESP32 using LITTLEFS Library
27
+ 1.4.0 K Hoang 18/12/2020 Fix staticIP not saved. Add functions. Add complex examples.
27
28
*****************************************************************************************************************************/
28
29
#if !( defined(ESP8266) || defined(ESP32) )
29
30
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
@@ -215,13 +216,84 @@ bool initialConfig = false;
215
216
IPAddress dns1IP = gatewayIP;
216
217
IPAddress dns2IP = IPAddress(8 , 8 , 8 , 8 );
217
218
219
+ IPAddress APStaticIP = IPAddress(192 , 168 , 100 , 1 );
220
+ IPAddress APStaticGW = IPAddress(192 , 168 , 100 , 1 );
221
+ IPAddress APStaticSN = IPAddress(255 , 255 , 255 , 0 );
222
+
218
223
#include < ESPAsync_WiFiManager.h> // https://github.com/khoih-prog/ESPAsync_WiFiManager
219
224
220
225
#define HTTP_PORT 80
221
226
222
227
AsyncWebServer webServer (HTTP_PORT);
223
228
DNSServer dnsServer;
224
229
230
+ // /////////////////////////////////////////
231
+ // New in v1.4.0
232
+ /* *****************************************
233
+ * // Defined in ESPAsync_WiFiManager.h
234
+ typedef struct
235
+ {
236
+ IPAddress _ap_static_ip;
237
+ IPAddress _ap_static_gw;
238
+ IPAddress _ap_static_sn;
239
+
240
+ } WiFi_AP_IPConfig;
241
+
242
+ typedef struct
243
+ {
244
+ IPAddress _sta_static_ip;
245
+ IPAddress _sta_static_gw;
246
+ IPAddress _sta_static_sn;
247
+ #if USE_CONFIGURABLE_DNS
248
+ IPAddress _sta_static_dns1;
249
+ IPAddress _sta_static_dns2;
250
+ #endif
251
+ } WiFi_STA_IPConfig;
252
+ ******************************************/
253
+
254
+ WiFi_AP_IPConfig WM_AP_IPconfig;
255
+ WiFi_STA_IPConfig WM_STA_IPconfig;
256
+
257
+ void initAPIPConfigStruct (WiFi_AP_IPConfig &in_WM_AP_IPconfig)
258
+ {
259
+ in_WM_AP_IPconfig._ap_static_ip = APStaticIP;
260
+ in_WM_AP_IPconfig._ap_static_gw = APStaticGW;
261
+ in_WM_AP_IPconfig._ap_static_sn = APStaticSN;
262
+ }
263
+
264
+ void initSTAIPConfigStruct (WiFi_STA_IPConfig &in_WM_STA_IPconfig)
265
+ {
266
+ in_WM_STA_IPconfig._sta_static_ip = stationIP;
267
+ in_WM_STA_IPconfig._sta_static_gw = gatewayIP;
268
+ in_WM_STA_IPconfig._sta_static_sn = netMask;
269
+ #if USE_CONFIGURABLE_DNS
270
+ in_WM_STA_IPconfig._sta_static_dns1 = dns1IP;
271
+ in_WM_STA_IPconfig._sta_static_dns2 = dns2IP;
272
+ #endif
273
+ }
274
+
275
+ void displayIPConfigStruct (WiFi_STA_IPConfig in_WM_STA_IPconfig)
276
+ {
277
+ LOGERROR3 (F (" stationIP =" ), in_WM_STA_IPconfig._sta_static_ip , " , gatewayIP =" , in_WM_STA_IPconfig._sta_static_gw );
278
+ LOGERROR1 (F (" netMask =" ), in_WM_STA_IPconfig._sta_static_sn );
279
+ #if USE_CONFIGURABLE_DNS
280
+ LOGERROR3 (F (" dns1IP =" ), in_WM_STA_IPconfig._sta_static_dns1 , " , dns2IP =" , in_WM_STA_IPconfig._sta_static_dns2 );
281
+ #endif
282
+ }
283
+
284
+ void configWiFi (WiFi_STA_IPConfig in_WM_STA_IPconfig)
285
+ {
286
+ #if USE_CONFIGURABLE_DNS
287
+ // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
288
+ WiFi.config (in_WM_STA_IPconfig._sta_static_ip , in_WM_STA_IPconfig._sta_static_gw , in_WM_STA_IPconfig._sta_static_sn , in_WM_STA_IPconfig._sta_static_dns1 , in_WM_STA_IPconfig._sta_static_dns2 );
289
+ #else
290
+ // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
291
+ WiFi.config (in_WM_STA_IPconfig._sta_static_ip , in_WM_STA_IPconfig._sta_static_gw , in_WM_STA_IPconfig._sta_static_sn );
292
+ #endif
293
+ }
294
+
295
+ // /////////////////////////////////////////
296
+
225
297
uint8_t connectMultiWiFi ()
226
298
{
227
299
#if ESP32
@@ -256,14 +328,10 @@ uint8_t connectMultiWiFi()
256
328
257
329
WiFi.mode (WIFI_STA);
258
330
259
- #if !USE_DHCP_IP
260
- #if USE_CONFIGURABLE_DNS
261
- // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
262
- WiFi.config (stationIP, gatewayIP, netMask, dns1IP, dns2IP);
263
- #else
264
- // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
265
- WiFi.config (stationIP, gatewayIP, netMask);
266
- #endif
331
+ #if !USE_DHCP_IP
332
+ // New in v1.4.0
333
+ configWiFi (WM_STA_IPconfig);
334
+ // ////
267
335
#endif
268
336
269
337
int i = 0 ;
@@ -353,11 +421,26 @@ void loadConfigData()
353
421
File file = FileFS.open (CONFIG_FILENAME, " r" );
354
422
LOGERROR (F (" LoadWiFiCfgFile " ));
355
423
424
+ memset (&WM_config, sizeof (WM_config), 0 );
425
+
426
+ // New in v1.4.0
427
+ memset (&WM_STA_IPconfig, sizeof (WM_STA_IPconfig), 0 );
428
+ // ////
429
+
356
430
if (file)
357
431
{
358
- file.readBytes ((char *) &WM_config, sizeof (WM_config));
432
+ file.readBytes ((char *) &WM_config, sizeof (WM_config));
433
+
434
+ // New in v1.4.0
435
+ file.readBytes ((char *) &WM_STA_IPconfig, sizeof (WM_STA_IPconfig));
436
+ // ////
437
+
359
438
file.close ();
360
439
LOGERROR (F (" OK" ));
440
+
441
+ // New in v1.4.0
442
+ displayIPConfigStruct (WM_STA_IPconfig);
443
+ // ////
361
444
}
362
445
else
363
446
{
@@ -372,7 +455,12 @@ void saveConfigData()
372
455
373
456
if (file)
374
457
{
375
- file.write ((uint8_t *) &WM_config, sizeof (WM_config));
458
+ file.write ((uint8_t *) &WM_config, sizeof (WM_config));
459
+
460
+ // New in v1.4.0
461
+ file.write ((uint8_t *) &WM_STA_IPconfig, sizeof (WM_STA_IPconfig));
462
+ // ////
463
+
376
464
file.close ();
377
465
LOGERROR (F (" OK" ));
378
466
}
@@ -390,7 +478,7 @@ void setup()
390
478
391
479
Serial.print (" \n Starting Async_AutoConnectAP using " + String (FS_Name));
392
480
Serial.println (" on " + String (ARDUINO_BOARD));
393
- Serial.println (" ESPAsync_WiFiManager Version " + String ( ESP_ASYNC_WIFIMANAGER_VERSION) );
481
+ Serial.println (ESP_ASYNC_WIFIMANAGER_VERSION);
394
482
395
483
if (FORMAT_FILESYSTEM)
396
484
FileFS.format ();
@@ -412,6 +500,11 @@ void setup()
412
500
413
501
unsigned long startedAt = millis ();
414
502
503
+ // New in v1.4.0
504
+ initAPIPConfigStruct (WM_AP_IPconfig);
505
+ initSTAIPConfigStruct (WM_STA_IPconfig);
506
+ // ////
507
+
415
508
// Local intialization. Once its business is done, there is no need to keep it around
416
509
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
417
510
// ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer);
@@ -424,8 +517,10 @@ void setup()
424
517
// ESPAsync_wifiManager.resetSettings();
425
518
426
519
// set custom ip for portal
427
- ESPAsync_wifiManager.setAPStaticIPConfig (IPAddress (192 , 168 , 100 , 1 ), IPAddress (192 , 168 , 100 , 1 ), IPAddress (255 , 255 , 255 , 0 ));
428
-
520
+ // New in v1.4.0
521
+ ESPAsync_wifiManager.setAPStaticIPConfig (WM_AP_IPconfig);
522
+ // ////
523
+
429
524
ESPAsync_wifiManager.setMinimumSignalQuality (-1 );
430
525
431
526
// From v1.0.10 only
@@ -434,13 +529,10 @@ void setup()
434
529
// ////
435
530
436
531
#if !USE_DHCP_IP
437
- #if USE_CONFIGURABLE_DNS
438
- // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
439
- ESPAsync_wifiManager.setSTAStaticIPConfig (stationIP, gatewayIP, netMask, dns1IP, dns2IP);
440
- #else
441
- // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
442
- ESPAsync_wifiManager.setSTAStaticIPConfig (stationIP, gatewayIP, netMask);
443
- #endif
532
+ // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5
533
+ // New in v1.4.0
534
+ ESPAsync_wifiManager.setSTAStaticIPConfig (WM_STA_IPconfig);
535
+ // ////
444
536
#endif
445
537
446
538
// New from v1.1.1
@@ -514,6 +606,11 @@ void setup()
514
606
}
515
607
}
516
608
609
+ // New in v1.4.0
610
+ ESPAsync_wifiManager.getSTAStaticIPConfig (WM_STA_IPconfig);
611
+ displayIPConfigStruct (WM_STA_IPconfig);
612
+ // ////
613
+
517
614
saveConfigData ();
518
615
}
519
616
else
0 commit comments