Release for the static IP support

pull/8/head
Hieromon Ikasamo 7 years ago
parent f276768f0b
commit e40b37579d
  1. 40
      docs/advancedusage/index.html
  2. 104
      docs/api/index.html
  3. 20
      docs/changelog/index.html
  4. 23
      mkdocs/advancedusage.md
  5. 44
      mkdocs/api.md
  6. 4
      mkdocs/changelog.md
  7. 21
      src/AutoConnect.cpp
  8. 28
      src/AutoConnect.h

@ -462,6 +462,13 @@
Relocate the AutoConnect home path Relocate the AutoConnect home path
</a> </a>
</li>
<li class="md-nav__item">
<a href="#static-ip-assignment" title=" Static IP assignment" class="md-nav__link">
Static IP assignment
</a>
</li> </li>
</ul> </ul>
@ -668,6 +675,13 @@
Relocate the AutoConnect home path Relocate the AutoConnect home path
</a> </a>
</li>
<li class="md-nav__item">
<a href="#static-ip-assignment" title=" Static IP assignment" class="md-nav__link">
Static IP assignment
</a>
</li> </li>
</ul> </ul>
@ -701,7 +715,7 @@
<p>By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the <a href="../api/index.html#autosave"><strong>autoSave</strong></a> parameter specified by <a href="../api/index.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a>.</p> <p>By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the <a href="../api/index.html#autosave"><strong>autoSave</strong></a> parameter specified by <a href="../api/index.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a>.</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>
<span class="n">AutoConnectConfig</span> <span class="n">Config</span><span class="p">;</span> <span class="n">AutoConnectConfig</span> <span class="n">Config</span><span class="p">;</span>
<span class="hll"><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="hll"><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="n">f</span>
</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><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="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span> <span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div> </pre></div>
@ -849,7 +863,7 @@
<p><img src="../images/PageBuilder.png" style="width:640px;"/></p> <p><img src="../images/PageBuilder.png" style="width:640px;"/></p>
<h2 id="configuration-functions">Configuration functions<a class="headerlink" href="#configuration-functions" title="Permanent link">&para;</a></h2> <h2 id="configuration-functions">Configuration functions<a class="headerlink" href="#configuration-functions" title="Permanent link">&para;</a></h2>
<h3 id="configuration-for-soft-ap"><i class="fa fa-caret-right"></i> Configuration for Soft AP<a class="headerlink" href="#configuration-for-soft-ap" title="Permanent link">&para;</a></h3> <h3 id="configuration-for-soft-ap"><i class="fa fa-caret-right"></i> Configuration for Soft AP<a class="headerlink" href="#configuration-for-soft-ap" title="Permanent link">&para;</a></h3>
<p>AutoConnect will activate SoftAP at failed initial WiFi.Begin. It SoftAP settings are stored in <a href="../api/index.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a> as the following parameters. The sketch could be configured SoftAP using these parameters, refer the <a href="../api/index.html#autoconnectconfig-api">AutoConnectConfig API</a> for details.</p> <p>AutoConnect will activate SoftAP at failed the first <em>WiFi.begin</em>. It SoftAP settings are stored in <a href="../api/index.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a> as the following parameters. The sketch could be configured SoftAP using these parameters, refer the <a href="../api/index.html#autoconnectconfig-api">AutoConnectConfig API</a> for details.</p>
<ul> <ul>
<li>IP address of SoftAP activated.</li> <li>IP address of SoftAP activated.</li>
<li>Gateway IP address.</li> <li>Gateway IP address.</li>
@ -877,6 +891,28 @@
<div class="codehilite"><pre><span></span><span class="cp">#define AUTOCONNECT_URI &quot;/_ac&quot;</span> <div class="codehilite"><pre><span></span><span class="cp">#define AUTOCONNECT_URI &quot;/_ac&quot;</span>
</pre></div> </pre></div>
<h3 id="static-ip-assignment"><i class="fa fa-caret-right"></i> Static IP assignment<a class="headerlink" href="#static-ip-assignment" title="Permanent link">&para;</a></h3>
<p>It is also possible to assign static IP Address to ESP8266 in STA mode. By default DHCP is enabled and it becomes the IP address assigned by the DHCP server with <em>WiFi.begin</em>.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup></p>
<p>To assign a static IP Address, specify it in the <a href="../api/index.html#staip">AutoConnectConfig parameter</a>. In the case of assigning a static IP Address, specify the gateway, subnet mask, and DNS server is needed.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">portal</span><span class="p">;</span>
<span class="n">AutoConnectConfig</span> <span class="n">Config</span><span class="p">;</span>
<span class="n">Config</span><span class="p">.</span><span class="n">staip</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">1</span><span class="p">,</span><span class="mi">10</span><span class="p">);</span>
<span class="n">Config</span><span class="p">.</span><span class="n">staGateway</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">1</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">Config</span><span class="p">.</span><span class="n">staNetmask</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="n">Config</span><span class="p">.</span><span class="n">dns1</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">1</span><span class="p">,</span><span class="mi">1</span><span class="p">);</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="n">portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div>
<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p>Static IP address assignment is available from version 0.9.3.&#160;<a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
</ol>
</div>

