Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 1e24e51

Browse files
authored
Major Releases v1.4.0
### Major Releases v1.4.0 1. Fix staticIP not saved in examples. See [ESP32 static IP not saved after restarting the device](#19) 2. Add structures and functions to handle AP and STA IPs. 3. Add complex examples * [Async_ConfigOnDRD_FS_MQTT_Ptr_Complex](examples/Async_ConfigOnDRD_FS_MQTT_Ptr_Complex) to demo usage of std::map * [Async_ConfigOnDRD_FS_MQTT_Ptr_Medium](examples/Async_ConfigOnDRD_FS_MQTT_Ptr_Medium). 4. Add simple minimal examples * [Async_ConfigOnDRD_ESP32_minimal](examples/Async_ConfigOnDRD_ESP32_minimal) * [Async_ConfigOnDRD_ESP8266_minimal](examples/Async_ConfigOnDRD_ESP8266_minimal) * [Async_AutoConnect_ESP32_minimal](examples/Async_AutoConnect_ESP32_minimal) * [Async_AutoConnect_ESP8266_minimal](examples/Async_AutoConnect_ESP8266_minimal) 5. Modify Version String 6. Add Table of Contents
1 parent e32b0b7 commit 1e24e51

File tree

39 files changed

+6108
-1175
lines changed

39 files changed

+6108
-1175
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Visual Studio folder and files
35+
.vs

README.md

Lines changed: 528 additions & 109 deletions
Large diffs are not rendered by default.

examples/Async_AutoConnect/Async_AutoConnect.ino

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Built by Khoi Hoang https://github.com/khoih-prog/ESPAsync_WiFiManager
1515
Licensed under MIT license
16-
Version: 1.3.0
16+
Version: 1.4.0
1717
1818
Version Modified By Date Comments
1919
------- ----------- ---------- -----------
@@ -24,6 +24,7 @@
2424
1.1.2 K Hoang 17/09/2020 Fix bug in examples.
2525
1.2.0 K Hoang 15/10/2020 Restore cpp code besides Impl.h code to use if linker error. Fix bug.
2626
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.
2728
*****************************************************************************************************************************/
2829
#if !( defined(ESP8266) || defined(ESP32) )
2930
#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;
215216
IPAddress dns1IP = gatewayIP;
216217
IPAddress dns2IP = IPAddress(8, 8, 8, 8);
217218

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+
218223
#include <ESPAsync_WiFiManager.h> //https://github.com/khoih-prog/ESPAsync_WiFiManager
219224

220225
#define HTTP_PORT 80
221226

222227
AsyncWebServer webServer(HTTP_PORT);
223228
DNSServer dnsServer;
224229

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+
225297
uint8_t connectMultiWiFi()
226298
{
227299
#if ESP32
@@ -256,14 +328,10 @@ uint8_t connectMultiWiFi()
256328

257329
WiFi.mode(WIFI_STA);
258330

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+
//////
267335
#endif
268336

269337
int i = 0;
@@ -353,11 +421,26 @@ void loadConfigData()
353421
File file = FileFS.open(CONFIG_FILENAME, "r");
354422
LOGERROR(F("LoadWiFiCfgFile "));
355423

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+
356430
if (file)
357431
{
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+
359438
file.close();
360439
LOGERROR(F("OK"));
440+
441+
// New in v1.4.0
442+
displayIPConfigStruct(WM_STA_IPconfig);
443+
//////
361444
}
362445
else
363446
{
@@ -372,7 +455,12 @@ void saveConfigData()
372455

373456
if (file)
374457
{
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+
376464
file.close();
377465
LOGERROR(F("OK"));
378466
}
@@ -390,7 +478,7 @@ void setup()
390478

391479
Serial.print("\nStarting Async_AutoConnectAP using " + String(FS_Name));
392480
Serial.println(" on " + String(ARDUINO_BOARD));
393-
Serial.println("ESPAsync_WiFiManager Version " + String(ESP_ASYNC_WIFIMANAGER_VERSION));
481+
Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION);
394482

395483
if (FORMAT_FILESYSTEM)
396484
FileFS.format();
@@ -412,6 +500,11 @@ void setup()
412500

413501
unsigned long startedAt = millis();
414502

503+
// New in v1.4.0
504+
initAPIPConfigStruct(WM_AP_IPconfig);
505+
initSTAIPConfigStruct(WM_STA_IPconfig);
506+
//////
507+
415508
//Local intialization. Once its business is done, there is no need to keep it around
416509
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
417510
//ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer);
@@ -424,8 +517,10 @@ void setup()
424517
//ESPAsync_wifiManager.resetSettings();
425518

426519
//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+
429524
ESPAsync_wifiManager.setMinimumSignalQuality(-1);
430525

431526
// From v1.0.10 only
@@ -434,13 +529,10 @@ void setup()
434529
//////
435530

436531
#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+
//////
444536
#endif
445537

446538
// New from v1.1.1
@@ -514,6 +606,11 @@ void setup()
514606
}
515607
}
516608

609+
// New in v1.4.0
610+
ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig);
611+
displayIPConfigStruct(WM_STA_IPconfig);
612+
//////
613+
517614
saveConfigData();
518615
}
519616
else

0 commit comments

Comments
 (0)