Merge pull request #129 from Hieromon/patches/v102

Patches/v102
pull/131/head
Hieromon Ikasamo 5 years ago committed by GitHub
commit b23032cb28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      README.md
  2. 24
      docs/changelog.html
  3. 46
      docs/faq.html
  4. 2
      docs/search/search_index.json
  5. 59
      docs/sitemap.xml
  6. BIN
      docs/sitemap.xml.gz
  7. 2
      library.json
  8. 2
      library.properties
  9. 5
      mkdocs/changelog.md
  10. 23
      mkdocs/faq.md
  11. 38
      src/AutoConnect.cpp
  12. 6
      src/AutoConnectCredential.cpp
  13. 30
      src/AutoConnectCredential.h
  14. 9
      src/AutoConnectPage.cpp

@ -101,6 +101,11 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some
## Change log
### [1.0.2] Sept. 17, 2019
- Fixed SSID non termination. (issue #128)
- Fixed compilation error that getBytesLength missing with ESP32. (issue #125)
- Added #include directive restriction for EEPROM and ESP8266httpUpdate to FAQ. (issue #127)
### [1.0.1] Sept. 13, 2019
- Added a sketch for ESP32 boards that migrates credentials stored in EEPROM partition to the Preferences.

@ -122,7 +122,7 @@
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
<a href="#101-sept-13-2019" tabindex="1" class="md-skip">
<a href="#102-sept-17-2019" tabindex="1" class="md-skip">
Skip to content
</a>
@ -725,6 +725,13 @@
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#102-sept-17-2019" title="[1.0.2] Sept. 17, 2019" class="md-nav__link">
[1.0.2] Sept. 17, 2019
</a>
</li>
<li class="md-nav__item">
<a href="#101-sept-13-2019" title="[1.0.1] Sept. 13, 2019" class="md-nav__link">
[1.0.1] Sept. 13, 2019
@ -864,6 +871,13 @@
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#102-sept-17-2019" title="[1.0.2] Sept. 17, 2019" class="md-nav__link">
[1.0.2] Sept. 17, 2019
</a>
</li>
<li class="md-nav__item">
<a href="#101-sept-13-2019" title="[1.0.1] Sept. 13, 2019" class="md-nav__link">
[1.0.1] Sept. 13, 2019
@ -981,7 +995,13 @@
<h1>Change log</h1>
<h4 id="101-sept-13-2019">[1.0.1] Sept. 13, 2019<a class="headerlink" href="#101-sept-13-2019" title="Permanent link">&para;</a></h4>
<h4 id="102-sept-17-2019">[1.0.2] Sept. 17, 2019<a class="headerlink" href="#102-sept-17-2019" title="Permanent link">&para;</a></h4>
<ul>
<li>Fixed SSID non termination.</li>
<li>Fixed compilation error that getBytesLength missing with ESP32.</li>
<li>Added #include directive restriction for EEPROM and ESP8266httpUpdate to FAQ.</li>
</ul>
<h4 id="101-sept-13-2019">[1.0.1] Sept. 13, 2019<a class="headerlink" href="#101-sept-13-2019" title="Permanent link">&para;</a></h4>
<ul>
<li>Added a sketch for ESP32 boards that migrates credentials stored in EEPROM partition to the Preferences.</li>
</ul>

@ -732,6 +732,20 @@
An esp8266ap as SoftAP was connected but Captive portal does not start.
</a>
</li>
<li class="md-nav__item">
<a href="#compile-error-that-eeprom-was-not-declared-in-this-scope" title=" Compile error that 'EEPROM' was not declared in this scope" class="md-nav__link">
Compile error that 'EEPROM' was not declared in this scope
</a>
</li>
<li class="md-nav__item">
<a href="#compile-error-that-esphttpupdate-was-not-declared-in-this-scope" title=" Compile error that 'ESPhttpUpdate' was not declared in this scope" class="md-nav__link">
Compile error that 'ESPhttpUpdate' was not declared in this scope
</a>
</li>
<li class="md-nav__item">
@ -985,6 +999,20 @@
An esp8266ap as SoftAP was connected but Captive portal does not start.
</a>
</li>
<li class="md-nav__item">
<a href="#compile-error-that-eeprom-was-not-declared-in-this-scope" title=" Compile error that 'EEPROM' was not declared in this scope" class="md-nav__link">
Compile error that 'EEPROM' was not declared in this scope
</a>
</li>
<li class="md-nav__item">
<a href="#compile-error-that-esphttpupdate-was-not-declared-in-this-scope" title=" Compile error that 'ESPhttpUpdate' was not declared in this scope" class="md-nav__link">
Compile error that 'ESPhttpUpdate' was not declared in this scope
</a>
</li>
<li class="md-nav__item">
@ -1198,6 +1226,24 @@ For AutoConnect menus to work properly, call <a href="api.html#handlerequest"><e
</div>
<h2 id="an-esp8266ap-as-softap-was-connected-but-captive-portal-does-not-start"><i class="fa fa-question-circle"></i> An esp8266ap as SoftAP was connected but Captive portal does not start.<a class="headerlink" href="#an-esp8266ap-as-softap-was-connected-but-captive-portal-does-not-start" title="Permanent link">&para;</a></h2>
<p>Captive portal detection could not be trapped. It is necessary to disconnect and reset ESP8266 to clear memorized connection data in ESP8266. Also, It may be displayed on the smartphone if the connection information of esp8266ap is wrong. In that case, delete the connection information of esp8266ap memorized by the smartphone once.</p>
<h2 id="compile-error-that-eeprom-was-not-declared-in-this-scope"><i class="fa fa-question-circle"></i> Compile error that 'EEPROM' was not declared in this scope<a class="headerlink" href="#compile-error-that-eeprom-was-not-declared-in-this-scope" title="Permanent link">&para;</a></h2>
<p>If the user sketch includes the header file as <code>EEPROM.h</code>, this compilation error may occur depending on the order of the <code>#include</code> directives. <code>AutoConnectCredentials.h</code> including in succession linked from <code>AutoConnect.h</code> defines <strong>NO_GLOBAL_EEPROM</strong> internally, so if your sketch includes <code>EEPROM.h</code> after <code>AutoConnect.h</code>, the <strong>EEPROM</strong> global variable will be lost.</p>
<p>If you use EEPROM with your sketch, declare <code>#include &lt;EEPROM.h&gt;</code> in front of <code>#include &lt;AutoConnect.h&gt;</code>.</p>
<h2 id="compile-error-that-esphttpupdate-was-not-declared-in-this-scope"><i class="fa fa-question-circle"></i> Compile error that 'ESPhttpUpdate' was not declared in this scope<a class="headerlink" href="#compile-error-that-esphttpupdate-was-not-declared-in-this-scope" title="Permanent link">&para;</a></h2>
<p>If the user sketch includes the header file as <code>ESP8266httpUpdate.h</code>, this compilation error may occur depending on the order of the <code>#include</code> directives. <code>AutoConnectUpdate.h</code> including in succession linked from <code>AutoConnect.h</code> defines <strong>NO_GLOBAL_HTTPUPDATE</strong> internally, so if your sketch includes <code>ESP8266httpUpdate.h</code> after <code>AutoConnect.h</code>, the <strong>ESPhttpUpdate</strong> global variable will be lost.</p>
<p>You can avoid a compile error in one of two ways:</p>
<ol>
<li>
<p>Disable an AutoConnectUpdate feature if you don't need.</p>
<p>You can disable the AutoConnectUpdate feature by commenting out the <strong>AUTOCONNECT_USE_UPDATE</strong> macro in the <code>AutoConnectDefs.h</code> header file.
<div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #75715e">#define AUTOCONNECT_USE_UPDATE</span>
</pre></div></p>
</li>
<li>
<p>Change the order of <code>#include</code> directives.</p>
<p>With the sketch, <code>#include &lt;ESP8266httpUpdate.h&gt;</code> before <code>#include &lt;AutoConnect.h&gt;</code>.</p>
</li>
</ol>
<h2 id="connection-lost-immediately-after-establishment-with-ap"><i class="fa fa-question-circle"></i> Connection lost immediately after establishment with AP<a class="headerlink" href="#connection-lost-immediately-after-establishment-with-ap" title="Permanent link">&para;</a></h2>
<p>A captive portal is disconnected immediately after the connection establishes with the new AP. This is a known problem of ESP32, and it may occur when the following conditions are satisfied at the same time.</p>
<ul>

File diff suppressed because one or more lines are too long

@ -2,146 +2,147 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://Hieromon.github.io/AutoConnect/index.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/gettingstarted.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/menu.html</loc>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/basicusage.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/advancedusage.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/acintro.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/acelements.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/acjson.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/achandling.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/otaupdate.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/otabrowser.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/otaserver.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/api.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/apiaux.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/apiconfig.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/apielements.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/apiupdate.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/apiextra.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/howtoembed.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/datatips.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/menuize.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/wojson.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/lsbegin.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/credit.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/acupload.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/colorized.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/faq.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/changelog.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://Hieromon.github.io/AutoConnect/license.html</loc>
<lastmod>2019-09-13</lastmod>
<lastmod>2019-09-17</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
</urlset>

Binary file not shown.

@ -25,6 +25,6 @@
"espressif8266",
"espressif32"
],
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT"
}