@ -589,6 +589,20 @@
channel channel
</a> </a>
</li>
<li class="md-nav__item">
<a href="#dns1" title="dns1" class="md-nav__link">
dns1
</a>
</li>
<li class="md-nav__item">
<a href="#dns2" title="dns2" class="md-nav__link">
dns2
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -624,6 +638,27 @@
psk psk
</a> </a>
</li>
<li class="md-nav__item">
<a href="#staip" title="staip" class="md-nav__link">
staip
</a>
</li>
<li class="md-nav__item">
<a href="#stagateway" title="staGateway" class="md-nav__link">
staGateway
</a>
</li>
<li class="md-nav__item">
<a href="#stanetmask" title="staNetmask" class="md-nav__link">
staNetmask
</a>
</li> </li>
</ul> </ul>
@ -952,6 +987,20 @@
channel channel
</a> </a>
</li>
<li class="md-nav__item">
<a href="#dns1" title="dns1" class="md-nav__link">
dns1
</a>
</li>
<li class="md-nav__item">
<a href="#dns2" title="dns2" class="md-nav__link">
dns2
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -987,6 +1036,27 @@
psk psk
</a> </a>
</li>
<li class="md-nav__item">
<a href="#staip" title="staip" class="md-nav__link">
staip
</a>
</li>
<li class="md-nav__item">
<a href="#stagateway" title="staGateway" class="md-nav__link">
staGateway
</a>
</li>
<li class="md-nav__item">
<a href="#stanetmask" title="staNetmask" class="md-nav__link">
staNetmask
</a>
</li> </li>
</ul> </ul>
@ -1252,6 +1322,18 @@ The default value is 0.
<p class="admonition-title">How do I choose Channel</p> <p class="admonition-title">How do I choose Channel</p>
<p>Espressif Systems had announced the <a href="https://www.espressif.com/sites/default/files/esp8266_wi-fi_channel_selection_guidelines.pdf">application note</a> about Wi-Fi channel selection.</p> <p>Espressif Systems had announced the <a href="https://www.espressif.com/sites/default/files/esp8266_wi-fi_channel_selection_guidelines.pdf">application note</a> about Wi-Fi channel selection.</p>
</div> </div>
<h4 id="dns1">dns1<a class="headerlink" href="#dns1" title="Permanent link">&para;</a></h4>
<p>Set primary DNS server address when using static IP address.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>IPAddress</dd>
</dl></p>
<h4 id="dns2">dns2<a class="headerlink" href="#dns2" title="Permanent link">&para;</a></h4>
<p>Set secondary DNS server address when using static IP address.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>IPAddress</dd>
</dl></p>
<h4 id="gateway">gateway<a class="headerlink" href="#gateway" title="Permanent link">&para;</a></h4> <h4 id="gateway">gateway<a class="headerlink" href="#gateway" title="Permanent link">&para;</a></h4>
<p>Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this. <p>Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
<dl class="apidl"> <dl class="apidl">
@ -1285,6 +1367,24 @@ The default value is 0.
<dt><strong>Type</strong></dt> <dt><strong>Type</strong></dt>
<dd>String</dd> <dd>String</dd>
</dl></p> </dl></p>
<h4 id="staip">staip<a class="headerlink" href="#staip" title="Permanent link">&para;</a></h4>
<p>Set a static IP address. The IP will behave with STA mode.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>IPAddress</dd>
</dl></p>
<h4 id="stagateway">staGateway<a class="headerlink" href="#stagateway" title="Permanent link">&para;</a></h4>
<p>Set the gateway address when using static IP address.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>IPAddress</dd>
</dl></p>
<h4 id="stanetmask">staNetmask<a class="headerlink" href="#stanetmask" title="Permanent link">&para;</a></h4>
<p>Set the subnetmask when using static IP address.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>IPAddress</dd>
</dl></p>
<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>
@ -1295,6 +1395,10 @@ The default value is 0.
<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">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">Config</span><span class="p">.</span><span class="n">staip</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">10</span><span class="p">);</span> <span class="c1">// Sets static IP</span>
<span class="n">Config</span><span class="p">.</span><span class="n">staGateway</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 WiFi router address</span>
<span class="n">Config</span><span class="p">.</span><span class="n">staNetmask</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">dns1</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 primary DNS address</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>
</pre></div> </pre></div>

