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

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Dec 20, 2019
1 parent ce16312 commit 1dabc07
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 32 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This works with
See ["Installing Arduino libraries"](https://www.arduino.cc/en/Guide/Libraries) and use the Importing a .zip Library method or preferably use manual installation as you can checkout the release from github and use that. This makes it easier to keep current with updates. Installing using the Library Manager currently does not work with this version of the library.

#### Compatibility
Github version `1.0.1` currently works with :
Github version `1.0.2` currently works with :
1. release `2.6.2` or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)
2. release `1.0.4` or newer of the [ESP32 core for Arduino](https://github.com/espressif/arduino-esp32)

Expand Down Expand Up @@ -98,7 +98,7 @@ Also see examples:
2. [ConfigOnSwitchFS](examples/ConfigOnSwitchFS)
3. [ConfigOnStartup](examples/ConfigOnStartup)
4. [ConfigOnDoubleReset](examples/ConfigOnDoubleReset)
5. [ConfigPortalParamsOnSwitch](examples//ConfigPortalParamsOnSwitch) ***New to configure Portal Credentials***
5. [ConfigPortalParamsOnSwitch](examples/ConfigPortalParamsOnSwitch)

## Documentation

Expand Down Expand Up @@ -269,14 +269,17 @@ Sometimes, the library will only work if you update the `ESP32 / ESP8266` core t
If you connect to the created configuration Access Point but the configuration portal does not show up, just open a browser and type in the IP of the web portal, by default `192.168.4.1`.


## Releases
#### 1.0.1
## Releases 1.0.2

- Forked, modified, bug-fixed and improved from these versions of WiFiManager.

See [Tzapu's version](https://github.com/tzapu/WiFiManager) for previous release information.
See [KenTaylor's version]( https://github.com/kentaylor/WiFiManager) for previous release information.

#### New in v1.0.2

- Fix bug that keeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
- Add example ConfigPortalParamsOnSwitch to enable ConfigPortal credentials to be reconfigurable using ConfigPortal.

### Contributions and thanks
Forked from [Tzapu](https://github.com/tzapu/WiFiManager) and [KenTaylor's version]( https://github.com/kentaylor/WiFiManager)
Expand Down
46 changes: 33 additions & 13 deletions examples/ConfigPortalParamsOnSwitch/ConfigPortalParamsOnSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*
* Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
* Licensed under MIT license
* Version: 1.0.1
* Version: 1.0.2
*
* Version Modified By Date Comments
* ------- ----------- ---------- -----------
* 1.0.0 K Hoang 07/10/2019 Initial coding
* 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
* 1.0.2 K Hoang 19/12/2019 Fix bug that keeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
*****************************************************************************************************************************/
/****************************************************************************************************************************
* This example will open a configuration portal when a predetermined button is pressed
Expand Down Expand Up @@ -67,10 +68,11 @@
// Default Config Portal SID and Password
// SSID and PW for Config Portal

//String PortalSSID = "ESP_" + String(ESP_getChipId(), HEX);
String DefaultPortalSSID = "ESP_" + String(ESP_getChipId(), HEX);
char PortalSSID[SSID_MAX_LENGTH + 1] = "your_ssid";

//char* password = "your_password";
// Use in case PortalSSID or PortalPassword is invalid (NULL)
String DefaultPortalPassword = "My" + DefaultPortalSSID;
char PortalPassword[PASSWORD_MAX_LENGTH + 1] = "your_password";

#define PortalSSID_Label "PortalSSID"
Expand Down Expand Up @@ -284,10 +286,22 @@ void setup()

//it starts an access point
//and goes into a blocking loop awaiting configuration
if (!ESP_wifiManager.startConfigPortal((const char *) PortalSSID, PortalPassword))
Serial.println("Not connected to WiFi but continuing anyway.");
// If Invalid PortalSSID or PortalPassword => use default

bool resultConfigPortal;
if ( (PortalSSID[0] == 0) || (PortalPassword[0] == 0) )
{
resultConfigPortal = ESP_wifiManager.startConfigPortal((const char *) DefaultPortalSSID.c_str(), DefaultPortalPassword.c_str());
}
else
{
resultConfigPortal = ESP_wifiManager.startConfigPortal((const char *) PortalSSID, PortalPassword);
}

if (resultConfigPortal)
Serial.println("WiFi connected...yeey :)");
else
Serial.println("WiFi connected...yeey :)");
Serial.println("Not connected to WiFi but continuing anyway.");
}

digitalWrite(PIN_LED, LED_OFF); // Turn led off as we are not in configuration mode.
Expand Down Expand Up @@ -373,21 +387,27 @@ void loop()
// Sets timeout in seconds until configuration portal gets turned off.
// If not specified device will remain in configuration mode until
// switched off via webserver or device is restarted.
// ESP_wifiManager.setConfigPortalTimeout(600);
ESP_wifiManager.setConfigPortalTimeout(60);

// It starts an access point
// and goes into a blocking loop awaiting configuration.
// Once the user leaves the portal with the exit button
// processing will continue
if (!ESP_wifiManager.startConfigPortal((const char *) PortalSSID, PortalPassword))

static bool resultConfigPortal;
if ( (PortalSSID[0] == 0) || (PortalPassword[0] == 0) )
{
Serial.println("Not connected to WiFi but continuing anyway.");
}
else
resultConfigPortal = ESP_wifiManager.startConfigPortal((const char *) DefaultPortalSSID.c_str(), DefaultPortalPassword.c_str());
}
else
{
// If you get here you have connected to the WiFi
Serial.println("Connected...yeey :)");
resultConfigPortal = ESP_wifiManager.startConfigPortal((const char *) PortalSSID, PortalPassword);
}

if (resultConfigPortal)
Serial.println("WiFi connected...yeey :)");
else
Serial.println("Not connected to WiFi but continuing anyway.");

// Getting posted form values and overriding local variables parameters
// Config file is written regardless the connection state
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
},
"frameworks": "arduino",
"platforms": "espressif",
"version": "1.0.1"
"version": "1.0.2"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP_WiFiManager
version=1.0.1
version=1.0.2
author=Khoi Hoang
maintainer=Khoi Hoang <[email protected]>
license=MIT
Expand Down
18 changes: 13 additions & 5 deletions src/ESP_WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*
* Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
* Licensed under MIT license
* Version: 1.0.1
* Version: 1.0.2
*
* Version Modified By Date Comments
* ------- ----------- ---------- -----------
* 1.0.0 K Hoang 07/10/2019 Initial coding
* 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
* 1.0.2 K Hoang 19/12/2019 Fix bug that keeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
*****************************************************************************************************************************/

#include "ESP_WiFiManager.h"
Expand Down Expand Up @@ -413,6 +414,8 @@ boolean ESP_WiFiManager::startConfigPortal(char const *apName, char const *apPa
TimedOut = false;
delay(2000);

//DEBUG_WM(F("_configPortalTimeout ="));
//DEBUG_WM(_configPortalTimeout);
DEBUG_WM(F("Connecting to new AP"));

// using user-provided _ssid, _pass in place of system-stored ssid and pass
Expand Down Expand Up @@ -741,7 +744,7 @@ void ESP_WiFiManager::handleWifi()
DEBUG_WM(F("Handle WiFi"));

// Disable _configPortalTimeout when someone accessing Portal to give some time to config
_configPortalTimeout = 0; //KH
_configPortalTimeout = 0; //KH

server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server->sendHeader("Pragma", "no-cache");
Expand Down Expand Up @@ -958,6 +961,9 @@ void ESP_WiFiManager::handleWifiSave()
DEBUG_WM(F("Sent wifi save page"));

connect = true; //signal ready to connect/reset

// Restore when Press Save WiFi
_configPortalTimeout = DEFAULT_PORTAL_TIMEOUT;
}

/** Handle shut down the server page */
Expand Down Expand Up @@ -985,8 +991,10 @@ void ESP_WiFiManager::handleServerClose()
page += FPSTR(HTTP_END);
server->send(200, "text/html", page);
//stopConfigPortal = true; //signal ready to shutdown config portal //KH crash if use this ???
DEBUG_WM(F("Sent server close page"));
DEBUG_WM(F("Sent server close page"));

// Restore when Press Save WiFi
_configPortalTimeout = DEFAULT_PORTAL_TIMEOUT;
}

/** Handle the info page */
Expand All @@ -995,7 +1003,7 @@ void ESP_WiFiManager::handleInfo()
DEBUG_WM(F("Info"));

// Disable _configPortalTimeout when someone accessing Portal to give some time to config
_configPortalTimeout = 0; //KH
_configPortalTimeout = 0; //KH

//DEBUG_WM(F("Info"));
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Expand Down Expand Up @@ -1132,7 +1140,7 @@ void ESP_WiFiManager::handleScan()
DEBUG_WM(F("Scan"));

// Disable _configPortalTimeout when someone accessing Portal to give some time to config
_configPortalTimeout = 0; //KH
_configPortalTimeout = 0; //KH

DEBUG_WM(F("State - json"));
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Expand Down
20 changes: 12 additions & 8 deletions src/ESP_WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* ------- ----------- ---------- -----------
* 1.0.0 K Hoang 07/10/2019 Initial coding
* 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
* 1.0.2 K Hoang 19/12/2019 Fix bug thatkeeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
*****************************************************************************************************************************/

#ifndef ESP_WiFiManager_h
Expand Down Expand Up @@ -115,6 +116,7 @@ class ESP_WMParameter {
};

#define USE_DYNAMIC_PARAMS true
#define DEFAULT_PORTAL_TIMEOUT 60000L

class ESP_WiFiManager
{
Expand Down Expand Up @@ -226,13 +228,15 @@ class ESP_WiFiManager
void startWPS();
//const char* getStatus(int status);

const char* _apName = "no-net";
const char* _apPassword = NULL;
String _ssid = "";
String _pass = "";
unsigned long _configPortalTimeout = 0;
unsigned long _connectTimeout = 0;
unsigned long _configPortalStart = 0;
const char* _apName = "no-net";
const char* _apPassword = NULL;
String _ssid = "";
String _pass = "";

unsigned long _configPortalTimeout = 0;

unsigned long _connectTimeout = 0;
unsigned long _configPortalStart = 0;

int numberOfNetworks;
int *networkIndices;
Expand Down Expand Up @@ -278,7 +282,7 @@ class ESP_WiFiManager

boolean connect;
boolean stopConfigPortal = false;
boolean _debug = true;
boolean _debug = false; //true;

void (*_apcallback)(ESP_WiFiManager*) = NULL;
void (*_savecallback)(void) = NULL;
Expand Down

0 comments on commit 1dabc07

Please sign in to comment.