@ -1,5 +1,5 @@
name=AutoConnect
version=1.0.1
version=1.0.2
author=Hieromon Ikasamo <hieromon@gmail.com>
maintainer=Hieromon Ikasamo <hieromon@gmail.com>
sentence=ESP8266/ESP32 WLAN configuration at runtime with web interface.

@ -1,3 +1,8 @@
#### [1.0.2] Sept. 17, 2019
- Fixed SSID non termination.
- Fixed compilation error that getBytesLength missing with ESP32.
- Added #include directive restriction for EEPROM and ESP8266httpUpdate to FAQ.
#### [1.0.1] Sept. 13, 2019
- Added a sketch for ESP32 boards that migrates credentials stored in EEPROM partition to the Preferences.

@ -18,6 +18,29 @@ You can migrate the past saved credentials using [**CreditMigrate.ino**](https:/
Captive portal detection could not be trapped. It is necessary to disconnect and reset ESP8266 to clear memorized connection data in ESP8266. Also, It may be displayed on the smartphone if the connection information of esp8266ap is wrong. In that case, delete the connection information of esp8266ap memorized by the smartphone once.
## <i class="fa fa-question-circle"></i> Compile error that 'EEPROM' was not declared in this scope
If the user sketch includes the header file as `EEPROM.h`, this compilation error may occur depending on the order of the `#include` directives. `AutoConnectCredentials.h` including in succession linked from `AutoConnect.h` defines **NO_GLOBAL_EEPROM** internally, so if your sketch includes `EEPROM.h` after `AutoConnect.h`, the **EEPROM** global variable will be lost.
If you use EEPROM with your sketch, declare `#include <EEPROM.h>` in front of `#include <AutoConnect.h>`.
## <i class="fa fa-question-circle"></i> Compile error that 'ESPhttpUpdate' was not declared in this scope
If the user sketch includes the header file as `ESP8266httpUpdate.h`, this compilation error may occur depending on the order of the `#include` directives. `AutoConnectUpdate.h` including in succession linked from `AutoConnect.h` defines **NO_GLOBAL_HTTPUPDATE** internally, so if your sketch includes `ESP8266httpUpdate.h` after `AutoConnect.h`, the **ESPhttpUpdate** global variable will be lost.
You can avoid a compile error in one of two ways:
1. Disable an AutoConnectUpdate feature if you don't need.
You can disable the AutoConnectUpdate feature by commenting out the **AUTOCONNECT_USE_UPDATE** macro in the `AutoConnectDefs.h` header file.
```cpp
#define AUTOCONNECT_USE_UPDATE
```
2. Change the order of `#include` directives.
With the sketch, `#include <ESP8266httpUpdate.h>` before `#include <AutoConnect.h>`.
## <i class="fa fa-question-circle"></i> Connection lost immediately after establishment with AP
A captive portal is disconnected immediately after the connection establishes with the new AP. This is a known problem of ESP32, and it may occur when the following conditions are satisfied at the same time.

@ -2,8 +2,8 @@
* AutoConnect class implementation.
* @file AutoConnect.cpp
* @author hieromon@gmail.com
* @version 1.0.0
* @date 2019-08-15
* @version 1.0.6
* @date 2019-09-17
* @copyright MIT license.
*/
@ -152,10 +152,16 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
// Load a valid credential.
if (_loadAvailCredential()) {
// Try to reconnect with a stored credential.
AC_DBG("autoReconnect loaded SSID:%s\n", reinterpret_cast<const char*>(_credential.ssid));
const char* psk = strlen(reinterpret_cast<const char*>(_credential.password)) ? reinterpret_cast<const char*>(_credential.password) : nullptr;
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), psk);
AC_DBG("WiFi.begin(%s%s%s)\n", _credential.ssid, psk == nullptr ? "" : ",", psk == nullptr ? "" : psk);
char ssid_c[sizeof(station_config::ssid) + 1];
char password_c[sizeof(station_config::password) + 1];
*ssid_c = '\0';
strncat(ssid_c, reinterpret_cast<const char*>(_credential.ssid), sizeof(ssid_c) - 1);
*password_c = '\0';
strncat(password_c, reinterpret_cast<const char*>(_credential.password), sizeof(password_c) - 1);
AC_DBG("autoReconnect loaded SSID:%s\n", ssid_c);
const char* psk = strlen(password_c) ? password_c : nullptr;
WiFi.begin(ssid_c, psk);
AC_DBG("WiFi.begin(%s%s%s)\n", ssid_c, psk == nullptr ? "" : ",", psk == nullptr ? "" : psk);
cs = _waitForConnect(_connectTimeout) == WL_CONNECTED;
}
}
@ -465,8 +471,14 @@ void AutoConnect::handleRequest(void) {
// An attempt to establish a new AP.
int32_t ch = _connectCh == 0 ? _apConfig.channel : _connectCh;
AC_DBG("Attempt:%s Ch(%d)\n", reinterpret_cast<const char*>(_credential.ssid), (int)ch);
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), ch);
char ssid_c[sizeof(station_config::ssid) + 1];
char password_c[sizeof(station_config::password) + 1];
*ssid_c = '\0';
strncat(ssid_c, reinterpret_cast<const char*>(_credential.ssid), sizeof(ssid_c) - 1);
*password_c = '\0';
strncat(password_c, reinterpret_cast<const char*>(_credential.password), sizeof(password_c) - 1);
AC_DBG("Attempt:%s Ch(%d)\n", ssid_c, (int)ch);
WiFi.begin(ssid_c, password_c, ch);
if (_waitForConnect(_connectTimeout) == WL_CONNECTED) {
if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
@ -477,16 +489,16 @@ void AutoConnect::handleRequest(void) {
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset);
if (credit.save(&_credential))
AC_DBG("%s credential saved\n", reinterpret_cast<const char*>(_credential.ssid));
AC_DBG("%*s credential saved\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
else
AC_DBG("credential %s save failed\n", reinterpret_cast<const char*>(_credential.ssid));
AC_DBG("credential %*s save failed\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
}
// Ensures that keeps a connection with the current AP while the portal behaves.
_setReconnect(AC_RECONNECT_SET);
}
else
AC_DBG("%s has no BSSID, saving is unavailable\n", reinterpret_cast<const char*>(_credential.ssid));
AC_DBG("%*s has no BSSID, saving is unavailable\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
// Activate AutoConnectUpdate if it is attached and incorporate
// it into the AutoConnect menu.
@ -730,7 +742,7 @@ String AutoConnect::_induceConnect(PageArgument& args) {
credential.load(args.arg(String(F(AUTOCONNECT_PARAMID_CRED))).c_str(), &entry);
strncpy(reinterpret_cast<char*>(_credential.ssid), reinterpret_cast<const char*>(entry.ssid), sizeof(_credential.ssid));
strncpy(reinterpret_cast<char*>(_credential.password), reinterpret_cast<const char*>(entry.password), sizeof(_credential.password));
AC_DBG("Credential loaded:%s\n", _credential.ssid);
AC_DBG("Credential loaded:%*s\n", sizeof(station_config::ssid), _credential.ssid);
}
else {
AC_DBG("Queried SSID:%s\n", args.arg(AUTOCONNECT_PARAMID_SSID).c_str());
@ -743,7 +755,7 @@ String AutoConnect::_induceConnect(PageArgument& args) {
_connectCh = 0;
for (uint8_t nn = 0; nn < _scanCount; nn++) {
String ssid = WiFi.SSID(nn);
if (!strcmp(ssid.c_str(), reinterpret_cast<const char*>(_credential.ssid))) {
if (!strncmp(ssid.c_str(), reinterpret_cast<const char*>(_credential.ssid), sizeof(station_config::ssid))) {
_connectCh = WiFi.channel(nn);
break;
}

@ -2,8 +2,8 @@
* AutoConnectCredential class dispatcher.
* @file AutoConnectCredential.cpp
* @author hieromon@gmail.com
* @version 1.0.0
* @date 2019-08-15
* @version 1.0.2
* @date 2019-09-16
* @copyright MIT license.
*/
@ -520,7 +520,7 @@ bool AutoConnectCredential::_del(const char* ssid, const bool commit) {
uint8_t AutoConnectCredential::_import(void) {
uint8_t cn = 0;
if (_pref->begin(AC_CREDENTIAL_NVSNAME, true)) {
size_t psz = _pref->getBytesLength(AC_CREDENTIAL_NVSKEY);
size_t psz = _getPrefBytesLength<Preferences>(_pref.get(), AC_CREDENTIAL_NVSKEY);
if (psz) {
uint8_t* credtPool = (uint8_t*)malloc(psz);
if (credtPool) {

@ -2,8 +2,8 @@
* Declaration of AutoConnectCredential class.
* @file AutoConnectCredential.h
* @author hieromon@gmail.com
* @version 1.0.0
* @date 2019-08-15
* @version 1.0.2
* @date 2019-09-16
* @copyright MIT license.
*/
@ -40,6 +40,7 @@ uint8_t bssid[6];
wifi_fast_scan_threshold_t threshold;
};
#endif
#include "AutoConnectDefs.h"
/**
* Credential storage area offset specifier in EEPROM.
@ -105,12 +106,19 @@ class AutoConnectCredential : public AutoConnectCredentialBase {
#else
// #pragma message "AutoConnectCredential applies the Preferences"
#include <type_traits>
#include <map>
#include <Preferences.h>
#include <nvs.h>
#define AC_CREDENTIAL_NVSNAME AC_IDENTIFIER
#define AC_CREDENTIAL_NVSKEY AC_CREDENTIAL_NVSNAME
/** Declare the member function existence determination */
namespace AutoConnectUtil {
AC_HAS_FUNC(getBytesLength);
}
/** AutoConnectCredential class using Preferences for ESP32 */
class AutoConnectCredential : public AutoConnectCredentialBase {
public:
@ -138,6 +146,24 @@ class AutoConnectCredential : public AutoConnectCredentialBase {
bool _del(const char* ssid, const bool commit); /**< Deletes an entry */
uint8_t _import(void); /**< Import from the nvs */
void _obtain(AC_CREDT_t::iterator const& it, station_config_t* config); /**< Obtain an entry from iterator */
template<typename T>
typename std::enable_if<AutoConnectUtil::has_func_getBytesLength<T>::value, size_t>::type _getPrefBytesLength(T* pref, const char* key) {
return pref->getBytesLength(key);
}
template<typename T>
typename std::enable_if<!AutoConnectUtil::has_func_getBytesLength<T>::value, size_t>::type _getPrefBytesLength(T* pref, const char* key) {
AC_UNUSED(pref);
uint32_t handle;
size_t len;
esp_err_t err = nvs_open(AC_CREDENTIAL_NVSNAME, NVS_READONLY, &handle);
if (err)
len = 0;
else {
(void)nvs_get_blob(handle, key, NULL, &len);
nvs_close(handle);
}
return len;
}
AC_CREDT_t _credit; /**< Dictionary to maintain the credentials */
std::unique_ptr<Preferences> _pref; /**< Preferences class instance to access the nvs */

@ -2,8 +2,8 @@
* AutoConnect portal site web page implementation.
* @file AutoConnectPage.h
* @author hieromon@gmail.com
* @version 1.0.0
* @date 2019-08-15
* @version 1.0.2
* @date 2019-09-17
* @copyright MIT license.
*/
@ -1240,7 +1240,10 @@ String AutoConnect::_token_BOOTURI(PageArgument& args) {
String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
AC_UNUSED(args);
String ssid = reinterpret_cast<char*>(_credential.ssid);
char ssid_c[sizeof(station_config::ssid) + 1];
*ssid_c = '\0';
strncat(ssid_c, reinterpret_cast<char*>(_credential.ssid), sizeof(ssid_c) - 1);
String ssid = String(ssid_c);
return ssid;
}

Loading…
Cancel
Save