@ -101,7 +101,7 @@
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="search"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="search">
<label class="md-overlay" data-md-component="overlay" for="drawer"></label> <label class="md-overlay" data-md-component="overlay" for="drawer"></label>
<a href="#092-march-19-2018" tabindex="1" class="md-skip"> <a href="#093-march-23-2018" tabindex="1" class="md-skip">
Skip to content Skip to content
</a> </a>
@ -400,6 +400,13 @@
<label class="md-nav__title" for="toc">Table of contents</label> <label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#093-march-23-2018" title="[0.9.3] March 23, 2018." class="md-nav__link">
[0.9.3] March 23, 2018.
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#092-march-19-2018" title="[0.9.2] March 19, 2018." class="md-nav__link"> <a href="#092-march-19-2018" title="[0.9.2] March 19, 2018." class="md-nav__link">
[0.9.2] March 19, 2018. [0.9.2] March 19, 2018.
@ -455,6 +462,13 @@
<label class="md-nav__title" for="toc">Table of contents</label> <label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#093-march-23-2018" title="[0.9.3] March 23, 2018." class="md-nav__link">
[0.9.3] March 23, 2018.
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#092-march-19-2018" title="[0.9.2] March 19, 2018." class="md-nav__link"> <a href="#092-march-19-2018" title="[0.9.2] March 19, 2018." class="md-nav__link">
[0.9.2] March 19, 2018. [0.9.2] March 19, 2018.
@ -488,6 +502,10 @@
<h1>Change log</h1> <h1>Change log</h1>
<h4 id="093-march-23-2018">[0.9.3] March 23, 2018.<a class="headerlink" href="#093-march-23-2018" title="Permanent link">&para;</a></h4>
<ul>
<li>Supports a static IP address assignment.</li>
</ul>
<h4 id="092-march-19-2018">[0.9.2] March 19, 2018.<a class="headerlink" href="#092-march-19-2018" title="Permanent link">&para;</a></h4> <h4 id="092-march-19-2018">[0.9.2] March 19, 2018.<a class="headerlink" href="#092-march-19-2018" title="Permanent link">&para;</a></h4>
<ul> <ul>
<li>Improvement of string literal declaration with the examples, no library change.</li> <li>Improvement of string literal declaration with the examples, no library change.</li>

