Added boundaryOffet

pull/8/head
Hieromon Ikasamo 7 years ago
parent 896f69c541
commit 77d5cb5dc6
  1. 2
      docs/advancedusage/index.html
  2. 53
      docs/api/index.html
  3. 2
      docs/examples/index.html
  4. 25
      docs/faq/index.html
  5. 33
      docs/search/search_index.json
  6. 16
      examples/Credential/Credential.ino
  7. 2
      mkdocs/advancedusage.md
  8. 27
      mkdocs/api.md
  9. 2
      mkdocs/examples.md
  10. 14
      mkdocs/faq.md
  11. 4
      src/AutoConnect.cpp
  12. 10
      src/AutoConnect.h
  13. 23
      src/AutoConnectCredential.cpp
  14. 2
      src/AutoConnectPage.cpp

@ -812,7 +812,7 @@
<p>EEPROM library uses one sector of flash located <a href="http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom">just after the SPIFFS</a>.</p> <p>EEPROM library uses one sector of flash located <a href="http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom">just after the SPIFFS</a>.</p>
</blockquote> </blockquote>
<p>So in the default state, the credential storage area used by AutoConnect conflicts with data area owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this.</p> <p>So in the default state, the credential storage area used by AutoConnect conflicts with data area owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this.</p>
<p>The <a href="../api/index.html#saveoffset"><strong>saveOffset</strong></a> in <a href="../api/index.html#autoconnectconfig-api"><strong>AutoConnectConfig</strong></a> specifies the start offset of the credentials storage area. The default value is 0.</p> <p>The <a href="../api/index.html#boundaryoffset"><strong>boundaryOffset</strong></a> in <a href="../api/index.html#autoconnectconfig-api"><strong>AutoConnectConfig</strong></a> specifies the start offset of the credentials storage area. The default value is 0.</p>
<h3 id="refers-the-hosted-esp8266webserver"><i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer<a class="headerlink" href="#refers-the-hosted-esp8266webserver" title="Permanent link">&para;</a></h3> <h3 id="refers-the-hosted-esp8266webserver"><i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer<a class="headerlink" href="#refers-the-hosted-esp8266webserver" title="Permanent link">&para;</a></h3>
<p>Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by <a href="../api/index.html#host"><em>AutoConnect::host()</em></a> function to access ESP8266WebServer instance as like below.</p> <p>Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by <a href="../api/index.html#host"><em>AutoConnect::host()</em></a> function to access ESP8266WebServer instance as like below.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span> <div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>