@ -11,7 +11,7 @@ By default, AutoConnect saves the credentials of the established connection in E
```arduino hl_lines="3" ```arduino hl_lines="3"
AutoConnect Portal; AutoConnect Portal;
AutoConnectConfig Config; AutoConnectConfig Config;
Config.autoSave = AC_SAVECREDENTIAL_NEVER; Config.autoSave = AC_SAVECREDENTIAL_NEVER;f
Portal.config(Config); Portal.config(Config);
Portal.begin(); Portal.begin();
``` ```
@ -185,7 +185,7 @@ An example sketch used with the PageBuilder as follows and it explains how it ai
### <i class="fa fa-caret-right"></i> Configuration for Soft AP ### <i class="fa fa-caret-right"></i> Configuration for Soft AP
AutoConnect will activate SoftAP at failed initial WiFi.Begin. It SoftAP settings are stored in [**AutoConnectConfig**](api.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](api.md#autoconnectconfig-api) for details. AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP settings are stored in [**AutoConnectConfig**](api.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](api.md#autoconnectconfig-api) for details.
- IP address of SoftAP activated. - IP address of SoftAP activated.
- Gateway IP address. - Gateway IP address.
@ -217,3 +217,22 @@ A home path of AutoConnect is **/\_ac** by default. You can access from the brow
```cpp ```cpp
#define AUTOCONNECT_URI "/_ac" #define AUTOCONNECT_URI "/_ac"
``` ```
### <i class="fa fa-caret-right"></i> Static IP assignment
It is also possible to assign static IP Address to ESP8266 in STA mode. By default DHCP is enabled and it becomes the IP address assigned by the DHCP server with *WiFi.begin*.[^1]
To assign a static IP Address, specify it in the [AutoConnectConfig parameter](api.md#staip). In the case of assigning a static IP Address, specify the gateway, subnet mask, and DNS server is needed.
```arduino
AutoConnect portal;
AutoConnectConfig Config;
Config.staip = IPAddress(192,168,1,10);
Config.staGateway = IPAddress(192,168,1,1);
Config.staNetmask = IPAddress(255,255,255,0);
Config.dns1 = IPAddress(192,168,1,1);
portal.config(Config);
portal.begin();
```
[^1]:Static IP address assignment is available from version 0.9.3.

@ -285,6 +285,22 @@ The channel number of WIFi when SoftAP starts.
!!! info "How do I choose Channel" !!! info "How do I choose Channel"
Espressif Systems had announced the [application note](https://www.espressif.com/sites/default/files/esp8266_wi-fi_channel_selection_guidelines.pdf) about Wi-Fi channel selection. Espressif Systems had announced the [application note](https://www.espressif.com/sites/default/files/esp8266_wi-fi_channel_selection_guidelines.pdf) about Wi-Fi channel selection.
#### dns1
Set primary DNS server address when using static IP address.
<dl class="apidl">
<dt>**Type**</dt>
<dd>IPAddress</dd>
</dl>
#### dns2
Set secondary DNS server address when using static IP address.
<dl class="apidl">
<dt>**Type**</dt>
<dd>IPAddress</dd>
</dl>
#### gateway #### gateway
Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this. Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
@ -328,6 +344,30 @@ 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>
#### staip
Set a static IP address. The IP will behave with STA mode.
<dl class="apidl">
<dt>**Type**</dt>
<dd>IPAddress</dd>
</dl>
#### staGateway
Set the gateway address when using static IP address.
<dl class="apidl">
<dt>**Type**</dt>
<dd>IPAddress</dd>
</dl>
#### staNetmask
Set the subnetmask when using static IP address.
<dl class="apidl">
<dt>**Type**</dt>
<dd>IPAddress</dd>
</dl>
### <i class="fa fa-code"></i> AutoConnectConfig example ### <i class="fa fa-code"></i> AutoConnectConfig example
```arduino ```arduino
@ -340,6 +380,10 @@ 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.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
Config.staip = IPAddress(192,168,10,10); // Sets static IP
Config.staGateway = IPAddress(192,168,10,1); // Sets WiFi router address
Config.staNetmask = IPAddress(255,255,255,0); // Sets WLAN scope
Config.dns1 = IPAddress(192,168,10,1); // Sets primary DNS address
Portal.config(Config); // Configure AutoConnect Portal.config(Config); // Configure AutoConnect
Portal.begin(); // Starts and behaves captive portal Portal.begin(); // Starts and behaves captive portal
``` ```

@ -1,3 +1,7 @@
#### [0.9.3] March 23, 2018.
- Supports a static IP address assignment.
#### [0.9.2] March 19, 2018. #### [0.9.2] March 19, 2018.
- Improvement of string literal declaration with the examples, no library change. - Improvement of string literal declaration with the examples, no library change.

@ -2,8 +2,8 @@
* AutoConnect class implementation. * AutoConnect class implementation.
* @file AutoConnect.cpp * @file AutoConnect.cpp
* @author hieromon@gmail.com * @author hieromon@gmail.com
* @version 0.9.1 * @version 0.9.3
* @date 2018-02-13 * @date 2018-03-23
* @copyright MIT license. * @copyright MIT license.
*/ */
@ -87,8 +87,25 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
bool AutoConnect::begin(const char* ssid, const char* passphrase) { bool AutoConnect::begin(const char* ssid, const char* passphrase) {
bool cs; bool cs;
// Start WiFi connection.
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
delay(100); delay(100);
// Advance configuration for STA mode.
#ifdef AC_DEBUG
String staip_s = _apConfig.staip.toString();
String staGateway_s = _apConfig.staGateway.toString();
String staNetmask_s = _apConfig.staNetmask.toString();
String dns1_s = _apConfig.dns1.toString();
String dns2_s = _apConfig.dns2.toString();
AC_DBG("WiFi.config(IP=%s, Gateway=%s, Subnetmask=%s, DNS1=%s, DNS2=%s) ", staip_s.c_str(), staGateway_s.c_str(), staNetmask_s.c_str(), dns1_s.c_str(), dns2_s.c_str());
#endif
if (!WiFi.config(_apConfig.staip, _apConfig.staGateway, _apConfig.staNetmask, _apConfig.dns1, _apConfig.dns2)) {
AC_DBG("failed\n");
return false;
}
AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED");
// Try to connect by STA immediately. // Try to connect by STA immediately.
if (ssid == nullptr && passphrase == nullptr) if (ssid == nullptr && passphrase == nullptr)
WiFi.begin(); WiFi.begin();

@ -2,8 +2,8 @@
* Declaration of AutoConnect class and accompanying AutoConnectConfig class. * Declaration of AutoConnect class and accompanying AutoConnectConfig class.
* @file AutoConnect.h * @file AutoConnect.h
* @author hieromon@gmail.com * @author hieromon@gmail.com
* @version 0.9.1 * @version 0.9.3
* @date 2018-02-13 * @date 2018-03-23
* @copyright MIT license. * @copyright MIT license.
*/ */
@ -119,7 +119,12 @@ class AutoConnectConfig {
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true), autoRise(true),
autoReset(true), autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {} homeUri(AUTOCONNECT_HOMEURI),
staip(0U),
staGateway(0U),
staNetmask(0U),
dns1(0U),
dns2(0U) {}
/** /**
* Configure by SSID for the captive portal access point and password. * Configure by SSID for the captive portal access point and password.
*/ */
@ -136,7 +141,12 @@ class AutoConnectConfig {
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true), autoRise(true),
autoReset(true), autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {} homeUri(AUTOCONNECT_HOMEURI),
staip(0U),
staGateway(0U),
staNetmask(0U),
dns1(0U),
dns2(0U) {}
~AutoConnectConfig() {} ~AutoConnectConfig() {}
@ -154,6 +164,11 @@ class AutoConnectConfig {
autoRise = o.autoRise; autoRise = o.autoRise;
autoReset = o.autoReset; autoReset = o.autoReset;
homeUri = o.homeUri; homeUri = o.homeUri;
staip = o.staip;
staGateway = o.staGateway;
staNetmask = o.staNetmask;
dns1 = o.dns1;
dns2 = o.dns2;
return *this; return *this;
} }
@ -170,6 +185,11 @@ class AutoConnectConfig {
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. */
String homeUri; /**< A URI of user site */ String homeUri; /**< A URI of user site */
IPAddress staip; /**< Station static IP address */
IPAddress staGateway; /**< Station gateway address */
IPAddress staNetmask; /**< Station subnet mask */
IPAddress dns1; /**< Primary DNS server */
IPAddress dns2; /**< Secondary DNS server */
}; };
class AutoConnect { class AutoConnect {

Loading…
Cancel
Save