@ -606,6 +606,13 @@
autoSave autoSave
</a> </a>
</li>
<li class="md-nav__item">
<a href="#boundaryoffset" title="boundaryOffset" class="md-nav__link">
boundaryOffset
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -648,13 +655,6 @@
psk psk
</a> </a>
</li>
<li class="md-nav__item">
<a href="#saveoffset" title="saveOffset" class="md-nav__link">
saveOffset
</a>
</li> </li>
</ul> </ul>
@ -957,6 +957,13 @@
autoSave autoSave
</a> </a>
</li>
<li class="md-nav__item">
<a href="#boundaryoffset" title="boundaryOffset" class="md-nav__link">
boundaryOffset
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -999,13 +1006,6 @@
psk psk
</a> </a>
</li>
<li class="md-nav__item">
<a href="#saveoffset" title="saveOffset" class="md-nav__link">
saveOffset
</a>
</li> </li>
</ul> </ul>
@ -1235,7 +1235,7 @@ Register the handler function for undefined URL request detected.
<dt><strong>Type</strong></dt> <dt><strong>Type</strong></dt>
<dd>bool</dd> <dd>bool</dd>
<dt><strong>Value</strong></dt> <dt><strong>Value</strong></dt>
<dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is a default.</dd> <dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is the default.</dd>
<dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd> <dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd>
</dl></p> </dl></p>
<h4 id="autosave">autoSave<a class="headerlink" href="#autosave" title="Permanent link">&para;</a></h4> <h4 id="autosave">autoSave<a class="headerlink" href="#autosave" title="Permanent link">&para;</a></h4>
@ -1247,6 +1247,17 @@ Register the handler function for undefined URL request detected.
<dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_AUTO</span>The credential saved automatically.</dd> <dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_AUTO</span>The credential saved automatically.</dd>
<dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_NEVER</span>The credential no saved.</dd> <dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_NEVER</span>The credential no saved.</dd>
</dl></p> </dl></p>
<h4 id="boundaryoffset">boundaryOffset<a class="headerlink" href="#boundaryoffset" title="Permanent link">&para;</a></h4>
<p>Sets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)<br />
The default value is 0.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>uint16_t</dd>
</dl></p>
<div class="admonition warning">
<p class="admonition-title">It will conflict with user data.</p>
<p>If the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.</p>
</div>
<h4 id="channel">channel<a class="headerlink" href="#channel" title="Permanent link">&para;</a></h4> <h4 id="channel">channel<a class="headerlink" href="#channel" title="Permanent link">&para;</a></h4>
<p>The channel number of WIFi when SoftAP starts. <p>The channel number of WIFi when SoftAP starts.
<dl class="apidl"> <dl class="apidl">
@ -1292,17 +1303,6 @@ Register the handler function for undefined URL request detected.
<dt><strong>Type</strong></dt> <dt><strong>Type</strong></dt>
<dd>String</dd> <dd>String</dd>
</dl></p> </dl></p>
<h4 id="saveoffset">saveOffset<a class="headerlink" href="#saveoffset" title="Permanent link">&para;</a></h4>
<p>Sets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)<br />
The default value is 0.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>uint16_t</dd>
</dl></p>
<div class="admonition warning">
<p class="admonition-title">It will conflict with user data.</p>
<p>If the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.</p>
</div>
<h3 id="autoconnectconfig-example"><i class="fa fa-code"></i> AutoConnectConfig example<a class="headerlink" href="#autoconnectconfig-example" title="Permanent link">&para;</a></h3> <h3 id="autoconnectconfig-example"><i class="fa fa-code"></i> AutoConnectConfig example<a class="headerlink" href="#autoconnectconfig-example" title="Permanent link">&para;</a></h3>
<div class="codehilite"><pre><span></span><span class="n">AutoConenct</span> <span class="n">Portal</span><span class="p">;</span> <div class="codehilite"><pre><span></span><span class="n">AutoConenct</span> <span class="n">Portal</span><span class="p">;</span>
<span class="n">AutoConenctConfig</span> <span class="nf">Config</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="s">&quot;passpass&quot;</span><span class="p">);</span> <span class="c1">// SoftAp name is determined at runtime</span> <span class="n">AutoConenctConfig</span> <span class="nf">Config</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="s">&quot;passpass&quot;</span><span class="p">);</span> <span class="c1">// SoftAp name is determined at runtime</span>
@ -1311,6 +1311,7 @@ The default value is 0.
<span class="n">Config</span><span class="p">.</span><span class="n">gateway</span> <span class="o">=</span> <span class="nf">IPAddress</span><span class="p">(</span><span class="mi">192</span><span class="p">,</span><span class="mi">168</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span> <span class="c1">// Sets WLAN router IP address</span> <span class="n">Config</span><span class="p">.</span><span class="n">gateway</span> <span class="o">=</span> <span class="nf">IPAddress</span><span class="p">(</span><span class="mi">192</span><span class="p">,</span><span class="mi">168</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span> <span class="c1">// Sets WLAN router IP address</span>
<span class="n">Config</span><span class="p">.</span><span class="n">netmask</span> <span class="o">=</span> <span class="nf">IPAddress</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span> <span class="c1">// Sets WLAN scope</span> <span class="n">Config</span><span class="p">.</span><span class="n">netmask</span> <span class="o">=</span> <span class="nf">IPAddress</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span> <span class="c1">// Sets WLAN scope</span>
<span class="n">Config</span><span class="p">.</span><span class="n">autoSave</span> <span class="o">=</span> <span class="n">AC_SAVECREDENTIAL_NEVER</span><span class="p">;</span> <span class="c1">// No save credential</span> <span class="n">Config</span><span class="p">.</span><span class="n">autoSave</span> <span class="o">=</span> <span class="n">AC_SAVECREDENTIAL_NEVER</span><span class="p">;</span> <span class="c1">// No save credential</span>
<span class="n">COnfig</span><span class="p">.</span><span class="n">boundaryOffet</span> <span class="o">=</span> <span class="mi">64</span><span class="p">;</span> <span class="c1">// Reserve 64 bytes for the user data in EEPROM. </span>
<span class="n">Config</span><span class="p">.</span><span class="n">homeUri</span> <span class="o">=</span> <span class="s">&quot;/index.html&quot;</span> <span class="c1">// Sets home path of the sketch application</span> <span class="n">Config</span><span class="p">.</span><span class="n">homeUri</span> <span class="o">=</span> <span class="s">&quot;/index.html&quot;</span> <span class="c1">// Sets home path of the sketch application</span>
<span class="n">Portal</span><span class="p">.</span><span class="nf">config</span><span class="p">(</span><span class="n">Config</span><span class="p">);</span> <span class="c1">// Configure AutoConnect</span> <span class="n">Portal</span><span class="p">.</span><span class="nf">config</span><span class="p">(</span><span class="n">Config</span><span class="p">);</span> <span class="c1">// Configure AutoConnect</span>
<span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span> <span class="c1">// Starts and behaves captive portal</span> <span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span> <span class="c1">// Starts and behaves captive portal</span>

@ -565,7 +565,7 @@
<p>Here holds two case examples. Both examples perform the same function. Only how to incorporate the <strong>AutoConnect</strong> into the sketch differs. Also included in the sample folder, HandlePortal.ino also shows how to use the <a href="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library for HTML assemblies.</p> <p>Here holds two case examples. Both examples perform the same function. Only how to incorporate the <strong>AutoConnect</strong> into the sketch differs. Also included in the sample folder, HandlePortal.ino also shows how to use the <a href="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library for HTML assemblies.</p>
<h2 id="what-does-this-example-do">What does this example do?<a class="headerlink" href="#what-does-this-example-do" title="Permanent link">&para;</a></h2> <h2 id="what-does-this-example-do">What does this example do?<a class="headerlink" href="#what-does-this-example-do" title="Permanent link">&para;</a></h2>
<p>Uses the web interface to light the LED connected to the <strong><a href="https://github.com/nodemcu/nodemcu-devkit-v1.0">NodeMCU</a></strong> module D0 port (which could be referred to as <em>BUILTIN_LED</em>), the following animation is it.</p> <p>Uses the web interface to light the LED connected to the <strong><a href="https://github.com/nodemcu/nodemcu-devkit-v1.0">NodeMCU</a></strong> module D0 port (which could be referred to as <em>BUILTIN_LED</em>), the following animation is it.</p>
<p>Access to the ESP8266 module connected WiFi from the browser then the page contains the current value of the D0 port would be displayed. The page has the buttons to switch the port value. The LED blinks according to the value of the button that was clicked. This example is a typical sketch of manipulating ESP8266's GPIO via WLN.</p> <p>Access to the ESP8266 module connected WiFi from the browser then the page contains the current value of the D0 port would be displayed. The page has the buttons to switch the port value. The LED blinks according to the value of the button that was clicked. This example is a typical sketch of manipulating ESP8266's GPIO via WLAN.</p>
<p><img data-gifffer="../images/ac2.gif" /></p> <p><img data-gifffer="../images/ac2.gif" /></p>
<p>Embed AutoConnect library into this sketch. There are few places to be changed. And you can use AutoConnect's captive portal function to establish a connection freely to other WiFi spots.</p> <p>Embed AutoConnect library into this sketch. There are few places to be changed. And you can use AutoConnect's captive portal function to establish a connection freely to other WiFi spots.</p>
<h2 id="embed-autoconnect">Embed AutoConnect<a class="headerlink" href="#embed-autoconnect" title="Permanent link">&para;</a></h2> <h2 id="embed-autoconnect">Embed AutoConnect<a class="headerlink" href="#embed-autoconnect" title="Permanent link">&para;</a></h2>

@ -469,6 +469,13 @@
<nav class="md-nav"> <nav class="md-nav">
<ul class="md-nav__list"> <ul class="md-nav__list">
<li class="md-nav__item">
<a href="#include-header" title="Include header" class="md-nav__link">
Include header
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#constructor" title="Constructor" class="md-nav__link"> <a href="#constructor" title="Constructor" class="md-nav__link">
Constructor Constructor
@ -627,6 +634,13 @@
<nav class="md-nav"> <nav class="md-nav">
<ul class="md-nav__list"> <ul class="md-nav__list">
<li class="md-nav__item">
<a href="#include-header" title="Include header" class="md-nav__link">
Include header
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#constructor" title="Constructor" class="md-nav__link"> <a href="#constructor" title="Constructor" class="md-nav__link">
Constructor Constructor
@ -758,12 +772,19 @@ wdt reset
<h2 id="how-erase-the-credentials-saved-in-eeprom"><i class="fa fa-question-circle"></i> How erase the credentials saved in EEPROM?<a class="headerlink" href="#how-erase-the-credentials-saved-in-eeprom" title="Permanent link">&para;</a></h2> <h2 id="how-erase-the-credentials-saved-in-eeprom"><i class="fa fa-question-circle"></i> How erase the credentials saved in EEPROM?<a class="headerlink" href="#how-erase-the-credentials-saved-in-eeprom" title="Permanent link">&para;</a></h2>
<p>Make some sketches for erasing the EEPROM area, or some erasing utility is needed. You can prepare the sketch to erase the saved credential with <em>AutoConnectCredential</em>. The <em>AutoConnectCrendential</em> class provides the access method to the saved credential in EEPROM and library source file is including it.</p> <p>Make some sketches for erasing the EEPROM area, or some erasing utility is needed. You can prepare the sketch to erase the saved credential with <em>AutoConnectCredential</em>. The <em>AutoConnectCrendential</em> class provides the access method to the saved credential in EEPROM and library source file is including it.</p>
<p>A class description of AutoConnectCredential is follows.</p> <p>A class description of AutoConnectCredential is follows.</p>
<h3 id="constructor">Constructor<a class="headerlink" href="#constructor" title="Permanent link">&para;</a></h3> <h3 id="include-header">Include header<a class="headerlink" href="#include-header" title="Permanent link">&para;</a></h3>
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;AutoConnectCredential.h&gt;</span><span class="cp"></span> <div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;AutoConnectCredential.h&gt;</span><span class="cp"></span>
</pre></div>
<h3 id="constructor">Constructor<a class="headerlink" href="#constructor" title="Permanent link">&para;</a></h3>
<div class="codehilite"><pre><span></span><span class="n">AutoConnectCredential</span><span class="p">();</span>
</pre></div>
<span class="n">AutoConnectCredential</span><span class="p">();</span> <p>AutoConnectCredential default constructor. The default offset value is 0. If the offset value is 0, the credential storage area starts from the top of the EEPROM. AutoConnect sometimes overwrites data when using this area with user sketch.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnectCredential</span><span class="p">(</span><span class="kt">uint16_t</span> <span class="n">offset</span><span class="p">);</span>
</pre></div> </pre></div>
<p>Specify offset from the top of the EEPROM for the credential storage area together. The offset value is from 0 to the flash sector size.</p>
<h3 id="public-member-functions">Public member functions<a class="headerlink" href="#public-member-functions" title="Permanent link">&para;</a></h3> <h3 id="public-member-functions">Public member functions<a class="headerlink" href="#public-member-functions" title="Permanent link">&para;</a></h3>
<ul> <ul>
<li> <li>

File diff suppressed because one or more lines are too long

@ -23,6 +23,10 @@ AutoConnect Portal(Server);
String viewCredential(PageArgument&); String viewCredential(PageArgument&);
String delCredential(PageArgument&); String delCredential(PageArgument&);
// Specified the offset if the user data exists.
//#define CREDENTIAL_OFFSET 0
#define CREDENTIAL_OFFSET 64
/** /**
* An HTML for the operation page. * An HTML for the operation page.
* In PageBuilder, the token {{SSID}} contained in an HTML template below is * In PageBuilder, the token {{SSID}} contained in an HTML template below is
@ -81,7 +85,7 @@ PageBuilder delPage("/del", { elmDel });
// Retrieve the credential entries from EEPROM, Build the SSID line // Retrieve the credential entries from EEPROM, Build the SSID line
// with the <li> tag. // with the <li> tag.
String viewCredential(PageArgument& args) { String viewCredential(PageArgument& args) {
AutoConnectCredential ac; AutoConnectCredential ac(CREDENTIAL_OFFSET);
struct station_config entry; struct station_config entry;
String content = ""; String content = "";
uint8_t count = ac.entries(); // Get number of entries. uint8_t count = ac.entries(); // Get number of entries.
@ -99,14 +103,14 @@ String viewCredential(PageArgument& args) {
// Delete a credential entry, the entry to be deleted is passed in the // Delete a credential entry, the entry to be deleted is passed in the
// request parameter 'num'. // request parameter 'num'.
String delCredential(PageArgument& args) { String delCredential(PageArgument& args) {
AutoConnectCredential ac; AutoConnectCredential ac(CREDENTIAL_OFFSET);
if (args.hasArg("num")) { if (args.hasArg("num")) {
int8_t e = args.arg("num").toInt(); int8_t e = args.arg("num").toInt();
if (e > 0) { if (e > 0) {
struct station_config entry; struct station_config entry;
// If the input number is valid, delete that entry. // If the input number is valid, delete that entry.
int8_t de = ac.load(e, &entry); int8_t de = ac.load(e - 1, &entry); // A base of entry num is 0.
if (de > 0) { if (de > 0) {
ac.del((char *)entry.ssid); ac.del((char *)entry.ssid);
@ -134,6 +138,12 @@ void setup() {
rootPage.insert(Server); // Instead of Server.on("/", ...); rootPage.insert(Server); // Instead of Server.on("/", ...);
delPage.insert(Server); // Instead of Server.on("/del", ...); delPage.insert(Server); // Instead of Server.on("/del", ...);
// Set an address of the credential area.
AutoConnectConfig Config;
Config.boundaryOffset = CREDENTIAL_OFFSET;
Portal.config(Config);
// Start
if (Portal.begin()) { if (Portal.begin()) {
Serial.println("WiFi connected: " + WiFi.localIP().toString()); Serial.println("WiFi connected: " + WiFi.localIP().toString());
} }

@ -114,7 +114,7 @@ and
So in the default state, the credential storage area used by AutoConnect conflicts with data area owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this. So in the default state, the credential storage area used by AutoConnect conflicts with data area owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this.
The [**saveOffset**](api.md#saveoffset) in [**AutoConnectConfig**](api.md#autoconnectconfig-api) specifies the start offset of the credentials storage area. The default value is 0. The [**boundaryOffset**](api.md#boundaryoffset) in [**AutoConnectConfig**](api.md#autoconnectconfig-api) specifies the start offset of the credentials storage area. The default value is 0.
### <i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer ### <i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer

@ -243,7 +243,7 @@ Captive portal activation switch. False for disabling the captive portal. It pre
<dt>**Type**</dt> <dt>**Type**</dt>
<dd>bool</dd> <dd>bool</dd>
<dt>**Value**</dt> <dt>**Value**</dt>
<dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is a default.</dd> <dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is the default.</dd>
<dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd> <dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd>
</dl> </dl>
@ -258,6 +258,18 @@ The credential saved automatically at the connection establishment.
<dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_NEVER</span>The credential no saved.</dd> <dd><span class="apidef" style="width:230px;">AC_SAVECREDENTIAL_NEVER</span>The credential no saved.</dd>
</dl> </dl>
#### boundaryOffset
Sets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)
The default value is 0.
<dl class="apidl">
<dt>**Type**</dt>
<dd>uint16_t</dd>
</dl>
!!! warning "It will conflict with user data."
If the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.
#### channel #### channel
The channel number of WIFi when SoftAP starts. The channel number of WIFi when SoftAP starts.
@ -314,18 +326,6 @@ Sets password for SoftAP. The length should be from 8 to up to 63. The default v
<dd>String</dd> <dd>String</dd>
</dl> </dl>
#### saveOffset
Sets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)
The default value is 0.
<dl class="apidl">
<dt>**Type**</dt>
<dd>uint16_t</dd>
</dl>
!!! warning "It will conflict with user data."
If the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.
### <i class="fa fa-code"></i> AutoConnectConfig example ### <i class="fa fa-code"></i> AutoConnectConfig example
```arduino ```arduino
@ -336,6 +336,7 @@ Config.apip = IPAddress(192,168,10,101); // Sets SoftAP IP address
Config.gateway = IPAddress(192,168,10,1); // Sets WLAN router IP address Config.gateway = IPAddress(192,168,10,1); // Sets WLAN router IP address
Config.netmask = IPAddress(255,255,255,0); // Sets WLAN scope Config.netmask = IPAddress(255,255,255,0); // Sets WLAN scope
Config.autoSave = AC_SAVECREDENTIAL_NEVER; // No save credential Config.autoSave = AC_SAVECREDENTIAL_NEVER; // No save credential
COnfig.boundaryOffet = 64; // Reserve 64 bytes for the user data in EEPROM.
Config.homeUri = "/index.html" // Sets home path of the sketch application Config.homeUri = "/index.html" // Sets home path of the sketch application
Portal.config(Config); // Configure AutoConnect Portal.config(Config); // Configure AutoConnect
Portal.begin(); // Starts and behaves captive portal Portal.begin(); // Starts and behaves captive portal

@ -6,7 +6,7 @@ Here holds two case examples. Both examples perform the same function. Only how
Uses the web interface to light the LED connected to the **[NodeMCU](https://github.com/nodemcu/nodemcu-devkit-v1.0)** module D0 port (which could be referred to as *BUILTIN_LED*), the following animation is it. Uses the web interface to light the LED connected to the **[NodeMCU](https://github.com/nodemcu/nodemcu-devkit-v1.0)** module D0 port (which could be referred to as *BUILTIN_LED*), the following animation is it.
Access to the ESP8266 module connected WiFi from the browser then the page contains the current value of the D0 port would be displayed. The page has the buttons to switch the port value. The LED blinks according to the value of the button that was clicked. This example is a typical sketch of manipulating ESP8266's GPIO via WLN. Access to the ESP8266 module connected WiFi from the browser then the page contains the current value of the D0 port would be displayed. The page has the buttons to switch the port value. The LED blinks according to the value of the button that was clicked. This example is a typical sketch of manipulating ESP8266's GPIO via WLAN.
<img data-gifffer="../images/ac2.gif" /> <img data-gifffer="../images/ac2.gif" />

@ -68,14 +68,26 @@ Make some sketches for erasing the EEPROM area, or some erasing utility is neede
A class description of AutoConnectCredential is follows. A class description of AutoConnectCredential is follows.
### Constructor ### Include header
```cpp ```cpp
#include <AutoConnectCredential.h> #include <AutoConnectCredential.h>
```
### Constructor
```cpp
AutoConnectCredential(); AutoConnectCredential();
``` ```
AutoConnectCredential default constructor. The default offset value is 0. If the offset value is 0, the credential storage area starts from the top of the EEPROM. AutoConnect sometimes overwrites data when using this area with user sketch.
```cpp
AutoConnectCredential(uint16_t offset);
```
Specify offset from the top of the EEPROM for the credential storage area together. The offset value is from 0 to the flash sector size.
### Public member functions ### Public member functions
- uint8_t **entries()** - uint8_t **entries()**

@ -298,7 +298,7 @@ void AutoConnect::handleRequest() {
// Save current credential // Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) { if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.saveOffset); AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential); credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid); AC_DBG("%s credential saved\n", _credential.ssid);
} }
@ -443,7 +443,7 @@ String AutoConnect::_induceConnect(PageArgument& args) {
// Retrieve credential from the post method content. // Retrieve credential from the post method content.
if (args.hasArg(AUTOCONNECT_PARAMID_CRED)) { if (args.hasArg(AUTOCONNECT_PARAMID_CRED)) {
// Read from EEPROM // Read from EEPROM
AutoConnectCredential credential(_apConfig.saveOffset); AutoConnectCredential credential(_apConfig.boundaryOffset);
struct station_config entry; struct station_config entry;
AC_DBG("Load credential:%s\n", args.arg(AUTOCONNECT_PARAMID_CRED).c_str()); AC_DBG("Load credential:%s\n", args.arg(AUTOCONNECT_PARAMID_CRED).c_str());
credential.load(args.arg(AUTOCONNECT_PARAMID_CRED).c_str(), &entry); credential.load(args.arg(AUTOCONNECT_PARAMID_CRED).c_str(), &entry);

@ -25,7 +25,7 @@ extern "C" {
#include "AutoConnectCredential.h" #include "AutoConnectCredential.h"
// Uncomment the following AC_DEBUG to enable debug output. // Uncomment the following AC_DEBUG to enable debug output.
#define AC_DEBUG //#define AC_DEBUG
// Debug output destination can be defined externally with AC_DEBUG_PORT // Debug output destination can be defined externally with AC_DEBUG_PORT
#ifndef AC_DEBUG_PORT #ifndef AC_DEBUG_PORT
@ -115,7 +115,7 @@ class AutoConnectConfig {
channel(1), channel(1),
hidden(0), hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO), autoSave(AC_SAVECREDENTIAL_AUTO),
saveOffset(AC_IDENTIFIER_OFFSET), boundaryOffset(AC_IDENTIFIER_OFFSET),
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true), autoRise(true),
autoReset(true), autoReset(true),
@ -132,7 +132,7 @@ class AutoConnectConfig {
channel(1), channel(1),
hidden(0), hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO), autoSave(AC_SAVECREDENTIAL_AUTO),
saveOffset(AC_IDENTIFIER_OFFSET), boundaryOffset(AC_IDENTIFIER_OFFSET),
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true), autoRise(true),
autoReset(true), autoReset(true),
@ -149,7 +149,7 @@ class AutoConnectConfig {
channel = o.channel; channel = o.channel;
hidden = o.hidden; hidden = o.hidden;
autoSave = o.autoSave; autoSave = o.autoSave;
saveOffset = o.saveOffset; boundaryOffset = o.boundaryOffset;
uptime = o.uptime; uptime = o.uptime;
autoRise = o.autoRise; autoRise = o.autoRise;
autoReset = o.autoReset; autoReset = o.autoReset;
@ -165,7 +165,7 @@ class AutoConnectConfig {
uint8_t channel; /**< SoftAP used wifi channel */ uint8_t channel; /**< SoftAP used wifi channel */
uint8_t hidden; /**< SoftAP SSID hidden */ uint8_t hidden; /**< SoftAP SSID hidden */
AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */ AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */
uint16_t saveOffset; /**< The save storage offset of EEPROM */ uint16_t boundaryOffset; /**< The save storage offset of EEPROM */
int uptime; /**< Length of start up time */ int uptime; /**< Length of start up time */
bool autoRise; /**< Automatic starting the captive portal */ bool autoRise; /**< Automatic starting the captive portal */
bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */ bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */

@ -52,13 +52,14 @@ void AutoConnectCredential::_allocateEntry() {
// Validate the save area of the EEPROM. // Validate the save area of the EEPROM.
// If it is a valid area, retrieve the stored number of entries, // If it is a valid area, retrieve the stored number of entries,
// if the identifier is not saved, initialize the EEPROM area. // if the identifier is not saved, initialize the EEPROM area.
for (c = _offset; c < _offset + sizeof(id_c); c++) { _dp = _offset;
id_c[c] = static_cast<char>(EEPROM.read(c)); for (c = 0; c < sizeof(id_c); c++) {
id_c[c] = static_cast<char>(EEPROM.read(_dp++));
} }
if (!strncmp(id_c, AC_IDENTIFIER, sizeof(id_c))) { if (!strncmp(id_c, AC_IDENTIFIER, sizeof(id_c))) {
_entries = EEPROM.read(static_cast<int>(c++)); _entries = EEPROM.read(static_cast<int>(_dp++));
_containSize = EEPROM.read(static_cast<int>(c++)); _containSize = EEPROM.read(static_cast<int>(_dp++));
_containSize += EEPROM.read(static_cast<int>(c)) << 8; _containSize += EEPROM.read(static_cast<int>(_dp)) << 8;
} }
else { else {
_entries = 0; _entries = 0;
@ -106,7 +107,7 @@ bool AutoConnectCredential::del(const char* ssid) {
// End 0xff writing, update headers. // End 0xff writing, update headers.
_entries--; _entries--;
EEPROM.write(static_cast<int>(sizeof(AC_IDENTIFIER)) - 1, _entries); EEPROM.write(_offset + static_cast<int>(sizeof(AC_IDENTIFIER)) - 1, _entries);
// commit it. // commit it.
rc = EEPROM.commit(); rc = EEPROM.commit();
@ -203,9 +204,9 @@ bool AutoConnectCredential::save(const struct station_config* config) {
// Same entry not found. increase the entry. // Same entry not found. increase the entry.
_entries++; _entries++;
int i; int i;
for (i = AC_IDENTIFIER_OFFSET; i < static_cast<int>(sizeof(_id)) - 1; i++) for (i = 0; i < static_cast<int>(sizeof(_id)) - 1; i++)
EEPROM.write(i, (uint8_t)_id[i]); EEPROM.write(i + _offset, (uint8_t)_id[i]);
EEPROM.write(i, _entries); EEPROM.write(i + _offset, _entries);
} }
// Seek insertion point, evaluate capacity to insert the new entry. // Seek insertion point, evaluate capacity to insert the new entry.
@ -245,8 +246,8 @@ bool AutoConnectCredential::save(const struct station_config* config) {
// Update container size // Update container size
_containSize = _dp - AC_HEADERSIZE; _containSize = _dp - AC_HEADERSIZE;
EEPROM.write(sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize); EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize);
EEPROM.write(sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8)); EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8));
} }
bool rc = EEPROM.commit(); bool rc = EEPROM.commit();

@ -899,7 +899,7 @@ String AutoConnect::_token_HIDDEN_COUNT(PageArgument& args) {
} }
String AutoConnect::_token_OPEN_SSID(PageArgument& args) { String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
AutoConnectCredential credit; AutoConnectCredential credit(_apConfig.boundaryOffset);
struct station_config entry; struct station_config entry;
String ssidList = ""; String ssidList = "";

Loading…
Cancel
Save