Merge pull request #11 from Hieromon/feature/esp32

Feature/esp32
pull/14/head
Hieromon Ikasamo 6 years ago committed by GitHub
commit 46629eecfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      .travis.yml
  2. 28
      README.md
  3. 10
      docs/404.html
  4. 57
      docs/advancedusage/index.html
  5. 87
      docs/api/index.html
  6. 105
      docs/basicusage/index.html
  7. 33
      docs/changelog/index.html
  8. 12
      docs/examples/index.html
  9. 10
      docs/faq/index.html
  10. 30
      docs/gettingstarted/index.html
  11. 45
      docs/index.html
  12. 10
      docs/license/index.html
  13. 30
      docs/menu/index.html
  14. 139
      docs/search/search_index.json
  15. 20
      docs/sitemap.xml
  16. 10
      examples/Credential/Credential.ino
  17. 50
      examples/FSBrowser/FSBrowser.ino
  18. 20
      examples/HandleClient/HandleClient.ino
  19. 19
      examples/HandlePortal/HandlePortal.ino
  20. 17
      examples/HandlePortalEX/HandlePortalEX.ino
  21. 9
      examples/Simple/Simple.ino
  22. 22
      examples/mqttRSSI/mqttRSSI.ino
  23. 12
      library.json
  24. 8
      library.properties
  25. 4
      mkdocs.yml
  26. 30
      mkdocs/advancedusage.md
  27. 61
      mkdocs/api.md
  28. 61
      mkdocs/basicusage.md
  29. 5
      mkdocs/changelog.md
  30. 2
      mkdocs/examples.md
  31. 13
      mkdocs/gettingstarted.md
  32. 34
      mkdocs/index.md
  33. 20
      mkdocs/menu.md
  34. 96
      src/AutoConnect.cpp
  35. 38
      src/AutoConnect.h
  36. 2
      src/AutoConnectCredential.cpp
  37. 13
      src/AutoConnectCredential.h
  38. 98
      src/AutoConnectPage.cpp

@ -1,36 +1,35 @@
sudo: required
dist: trusty
group: deprecated-2017Q4
language: c
language: generic
env:
- BD=esp8266:esp8266:nodemcuv2:CpuFrequency=160,FlashSize=4M3M
global:
- IDE_VERSION=1.8.5
matrix:
- BOARD="esp8266:esp8266:nodemcuv2:CpuFrequency=160,FlashSize=4M3M"
- BOARD="esp32:esp32:esp32:FlashFreq=80,FlashSize=4M"
before_install:
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
- sleep 3
- export DISPLAY=:1.0
- wget http://downloads.arduino.cc/arduino-1.8.2-linux64.tar.xz
- tar xf arduino-1.8.2-linux64.tar.xz
- sudo mv arduino-1.8.2 /usr/local/share/arduino
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
- sudo mv arduino-$IDE_VERSION ~/arduino-ide
- export PATH=$PATH:~/arduino-ide
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json,http://dl.espressif.com/dl/package_esp32_index.json" --save-prefs
- if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then
arduino --install-boards esp8266:esp8266;
fi
- if [[ "$BOARD" =~ "esp32:esp32:" ]]; then
arduino --install-boards esp32:esp32;
fi
- arduino --install-library PubSubClient,PageBuilder:1.1.0
- buildExampleSketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/$1/$1.ino; }
install:
- ln -s $PWD /usr/local/share/arduino/libraries/AutoConnect
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
- arduino --install-boards esp8266:esp8266
- arduino --board $BD --save-prefs
- arduino --pref "compiler.warning_level=all" --save-prefs
# - arduino --install-library "PageBuilder"
- git clone https://github.com/Hieromon/PageBuilder /usr/local/share/arduino/libraries/PageBuilder
- arduino --install-library "PubSubClient"
- mkdir -p ~/Arduino/libraries
- ln -s $PWD ~/Arduino/libraries/.
script:
- arduino --verify --board $BD $PWD/examples/Credential/Credential.ino
- arduino --verify --board $BD $PWD/examples/FSBrowser/FSBrowser.ino
- arduino --verify --board $BD $PWD/examples/HandleClient/HandleClient.ino
- arduino --verify --board $BD $PWD/examples/HandlePortal/HandlePortal.ino
- arduino --verify --board $BD $PWD/examples/HandlePortalEX/HandlePortalEX.ino
- arduino --verify --board $BD $PWD/examples/mqttRSSI/mqttRSSI.ino
- arduino --verify --board $BD $PWD/examples/Simple/Simple.ino
notifications:
email:
on_success: change
on_failure: change
- buildExampleSketch Credential
- buildExampleSketch FSBrowser
- buildExampleSketch HandleClient
- buildExampleSketch HandlePortal
- buildExampleSketch HandlePortalEX
- buildExampleSketch Simple
- buildExampleSketch mqttRSSI

@ -1,17 +1,17 @@
# AutoConnect for ESP8266
# AutoConnect for ESP8266/ESP32
An Arduino library for ESP8266 WLAN configuration at run time with web interface. [![Build Status](https://travis-ci.org/Hieromon/AutoConnect.svg?branch=master)](https://travis-ci.org/Hieromon/AutoConnect)
An Arduino library for ESP8266/ESP32 WLAN configuration at run time with web interface. [![Build Status](https://travis-ci.org/Hieromon/AutoConnect.svg?branch=master)](https://travis-ci.org/Hieromon/AutoConnect)
## Overview
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class.
Easily implementing the Web interface constituting the WLAN for ESP8266 WiFi connection. With this library to make a sketch easily which connects from ESP8266 to the access point at runtime by the web interface without hard-coded SSID and password.
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class of ESP8266 or *WebServer* class of ESP32.
Easily implementing the Web interface constituting the WLAN for ESP8266/ESP32 WiFi connection. With this library to make a sketch easily which connects from ESP8266/ESP32 to the access point at runtime by the web interface without hard-coded SSID and password.
<div align="center"><img alt="Overview" width="460" src="docs/images/ov.png" />&emsp;&emsp;&emsp;<img alt="Captiveportal" width="182" src="docs/images/ov.gif" /></div>
### No need pre-coded SSID &amp; password
It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.
It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266/ESP32 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.
### Simple usage
@ -19,7 +19,7 @@ AutoConnect control screen will be displayed automatically for establishing new
### Store the established connection
The connection authentication data as credentials are saved automatically in EEPROM of ESP8266 and You can select the past SSID from the [AutoConnect menu](https://hieromon.github.io/AutoConnect/menu/index.html).
The connection authentication data as credentials are saved automatically in EEPROM of ESP8266/ESP32 and You can select the past SSID from the [AutoConnect menu](https://hieromon.github.io/AutoConnect/menu/index.html).
### Easy to embed in
@ -27,7 +27,7 @@ AutoConnect can be embedded easily into your sketch, just "**begin**" and "**han
### Lives with the your sketches
The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.
The sketches which provide the web page using ESP8266WebServer/WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object(ESP8266) or WebServer object(ESP32), or itself can assign it.
## Supported hardware
@ -42,6 +42,16 @@ Apply the [Arduino core](https://github.com/esp8266/Arduino) of the ESP8266 Comm
- SparkFun Thing
- SweetPea ESP-210
Alter the platform applying the [arduino-esp32](https://github.com/espressif/arduino-esp32) for the ESP32 modules.
- ESP32Dev Board
- SparkFun ESP32 Thing
- WEMOS LOLIN D32
- Ai-Thinker NodeMCU-32S
- Heltec WiFi Kit 32
- M5Stack
- And other ESP32 modules supported by the Additional Board Manager URLs of the Arduino-IDE.
## Simple usage
### The AutoConnect menu
@ -68,6 +78,10 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some
## Change log
### [0.9.5] Aug. 27, 2018
- Supports the espressif arduino-esp32 core.
- Fixed that crash may occur if the number of stored credentials in the EEPROM is smaller than the number of found WiFi networks.
### [0.9.4] May 5, 2018.
- Automatically focus passphrase after selecting SSID with Configure New AP.
- Supports AutoConnectConfig::autoReconnect option, it will scan the WLAN when it can not connect to the default SSID, apply the applicable credentials if it is saved, and try reconnecting.

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
@ -40,7 +40,7 @@
<title>AutoConnect for ESP8266</title>
<title>AutoConnect for ESP8266/ESP32</title>
@ -104,7 +104,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="/AutoConnect/images/arduino-logo.svg" width="24" height="24">
@ -118,7 +118,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
@ -243,7 +243,7 @@
<img src="/AutoConnect/images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/advancedusage/index.html">
@ -42,7 +42,7 @@
<title>Advanced usage - AutoConnect for ESP8266</title>
<title>Advanced usage - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Advanced usage
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -417,15 +417,15 @@
</li>
<li class="md-nav__item">
<a href="#refers-the-hosted-esp8266webserver" title=" Refers the hosted ESP8266WebServer" class="md-nav__link">
Refers the hosted ESP8266WebServer
<a href="#refers-the-hosted-esp8266webserverwebserver" title=" Refers the hosted ESP8266WebServer/WebServer" class="md-nav__link">
Refers the hosted ESP8266WebServer/WebServer
</a>
</li>
<li class="md-nav__item">
<a href="#usage-for-automatically-instantiated-esp8266webserver" title=" Usage for automatically instantiated ESP8266WebServer" class="md-nav__link">
Usage for automatically instantiated ESP8266WebServer
<a href="#usage-for-automatically-instantiated-esp8266webserverwebserver" title=" Usage for automatically instantiated ESP8266WebServer/WebServer" class="md-nav__link">
Usage for automatically instantiated ESP8266WebServer/WebServer
</a>
</li>
@ -637,15 +637,15 @@
</li>
<li class="md-nav__item">
<a href="#refers-the-hosted-esp8266webserver" title=" Refers the hosted ESP8266WebServer" class="md-nav__link">
Refers the hosted ESP8266WebServer
<a href="#refers-the-hosted-esp8266webserverwebserver" title=" Refers the hosted ESP8266WebServer/WebServer" class="md-nav__link">
Refers the hosted ESP8266WebServer/WebServer
</a>
</li>
<li class="md-nav__item">
<a href="#usage-for-automatically-instantiated-esp8266webserver" title=" Usage for automatically instantiated ESP8266WebServer" class="md-nav__link">
Usage for automatically instantiated ESP8266WebServer
<a href="#usage-for-automatically-instantiated-esp8266webserverwebserver" title=" Usage for automatically instantiated ESP8266WebServer/WebServer" class="md-nav__link">
Usage for automatically instantiated ESP8266WebServer/WebServer
</a>
</li>
@ -724,9 +724,10 @@
<h2 id="advanced-usage">Advanced usage<a class="headerlink" href="#advanced-usage" title="Permanent link">&para;</a></h2>
<h3 id="404-handler"><i class="fa fa-caret-right"></i> 404 handler<a class="headerlink" href="#404-handler" title="Permanent link">&para;</a></h3>
<p>Registering the "not found" handler is a different way than ESP8266WebServer. The <em>onNotFound</em> of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides <em>ESP8266WebServer::onNotFound</em> to handle a captive portal. To register "not found" handler, use <a href="../api/index.html#onnotfound"><em>AutoConnect::onNotFound</em></a>.</p>
<p>Registering the "not found" handler is a different way than ESP8266WebServer/WebServer. The <em>onNotFound</em> of ESP8266WebServer/WebServer does not work with AutoConnect. AutoConnect overrides <em>ESP8266WebServer::onNotFound</em>/<em>WebServer::onNotFound</em> to handle a captive portal. To register "not found" handler, use <a href="../api/index.html#onnotfound"><em>AutoConnect::onNotFound</em></a>.</p>
<h3 id="automatic-reconnect"><i class="fa fa-caret-right"></i> Automatic reconnect<a class="headerlink" href="#automatic-reconnect" title="Permanent link">&para;</a></h3>
<p>When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost.<br />
<p>When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost but then the reconnect behavior of ESP32 is somewhat different from this.<br />
The <a href="https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46">WiFiSTAClass::disconnect</a> function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the <a href="https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296">ESP8266WiFiSTAClass</a> has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin() without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core.<br />
If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong></a> option of the <a href="../api/index.html#autoconnectconfig-api"><strong>AutoConnectConfig</strong></a> class is enabled, it automatically attempts to reconnect to the disconnected past access point. When the autoReconnect option is specified, AutoConnect will not start SoftAP immediately if the first WiFi.begin fails. It will scan WiFi signal and the same connection information as the detected BSSID is stored in EEPROM as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun.</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>
@ -745,6 +746,10 @@ If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong><
<span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div>
<div class="admonition note">
<p class="admonition-title">In ESP32, the credentials for AutoConnect are not in NVS</p>
<p>The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the eeprom partition. You can find the partition table for default as <a href="https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv">default.csv</a></p>
</div>
<h3 id="captive-portal-start-detection"><i class="fa fa-caret-right"></i> Captive portal start detection<a class="headerlink" href="#captive-portal-start-detection" title="Permanent link">&para;</a></h3>
<p>The captive portal will only be activated if the first <em>WiFi::begin</em> fails. Sketch can detect with the <a href="../api/index.html#ondetect"><em>AutoConnect::onDetect</em></a> function that the captive portal has started. For example, the sketch can be written like as follows that turns on the LED at the start captive portal.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>
@ -823,10 +828,10 @@ If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong><
<blockquote>
<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>
<p>So in the default state, the credential storage area used by AutoConnect conflicts with data 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>Also, the placement of the EEPROM area of ESP32 is described in the <a href="https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv">partition table</a>. So in the default state, the credential storage area used by AutoConnect conflicts with data 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#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>
<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>
<h3 id="refers-the-hosted-esp8266webserverwebserver"><i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer/WebServer<a class="headerlink" href="#refers-the-hosted-esp8266webserverwebserver" title="Permanent link">&para;</a></h3>
<p>Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer/WebServer 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/WebServer 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>
<span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
@ -838,8 +843,8 @@ If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong><
<p class="admonition-title">When host() is valid</p>
<p>The host() can be referred at after <em>AutoConnect::begin</em>.</p>
</div>
<h3 id="usage-for-automatically-instantiated-esp8266webserver"><i class="fa fa-caret-right"></i> Usage for automatically instantiated ESP8266WebServer<a class="headerlink" href="#usage-for-automatically-instantiated-esp8266webserver" title="Permanent link">&para;</a></h3>
<p>The sketch can handle URL requests using ESP8266WebServer that AutoConnect started internally. ESP8266WebServer instantiated dynamically by AutoConnect can be referred to by <a href="../api/index.html#host"><em>AutoConnect::host</em></a> function. The sketch can use the '<strong>on</strong>' function, '<strong>send</strong>' function, '<strong>client</strong>' function and others by ESP8266WebServer reference of its return value.</p>
<h3 id="usage-for-automatically-instantiated-esp8266webserverwebserver"><i class="fa fa-caret-right"></i> Usage for automatically instantiated ESP8266WebServer/WebServer<a class="headerlink" href="#usage-for-automatically-instantiated-esp8266webserverwebserver" title="Permanent link">&para;</a></h3>
<p>The sketch can handle URL requests using ESP8266WebServer or WebServer that AutoConnect started internally. ESP8266WebServer/WebServer instantiated dynamically by AutoConnect can be referred to by <a href="../api/index.html#host"><em>AutoConnect::host</em></a> function. The sketch can use the '<strong>on</strong>' function, '<strong>send</strong>' function, '<strong>client</strong>' function and others by ESP8266WebServer/WebServer reference of its return value.</p>
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WiFi.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span><span class="cp"></span>
@ -875,12 +880,12 @@ If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong><
</pre></div>
<div class="admonition note">
<p class="admonition-title">ESP8266WebServer function should be called after AutoConnect::begin</p>
<p>The sketch cannot refer to an instance of ESP8266WebServer until AutoConnect::begin completes successfully.</p>
<p class="admonition-title">ESP8266WebServer/WebServer function should be called after AutoConnect::begin</p>
<p>The sketch cannot refer to an instance of ESP8266WebServer/WebServer until AutoConnect::begin completes successfully.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Do not use with ESP8266WebServer::begin</p>
<p>ESP8266WebServer is already running inside the AutoConnect.</p>
<p class="admonition-title">Do not use with ESP8266WebServer::begin or WebServer::begin</p>
<p>ESP8266WebServer/WebServer is already running inside the AutoConnect.</p>
</div>
<h3 id="use-with-the-pagebuilder-library"><i class="fa fa-caret-right"></i> Use with the <a href="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library<a class="headerlink" href="#use-with-the-pagebuilder-library" title="Permanent link">&para;</a></h3>
<p>In ordinary, the URL handler will respond the request by sending some HTML. <a href="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library is HTML assembly aid. it can handle predefined HTML as like a template and simplify an HTML string assemble logic, and also the generated HTML send automatically.</p>
@ -917,8 +922,8 @@ If the <a href="../api/index.html#autoreconnect"><strong>autoReconnect</strong><
</pre></div>
<h3 id="static-ip-assignment-1"><i class="fa fa-caret-right"></i> Static IP assignment <sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup><a class="headerlink" href="#static-ip-assignment-1" 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>.</p>
<p>To assign a static IP to ESP8266 with WIFI_MODE_STA, the following parameters are required:</p>
<p>It is also possible to assign static IP Address to ESP8266/ESP32 in STA mode. By default DHCP is enabled and it becomes the IP address assigned by the DHCP server with <em>WiFi.begin</em>.</p>
<p>To assign a static IP to ESP8266/ESP32 with WIFI_MODE_STA, the following parameters are required:</p>
<ul>
<li>IP address.</li>
<li>Gateway address.</li>

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/api/index.html">
@ -42,7 +42,7 @@
<title>Library APIs - AutoConnect for ESP8266</title>
<title>Library APIs - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Library APIs
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -381,8 +381,8 @@
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#define-macros" title="Define macros" class="md-nav__link">
Define macros
<a href="#defined-macros" title="Defined macros" class="md-nav__link">
Defined macros
</a>
</li>
@ -786,8 +786,8 @@
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#define-macros" title="Define macros" class="md-nav__link">
Define macros
<a href="#defined-macros" title="Defined macros" class="md-nav__link">
Defined macros
</a>
</li>
@ -1121,7 +1121,7 @@
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span><span class="cp"></span>
</pre></div>
<h4 id="define-macros">Define macros<a class="headerlink" href="#define-macros" title="Permanent link">&para;</a></h4>
<h4 id="defined-macros">Defined macros<a class="headerlink" href="#defined-macros" title="Permanent link">&para;</a></h4>
<div class="codehilite"><pre><span></span><span class="cp">#define AC_DEBUG </span><span class="c1">// Monitor message output activation</span>
<span class="cp">#define AC_DEBUG_PORT Serial </span><span class="c1">// Default message output device</span>
<span class="cp">#define AUTOCONNECT_AP_IP 0x01F4A8C0 </span><span class="c1">// Default SoftAP IP</span>
@ -1142,27 +1142,36 @@
</pre></div>
<p><a id="withparameter"></a></p>
<p>AutoConnect default constructor. This entry internally allocates the ESP8266WebServer and is activated internally.</p>
<p>AutoConnect default constructor. This entry internally allocates the ESP8266WebServer for ESP8266 or WebServer for ESP32 and is activated internally.</p>
<ul>
<li>For ESP8266</li>
</ul>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span><span class="p">(</span><span class="n">ESP8266WebServer</span><span class="o">&amp;</span> <span class="n">webServer</span><span class="p">)</span>
</pre></div>
<p>Run the AutoConnect site using the externally ensured ESP8266WebServer.</p>
<p>The <a href="index.html#handleclient"><strong>handleClient</strong></a> function of AutoConnect can include the response of the URI handler added by the user using the "<em>on</em>" function of ESP8266WebServer. If ESP8266WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the <a href="../api.me#host"><strong>host</strong></a> function.
<ul>
<li>For ESP32</li>
</ul>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span><span class="p">(</span><span class="n">WebServer</span><span class="o">&amp;</span> <span class="n">webServer</span><span class="p">)</span>
</pre></div>
<p>Run the AutoConnect site using the externally ensured ESP8266WebServer for ESP8266 or WebServer for ESP32.</p>
<p>The <a href="index.html#handleclient"><strong>handleClient</strong></a> function of AutoConnect can include the response of the URI handler added by the user using the "<em>on</em>" function of ESP8266WebServer/WebServer. If ESP8266WebServer/WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the <a href="../api.me#host"><strong>host</strong></a> function.
<dl class="apidl">
<dt><strong>Parameters</strong></dt>
<dd><span class="apidef">webServer</span>A reference of ESP8266WebServer instance.</dd>
<dd><span class="apidef">webServer</span>A reference of ESP8266WebServer or WebServer instance.</dd>
</dl></p>
<h3 id="public-member-functions"><i class="fa fa-code"></i> Public member functions<a class="headerlink" href="#public-member-functions" title="Permanent link">&para;</a></h3>
<h4 id="begin">begin<a class="headerlink" href="#begin" title="Permanent link">&para;</a></h4>
<p><div class="codehilite"><pre><span></span><span class="kt">bool</span> <span class="n">begin</span><span class="p">()</span>
</pre></div>
<div class="codehilite"><pre><span></span><span class="kt">bool</span> <span class="n">begin</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">ssid</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">passphraase</span><span class="p">)</span>
<div class="codehilite"><pre><span></span><span class="kt">bool</span> <span class="n">begin</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">ssid</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">passphrase</span><span class="p">)</span>
</pre></div>
<div class="codehilite"><pre><span></span><span class="kt">bool</span> <span class="n">begin</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">ssid</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">passphraase</span><span class="p">,</span> <span class="n">unsinged</span> <span class="kt">long</span> <span class="n">timeout</span><span class="p">)</span>
<div class="codehilite"><pre><span></span><span class="kt">bool</span> <span class="n">begin</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">ssid</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">passphrase</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">timeout</span><span class="p">)</span>
</pre></div></p>
<p>Starts establishing the WiFi connection.<br />
AutoConnect first invokes <em>WiFi.begin</em>. If the case of SSID and Password missing, its <em>WiFi.begin</em> has no SSID and Password. The WiFi mode at this time is WIFI_STA. Then ESP8266WebServer will be started immediately after the first <em>WiFi.beign</em> regardless of the result.</p>
<p>The captive portal will not be started if the connection has been established with first <em>WiFi.begin</em>. If the connection cannot establish, switch to WIFI_AP_STA mode and activate SoftAP. Then DNS server starts.
<p>Starts establishing the WiFi connection. The WiFi mode at this time is WIFI_STA.<br />
AutoConnect first invokes <em>WiFi.begin</em>. If the <em>ssid</em> and the <em>passphrase</em> are missing, its <em>WiFi.begin</em> has no SSID and Password. Regardless of the result, ESP8266WebServer/WebServer will start immediately after the first <em>WiFi.begin</em>.<br />
The captive portal will not be started if the connection has been established with first <em>WiFi.begin</em>. If the connection cannot establish, switch to WIFI_AP_STA mode and activate SoftAP. Then DNS server starts.
<dl class="apidl">
<dt><strong>Parameters</strong></dt>
<dd><span class="apidef">ssid</span>SSID to be connected.</dd>
@ -1181,7 +1190,7 @@ AutoConnect first invokes <em>WiFi.begin</em>. If the case of SSID and Password
<dl class="apidl">
<dt><strong>Parameters</strong></dt>
<dd><span class="apidef">config</span>Reference to <a href="index.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a> containing SoftAP's parameters and static IP parameters.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The default value is <strong>esp8266ap</strong>.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The default value is <strong>esp8266ap</strong> for ESP8266, <strong>esp32ap</strong> for ESP32.</dd>
<dd><span class="apidef">password</span>Password for SodtAP. The default value is <strong>12345678</strong>.</dd>
<dt><strong>Return value</strong></dt>
<dd><span class="apidef">true</span>Successfully configured.</dd>
@ -1191,16 +1200,16 @@ AutoConnect first invokes <em>WiFi.begin</em>. If the case of SSID and Password
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">end</span><span class="p">()</span>
</pre></div>
<p>Stops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer. </p>
<p>Stops AutoConnect captive portal service. Release ESP8266WebServer/WebServer and DNSServer. </p>
<div class="admonition warning">
<p class="admonition-title">Attention to end</p>
<p>The end function releases the instance of ESP8266WebServer and DNSServer. It can not process them after the end function.</p>
<p>The end function releases the instance of ESP8266WebServer/WebServer and DNSServer. It can not process them after the end function.</p>
</div>
<h4 id="handleclient">handleClient<a class="headerlink" href="#handleclient" title="Permanent link">&para;</a></h4>
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">handleClient</span><span class="p">()</span>
</pre></div>
<p>Process the AutoConnect menu interface. It will be processed the client request too contained in the user sketch handler by calling from inside of AutoConnect to the hosted <em>ESP8266WebServer::handleClient</em>.</p>
<p>Process the AutoConnect menu interface. The handleClient() function of the ESP8266WebServer/WebServer hosted by AutoConnect is also called from within AutoConnect, and the client request handlers contained in the user sketch are also handled.</p>
<h4 id="handlerequest">handleRequest<a class="headerlink" href="#handlerequest" title="Permanent link">&para;</a></h4>
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">handleRequest</span><span class="p">()</span>
</pre></div>
@ -1208,7 +1217,7 @@ AutoConnect first invokes <em>WiFi.begin</em>. If the case of SSID and Password
<p>Handling for the AutoConnect menu request.</p>
<div class="admonition warning">
<p class="admonition-title">About used in combination with handleClient</p>
<p>The handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266::handleClient.</p>
<p>The handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266WebServer::handleClient or WebServer::handleClient.</p>
</div>
<h4 id="home">home<a class="headerlink" href="#home" title="Permanent link">&para;</a></h4>
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">home</span><span class="p">(</span><span class="n">String</span> <span class="n">uri</span><span class="p">)</span>
@ -1220,12 +1229,21 @@ AutoConnect first invokes <em>WiFi.begin</em>. If the case of SSID and Password
<dd><span class="apidef">uri</span> A URI string of user site's home path.</dd>
</dl></p>
<h4 id="host">host<a class="headerlink" href="#host" title="Permanent link">&para;</a></h4>
<p>Returns the reference of the ESP8266WebServer which is allocated in AutoConnect automatically.</p>
<p><div class="codehilite"><pre><span></span><span class="n">ESP8266WebServer</span><span class="o">&amp;</span> <span class="n">host</span><span class="p">()</span>
<p>Returns the reference of the ESP8266WebServer/WebServer which is allocated in AutoConnect automatically.</p>
<ul>
<li>For ESP8266</li>
</ul>
<div class="codehilite"><pre><span></span><span class="n">ESP8266WebServer</span><span class="o">&amp;</span> <span class="n">host</span><span class="p">()</span>
</pre></div>
<ul>
<li>For ESP32</li>
</ul>
<p><div class="codehilite"><pre><span></span><span class="n">WebServer</span><span class="o">&amp;</span> <span class="n">host</span><span class="p">()</span>
</pre></div>
<dl class="apidl">
<dt><strong>Return value</strong></dt>
<dd>A reference of the ESP8266WebServer.</dd>
<dd>A reference of the ESP8266WebServer/WebServer.</dd>
</dl></p>
<div class="admonition note">
<p class="admonition-title">&amp;reference is not a pointer</p>
@ -1257,7 +1275,16 @@ Register the function which will call from AutoConnect at the start of the capti
<dd><span class="apidef">false</span>Cancel the captive portal. AutoConnect::begin function will return with a false.</dd>
</dl></p>
<h4 id="onnotfound">onNotFound<a class="headerlink" href="#onnotfound" title="Permanent link">&para;</a></h4>
<p><div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">onNotFound</span><span class="p">(</span><span class="n">ESP8266WebServer</span><span class="o">::</span><span class="n">THandlerFunction</span> <span class="n">fn</span><span class="p">)</span>
<ul>
<li>For ESP8266</li>
</ul>
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">onNotFound</span><span class="p">(</span><span class="n">ESP8266WebServer</span><span class="o">::</span><span class="n">THandlerFunction</span> <span class="n">fn</span><span class="p">)</span>
</pre></div>
<ul>
<li>For ESP32</li>
</ul>
<p><div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="n">onNotFound</span><span class="p">(</span><span class="n">WebServer</span><span class="o">::</span><span class="n">THandlerFunction</span> <span class="n">fn</span><span class="p">)</span>
</pre></div>
Register the handler function for undefined URL request detected.
<dl class="apidl">
@ -1273,7 +1300,7 @@ Register the handler function for undefined URL request detected.
</pre></div>
<dl class="apidl">
<dt><strong>Parameters</strong></dt>
<dd><span class="apidef">ap</span>SSID for SoftAP. The length should be up to 31. The default value is <strong>esp8266ap</strong>.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The length should be up to 31. The default value is <strong>esp8266ap</strong> for ESP8266, <strong>esp32ap</strong> for ESP32.</dd>
<dd><span class="apidef">password</span>Password for SodtAP. The length should be from 8 to up to 63. The default value is <strong>12345678</strong>.</dd>
</dl></p>
<h3 id="public-member-variables"><i class="fa fa-code"></i> Public member variables<a class="headerlink" href="#public-member-variables" title="Permanent link">&para;</a></h3>
@ -1290,7 +1317,7 @@ Register the handler function for undefined URL request detected.
<dd><span class="apidef" style="width:230px;">IPAddress</span>The default value is <strong>192.168.244.1</strong></dd>
</dl></p>
<h4 id="autoreconnect">autoReconnect<a class="headerlink" href="#autoreconnect" title="Permanent link">&para;</a></h4>
<p>Automatically reconnect to past established access point (BSSID) when the current configured SSID in ESP8266 could not be connected. By enabling this option, <em>AutoConnect::begin()</em> function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.<br />
<p>Automatically will try to reconnect with the past established access point (BSSID) when the current configured SSID in ESP8266/ESP32 could not be connected. By enabling this option, <em>AutoConnect::begin()</em> function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.<br />
If the connection fails, starts the captive portal in SoftAP + STA mode.<br />
<dl class="apidl">
<dt><strong>Type</strong></dt>

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/basicusage/index.html">
@ -42,7 +42,7 @@
<title>Basic usage - AutoConnect for ESP8266</title>
<title>Basic usage - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Basic usage
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -398,8 +398,8 @@
</li>
<li class="md-nav__item">
<a href="#4-alternate-esp8266webserverbegin" title="4. Alternate ESP8266WebServer::begin()" class="md-nav__link">
4. Alternate ESP8266WebServer::begin()
<a href="#4-alternate-esp8266webserverbegin-and-webserverbegin" title="4. Alternate ESP8266WebServer::begin() and WebServer::begin()" class="md-nav__link">
4. Alternate ESP8266WebServer::begin() and WebServer::begin()
</a>
</li>
@ -412,15 +412,15 @@
</li>
<li class="md-nav__item">
<a href="#6-use-esp8266webserveron-to-handle-url" title="6. Use ESP8266WebServer::on to handle URL" class="md-nav__link">
6. Use ESP8266WebServer::on to handle URL
<a href="#6-use-esp8266webserveron-and-webserveron-to-handle-url" title="6. Use ESP8266WebServer::on and WebServer::on to handle URL" class="md-nav__link">
6. Use ESP8266WebServer::on and WebServer::on to handle URL
</a>
</li>
<li class="md-nav__item">
<a href="#7-use-either-esp8266webserverhandleclient-or-autoconnecthandleclient" title="7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()" class="md-nav__link">
7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()
<a href="#7-use-either-esp8266webserverhandleclientwebserverhandleclient-or-autoconnecthandleclient" title="7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()" class="md-nav__link">
7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()
</a>
</li>
@ -431,8 +431,8 @@
</li>
<li class="md-nav__item">
<a href="#esp8266webserver-hosted-or-parasitic" title=" ESP8266WebServer hosted or parasitic" class="md-nav__link">
ESP8266WebServer hosted or parasitic
<a href="#esp8266webserverwebserver-hosted-or-parasitic" title=" ESP8266WebServer/WebServer hosted or parasitic" class="md-nav__link">
ESP8266WebServer/WebServer hosted or parasitic
</a>
</li>
@ -601,8 +601,8 @@
</li>
<li class="md-nav__item">
<a href="#4-alternate-esp8266webserverbegin" title="4. Alternate ESP8266WebServer::begin()" class="md-nav__link">
4. Alternate ESP8266WebServer::begin()
<a href="#4-alternate-esp8266webserverbegin-and-webserverbegin" title="4. Alternate ESP8266WebServer::begin() and WebServer::begin()" class="md-nav__link">
4. Alternate ESP8266WebServer::begin() and WebServer::begin()
</a>
</li>
@ -615,15 +615,15 @@
</li>
<li class="md-nav__item">
<a href="#6-use-esp8266webserveron-to-handle-url" title="6. Use ESP8266WebServer::on to handle URL" class="md-nav__link">
6. Use ESP8266WebServer::on to handle URL
<a href="#6-use-esp8266webserveron-and-webserveron-to-handle-url" title="6. Use ESP8266WebServer::on and WebServer::on to handle URL" class="md-nav__link">
6. Use ESP8266WebServer::on and WebServer::on to handle URL
</a>
</li>
<li class="md-nav__item">
<a href="#7-use-either-esp8266webserverhandleclient-or-autoconnecthandleclient" title="7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()" class="md-nav__link">
7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()
<a href="#7-use-either-esp8266webserverhandleclientwebserverhandleclient-or-autoconnecthandleclient" title="7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()" class="md-nav__link">
7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()
</a>
</li>
@ -634,8 +634,8 @@
</li>
<li class="md-nav__item">
<a href="#esp8266webserver-hosted-or-parasitic" title=" ESP8266WebServer hosted or parasitic" class="md-nav__link">
ESP8266WebServer hosted or parasitic
<a href="#esp8266webserverwebserver-hosted-or-parasitic" title=" ESP8266WebServer/WebServer hosted or parasitic" class="md-nav__link">
ESP8266WebServer/WebServer hosted or parasitic
</a>
</li>
@ -666,7 +666,7 @@
<h2 id="simple-usage">Simple usage<a class="headerlink" href="#simple-usage" title="Permanent link">&para;</a></h2>
<h3 id="embed-to-the-sketches"><i class="fa fa-edit"></i> Embed to the sketches<a class="headerlink" href="#embed-to-the-sketches" title="Permanent link">&para;</a></h3>
<p>How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps.</p>
<p>How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps. The below sketch is for ESP8266. For ESP32, replace <code class="codehilite">ESP8266WebServer</code> with <code class="codehilite">WebServer</code> and <code class="codehilite">ESP8266WiFi.h</code> with <code class="codehilite">WiFi.h</code> respectively.</p>
<p><img src="../images/BeforeAfter.svg" /></p>
<ul class="ulsty-edit" style="list-style:none;">
<li>Insert <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span></code> to behind of <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span></code>.</li>
@ -682,22 +682,23 @@
<h4 id="1-a-typical-logic-sequence">1. A typical logic sequence<a class="headerlink" href="#1-a-typical-logic-sequence" title="Permanent link">&para;</a></h4>
<div class="admonition note">
<ol>
<li><strong>Include headers,</strong> <code class="codehilite">ESP8266WebServer.h</code> and <code class="codehilite">AutoConnect.h</code> </li>
<li><strong>Declare ESP8266WebServer variable.</strong> </li>
<li><strong>Declare AutoConnect variable.</strong> </li>
<li><strong>Implements the URL handler with the <em>function()</em>.</strong> </li>
<li><strong>Include headers,</strong> <code class="codehilite">ESP8266WebServer.h</code>/<code class="codehilite">WebServer.h</code> and <code class="codehilite">AutoConnect.h</code> </li>
<li><strong>Declare an ESP8266WebServer variable for ESP8266 or a WebServer variable for ESP32.</strong> </li>
<li><strong>Declare an AutoConnect variable.</strong> </li>
<li><strong>Implement the URL handlers provided for the </strong><code class="codehilite">on</code><strong> method of ESP8266WebServer/WebServer with the <em>function()</em>.</strong> </li>
<li><strong>setup()</strong><br />
5.1 <strong>Sets URL handler <em>function()</em> to ESP8266WebServer by</strong><code class="codehilite">ESP8266WebServer::on</code><strong>.</strong><br />
5.1 <strong>Sets URL handler the <em>function()</em> to ESP8266WebServer/WebServer by</strong><code class="codehilite">ESP8266WebServer::on</code><strong>/</strong><code class="codehilite">WebServer::on</code><strong>.</strong><br />
5.2 <strong>Starts </strong><code class="codehilite">AutoConnect::begin()</code><strong>.</strong><br />
5.3 <strong>Check WiFi connection status.</strong> </li>
<li><strong>loop()</strong><br />
6.1 <strong>Invokes </strong><code class="codehilite">AutoConnect::handleClient()</code><strong>, or invokes </strong><code class="codehilite">ESP8266WebServer::handleClient()</code><strong> then </strong><code class="codehilite">AutoConnect::handleRequest()</code><strong>.</strong><br />
6.2 <strong>Do the process for actual sketch.</strong> </li>
6.1 <strong>Do the process for actual sketch.</strong><br />
6.2 <strong>Invokes </strong><code class="codehilite">AutoConnect::handleClient()</code><strong>, or invokes </strong><code class="codehilite">ESP8266WebServer::handleClient()</code><strong>/</strong><code class="codehilite">WebServer::handleClient</code><strong> then </strong><code class="codehilite">AutoConnect::handleRequest()</code><strong>.</strong> </li>
</ol>
</div>
<h4 id="2-declare-autoconnect-object">2. Declare AutoConnect object<a class="headerlink" href="#2-declare-autoconnect-object" title="Permanent link">&para;</a></h4>
<p><a href="#esp8266webserver-hosted-or-parasitic">Two options</a> are available for <a href="../api/index.html#constructors">AutoConnect constructor</a>.</p>
<p><div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="nf">VARIABLE</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ESP8266WebServer</span><span class="p">);</span>
<p><div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="nf">VARIABLE</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ESP8266WebServer</span><span class="p">);</span> <span class="c1">// For ESP8266</span>
<span class="n">AutoConnect</span> <span class="nf">VARIABLE</span><span class="p">(</span><span class="o">&amp;</span><span class="n">WebServer</span><span class="p">);</span> <span class="c1">// For ESP32</span>
</pre></div>
or</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">VARIABLE</span><span class="p">;</span>
@ -705,44 +706,44 @@ or</p>
<ul>
<li>
<p><strong>The parameter with an ESP8266WebServer variable:</strong> An ESP8266WebServer object variable must be declared. AutoConnect uses its variable to handles the <a href="../menu/index.html">AutoConnect menu</a>.</p>
<p><strong>The parameter with an ESP8266WebServer/WebServer variable:</strong> An ESP8266WebServer/WebServer object variable must be declared. AutoConnect uses its variable to handles the <a href="../menu/index.html">AutoConnect menu</a>.</p>
</li>
<li>
<p><strong>With no parameter:</strong> The sketch does not declare ESP8266WebServer object. In this case, AutoConnect allocates an instance of the ESP8266WebServer internally. The logic sequence of the sketch is somewhat different as the above. To register a URL handler function by <em>ESP8266WebServer::on</em> should be performed after <a href="../api/index.html#begin"><em>AutoConnect::begin</em></a>.</p>
<p><strong>With no parameter:</strong> The sketch does not declare ESP8266WebServer/WebServer object. In this case, AutoConnect allocates an instance of the ESP8266WebServer/WebServer internally. The logic sequence of the sketch is somewhat different as the above. To register a URL handler function by <em>ESP8266WebServer::on</em> or <em>WebServer::on</em> should be performed after <a href="../api/index.html#begin"><em>AutoConnect::begin</em></a>.</p>
</li>
</ul>
<h4 id="3-no-need-wifibegin">3. No need WiFI.begin(...)<a class="headerlink" href="#3-no-need-wifibegin" title="Permanent link">&para;</a></h4>
<p>AutoConnect internally performs <em>WiFi.begin</em> to establish a WiFi connection. There is no need for a general process to establish a connection using <em>WiFi.begin</em> with a sketch code.</p>
<h4 id="4-alternate-esp8266webserverbegin">4. Alternate ESP8266WebServer::begin()<a class="headerlink" href="#4-alternate-esp8266webserverbegin" title="Permanent link">&para;</a></h4>
<p><a href="../api/index.html#begin"><em>AutoConnect::begin</em></a> executes <em>ESP8266WebServer::begin</em> internally too and it starts the DNS server to behave as a Captive portal. So it is not needed to call <em>ESP8266WebServer::begin</em> with the sketch.</p>
<h4 id="4-alternate-esp8266webserverbegin-and-webserverbegin">4. Alternate ESP8266WebServer::begin() and WebServer::begin()<a class="headerlink" href="#4-alternate-esp8266webserverbegin-and-webserverbegin" title="Permanent link">&para;</a></h4>
<p><a href="../api/index.html#begin"><em>AutoConnect::begin</em></a> executes <em>ESP8266WebServer::begin</em>/<em>WebServer::begin</em> internally too and it starts the DNS server to behave as a Captive portal. So it is not needed to call <em>ESP8266WebServer::begin</em>/<em>WebServer::begin</em> in the sketch.</p>
<div class="admonition info">
<p class="admonition-title">Why DNS Server starts</p>
<p>AutoConnect traps the detection of the captive portal and achieves a connection with the WLAN interactively by the AutoConnect menu. It responds SoftAP address to all DNS queries temporarily to trap. When the WLAN connection establishes, then stops DNS server.</p>
<p>AutoConnect traps the detection of the captive portal and achieves a connection with the WLAN interactively by the AutoConnect menu. It responds SoftAP address to all DNS queries temporarily to trap. Once a WiFi connection establishes, the DNS server contributed by AutoConnect stops.</p>
</div>
<h4 id="5-autoconnectbegin-with-ssid-and-password">5. AutoConnect::begin with SSID and Password<a class="headerlink" href="#5-autoconnectbegin-with-ssid-and-password" title="Permanent link">&para;</a></h4>
<p>SSID and Password can also specify by <a href="../api.me#begin"><em>AutoConnect::begin</em></a>. ESP8266 uses provided SSID and Password explicitly. If the connection false with specified SSID with Password then a captive portal is activated. SSID and Password are not present, ESP8266 SDK will attempt to connect using the still effectual SSID and password. Usually, it succeeds.</p>
<h4 id="6-use-esp8266webserveron-to-handle-url">6. Use ESP8266WebServer::on to handle URL<a class="headerlink" href="#6-use-esp8266webserveron-to-handle-url" title="Permanent link">&para;</a></h4>
<p>AutoConnect is designed to coexist with the process for handling the web pages by user sketches. The page processing function which will send an HTML to the client invoked by the "<em>on::ESP8266WebServer</em>" function is the same as when using ESP8266WebServer natively.</p>
<h4 id="7-use-either-esp8266webserverhandleclient-or-autoconnecthandleclient">7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()<a class="headerlink" href="#7-use-either-esp8266webserverhandleclient-or-autoconnecthandleclient" title="Permanent link">&para;</a></h4>
<p>Both classes member function name is the same: <em>handleClient</em>, but the behavior is different. Using the AutoConnect embedded along with ESP8266WebServer::handleClient has limitations. Refer to the below section for details. </p>
<h3 id="esp8266webserver-hosted-or-parasitic"><i class="fa fa-caret-right"></i> ESP8266WebServer hosted or parasitic<a class="headerlink" href="#esp8266webserver-hosted-or-parasitic" title="Permanent link">&para;</a></h3>
<p>The interoperable process with an ESP8266WebServer depends on the parameters of the <a href="../api/index.html#constructors">AutoConnect constructor</a>.</p>
<p>SSID and Password can also specify by <a href="../api.me#begin"><em>AutoConnect::begin</em></a>. ESP8266/ESP32 uses provided SSID and Password explicitly. If the connection false with specified SSID with Password then a captive portal is activated. SSID and Password are not present, ESP8266 SDK will attempt to connect using the still effectual SSID and password. Usually, it succeeds.</p>
<h4 id="6-use-esp8266webserveron-and-webserveron-to-handle-url">6. Use ESP8266WebServer::on and WebServer::on to handle URL<a class="headerlink" href="#6-use-esp8266webserveron-and-webserveron-to-handle-url" title="Permanent link">&para;</a></h4>
<p>AutoConnect is designed to coexist with the process for handling the web pages by user sketches. The page processing function which will send an HTML to the client invoked by the "<em>on::ESP8266WebServer</em>" or the "<em>on::WebServer</em>" function is the same as when using ESP8266WebServer/WebServer natively.</p>
<h4 id="7-use-either-esp8266webserverhandleclientwebserverhandleclient-or-autoconnecthandleclient">7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()<a class="headerlink" href="#7-use-either-esp8266webserverhandleclientwebserverhandleclient-or-autoconnecthandleclient" title="Permanent link">&para;</a></h4>
<p>Both classes member function name is the same: <em>handleClient</em>, but the behavior is different. Using the AutoConnect embedded along with ESP8266WebServer::handleClient/WebServer::handleClient has limitations. Refer to the below section for details. </p>
<h3 id="esp8266webserverwebserver-hosted-or-parasitic"><i class="fa fa-caret-right"></i> ESP8266WebServer/WebServer hosted or parasitic<a class="headerlink" href="#esp8266webserverwebserver-hosted-or-parasitic" title="Permanent link">&para;</a></h3>
<p>The interoperable process with an ESP8266WebServer/WebServer depends on the parameters of the <a href="../api/index.html#constructors">AutoConnect constructor</a>.</p>
<table>
<thead>
<tr>
<th>Declaration parameter for the constructor</th>
<th>Use ESP8266WebServer::handleClient only</th>
<th>Use ESP8266WebServer::handleClient or WebServer::handleClient only</th>
<th>Use AutoConnect::handleClient</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="../api/index.html#constructors">None</a></td>
<td>AutoConnect menu not available.<br>To use AutoConnect menu, need <a href="../api/index.html#handlerequest">AutoConnect::handleRequest()</a>.<br>also to use ESP8266WebServer natively, need <a href="../api/index.html#host">AutoConnect::host()</a>.</td>
<td>AutoConnect menu available.<br>To use ESP8266WebServer natively, need <a href="../api/index.html#host">AutoConnect::host()</a>.</td>
<td>AutoConnect menu not available.<br>To use AutoConnect menu, need <a href="../api/index.html#handlerequest">AutoConnect::handleRequest()</a>.<br>also to use ESP8266WebServer/WebServer natively, need <a href="../api/index.html#host">AutoConnect::host()</a>.</td>
<td>AutoConnect menu available.<br>To use ESP8266WebServer/WebServer natively, need <a href="../api/index.html#host">AutoConnect::host()</a>.</td>
</tr>
<tr>
<td><a href="../api/index.html#withparameter">Reference to ESP8266WebServer</a></td>
<td><a href="../api/index.html#withparameter">Reference to ESP8266WebServer/WebServer</a></td>
<td>AutoConnect menu not available.<br>To use AutoConnect menu, need <a href="../api/index.html#handlerequest">AutoConnect::handleRequest()</a>.</td>
<td>AutoConnect menu available.</td>
</tr>
@ -750,22 +751,22 @@ or</p>
</table>
<ul>
<li>
<p><strong>By declaration for the AutoConnect variable with no parameter</strong>: The ESP8266WebServer instance is hosted by AutoConnect automatically then the sketches use <a href="../api/index.html#host"><em>AutoConnect::host</em></a> as API to get it after <a href="../api/index.html#begin"><em>AutoConnect::begin</em></a> performed.</p>
<p><strong>By declaration for the AutoConnect variable with no parameter</strong>: The ESP8266WebServer/WebServer instance is hosted by AutoConnect automatically then the sketches use <a href="../api/index.html#host"><em>AutoConnect::host</em></a> as API to get it after <a href="../api/index.html#begin"><em>AutoConnect::begin</em></a> performed.</p>
</li>
<li>
<p><strong>By declaration for the AutoConnect variable with the reference of ESP8266WebServer</strong>: AutoConnect will use it. The sketch can use it is too.</p>
<p><strong>By declaration for the AutoConnect variable with the reference of ESP8266WebServer/WebServer</strong>: AutoConnect will use it. The sketch can use it is too.</p>
</li>
<li>
<p><strong>In use ESP8266WebServer::handleClient()</strong>: AutoConnect menu can be dispatched but not works normally. It is necessary to call <a href="../api/index.html#void-handlerequest"><em>AutoConnect::handleRequest</em></a> after <em>ESP8255WebServer::handleClient</em> invoking.</p>
<p><strong>In use ESP8266WebServer::handleClient()/WebServer::handleClient()</strong>: AutoConnect menu can be dispatched but not works normally. It is necessary to call <a href="../api/index.html#void-handlerequest"><em>AutoConnect::handleRequest</em></a> after <em>ESP8255WebServer::handleClient</em>/<em>WebServer::handleClient</em> invoking.</p>
</li>
<li>
<p><strong>In use <a href="../api/index.html#void-handleclient">AutoConnect::handleClient()</a></strong>: The handleClient() process and the AutoConnect menu is available without calling <em>ESP8266WebServer::handleClient</em>.</p>
</li>
</ul>
<div class="admonition info">
<p class="admonition-title">Why AutoConnect::handleRequest is needed when using ESP8266::handleClient</p>
<p>The AutoConnect menu function may affect WiFi connection state. It follows that the menu process must execute outside <em>ESP8266WebServer::handleClient</em>.<br />
<a href="../api/index.html#void-handleclient"><em>AutoConnect::handleClient</em></a> is equivalent <em>ESP8266WebServer::handleClient</em> included <a href="../api/index.html#void-handlerequest"><em>AutoConnect::handleRequest</em></a>.</p>
<p class="admonition-title">Why AutoConnect::handleRequest is needed when using ESP8266WebServer::handleClient/WebServer::handleClient</p>
<p>The AutoConnect menu function may affect WiFi connection state. It follows that the menu process must execute outside <em>ESP8266WebServer::handleClient</em> and <em>WebServer::handleClient</em>.<br />
<a href="../api/index.html#void-handleclient"><em>AutoConnect::handleClient</em></a> is equivalent <em>ESP8266WebServer::handleClient</em> and <em>WEbServer::handleClient</em> included <a href="../api/index.html#void-handlerequest"><em>AutoConnect::handleRequest</em></a>.</p>
</div>
<div class="footnote">
<hr />

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/changelog/index.html">
@ -42,7 +42,7 @@
<title>Change log - AutoConnect for ESP8266</title>
<title>Change log - AutoConnect for ESP8266/ESP32</title>
@ -101,7 +101,7 @@
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="search">
<label class="md-overlay" data-md-component="overlay" for="drawer"></label>
<a href="#094-may-5-2018" tabindex="1" class="md-skip">
<a href="#095-aug27-2018" tabindex="1" class="md-skip">
Skip to content
</a>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Change log
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -400,6 +400,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="#095-aug27-2018" title="[0.9.5] Aug.27, 2018." class="md-nav__link">
[0.9.5] Aug.27, 2018.
</a>
</li>
<li class="md-nav__item">
<a href="#094-may-5-2018" title="[0.9.4] May 5, 2018." class="md-nav__link">
[0.9.4] May 5, 2018.
@ -469,6 +476,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="#095-aug27-2018" title="[0.9.5] Aug.27, 2018." class="md-nav__link">
[0.9.5] Aug.27, 2018.
</a>
</li>
<li class="md-nav__item">
<a href="#094-may-5-2018" title="[0.9.4] May 5, 2018." class="md-nav__link">
[0.9.4] May 5, 2018.
@ -516,7 +530,12 @@
<h1>Change log</h1>
<h4 id="094-may-5-2018">[0.9.4] May 5, 2018.<a class="headerlink" href="#094-may-5-2018" title="Permanent link">&para;</a></h4>
<h4 id="095-aug27-2018">[0.9.5] Aug.27, 2018.<a class="headerlink" href="#095-aug27-2018" title="Permanent link">&para;</a></h4>
<ul>
<li>Supports ESP32.</li>
<li>Fixed that crash may occur if the number of stored credentials in the EEPROM is smaller than the number of found WiFi networks.</li>
</ul>
<h4 id="094-may-5-2018">[0.9.4] May 5, 2018.<a class="headerlink" href="#094-may-5-2018" title="Permanent link">&para;</a></h4>
<ul>
<li>Automatically focus passphrase after selecting SSID with Configure New AP.</li>
<li>Supports AutoConnectConfig::autoReconnect option, it will scan the WLAN when it can not connect to the default SSID, apply the applicable credentials if it is saved, and try reconnecting.</li>

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/examples/index.html">
@ -42,7 +42,7 @@
<title>Examples - AutoConnect for ESP8266</title>
<title>Examples - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Examples
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -683,7 +683,7 @@
<p>Declare only AutoConnect, performs handleClient.</p>
<p><img src="../images/handlePortal.svg" /></p>
<h2 id="used-with-mqtt-as-a-client-application">Used with MQTT as a client application<a class="headerlink" href="#used-with-mqtt-as-a-client-application" title="Permanent link">&para;</a></h2>
<p>The effect of AutoConnect is not only for ESP8266 as the Web server. It has advantages for something WiFi client as well. For example, AutoConnect is also effective for publishing MQTT messages from various measurement points. Even if the SSID is different for each measurement point, it is not necessary to modify the sketch.</p>
<p>The effect of AutoConnect is not only for ESP8266/ESP32 as the web server. It has advantages for something WiFi client as well. For example, AutoConnect is also effective for publishing MQTT messages from various measurement points. Even if the SSID is different for each measurement point, it is not necessary to modify the sketch.</p>
<p>This example tries to publish the WiFi signal strength of ESP8266 with MQTT. It uses the <a href="https://thingspeak.com/">ThingSpeak</a> for MQTT broker. ESP8266 publishes the RSSI value to the channel created on ThingSpeak as <a href="https://github.com/knolleary/pubsubclient">MQTT client</a>. This example is well suited to demonstrate the usefulness of AutoConnect, as RSSI values are measured at each access point usually. Just adding a few lines of code makes it unnecessary to upload sketches with the different SSIDs rewrite for each access point.</p>
<p><img src="../images/ChannelStatus.png" width="70%"/></p>
<h3 id="advance-procedures">Advance procedures<a class="headerlink" href="#advance-procedures" title="Permanent link">&para;</a></h3>

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/faq/index.html">
@ -42,7 +42,7 @@
<title>FAQ - AutoConnect for ESP8266</title>
<title>FAQ - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
FAQ
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/gettingstarted/index.html">
@ -42,7 +42,7 @@
<title>Getting started - AutoConnect for ESP8266</title>
<title>Getting started - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Getting started
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -544,11 +544,11 @@
<h2 id="lets-do-the-most-simple-sketch">Let's do the most simple sketch<a class="headerlink" href="#lets-do-the-most-simple-sketch" title="Permanent link">&para;</a></h2>
<p>Open the Arduino IDE, write the following sketch and upload it. The feature of this sketch is that the SSID and Password are not coded.</p>
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WiFi.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span><span class="cp"></span>
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WiFi.h&gt; // Replace with WiFi.h for ESP32</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt; // Replace with WebServer.h for ESP32</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span><span class="cp"></span>
<span class="n">ESP8266WebServer</span> <span class="nf">Server</span><span class="p">;</span>
<span class="n">ESP8266WebServer</span> <span class="nf">Server</span><span class="p">;</span> <span class="c1">// Replace with WebServer for ESP32</span>
<span class="n">AutoConnect</span> <span class="nf">Portal</span><span class="p">(</span><span class="nf">Server</span><span class="p">);</span>
<span class="kr">void</span> <span class="nf">rootPage</span><span class="p">()</span> <span class="p">{</span>
@ -572,8 +572,11 @@
<span class="p">}</span>
</pre></div>
<div class="admonition note">
<p>The above code can be applied to ESP8266. To apply to ESP32, replace <code class="codehilite">ESP8266WebServer</code> class with <code class="codehilite">WebServer</code> and include <code class="codehilite">WiFi.h</code> and <code class="codehilite">WebServer.h</code> of arduino-esp32 appropriately.</p>
</div>
<h3 id="run-at-first"><i class="fa fa-play-circle"></i> Run at first<a class="headerlink" href="#run-at-first" title="Permanent link">&para;</a></h3>
<p>After about 30 seconds, if the ESP8266 cannot connect to nearby Wi-Fi spot, you pull out your smartphone and open <em>Wi-Fi settings</em> from the <em>Settings</em> Apps. You can see the <strong>esp8266ap</strong> in the list of <em>"CHOOSE A NETWORK..."</em>. Then tap the esp8266ap and enter password <strong>12345678</strong>, a something screen pops up automatically as shown below.</p>
<p>After about 30 seconds, if the ESP8266 cannot connect to nearby Wi-Fi spot, you pull out your smartphone and open <em>Wi-Fi settings</em> from the <em>Settings</em> Apps. You can see the <strong>esp8266ap</strong> <sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup> in the list of <em>"CHOOSE A NETWORK..."</em>. Then tap the esp8266ap and enter password <strong>12345678</strong>, a something screen pops up automatically as shown below.</p>
<p><span style="display:inline-block;width:282px;height:501px;border:1px solid lightgrey;"><img data-gifffer="../images/login_ani.gif" data-gifffer-width="280" style="width:280px;" /></span><img src="../images/arrow_right.svg" style="vertical-align:top;padding-top:120px;width:48px;margin-left:30px;margin-right:30px;" /><img src="../images/stat.png" style="border:1px solid lightgrey;width:280px;" /></span></p>
<p>This is the AutoConnect statistics screen. This screen displays the current status of the established connection, WiFi mode, IP address, free memory size, and etc. Also, the <strong>hamburger icon</strong> is the control menu of AutoConnect seems at the upper right. By tap the hamburger icon, the control menu appears as the below.</p>
<h3 id="join-to-the-new-access-point"><i class="fa fa-cog"></i> Join to the new access point<a class="headerlink" href="#join-to-the-new-access-point" title="Permanent link">&para;</a></h3>
@ -592,6 +595,15 @@ Or, "<strong>RESET</strong>" can be selected. The ESP8266 resets and reboots. Af
Gifffer();
}
</script>
<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p>When applied to ESP32, SSID will appear as <strong>esp32ap</strong>.&#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>

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/index.html">
@ -42,7 +42,7 @@
<title>AutoConnect for ESP8266</title>
<title>AutoConnect for ESP8266/ESP32</title>
@ -101,7 +101,7 @@
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="search">
<label class="md-overlay" data-md-component="overlay" for="drawer"></label>
<a href="#autoconnect-for-esp8266" tabindex="1" class="md-skip">
<a href="#autoconnect-for-esp8266esp32" tabindex="1" class="md-skip">
Skip to content
</a>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="./images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Overview
@ -249,7 +249,7 @@
<img src="./images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -654,22 +654,22 @@
<h1 id="autoconnect-for-esp8266">AutoConnect <small>for ESP8266</small><a class="headerlink" href="#autoconnect-for-esp8266" title="Permanent link">&para;</a></h1>
<p>An Arduino library for ESP8266 WLAN configuration at run time with web interface.</p>
<h1 id="autoconnect-for-esp8266esp32">AutoConnect <small>for ESP8266/ESP32</small><a class="headerlink" href="#autoconnect-for-esp8266esp32" title="Permanent link">&para;</a></h1>
<p>An Arduino library for ESP8266/ESP32 WLAN configuration at run time with web interface.</p>
<h2 id="overview">Overview<a class="headerlink" href="#overview" title="Permanent link">&para;</a></h2>
<p>To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with <em>ESP8266WebServer</em> class.
Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi connection. With this library to make a sketch easily which connects from ESP8266 to the access point at runtime by the web interface without hard-coded SSID and password.</p>
<p>To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with <em>ESP8266WebServer</em> class for ESP8266 or <em>WebServer</em> class for ESP32.
Easy implementing the Web interface constituting the WLAN for ESP8266/ESP32 WiFi connection. With this library to make a sketch easily which connects from ESP8266/ESP32 to the access point at runtime by the web interface without hard-coded SSID and password.</p>
<p><img style="display:inline-block;width:460px;margin-right:30px;" src="./images/ov.png" /><span style="display:inline-block;width:182px;height:322px;border:solid 1px lightgrey;"><img data-gifffer="./images/ov.gif" data-gifffer-width="180" style="width:180px;" /></span></p>
<h3 id="no-need-pre-coded-ssid-password"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> No need pre-coded SSID &amp; password<a class="headerlink" href="#no-need-pre-coded-ssid-password" title="Permanent link">&para;</a></h3>
<p><span class="lead">It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.</span></p>
<p><span class="lead">It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266/ESP32 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.</span></p>
<h3 id="simple-usage"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Simple usage<a class="headerlink" href="#simple-usage" title="Permanent link">&para;</a></h3>
<p><span class="lead">AutoConnect control screen will be displayed automatically for establishing new connections. It aids by the <a href="https://en.wikipedia.org/wiki/Captive_portal">captive portal</a> when vested the connection cannot be detected.<br>By using the <a href="menu/index.html">AutoConnect menu</a>, to manage the connections convenient.</span></p>
<h3 id="store-the-established-connection"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Store the established connection<a class="headerlink" href="#store-the-established-connection" title="Permanent link">&para;</a></h3>
<p><span class="lead">The connection authentication data as credentials are saved automatically in EEPROM of ESP8266 and You can select the past SSID from the <a href="menu/index.html">AutoConnect menu</a>.</span></p>
<p><span class="lead">The connection authentication data as credentials are saved automatically in EEPROM of ESP8266/ESP32 and You can select the past SSID from the <a href="menu/index.html">AutoConnect menu</a>.</span></p>
<h3 id="easy-to-embed-in"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Easy to embed in<a class="headerlink" href="#easy-to-embed-in" title="Permanent link">&para;</a></h3>
<p><span class="lead">AutoConnect can be placed easily in your sketch. It's "<strong>begin</strong>" and "<strong>handleClient</strong>" only.</span></p>
<h3 id="lives-with-the-your-sketches"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Lives with the your sketches<a class="headerlink" href="#lives-with-the-your-sketches" title="Permanent link">&para;</a></h3>
<p><span class="lead">The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.</span></p>
<p><span class="lead">The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.<br>This efficacy can also be applied to ESP32. The corresponding class for ESP32 will be the WebServer.</span></p>
<h2 id="installation">Installation<a class="headerlink" href="#installation" title="Permanent link">&para;</a></h2>
<h3 id="requirements">Requirements<a class="headerlink" href="#requirements" title="Permanent link">&para;</a></h3>
<h4 id="supported-hardware">Supported hardware<a class="headerlink" href="#supported-hardware" title="Permanent link">&para;</a></h4>
@ -682,6 +682,13 @@ Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi conne
<li class="task-list-item"><input type="checkbox" disabled checked/> Olimex MOD-WIFI-ESP8266</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> SparkFun Thing</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> SweetPea ESP-210</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> ESP32Dev Board (applying the Espressif's arduino-esp32 core)</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> SparkFun ESP32 Thing</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> WEMOS LOLIN D32</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> Ai-Thinker NodeMCU-32S</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> Heltec WiFi Kit 32</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> M5Stack</li>
<li class="task-list-item"><input type="checkbox" disabled checked/> And other ESP8266/ESP32 modules supported by the Additional Board Manager URLs of the Arduino-IDE.</li>
</ul>
<div class="admonition info">
<p class="admonition-title">About flash size on the module</p>
@ -694,15 +701,13 @@ Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi conne
<p><i class="fa fa-download"></i> <strong>ESP8266 Arduino core</strong></p>
<p>AutoConnect targets sketches made on the assumption of <a href="https://github.com/esp8266/Arduino">ESP8266 Community's Arduino core</a>. The <a href="https://github.com/esp8266/Arduino/releases/latest">latest release</a> is recommended.<br />
Install third-party platform using the <em>Boards Manager</em> of Arduino IDE. Package URL is <a href="http://arduino.esp8266.com/stable/package_esp8266com_index.json">http://arduino.esp8266.com/stable/package_esp8266com_index.json</a></p>
<p><i class="fa fa-download"></i> <strong>ESP32 Arduino core</strong></p>
<p>Also, to apply AutoConnect to ESP32, the <a href="https://github.com/espressif/arduino-esp32">arduino-esp32 core</a> provided by Espressif is needed. The <a href="https://github.com/espressif/arduino-esp32/releases/latest">latest release</a> is recommended.<br />
Install third-party platform using the <em>Boards Manager</em> of Arduino IDE. You can add multiple URLs into <em>Additional Board Manager URLs</em> field, separating them with commas. Package URL is <a href="https://dl.espressif.com/dl/package_esp32_index.json">https://dl.espressif.com/dl/package_esp32_index.json</a></p>
<p><i class="fa fa-download"></i> <strong>Additional necessary library</strong></p>
<p>The <a href="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library to build HTML for ESP8266WebServer is needed.<br />
To install the PageBuilder library into your Arduino IDE, you can use the <em>Library Manager</em>. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '<strong>PageBuilder</strong>' with the topic '<strong>Communication</strong>', then you can see the <em>PageBuilder</em>. The latest version or 1.0.0 later is required.</p>
To install the PageBuilder library into your Arduino IDE, you can use the <em>Library Manager</em>. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '<strong>PageBuilder</strong>' with the topic '<strong>Communication</strong>', then you can see the <em>PageBuilder</em>. The latest version is required 1.1.0 later for ESP32.</p>
<p><img src="./images/lm.png" width="640"/></p>
<div class="admonition warning">
<p class="admonition-title">Library Manager of Arduino IDE</p>
<p>The version of PageBuilder may not have been updated yet. If the library manager shows only version 0.93.0, please install the latest PageBuilder version than 1.0.0 from the Github repository. <a href="https://github.com/Hieromon/PageBuilder/releases/latest">The PageBuilder release</a> of the Github repository is the latest version. The <a href="https://platformio.org/lib/show/2010/PageBuilder">PlatformIO library</a> has the latest version of 1.0.0.<br />
In 0.93.0, the PageBuilder class has a compile error about without the 'cancel' method.</p>
</div>
<h3 id="install-the-autoconnect">Install the AutoConnect<a class="headerlink" href="#install-the-autoconnect" title="Permanent link">&para;</a></h3>
<p>Clone or download from the <a href="https://github.com/Hieromon/AutoConnect">AutoConnect GitHub repository</a>.</p>
<p><img src="./images/gitrepo.png" width="640"/></p>
@ -710,7 +715,7 @@ In 0.93.0, the PageBuilder class has a compile error about without the 'cancel'
<p><img src="./images/ins_lib.png" /></p>
<div class="admonition info">
<p class="admonition-title">Supported by Library manager.</p>
<p>AutoConnect was added to the Arduino IDE library manager as of March 17, 2018. It can be used with the PlatformIO library also.</p>
<p>AutoConnect was added to the Arduino IDE library manager. It can be used with the PlatformIO library also.</p>
</div>
<script>
window.onload = function() {

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/license/index.html">
@ -42,7 +42,7 @@
<title>License - AutoConnect for ESP8266</title>
<title>License - AutoConnect for ESP8266/ESP32</title>
@ -106,7 +106,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -120,7 +120,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
License
@ -245,7 +245,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">

@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266 WLAN configuration at run time with web interface">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/menu/index.html">
@ -42,7 +42,7 @@
<title>AutoConnect menu - AutoConnect for ESP8266</title>
<title>AutoConnect menu - AutoConnect for ESP8266/ESP32</title>
@ -110,7 +110,7 @@
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266" class="md-header-nav__button md-logo">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img src="../images/arduino-logo.svg" width="24" height="24">
@ -124,7 +124,7 @@
<span class="md-header-nav__topic">
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
AutoConnect menu
@ -249,7 +249,7 @@
<img src="../images/arduino-logo.svg" width="48" height="48">
</span>
AutoConnect for ESP8266
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
@ -549,10 +549,10 @@
<p>The AutoConnect menu is developed using the <a href="https://github.com/balzss/luxbar">LuxBar</a> which is licensed under the MIT License. See the <a href="../license/index.html">License</a>.</p>
</div>
<h2 id="where-the-from"><i class="fa fa-external-link"></i> Where the from<a class="headerlink" href="#where-the-from" title="Permanent link">&para;</a></h2>
<p>The AutoConnect menu appears when you access the <strong>AutoConnect root path</strong>. It is assigned "<strong>/_ac</strong>" located on ESP8266 <em>local IP address</em> by default. This location can be changed in the sketch. The following screen will appear at access to <code class="codehilite">http://{localIP}/_ac</code> as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap <i class="fa fa-bars"></i> at right on top. (e.g. <code class="codehilite">http://192.168.244.1/_ac</code> for SoftAP mode.)</p>
<p>The AutoConnect menu appears when you access the <strong>AutoConnect root path</strong>. It is assigned "<strong>/_ac</strong>" located on the <em>local IP address</em> of ESP8266/ESP32 module by default. This location can be changed in the sketch. The following screen will appear at access to <code class="codehilite">http://{localIP}/_ac</code> as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap <i class="fa fa-bars"></i> at right on top. (e.g. <code class="codehilite">http://192.168.244.1/_ac</code> for SoftAP mode.)</p>
<p><img src="../images/ac.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" /></p>
<div class="admonition note">
<p class="admonition-title">What's local IP?</p>
<p class="admonition-title">What's the local IP?</p>
<p>A local IP means Local IP at connection established or SoftAP's IP.</p>
</div>
<h2 id="right-on-top"><i class="fa fa-bars"></i> Right on top<a class="headerlink" href="#right-on-top" title="Permanent link">&para;</a></h2>
@ -561,26 +561,26 @@
<li><strong>Configure new AP</strong>: Configure SSID and Password for new access point.</li>
<li><strong>Open SSIDs</strong>: Opens the past SSID which has been established connection from EEPROM.</li>
<li><strong>Disconnect</strong>: Disconnects current connection.</li>
<li><strong>Reset...</strong>: Rest the ESP8266 module.</li>
<li><strong>Reset...</strong>: Rest the ESP8266/ESP32 module.</li>
<li><strong>HOME</strong>: Return to user home page.</li>
</ul>
<p><img src="../images/menu.png" style="width:280px;" /></p>
<h2 id="configure-new-ap"><i class="fa fa-bars"></i> Configure new AP<a class="headerlink" href="#configure-new-ap" title="Permanent link">&para;</a></h2>
<p>Scan all available access point and display it. Strength and security of the detected AP are marked. The <i class="fa fa-lock"></i> is indicated for the SSID that needs a security key. "<strong>Hidden:</strong>" means the number of hidden SSIDs discovered.<br />
Enter SSID and Passphrase and tap "<strong>apply</strong>" to starts a connection. </p>
<p>Scan all available access point in the vicinity and display it. Strength and security of the detected AP are marked. The <i class="fa fa-lock"></i> is indicated for the SSID that needs a security key. "<strong>Hidden:</strong>" means the number of hidden SSIDs discovered.<br />
Enter SSID and Passphrase and tap "<strong>apply</strong>" to starts WiFi connection. </p>
<p><img src="../images/newap.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" /></p>
<h2 id="open-ssids"><i class="fa fa-bars"></i> Open SSIDs<a class="headerlink" href="#open-ssids" title="Permanent link">&para;</a></h2>
<p>Once it was established connection, its SSID and Password will be stored to the EEPROM of ESP8266 automatically. The <strong>Open SSIDs</strong> menu reads the saved SSID credentials from the EEPROM. The stored credential data are listed by the SSID as shown below. Its label is a clickable button. Tap the SSID button, starts connection it.</p>
<p>Once it was established WiFi connection, its SSID and password will be saved in EEPROM of ESP8266/ESP32 automatically. The <strong>Open SSIDs</strong> menu reads the saved SSID credentials from the EEPROM. The stored credential data are listed by the SSID as shown below. Its label is a clickable button. Tap the SSID button, starts WiFi connection it.</p>
<p><img src="../images/open.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" /></p>
<h2 id="disconnect"><i class="fa fa-bars"></i> Disconnect<a class="headerlink" href="#disconnect" title="Permanent link">&para;</a></h2>
<p>Disconnect ESP8266 from the current connection. It can also reset the ESP8266 automatically after disconnection by instructing with using <a href="../api/index.html#autoreset">API</a> in the sketch.</p>
<p>Disconnect ESP8266/ESP32 from the current connection. It can also reset the ESP8266/ESP32 automatically after disconnection by instructing with using <a href="../api/index.html#autoreset">API</a> in the sketch.</p>
<p>After tapping "Disconnect", you will not be able to reach the AutoConnect menu. Once disconnected, you will need to set the SSID again for connecting the WLAN. </p>
<h2 id="reset"><i class="fa fa-bars"></i> Reset...<a class="headerlink" href="#reset" title="Permanent link">&para;</a></h2>
<p>Reset the ESP8266, it will start rebooting. After rebooting complete, the ESP8266 begins establishing the previous connection with WIFI_STA mode, and <em>esp8266ap</em> of an access point will disappear from WLAN.</p>
<p>Reset the ESP8266/ESP32 module, it will start rebooting. After rebooting complete, the ESP8266/ESP32 module begins establishing the previous connection with WIFI_STA mode, and <em>esp8266ap</em> or <em>esp32ap</em> of an access point will disappear from WLAN.</p>
<p><img src="../images/resetting.png" style="width:280px;" /></p>
<div class="admonition warning">
<p class="admonition-title">Not every module will be rebooted normally</p>
<p>The Reset menu is using the <strong>ESP.reset()</strong> function. This is an almost hardware reset. In order to resume the sketch normally, the <a href="https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process#esp-boot-modes">state of GPIO0</a> is important. Since this depends on the circuit implementation for each module, not every module will be rebooted normally. See also <a href="../faq/index.html#hang-up-after-reset">FAQ</a>.</p>
<p class="admonition-title">Not every ESP8266 module will be rebooted normally</p>
<p>The Reset menu is using the <strong>ESP.reset()</strong> function for ESP8266. This is an almost hardware reset. In order to resume the sketch normally, the <a href="https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process#esp-boot-modes">state of GPIO0</a> is important. Since this depends on the circuit implementation for each module, not every module will be rebooted normally. See also <a href="../faq/index.html#hang-up-after-reset">FAQ</a>.</p>
</div>

File diff suppressed because one or more lines are too long

@ -4,7 +4,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -12,7 +12,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//gettingstarted/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -20,7 +20,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//menu/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -28,7 +28,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//basicusage/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -36,7 +36,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//advancedusage/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -44,7 +44,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//api/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -52,7 +52,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//examples/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -60,7 +60,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//faq/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -68,7 +68,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//changelog/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>
@ -76,7 +76,7 @@
<url>
<loc>https://Hieromon.github.io/AutoConnect//license/index.html</loc>
<lastmod>2018-05-06</lastmod>
<lastmod>2018-09-18</lastmod>
<changefreq>daily</changefreq>
</url>

@ -14,13 +14,23 @@
This sketch uses PageBuilder to support handling of operation pages.
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <AutoConnect.h>
#include <AutoConnectCredential.h>
#include <PageBuilder.h>
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer Server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer Server;
#endif
AutoConnect Portal(Server);
String viewCredential(PageArgument&);
String delCredential(PageArgument&);

@ -22,11 +22,19 @@
access the sample web page at http://esp8266fs.local
edit the page by going to http://esp8266fs.local/edit
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#endif
//Add a below line for AutoConnect.
#include <AutoConnect.h>
@ -34,9 +42,15 @@
const char* ssid = "wifi-ssid";
const char* password = "wifi-password";
#if defined(ARDUINO_ARCH_ESP8266)
const char* host = "esp8266fs";
ESP8266WebServer server(80);
#elif defined(ARDUINO_ARCH_ESP32)
const char* host = "esp32fs";
WebServer server(80);
#endif
//Add a below line for AutoConnect.
AutoConnect portal(server);
//holds the current upload
@ -144,10 +158,15 @@ void handleFileList() {
String path = server.arg("dir");
DBG_OUTPUT_PORT.println("handleFileList: " + path);
#if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir(path);
#elif defined(ARDUINO_ARCH_ESP32)
File root = SPIFFS.open(path);
#endif
path = String();
String output = "[";
#if defined(ARDUINO_ARCH_ESP8266)
while(dir.next()){
File entry = dir.openFile("r");
if (output != "[") output += ',';
@ -159,6 +178,22 @@ void handleFileList() {
output += "\"}";
entry.close();
}
#elif defined(ARDUINO_ARCH_ESP32)
if(root.isDirectory()){
File file = root.openNextFile();
while(file){
if (output != "[") {
output += ',';
}
output += "{\"type\":\"";
output += (file.isDirectory()) ? "dir" : "file";
output += "\",\"name\":\"";
output += String(file.name()).substring(1);
output += "\"}";
file = root.openNextFile();
}
}
#endif
output += "]";
server.send(200, "text/json", output);
@ -170,12 +205,23 @@ void setup(void){
DBG_OUTPUT_PORT.setDebugOutput(true);
SPIFFS.begin();
{
#if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
#elif defined(ARDUINO_ARCH_ESP32)
File root = SPIFFS.open("/");
File file = root.openNextFile();
while(file){
String fileName = file.name();
size_t fileSize = file.size();
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
file = root.openNextFile();
}
#endif
DBG_OUTPUT_PORT.printf("\n");
}
@ -222,7 +268,11 @@ void setup(void){
String json = "{";
json += "\"heap\":"+String(ESP.getFreeHeap());
json += ", \"analog\":"+String(analogRead(A0));
#if defined(ARDUINO_ARCH_ESP8266)
json += ", \"gpio\":"+String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
#elif defined(ARDUINO_ARCH_ESP32)
json += ", \"gpio\":" + String((uint32_t)(0));
#endif
json += "}";
server.send(200, "text/json", json);
json = String();

@ -7,11 +7,25 @@
https://opensource.org/licenses/MIT
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <AutoConnect.h>
ESP8266WebServer server;
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer server;
#endif
#ifndef BUILTIN_LED
#define BUILTIN_LED 2 // backward compatibility
#endif
AutoConnect portal(server);
void handleRoot() {
@ -104,7 +118,11 @@ void loop() {
server.handleClient();
portal.handleRequest(); // Need to handle AutoConnect menu.
if (WiFi.status() == WL_IDLE_STATUS) {
#if defined(ARDUINO_ARCH_ESP8266)
ESP.reset();
#elif defined(ARDUINO_ARCH_ESP32)
ESP.restart();
#endif
delay(1000);
}
}

@ -14,10 +14,19 @@
It will help you understand AutoConnect usage.
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <AutoConnect.h>
#ifndef BUILTIN_LED
#define BUILTIN_LED 2 // backward compatibility
#endif
AutoConnect portal;
void handleRoot() {
@ -64,7 +73,7 @@ void handleRoot() {
}
void handleGPIO() {
ESP8266WebServer& server = portal.host();
WebServerClass& server = portal.host();
if (server.arg("v") == "low")
digitalWrite(BUILTIN_LED, LOW);
else if (server.arg("v") == "high")
@ -73,7 +82,7 @@ void handleGPIO() {
}
void sendRedirect(String uri) {
ESP8266WebServer& server = portal.host();
WebServerClass& server = portal.host();
server.sendHeader("Location", uri, true);
server.send(302, "text/plain", "");
server.client().stop();
@ -97,7 +106,7 @@ void setup() {
// Starts user web site included the AutoConnect portal.
portal.onDetect(atDetect);
if (portal.begin()) {
ESP8266WebServer& server = portal.host();
WebServerClass& server = portal.host();
server.on("/", handleRoot);
server.on("/io", handleGPIO);
Serial.println("Started, IP:" + WiFi.localIP().toString());
@ -111,7 +120,11 @@ void setup() {
void loop() {
portal.handleClient();
if (WiFi.status() == WL_IDLE_STATUS) {
#if defined(ARDUINO_ARCH_ESP8266)
ESP.reset();
#elif defined(ARDUINO_ARCH_ESP32)
ESP.restart();
#endif
delay(1000);
}
}

@ -15,12 +15,25 @@
It will help you understand AutoConnect usage.
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <PageBuilder.h>
#include <AutoConnect.h>
#ifndef BUILTIN_LED
#define BUILTIN_LED 2 // backward compatibility
#endif
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer server;
#endif
AutoConnect portal(server);
static const char PROGMEM mold_page[] = R"*lit(
@ -138,7 +151,11 @@ void setup() {
void loop() {
portal.handleClient();
if (WiFi.status() == WL_IDLE_STATUS) {
#if defined(ARDUINO_ARCH_ESP8266)
ESP.reset();
#elif defined(ARDUINO_ARCH_ESP32)
ESP.restart();
#endif
delay(1000);
}
}

@ -7,12 +7,21 @@
https://opensource.org/licenses/MIT
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <time.h>
#include <AutoConnect.h>
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer Server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer Server;
#endif
AutoConnect Portal(Server);
AutoConnectConfig Config; // Enable autoReconnect supported on v0.9.4

@ -1,5 +1,5 @@
/*
ESP8266 publish the RSSI as the WiFi signal strength to ThingSpeak channel.
ESP8266/ESP32 publish the RSSI as the WiFi signal strength to ThingSpeak channel.
This example is for explaining how to use the AutoConnect library.
In order to execute this example, the ThingSpeak account is needed. Sing up
@ -13,7 +13,11 @@
https://opensource.org/licenses/MIT
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#endif
#include <PubSubClient.h>
#include <AutoConnect.h>
@ -51,10 +55,11 @@ bool mqttConnect() {
} else {
Serial.println("Connection failed:" + String(mqttClient.state()));
if (!--retry)
return false;
break;
}
delay(3000);
}
return false;
}
void mqttPublish(String msg) {
@ -70,6 +75,17 @@ void mqttPublish(String msg) {
mqttClient.publish(topic, payload);
}
int getStrength(uint8_t points) {
uint8_t sc = points;
long rssi = 0;
while (sc--) {
rssi += WiFi.RSSI();
delay(20);
}
return points ? (int)(rssi / points) : 0;
}
unsigned long lastPub = 0;
void setup() {
@ -96,7 +112,7 @@ void loop() {
if (!mqttClient.connected()) {
mqttConnect();
}
String item = String("field1=") + String(WiFi.RSSI());
String item = String("field1=") + String(getStrength(7));
mqttPublish(item);
mqttClient.loop();
lastPub = millis();

@ -1,7 +1,7 @@
{
"name": "AutoConnect",
"keywords": "communication, http, server, web, wifi, wi-fi",
"description": "ESP8266 WLAN configuration at runtime with web interface.",
"description": "ESP8266/ESP32 WLAN configuration at runtime with web interface.",
"homepage": "https://hieromon.github.io/AutoConnect",
"repository":
{
@ -12,11 +12,15 @@
[
{
"name": "PageBuilder",
"version": ">=1.0.0"
"version": ">=1.1.0"
}
],
"frameworks": "arduino",
"platforms": "espressif8266",
"version": "0.9.4",
"platforms":
[
"espressif8266",
"espressif32"
],
"version": "0.9.5",
"license": "MIT"
}

@ -1,10 +1,10 @@
name=AutoConnect
version=0.9.4
version=0.9.5
author=Hieromon Ikasamo <hieromon@gmail.com>
maintainer=Hieromon Ikasamo <hieromon@gmail.com>
sentence=ESP8266 WLAN configuration at runtime with web interface.
sentence=ESP8266/ESP32 WLAN configuration at runtime with web interface.
paragraph=A library for easy implementing the Web interface constituting the WLAN for ESP8266 WiFi connection. With this library to make a sketch which connects from ESP8266 to the access point at runtime by the web interface without hardcoded SSID and password.
category=Communication
url=https://github.com/Hieromon/AutoConnect.git
dependencies=ESP8266WebServer, ESP8266WiFi
architectures=esp8266
dependencies=PageBuilder
architectures=esp8266, esp32

@ -1,6 +1,6 @@
# Project information
site_name: 'AutoConnect for ESP8266'
site_description: 'ESP8266 WLAN configuration at run time with web interface'
site_name: 'AutoConnect for ESP8266/ESP32'
site_description: 'ESP8266/ESP32 WLAN configuration at run time with web interface'
site_author: 'Hieromon Ikasamo'
site_url: 'https://Hieromon.github.io/AutoConnect/'

@ -2,11 +2,12 @@
### <i class="fa fa-caret-right"></i> 404 handler
Registering the "not found" handler is a different way than ESP8266WebServer. The *onNotFound* of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides *ESP8266WebServer::onNotFound* to handle a captive portal. To register "not found" handler, use [*AutoConnect::onNotFound*](api.md#onnotfound).
Registering the "not found" handler is a different way than ESP8266WebServer/WebServer. The *onNotFound* of ESP8266WebServer/WebServer does not work with AutoConnect. AutoConnect overrides *ESP8266WebServer::onNotFound*/*WebServer::onNotFound* to handle a captive portal. To register "not found" handler, use [*AutoConnect::onNotFound*](api.md#onnotfound).
### <i class="fa fa-caret-right"></i> Automatic reconnect
When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost.
When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost but then the reconnect behavior of ESP32 is somewhat different from this.
The [WiFiSTAClass::disconnect](https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46) function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the [ESP8266WiFiSTAClass](https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296) has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin() without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core.
If the [**autoReconnect**](api.md#autoreconnect) option of the [**AutoConnectConfig**](api.md#autoconnectconfig-api) class is enabled, it automatically attempts to reconnect to the disconnected past access point. When the autoReconnect option is specified, AutoConnect will not start SoftAP immediately if the first WiFi.begin fails. It will scan WiFi signal and the same connection information as the detected BSSID is stored in EEPROM as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun.
```arduino hl_lines="3"
@ -31,6 +32,9 @@ Portal.config(Config);
Portal.begin();
```
!!! note "In ESP32, the credentials for AutoConnect are not in NVS"
The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the eeprom partition. You can find the partition table for default as [default.csv](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv)
### <i class="fa fa-caret-right"></i> Captive portal start detection
The captive portal will only be activated if the first *WiFi::begin* fails. Sketch can detect with the [*AutoConnect::onDetect*](api.md#ondetect) function that the captive portal has started. For example, the sketch can be written like as follows that turns on the LED at the start captive portal.
@ -124,13 +128,13 @@ and
> EEPROM library uses one sector of flash located [just after the SPIFFS](http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom).
So in the default state, the credential storage area used by AutoConnect conflicts with data 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.
Also, the placement of the EEPROM area of ESP32 is described in the [partition table](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv). So in the default state, the credential storage area used by AutoConnect conflicts with data 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 [**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/WebServer
Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by [*AutoConnect::host()*](api.md#host) function to access ESP8266WebServer instance as like below.
Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer/WebServer inside the AutoConnect. This object variable could be referred by [*AutoConnect::host()*](api.md#host) function to access ESP8266WebServer/WebServer instance as like below.
```arduino hl_lines="4"
AutoConnect Portal;
@ -143,9 +147,9 @@ server.send(200, "text/plain", "Hello, world");
!!! info "When host() is valid"
The host() can be referred at after *AutoConnect::begin*.
### <i class="fa fa-caret-right"></i> Usage for automatically instantiated ESP8266WebServer
### <i class="fa fa-caret-right"></i> Usage for automatically instantiated ESP8266WebServer/WebServer
The sketch can handle URL requests using ESP8266WebServer that AutoConnect started internally. ESP8266WebServer instantiated dynamically by AutoConnect can be referred to by [*AutoConnect::host*](api.md#host) function. The sketch can use the '**on**' function, '**send**' function, '**client**' function and others by ESP8266WebServer reference of its return value.
The sketch can handle URL requests using ESP8266WebServer or WebServer that AutoConnect started internally. ESP8266WebServer/WebServer instantiated dynamically by AutoConnect can be referred to by [*AutoConnect::host*](api.md#host) function. The sketch can use the '**on**' function, '**send**' function, '**client**' function and others by ESP8266WebServer/WebServer reference of its return value.
```arduino hl_lines="8 9 13 14 20 21 27"
#include <ESP8266WiFi.h>
@ -182,11 +186,11 @@ void loop() {
}
```
!!! note "ESP8266WebServer function should be called after AutoConnect::begin"
The sketch cannot refer to an instance of ESP8266WebServer until AutoConnect::begin completes successfully.
!!! note "ESP8266WebServer/WebServer function should be called after AutoConnect::begin"
The sketch cannot refer to an instance of ESP8266WebServer/WebServer until AutoConnect::begin completes successfully.
!!! warning "Do not use with ESP8266WebServer::begin"
ESP8266WebServer is already running inside the AutoConnect.
!!! warning "Do not use with ESP8266WebServer::begin or WebServer::begin"
ESP8266WebServer/WebServer is already running inside the AutoConnect.
### <i class="fa fa-caret-right"></i> Use with the [PageBuilder](https://github.com/Hieromon/PageBuilder) library
@ -235,9 +239,9 @@ A home path of AutoConnect is **/\_ac** by default. You can access from the brow
### <i class="fa fa-caret-right"></i> Static IP assignment [^1]
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*.
It is also possible to assign static IP Address to ESP8266/ESP32 in STA mode. By default DHCP is enabled and it becomes the IP address assigned by the DHCP server with *WiFi.begin*.
To assign a static IP to ESP8266 with WIFI\_MODE\_STA, the following parameters are required:
To assign a static IP to ESP8266/ESP32 with WIFI\_MODE\_STA, the following parameters are required:
- IP address.
- Gateway address.

@ -6,7 +6,7 @@
#include <AutoConnect.h>
```
#### Define macros
#### Defined macros
```cpp
#define AC_DEBUG // Monitor message output activation
@ -34,18 +34,26 @@ AutoConnect()
<a id="withparameter"></a>
AutoConnect default constructor. This entry internally allocates the ESP8266WebServer and is activated internally.
AutoConnect default constructor. This entry internally allocates the ESP8266WebServer for ESP8266 or WebServer for ESP32 and is activated internally.
- For ESP8266
```cpp
AutoConnect(ESP8266WebServer& webServer)
```
Run the AutoConnect site using the externally ensured ESP8266WebServer.
- For ESP32
```cpp
AutoConnect(WebServer& webServer)
```
Run the AutoConnect site using the externally ensured ESP8266WebServer for ESP8266 or WebServer for ESP32.
The [**handleClient**](api.md#handleclient) function of AutoConnect can include the response of the URI handler added by the user using the "*on*" function of ESP8266WebServer. If ESP8266WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the [**host**](api.me#host) function.
The [**handleClient**](api.md#handleclient) function of AutoConnect can include the response of the URI handler added by the user using the "*on*" function of ESP8266WebServer/WebServer. If ESP8266WebServer/WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the [**host**](api.me#host) function.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">webServer</span>A reference of ESP8266WebServer instance.</dd>
<dd><span class="apidef">webServer</span>A reference of ESP8266WebServer or WebServer instance.</dd>
</dl>
### <i class="fa fa-code"></i> Public member functions
@ -56,15 +64,14 @@ The [**handleClient**](api.md#handleclient) function of AutoConnect can include
bool begin()
```
```cpp
bool begin(const char* ssid, const char* passphraase)
bool begin(const char* ssid, const char* passphrase)
```
```cpp
bool begin(const char* ssid, const char* passphraase, unsinged long timeout)
bool begin(const char* ssid, const char* passphrase, unsigned long timeout)
```
Starts establishing the WiFi connection.
AutoConnect first invokes *WiFi.begin*. If the case of SSID and Password missing, its *WiFi.begin* has no SSID and Password. The WiFi mode at this time is WIFI_STA. Then ESP8266WebServer will be started immediately after the first *WiFi.beign* regardless of the result.
Starts establishing the WiFi connection. The WiFi mode at this time is WIFI_STA.
AutoConnect first invokes *WiFi.begin*. If the *ssid* and the *passphrase* are missing, its *WiFi.begin* has no SSID and Password. Regardless of the result, ESP8266WebServer/WebServer will start immediately after the first *WiFi.begin*.
The captive portal will not be started if the connection has been established with first *WiFi.begin*. If the connection cannot establish, switch to WIFI_AP_STA mode and activate SoftAP. Then DNS server starts.
<dl class="apidl">
<dt>**Parameters**</dt>
@ -89,7 +96,7 @@ Set SoftAP's WiFi configuration and static IP configuration.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">config</span>Reference to [**AutoConnectConfig**](api.md#autoconnectconfig) containing SoftAP's parameters and static IP parameters.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The default value is **esp8266ap**.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The default value is **esp8266ap** for ESP8266, **esp32ap** for ESP32.</dd>
<dd><span class="apidef">password</span>Password for SodtAP. The default value is **12345678**.</dd>
<dt>**Return value**</dt>
<dd><span class="apidef">true</span>Successfully configured.</dd>
@ -102,10 +109,10 @@ Set SoftAP's WiFi configuration and static IP configuration.
void end()
```
Stops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer.
Stops AutoConnect captive portal service. Release ESP8266WebServer/WebServer and DNSServer.
!!! warning "Attention to end"
The end function releases the instance of ESP8266WebServer and DNSServer. It can not process them after the end function.
The end function releases the instance of ESP8266WebServer/WebServer and DNSServer. It can not process them after the end function.
#### handleClient
@ -113,7 +120,7 @@ Stops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer
void handleClient()
```
Process the AutoConnect menu interface. It will be processed the client request too contained in the user sketch handler by calling from inside of AutoConnect to the hosted *ESP8266WebServer::handleClient*.
Process the AutoConnect menu interface. The handleClient() function of the ESP8266WebServer/WebServer hosted by AutoConnect is also called from within AutoConnect, and the client request handlers contained in the user sketch are also handled.
#### handleRequest
@ -124,7 +131,7 @@ void handleRequest()
Handling for the AutoConnect menu request.
!!! warning "About used in combination with handleClient"
The handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266::handleClient.
The handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266WebServer::handleClient or WebServer::handleClient.
#### home
@ -140,14 +147,22 @@ Put a user site's home URI. The URI specified by home is linked from "HOME" in t
#### host
Returns the reference of the ESP8266WebServer which is allocated in AutoConnect automatically.
Returns the reference of the ESP8266WebServer/WebServer which is allocated in AutoConnect automatically.
- For ESP8266
```cpp
ESP8266WebServer& host()
```
- For ESP32
```cpp
WebServer& host()
```
<dl class="apidl">
<dt>**Return value**</dt>
<dd>A reference of the ESP8266WebServer.</dd>
<dd>A reference of the ESP8266WebServer/WebServer.</dd>
</dl>
!!! note "&reference is not a pointer"
@ -188,9 +203,17 @@ typedef std::function<bool(IPAddress softapIP)> DetectExit_ft
#### onNotFound
- For ESP8266
```cpp
void onNotFound(ESP8266WebServer::THandlerFunction fn)
```
- For ESP32
```cpp
void onNotFound(WebServer::THandlerFunction fn)
```
Register the handler function for undefined URL request detected.
<dl class="apidl">
<dt>**Parameters**</dt>
@ -211,7 +234,7 @@ AutoConnectConfig(const char* ap, const char* password);
```
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">ap</span>SSID for SoftAP. The length should be up to 31. The default value is **esp8266ap**.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The length should be up to 31. The default value is **esp8266ap** for ESP8266, **esp32ap** for ESP32.</dd>
<dd><span class="apidef">password</span>Password for SodtAP. The length should be from 8 to up to 63. The default value is **12345678**.</dd>
</dl>
@ -234,7 +257,7 @@ Sets IP address for Soft AP in captive portal. When AutoConnect fails the initia
#### autoReconnect
Automatically reconnect to past established access point (BSSID) when the current configured SSID in ESP8266 could not be connected. By enabling this option, *AutoConnect::begin()* function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.
Automatically will try to reconnect with the past established access point (BSSID) when the current configured SSID in ESP8266/ESP32 could not be connected. By enabling this option, *AutoConnect::begin()* function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.
If the connection fails, starts the captive portal in SoftAP + STA mode.
<dl class="apidl">
<dt>**Type**</dt>

@ -2,7 +2,7 @@
### <i class="fa fa-edit"></i> Embed to the sketches
How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps.
How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps. The below sketch is for ESP8266. For ESP32, replace ```ESP8266WebServer``` with ```WebServer``` and ```ESP8266WiFi.h``` with ```WiFi.h``` respectively.
<img src="../images/BeforeAfter.svg" />
@ -31,24 +31,25 @@ Replacement the **handleClient** method is not indispensable. AutoConnect can st
#### 1. A typical logic sequence
!!! note ""
1. <strong>Include headers,</strong> `ESP8266WebServer.h` and `AutoConnect.h`
2. <strong>Declare ESP8266WebServer variable.</strong>
3. <strong>Declare AutoConnect variable.</strong>
4. <strong>Implements the URL handler with the *function()*.</strong>
1. <strong>Include headers,</strong> `ESP8266WebServer.h`/`WebServer.h` and `AutoConnect.h`
2. <strong>Declare an ESP8266WebServer variable for ESP8266 or a WebServer variable for ESP32.</strong>
3. <strong>Declare an AutoConnect variable.</strong>
4. <strong>Implement the URL handlers provided for the </strong>`on`<strong> method of ESP8266WebServer/WebServer with the *function()*.</strong>
5. <strong>setup()</strong>
5.1 <strong>Sets URL handler *function()* to ESP8266WebServer by</strong>`ESP8266WebServer::on`<strong>.</strong>
5.1 <strong>Sets URL handler the *function()* to ESP8266WebServer/WebServer by</strong>`ESP8266WebServer::on`<strong>/</strong>`WebServer::on`<strong>.</strong>
5.2 <strong>Starts </strong>`AutoConnect::begin()`<strong>.</strong>
5.3 <strong>Check WiFi connection status.</strong>
6. <strong>loop()</strong>
6.1 <strong>Invokes </strong>`AutoConnect::handleClient()`<strong>, or invokes </strong>`ESP8266WebServer::handleClient()`<strong> then </strong>`AutoConnect::handleRequest()`<strong>.</strong>
6.2 <strong>Do the process for actual sketch.</strong>
6.1 <strong>Do the process for actual sketch.</strong>
6.2 <strong>Invokes </strong>`AutoConnect::handleClient()`<strong>, or invokes </strong>`ESP8266WebServer::handleClient()`<strong>/</strong>`WebServer::handleClient`<strong> then </strong>`AutoConnect::handleRequest()`<strong>.</strong>
#### 2. Declare AutoConnect object
[Two options](#esp8266webserver-hosted-or-parasitic) are available for [AutoConnect constructor](api.md#constructors).
```arduino
AutoConnect VARIABLE(&ESP8266WebServer);
AutoConnect VARIABLE(&ESP8266WebServer); // For ESP8266
AutoConnect VARIABLE(&WebServer); // For ESP32
```
or
@ -56,51 +57,51 @@ or
AutoConnect VARIABLE;
```
- **The parameter with an ESP8266WebServer variable:** An ESP8266WebServer object variable must be declared. AutoConnect uses its variable to handles the [AutoConnect menu](menu.md).
- **The parameter with an ESP8266WebServer/WebServer variable:** An ESP8266WebServer/WebServer object variable must be declared. AutoConnect uses its variable to handles the [AutoConnect menu](menu.md).
- **With no parameter:** The sketch does not declare ESP8266WebServer object. In this case, AutoConnect allocates an instance of the ESP8266WebServer internally. The logic sequence of the sketch is somewhat different as the above. To register a URL handler function by *ESP8266WebServer::on* should be performed after [*AutoConnect::begin*](api.md#begin).
- **With no parameter:** The sketch does not declare ESP8266WebServer/WebServer object. In this case, AutoConnect allocates an instance of the ESP8266WebServer/WebServer internally. The logic sequence of the sketch is somewhat different as the above. To register a URL handler function by *ESP8266WebServer::on* or *WebServer::on* should be performed after [*AutoConnect::begin*](api.md#begin).
#### 3. No need WiFI.begin(...)
AutoConnect internally performs *WiFi.begin* to establish a WiFi connection. There is no need for a general process to establish a connection using *WiFi.begin* with a sketch code.
#### 4. Alternate ESP8266WebServer::begin()
#### 4. Alternate ESP8266WebServer::begin() and WebServer::begin()
[*AutoConnect::begin*](api.md#begin) executes *ESP8266WebServer::begin* internally too and it starts the DNS server to behave as a Captive portal. So it is not needed to call *ESP8266WebServer::begin* with the sketch.
[*AutoConnect::begin*](api.md#begin) executes *ESP8266WebServer::begin*/*WebServer::begin* internally too and it starts the DNS server to behave as a Captive portal. So it is not needed to call *ESP8266WebServer::begin*/*WebServer::begin* in the sketch.
!!! info "Why DNS Server starts"
AutoConnect traps the detection of the captive portal and achieves a connection with the WLAN interactively by the AutoConnect menu. It responds SoftAP address to all DNS queries temporarily to trap. When the WLAN connection establishes, then stops DNS server.
AutoConnect traps the detection of the captive portal and achieves a connection with the WLAN interactively by the AutoConnect menu. It responds SoftAP address to all DNS queries temporarily to trap. Once a WiFi connection establishes, the DNS server contributed by AutoConnect stops.
#### 5. AutoConnect::begin with SSID and Password
SSID and Password can also specify by [*AutoConnect::begin*](api.me#begin). ESP8266 uses provided SSID and Password explicitly. If the connection false with specified SSID with Password then a captive portal is activated. SSID and Password are not present, ESP8266 SDK will attempt to connect using the still effectual SSID and password. Usually, it succeeds.
SSID and Password can also specify by [*AutoConnect::begin*](api.me#begin). ESP8266/ESP32 uses provided SSID and Password explicitly. If the connection false with specified SSID with Password then a captive portal is activated. SSID and Password are not present, ESP8266 SDK will attempt to connect using the still effectual SSID and password. Usually, it succeeds.
#### 6. Use ESP8266WebServer::on to handle URL
#### 6. Use ESP8266WebServer::on and WebServer::on to handle URL
AutoConnect is designed to coexist with the process for handling the web pages by user sketches. The page processing function which will send an HTML to the client invoked by the "*on::ESP8266WebServer*" function is the same as when using ESP8266WebServer natively.
AutoConnect is designed to coexist with the process for handling the web pages by user sketches. The page processing function which will send an HTML to the client invoked by the "*on::ESP8266WebServer*" or the "*on::WebServer*" function is the same as when using ESP8266WebServer/WebServer natively.
#### 7. Use either ESP8266WebServer::handleClient() or AutoConnect::handleClient()
#### 7. Use either ESP8266WebServer::handleClient()/WebServer::handleClient() or AutoConnect::handleClient()
Both classes member function name is the same: *handleClient*, but the behavior is different. Using the AutoConnect embedded along with ESP8266WebServer::handleClient has limitations. Refer to the below section for details.
Both classes member function name is the same: *handleClient*, but the behavior is different. Using the AutoConnect embedded along with ESP8266WebServer::handleClient/WebServer::handleClient has limitations. Refer to the below section for details.
### <i class="fa fa-caret-right"></i> ESP8266WebServer hosted or parasitic
### <i class="fa fa-caret-right"></i> ESP8266WebServer/WebServer hosted or parasitic
The interoperable process with an ESP8266WebServer depends on the parameters of the [AutoConnect constructor](api.md#constructors).
The interoperable process with an ESP8266WebServer/WebServer depends on the parameters of the [AutoConnect constructor](api.md#constructors).
Declaration parameter for the constructor | Use ESP8266WebServer::handleClient only | Use AutoConnect::handleClient
Declaration parameter for the constructor | Use ESP8266WebServer::handleClient or WebServer::handleClient only | Use AutoConnect::handleClient
----|----|---
[None](api.md#constructors) | AutoConnect menu not available.<br>To use AutoConnect menu, need [AutoConnect::handleRequest()](api.md#handlerequest).<br>also to use ESP8266WebServer natively, need [AutoConnect::host()](api.md#host). | AutoConnect menu available.<br>To use ESP8266WebServer natively, need [AutoConnect::host()](api.md#host).
[Reference to ESP8266WebServer](api.md#withparameter) | AutoConnect menu not available.<br>To use AutoConnect menu, need [AutoConnect::handleRequest()](api.md#handlerequest). | AutoConnect menu available.
[None](api.md#constructors) | AutoConnect menu not available.<br>To use AutoConnect menu, need [AutoConnect::handleRequest()](api.md#handlerequest).<br>also to use ESP8266WebServer/WebServer natively, need [AutoConnect::host()](api.md#host). | AutoConnect menu available.<br>To use ESP8266WebServer/WebServer natively, need [AutoConnect::host()](api.md#host).
[Reference to ESP8266WebServer/WebServer](api.md#withparameter) | AutoConnect menu not available.<br>To use AutoConnect menu, need [AutoConnect::handleRequest()](api.md#handlerequest). | AutoConnect menu available.
- **By declaration for the AutoConnect variable with no parameter**: The ESP8266WebServer instance is hosted by AutoConnect automatically then the sketches use [*AutoConnect::host*](api.md#host) as API to get it after [*AutoConnect::begin*](api.md#begin) performed.
- **By declaration for the AutoConnect variable with no parameter**: The ESP8266WebServer/WebServer instance is hosted by AutoConnect automatically then the sketches use [*AutoConnect::host*](api.md#host) as API to get it after [*AutoConnect::begin*](api.md#begin) performed.
- **By declaration for the AutoConnect variable with the reference of ESP8266WebServer**: AutoConnect will use it. The sketch can use it is too.
- **By declaration for the AutoConnect variable with the reference of ESP8266WebServer/WebServer**: AutoConnect will use it. The sketch can use it is too.
- **In use ESP8266WebServer::handleClient()**: AutoConnect menu can be dispatched but not works normally. It is necessary to call [*AutoConnect::handleRequest*](api.md#void-handlerequest) after *ESP8255WebServer::handleClient* invoking.
- **In use ESP8266WebServer::handleClient()/WebServer::handleClient()**: AutoConnect menu can be dispatched but not works normally. It is necessary to call [*AutoConnect::handleRequest*](api.md#void-handlerequest) after *ESP8255WebServer::handleClient*/*WebServer::handleClient* invoking.
- **In use [AutoConnect::handleClient()](api.md#void-handleclient)**: The handleClient() process and the AutoConnect menu is available without calling *ESP8266WebServer::handleClient*.
!!! info "Why AutoConnect::handleRequest is needed when using ESP8266::handleClient"
The AutoConnect menu function may affect WiFi connection state. It follows that the menu process must execute outside *ESP8266WebServer::handleClient*.
[*AutoConnect::handleClient*](api.md#void-handleclient) is equivalent *ESP8266WebServer::handleClient* included [*AutoConnect::handleRequest*](api.md#void-handlerequest).
!!! info "Why AutoConnect::handleRequest is needed when using ESP8266WebServer::handleClient/WebServer::handleClient"
The AutoConnect menu function may affect WiFi connection state. It follows that the menu process must execute outside *ESP8266WebServer::handleClient* and *WebServer::handleClient*.
[*AutoConnect::handleClient*](api.md#void-handleclient) is equivalent *ESP8266WebServer::handleClient* and *WEbServer::handleClient* included [*AutoConnect::handleRequest*](api.md#void-handlerequest).

@ -1,3 +1,8 @@
#### [0.9.5] Aug.27, 2018.
- Supports ESP32.
- Fixed that crash may occur if the number of stored credentials in the EEPROM is smaller than the number of found WiFi networks.
#### [0.9.4] May 5, 2018.
- Automatically focus passphrase after selecting SSID with Configure New AP.

@ -31,7 +31,7 @@ Declare only AutoConnect, performs handleClient.
## Used with MQTT as a client application
The effect of AutoConnect is not only for ESP8266 as the Web server. It has advantages for something WiFi client as well. For example, AutoConnect is also effective for publishing MQTT messages from various measurement points. Even if the SSID is different for each measurement point, it is not necessary to modify the sketch.
The effect of AutoConnect is not only for ESP8266/ESP32 as the web server. It has advantages for something WiFi client as well. For example, AutoConnect is also effective for publishing MQTT messages from various measurement points. Even if the SSID is different for each measurement point, it is not necessary to modify the sketch.
This example tries to publish the WiFi signal strength of ESP8266 with MQTT. It uses the [ThingSpeak](https://thingspeak.com/) for MQTT broker. ESP8266 publishes the RSSI value to the channel created on ThingSpeak as [MQTT client](https://github.com/knolleary/pubsubclient). This example is well suited to demonstrate the usefulness of AutoConnect, as RSSI values are measured at each access point usually. Just adding a few lines of code makes it unnecessary to upload sketches with the different SSIDs rewrite for each access point.

@ -3,11 +3,11 @@
Open the Arduino IDE, write the following sketch and upload it. The feature of this sketch is that the SSID and Password are not coded.
```arduino
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h> // Replace with WiFi.h for ESP32
#include <ESP8266WebServer.h> // Replace with WebServer.h for ESP32
#include <AutoConnect.h>
ESP8266WebServer Server;
ESP8266WebServer Server; // Replace with WebServer for ESP32
AutoConnect Portal(Server);
void rootPage() {
@ -31,9 +31,14 @@ void loop() {
}
```
!!! note ""
The above code can be applied to ESP8266. To apply to ESP32, replace ```ESP8266WebServer``` class with ```WebServer``` and include ```WiFi.h``` and ```WebServer.h``` of arduino-esp32 appropriately.
### <i class="fa fa-play-circle"></i> Run at first
After about 30 seconds, if the ESP8266 cannot connect to nearby Wi-Fi spot, you pull out your smartphone and open *Wi-Fi settings* from the *Settings* Apps. You can see the **esp8266ap** in the list of *"CHOOSE A NETWORK..."*. Then tap the esp8266ap and enter password **12345678**, a something screen pops up automatically as shown below.
After about 30 seconds, if the ESP8266 cannot connect to nearby Wi-Fi spot, you pull out your smartphone and open *Wi-Fi settings* from the *Settings* Apps. You can see the **esp8266ap** [^1] in the list of *"CHOOSE A NETWORK..."*. Then tap the esp8266ap and enter password **12345678**, a something screen pops up automatically as shown below.
[^1]:When applied to ESP32, SSID will appear as **esp32ap**.
<span style="display:inline-block;width:282px;height:501px;border:1px solid lightgrey;"><img data-gifffer="../images/login_ani.gif" data-gifffer-width="280" style="width:280px;" /></span><img src="../images/arrow_right.svg" style="vertical-align:top;padding-top:120px;width:48px;margin-left:30px;margin-right:30px;" /><img src="../images/stat.png" style="border:1px solid lightgrey;width:280px;" /></span>

@ -1,17 +1,17 @@
# AutoConnect <small>for ESP8266</small>
# AutoConnect <small>for ESP8266/ESP32</small>
An Arduino library for ESP8266 WLAN configuration at run time with web interface.
An Arduino library for ESP8266/ESP32 WLAN configuration at run time with web interface.
## Overview
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class.
Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi connection. With this library to make a sketch easily which connects from ESP8266 to the access point at runtime by the web interface without hard-coded SSID and password.
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class for ESP8266 or *WebServer* class for ESP32.
Easy implementing the Web interface constituting the WLAN for ESP8266/ESP32 WiFi connection. With this library to make a sketch easily which connects from ESP8266/ESP32 to the access point at runtime by the web interface without hard-coded SSID and password.
<img style="display:inline-block;width:460px;margin-right:30px;" src="./images/ov.png" /><span style="display:inline-block;width:182px;height:322px;border:solid 1px lightgrey;"><img data-gifffer="./images/ov.gif" data-gifffer-width="180" style="width:180px;" /></span>
### <i class="fa fa-arrow-circle-right" aria-hidden="true"></i> No need pre-coded SSID &amp; password
<span class="lead">It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.</span>
<span class="lead">It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266/ESP32 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.</span>
### <i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Simple usage
@ -19,7 +19,7 @@ Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi conne
### <i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Store the established connection
<span class="lead">The connection authentication data as credentials are saved automatically in EEPROM of ESP8266 and You can select the past SSID from the [AutoConnect menu](menu.md).</span>
<span class="lead">The connection authentication data as credentials are saved automatically in EEPROM of ESP8266/ESP32 and You can select the past SSID from the [AutoConnect menu](menu.md).</span>
### <i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Easy to embed in
@ -27,7 +27,7 @@ Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi conne
### <i class="fa fa-arrow-circle-right" aria-hidden="true"></i> Lives with the your sketches
<span class="lead">The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.</span>
<span class="lead">The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.<br>This efficacy can also be applied to ESP32. The corresponding class for ESP32 will be the WebServer.</span>
## Installation
@ -43,6 +43,13 @@ Easy implementing the Web interface constituting the WLAN for ESP8266 WiFi conne
* [X] Olimex MOD-WIFI-ESP8266
* [X] SparkFun Thing
* [X] SweetPea ESP-210
* [X] ESP32Dev Board (applying the Espressif's arduino-esp32 core)
* [X] SparkFun ESP32 Thing
* [X] WEMOS LOLIN D32
* [X] Ai-Thinker NodeMCU-32S
* [X] Heltec WiFi Kit 32
* [X] M5Stack
* [X] And other ESP8266/ESP32 modules supported by the Additional Board Manager URLs of the Arduino-IDE.
!!! info "About flash size on the module"
The AutoConnect sketch size is relatively large. Large flash capacity is necessary. 512Kbyte (4Mbits) flash inclusion module such as ESP-01 is not recommended.
@ -60,17 +67,18 @@ The current upstream at the 1.8 level or later is needed. Please install from th
AutoConnect targets sketches made on the assumption of [ESP8266 Community's Arduino core](https://github.com/esp8266/Arduino). The [latest release](https://github.com/esp8266/Arduino/releases/latest) is recommended.
Install third-party platform using the *Boards Manager* of Arduino IDE. Package URL is http://arduino.esp8266.com/stable/package_esp8266com_index.json
<i class="fa fa-download"></i> <strong>ESP32 Arduino core</strong>
Also, to apply AutoConnect to ESP32, the [arduino-esp32 core](https://github.com/espressif/arduino-esp32) provided by Espressif is needed. The [latest release](https://github.com/espressif/arduino-esp32/releases/latest) is recommended.
Install third-party platform using the *Boards Manager* of Arduino IDE. You can add multiple URLs into *Additional Board Manager URLs* field, separating them with commas. Package URL is https://dl.espressif.com/dl/package_esp32_index.json
<i class="fa fa-download"></i> <strong>Additional necessary library</strong>
The [PageBuilder](https://github.com/Hieromon/PageBuilder) library to build HTML for ESP8266WebServer is needed.
To install the PageBuilder library into your Arduino IDE, you can use the *Library Manager*. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '**PageBuilder**' with the topic '**Communication**', then you can see the *PageBuilder*. The latest version or 1.0.0 later is required.
To install the PageBuilder library into your Arduino IDE, you can use the *Library Manager*. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '**PageBuilder**' with the topic '**Communication**', then you can see the *PageBuilder*. The latest version is required 1.1.0 later for ESP32.
<img src="./images/lm.png" width="640"/>
!!! warning "Library Manager of Arduino IDE"
The version of PageBuilder may not have been updated yet. If the library manager shows only version 0.93.0, please install the latest PageBuilder version than 1.0.0 from the Github repository. [The PageBuilder release](https://github.com/Hieromon/PageBuilder/releases/latest) of the Github repository is the latest version. The [PlatformIO library](https://platformio.org/lib/show/2010/PageBuilder) has the latest version of 1.0.0.
In 0.93.0, the PageBuilder class has a compile error about without the 'cancel' method.
### Install the AutoConnect
Clone or download from the [AutoConnect GitHub repository](https://github.com/Hieromon/AutoConnect).
@ -82,7 +90,7 @@ When you select Download, you can import it to Arduino IDE immediately. After do
<img src="./images/ins_lib.png" />
!!! info "Supported by Library manager."
AutoConnect was added to the Arduino IDE library manager as of March 17, 2018. It can be used with the PlatformIO library also.
AutoConnect was added to the Arduino IDE library manager. It can be used with the PlatformIO library also.
<script>
window.onload = function() {

@ -3,11 +3,11 @@
## <i class="fa fa-external-link"></i> Where the from
The AutoConnect menu appears when you access the **AutoConnect root path**. It is assigned "**/_ac**" located on ESP8266 *local IP address* by default. This location can be changed in the sketch. The following screen will appear at access to `http://{localIP}/_ac` as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap <i class="fa fa-bars"></i> at right on top. (e.g. `http://192.168.244.1/_ac` for SoftAP mode.)
The AutoConnect menu appears when you access the **AutoConnect root path**. It is assigned "**/_ac**" located on the *local IP address* of ESP8266/ESP32 module by default. This location can be changed in the sketch. The following screen will appear at access to `http://{localIP}/_ac` as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap <i class="fa fa-bars"></i> at right on top. (e.g. `http://192.168.244.1/_ac` for SoftAP mode.)
<img src="../images/ac.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" />
!!! note "What's local IP?"
!!! note "What's the local IP?"
A local IP means Local IP at connection established or SoftAP's IP.
## <i class="fa fa-bars"></i> Right on top
@ -17,35 +17,35 @@ Currently, AutoConnect supports four menus. Undermost menu as "HOME" returns to
- **Configure new AP**: Configure SSID and Password for new access point.
- **Open SSIDs**: Opens the past SSID which has been established connection from EEPROM.
- **Disconnect**: Disconnects current connection.
- **Reset...**: Rest the ESP8266 module.
- **Reset...**: Rest the ESP8266/ESP32 module.
- **HOME**: Return to user home page.
<img src="../images/menu.png" style="width:280px;" />
## <i class="fa fa-bars"></i> Configure new AP
Scan all available access point and display it. Strength and security of the detected AP are marked. The <i class="fa fa-lock"></i> is indicated for the SSID that needs a security key. "**Hidden:**" means the number of hidden SSIDs discovered.
Enter SSID and Passphrase and tap "**apply**" to starts a connection.
Scan all available access point in the vicinity and display it. Strength and security of the detected AP are marked. The <i class="fa fa-lock"></i> is indicated for the SSID that needs a security key. "**Hidden:**" means the number of hidden SSIDs discovered.
Enter SSID and Passphrase and tap "**apply**" to starts WiFi connection.
<img src="../images/newap.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" />
## <i class="fa fa-bars"></i> Open SSIDs
Once it was established connection, its SSID and Password will be stored to the EEPROM of ESP8266 automatically. The **Open SSIDs** menu reads the saved SSID credentials from the EEPROM. The stored credential data are listed by the SSID as shown below. Its label is a clickable button. Tap the SSID button, starts connection it.
Once it was established WiFi connection, its SSID and password will be saved in EEPROM of ESP8266/ESP32 automatically. The **Open SSIDs** menu reads the saved SSID credentials from the EEPROM. The stored credential data are listed by the SSID as shown below. Its label is a clickable button. Tap the SSID button, starts WiFi connection it.
<img src="../images/open.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" />
## <i class="fa fa-bars"></i> Disconnect
Disconnect ESP8266 from the current connection. It can also reset the ESP8266 automatically after disconnection by instructing with using [API](api.md#autoreset) in the sketch.
Disconnect ESP8266/ESP32 from the current connection. It can also reset the ESP8266/ESP32 automatically after disconnection by instructing with using [API](api.md#autoreset) in the sketch.
After tapping "Disconnect", you will not be able to reach the AutoConnect menu. Once disconnected, you will need to set the SSID again for connecting the WLAN.
## <i class="fa fa-bars"></i> Reset...
Reset the ESP8266, it will start rebooting. After rebooting complete, the ESP8266 begins establishing the previous connection with WIFI_STA mode, and *esp8266ap* of an access point will disappear from WLAN.
Reset the ESP8266/ESP32 module, it will start rebooting. After rebooting complete, the ESP8266/ESP32 module begins establishing the previous connection with WIFI_STA mode, and *esp8266ap* or *esp32ap* of an access point will disappear from WLAN.
<img src="../images/resetting.png" style="width:280px;" />
!!! warning "Not every module will be rebooted normally"
The Reset menu is using the **ESP.reset()** function. This is an almost hardware reset. In order to resume the sketch normally, the [state of GPIO0](https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process#esp-boot-modes) is important. Since this depends on the circuit implementation for each module, not every module will be rebooted normally. See also [FAQ](faq.md#hang-up-after-reset).
!!! warning "Not every ESP8266 module will be rebooted normally"
The Reset menu is using the **ESP.reset()** function for ESP8266. This is an almost hardware reset. In order to resume the sketch normally, the [state of GPIO0](https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process#esp-boot-modes) is important. Since this depends on the circuit implementation for each module, not every module will be rebooted normally. See also [FAQ](faq.md#hang-up-after-reset).

@ -2,12 +2,24 @@
* AutoConnect class implementation.
* @file AutoConnect.cpp
* @author hieromon@gmail.com
* @version 0.9.4
* @date 2018-05-05
* @version 0.9.5
* @date 2018-08-27
* @copyright MIT license.
*/
#include "AutoConnect.h"
#ifdef ARDUINO_ARCH_ESP32
#include <esp_wifi.h>
#endif
/**
* An actual reset function dependent on the architecture
*/
#if defined(ARDUINO_ARCH_ESP8266)
#define SOFT_RESET() ESP.reset()
#elif defined(ARDUINO_ARCH_ESP32)
#define SOFT_RESET() ESP.restart()
#endif
/**
* AutoConnect default constructor. This entry activates WebServer
@ -25,7 +37,7 @@ AutoConnect::AutoConnect() {
* User's added URI handler response can be included in handleClient method.
* @param webServer A reference of ESP8266WebServer instance.
*/
AutoConnect::AutoConnect(ESP8266WebServer& webServer) {
AutoConnect::AutoConnect(WebServerClass& webServer) {
_initialize();
_webServer.reset(&webServer);
_dnsServer.reset(nullptr);
@ -91,7 +103,9 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
AC_DBG("failed\n");
return false;
}
#ifdef ARDUINO_ARCH_ESP8266
AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED");
#endif
// Try to connect by STA immediately.
if (ssid == nullptr && passphrase == nullptr)
@ -126,7 +140,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
// Change WiFi working mode, Enable AP with STA
WiFi.setAutoConnect(false);
WiFi.disconnect();
_disconnectWiFi(true);
WiFi.mode(WIFI_AP_STA);
delay(100);
@ -236,7 +250,7 @@ void AutoConnect::end() {
/**
* Returns the current hosted ESP8266WebServer.
*/
ESP8266WebServer& AutoConnect::host() {
WebServerClass& AutoConnect::host() {
return *_webServer;
}
@ -247,9 +261,9 @@ void AutoConnect::_startWebServer() {
// Boot Web server
if (!_webServer) {
// Only when hosting WebServer internally
_webServer.reset(new ESP8266WebServer(AUTOCONNECT_HTTPPORT));
_webServer.reset(new WebServerClass(AUTOCONNECT_HTTPPORT));
_webServerAlloc = AC_WEBSERVER_HOSTED;
AC_DBG("ESP8266WebServer allocated\n");
AC_DBG("WebServer allocated\n");
}
// Discard the original the not found handler to redirect captive portal detection.
// It is supposed to evacuate but ESP8266WebServer::_notFoundHandler is not accessible.
@ -300,25 +314,27 @@ void AutoConnect::handleRequest() {
// Handling processing requests to AutoConnect.
if (_rfConnect) {
// Leave from the AP currently.
if (WiFi.status() == WL_CONNECTED) {
WiFi.disconnect();
delay(100);
}
if (WiFi.status() == WL_CONNECTED)
_disconnectWiFi(true);
// An attempt to establish a new AP.
AC_DBG("Request for %s\n", (const char*)_credential.ssid);
WiFi.begin((const char*)_credential.ssid, (const char*)_credential.password);
if (_waitForConnect(_portalTimeout) == WL_CONNECTED) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
_currentHostIP = WiFi.localIP();
_redirectURI = String(AUTOCONNECT_URI_SUCCESS);
// Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid);
if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
_currentHostIP = WiFi.localIP();
_redirectURI = String(AUTOCONNECT_URI_SUCCESS);
// Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid);
}
}
else
AC_DBG("%s has no BSSID, saving is unavailable\n", _credential.ssid);
}
else {
_currentHostIP = WiFi.softAPIP();
@ -330,28 +346,24 @@ void AutoConnect::handleRequest() {
if (_rfReset) {
// Reset or disconnect by portal operation result
_stopPortal();
AC_DBG("Reset");
AC_DBG("Reset\n");
delay(1000);
ESP.reset();
SOFT_RESET();
delay(1000);
}
if (_rfDisconnect) {
// Disconnect from the current AP.
_stopPortal();
WiFi.disconnect();
while (WiFi.status() == WL_CONNECTED) {
delay(100);
yield();
}
AC_DBG("Disconnected");
_disconnectWiFi(true);
AC_DBG("Disconnected\n");
// Reset disconnection request, restore the menu title.
_rfDisconnect = false;
_menuTitle = String(AUTOCONNECT_MENU_TITLE);
if (_apConfig.autoReset) {
delay(1000);
ESP.reset();
SOFT_RESET();
delay(1000);
}
}
@ -369,7 +381,7 @@ void AutoConnect::onDetect(DetectExit_ft fn) {
* Register the handler function for undefined url request detected.
* @param fn A function of the not found handler.
*/
void AutoConnect::onNotFound(ESP8266WebServer::THandlerFunction fn) {
void AutoConnect::onNotFound(WebServerClass::THandlerFunction fn) {
_notFoundHandler = fn;
}
@ -380,14 +392,15 @@ void AutoConnect::onNotFound(ESP8266WebServer::THandlerFunction fn) {
bool AutoConnect::_loadAvailCredential() {
AutoConnectCredential credential(_apConfig.boundaryOffset);
if (credential.entries() >= 0) {
if (credential.entries() > 0) {
// Scan the vicinity only when the saved credentials are existing.
int8_t nn = WiFi.scanNetworks(false, true);
AC_DBG("%d network(s) found\n", (int)nn);
if (nn > 0) {
// Determine valid credentials by BSSID.
for (uint8_t i = 0; i < credential.entries(); i++) {
credential.load(i, &_credential);
for (uint8_t n = 0; n <= nn; n++) {
for (uint8_t n = 0; n < nn; n++) {
if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config::bssid)))
return true;
}
@ -411,6 +424,7 @@ void AutoConnect::_stopPortal() {
}
WiFi.softAPdisconnect(false);
AC_DBG("SoftAP stopped\n");
}
/**
@ -577,9 +591,9 @@ bool AutoConnect::_isIP(String ipStr) {
* @retval MAC address string in XX:XX:XX:XX:XX:XX format.
*/
String AutoConnect::_toMACAddressString(const uint8_t mac[]) {
String macAddr = "";
String macAddr = "";
for (uint8_t i = 0; i < 6; i++) {
char buf[3];
char buf[3];
sprintf(buf, "%02X", mac[i]);
macAddr += buf;
if (i < 5)
@ -629,3 +643,17 @@ wl_status_t AutoConnect::_waitForConnect(unsigned long timeout) {
AC_DBG("%s IP:%s\n", wifiStatus == WL_CONNECTED ? "established" : "time out", WiFi.localIP().toString().c_str());
return wifiStatus;
}
/**
* Disconnects the station from an associated access point.
* @param wifiOff The station mode turning switch.
*/
void AutoConnect::_disconnectWiFi(bool wifiOff) {
#if defined(ARDUINO_ARCH_ESP8266)
WiFi.disconnect(wifiOff);
#elif defined(ARDUINO_ARCH_ESP32)
WiFi.disconnect(wifiOff, true);
#endif
while (WiFi.status() == WL_CONNECTED)
delay(100);
}

@ -2,8 +2,8 @@
* Declaration of AutoConnect class and accompanying AutoConnectConfig class.
* @file AutoConnect.h
* @author hieromon@gmail.com
* @version 0.9.4
* @date 2018-05-05
* @version 0.9.5
* @date 2018-08-27
* @copyright MIT license.
*/
@ -14,18 +14,25 @@
#include <memory>
#include <functional>
#include <DNSServer.h>
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <PageBuilder.h>
extern "C" {
#include <user_interface.h>
}
using WebServerClass = ESP8266WebServer;
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
using WebServerClass = WebServer;
#endif
#include <EEPROM.h>
#include <PageBuilder.h>
#include "AutoConnectPage.h"
#include "AutoConnectCredential.h"
// 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
#ifndef AC_DEBUG_PORT
@ -38,7 +45,11 @@ extern "C" {
#endif
#ifndef AUTOCONNECT_APID
#if defined(ARDUINO_ARCH_ESP8266)
#define AUTOCONNECT_APID "esp8266ap"
#elif defined(ARDUINO_ARCH_ESP32)
#define AUTOCONNECT_APID "esp32ap"
#endif
#endif
#ifndef AUTOCONNECT_PSK
@ -199,7 +210,7 @@ class AutoConnectConfig {
class AutoConnect {
public:
AutoConnect();
AutoConnect(ESP8266WebServer& webServer);
AutoConnect(WebServerClass& webServer);
~AutoConnect();
bool config(AutoConnectConfig& Config);
bool config(const char* ap, const char* password = nullptr);
@ -209,11 +220,11 @@ class AutoConnect {
void end();
void handleClient();
void handleRequest();
ESP8266WebServer& host();
WebServerClass& host();
typedef std::function<bool(IPAddress)> DetectExit_ft;
void onDetect(DetectExit_ft fn);
void onNotFound(ESP8266WebServer::THandlerFunction fn);
void onNotFound(WebServerClass::THandlerFunction fn);
protected:
enum _webServerAllocateType {
@ -241,14 +252,17 @@ class AutoConnect {
bool _captivePortal();
bool _isIP(String ipStr);
wl_status_t _waitForConnect(unsigned long timeout);
void _disconnectWiFi(bool wifiOff);
/** Utilities */
static uint32_t _getChipId();
static uint32_t _getFlashChipRealSize();
static String _toMACAddressString(const uint8_t mac[]);
static unsigned int _toWiFiQuality(int32_t rssi);
DetectExit_ft _onDetectExit;
ESP8266WebServer::THandlerFunction _notFoundHandler;
WebServerClass::THandlerFunction _notFoundHandler;
std::unique_ptr<ESP8266WebServer> _webServer;
std::unique_ptr<WebServerClass> _webServer;
std::unique_ptr<DNSServer> _dnsServer;
AC_WEBSERVER_TYPE _webServerAlloc;
@ -321,7 +335,11 @@ class AutoConnect {
String _token_OPEN_SSID(PageArgument& args);
String _token_UPTIME(PageArgument& args);
#if defined(ARDUINO_ARCH_ESP8266)
friend class ESP8266WebServer;
#elif defined(ARDUINO_ARCH_ESP32)
friend class WebServer;
#endif
};
#endif // _AUTOCONNECT_H_

@ -2,7 +2,7 @@
* AutoConnectCredential class implementation.
* @file AutoConnectCredential.cpp
* @author hieromon@gmail.com
* @version 1.0.0
* @version 0.9.5
* @date 2018-02-17
* @copyright MIT license.
*/

@ -2,7 +2,7 @@
* Declaration of AutoConnectCredential class.
* @file AutoConnectCredential.h
* @author hieromon@gmail.com
* @version 1.0.0
* @version 0.9.5
* @date 2018-02-17
* @copyright MIT license.
*/
@ -11,9 +11,20 @@
#define _AUTOCONNECTCREDENTIAL_H_
#include <Arduino.h>
#if defined(ARDUINO_ARCH_ESP8266)
extern "C" {
#include <user_interface.h>
}
#elif defined(ARDUINO_ARCH_ESP32)
#include <esp_wifi.h>
struct station_config {
uint8_t ssid[32];
uint8_t password[64];
uint8_t bssid_set;
uint8_t bssid[6];
wifi_fast_scan_threshold_t threshold;
};
#endif
/** Credential storage area offset specifier in EEPROM.
* By defining AC_IDENTIFIER_OFFSET macro in the user sketch, the credential

@ -2,18 +2,24 @@
* AutoConnect portal site web page implementation.
* @file AutoConnectPage.h
* @author hieromon@gmail.com
* @version 0.9.4
* @date 2018-04-22
* @version 0.9.5
* @date 2018-08-27
* @copyright MIT license.
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include "AutoConnect.h"
#include "AutoConnectPage.h"
#include "AutoConnectCredential.h"
extern "C" {
#include <user_interface.h>
}
#elif defined(ARDUINO_ARCH_ESP32)
#include <esp_spi_flash.h>
#include <WiFi.h>
#define ENC_TYPE_NONE WIFI_AUTH_OPEN
#endif
#include "AutoConnect.h"
#include "AutoConnectPage.h"
#include "AutoConnectCredential.h"
/**< Basic CSS common to all pages */
const char AutoConnect::_CSS_BASE[] PROGMEM = {
@ -723,6 +729,24 @@ const char AutoConnect::_PAGE_DISCONN[] PROGMEM = {
"</html>"
};
uint32_t AutoConnect::_getChipId() {
#if defined(ARDUINO_ARCH_ESP8266)
return ESP.getChipId();
#elif defined(ARDUINO_ARCH_ESP32)
uint64_t chipId;
chipId = ESP.getEfuseMac();
return (uint32_t)(chipId >> 32);
#endif
}
uint32_t AutoConnect::_getFlashChipRealSize() {
#if defined(ARDUINO_ARCH_ESP8266)
return ESP.getFlashChipRealSize();
#elif defined(ARDUINO_ARCH_ESP32)
return (uint32_t)spi_flash_get_chip_size();
#endif
}
String AutoConnect::_token_CSS_BASE(PageArgument& args) {
return String(_CSS_BASE);
}
@ -780,6 +804,11 @@ String AutoConnect::_token_WIFI_MODE(PageArgument& args) {
case WIFI_AP_STA:
wifiMode = "AP_STA";
break;
#ifdef ARDUINO_ARCH_ESP32
case WIFI_MODE_MAX:
wifiMode = "MAX";
break;
#endif
}
return String(wifiMode);
}
@ -789,7 +818,10 @@ String AutoConnect::_token_WIFI_STATUS(PageArgument& args) {
}
String AutoConnect::_token_STATION_STATUS(PageArgument& args) {
uint8_t st;
const char* wlStatusSymbol;
#if defined(ARDUINO_ARCH_ESP8266)
static const char *wlStatusSymbols[] = {
"IDLE",
"CONNECTING",
@ -798,7 +830,7 @@ String AutoConnect::_token_STATION_STATUS(PageArgument& args) {
"CONNECT_FAIL",
"GOT_IP"
};
uint8_t st = wifi_station_get_connect_status();
st = wifi_station_get_connect_status();
switch (st) {
case STATION_IDLE:
wlStatusSymbol = wlStatusSymbols[0];
@ -819,7 +851,44 @@ String AutoConnect::_token_STATION_STATUS(PageArgument& args) {
wlStatusSymbol = wlStatusSymbols[5];
break;
}
return "(" + String(st) + ")" + String(wlStatusSymbol);
#elif defined(ARDUINO_ARCH_ESP32)
static const char *wlStatusSymbols[] = {
"IDLE",
"NO_SSID_AVAIL",
"SCAN_COMPLETED",
"CONNECTED",
"CONNECT_FAILED",
"CONNECTION_LOST",
"DISCONNECTED"
};
st = WiFi.status();
switch (st) {
case WL_IDLE_STATUS:
wlStatusSymbol = wlStatusSymbols[0];
break;
case WL_NO_SSID_AVAIL:
wlStatusSymbol = wlStatusSymbols[1];
break;
case WL_SCAN_COMPLETED:
wlStatusSymbol = wlStatusSymbols[2];
break;
case WL_CONNECTED:
wlStatusSymbol = wlStatusSymbols[3];
break;
case WL_CONNECT_FAILED:
wlStatusSymbol = wlStatusSymbols[4];
break;
case WL_CONNECTION_LOST:
wlStatusSymbol = wlStatusSymbols[5];
break;
case WL_DISCONNECTED:
wlStatusSymbol = wlStatusSymbols[6];
break;
}
#endif
return "(" + String(st) + ") " + String(wlStatusSymbol);
}
String AutoConnect::_token_LOCAL_IP(PageArgument& args) {
@ -864,11 +933,11 @@ String AutoConnect::_token_CPU_FREQ(PageArgument& args) {
}
String AutoConnect::_token_FLASH_SIZE(PageArgument& args) {
return String(ESP.getFlashChipRealSize());
return String(_getFlashChipRealSize());
}
String AutoConnect::_token_CHIP_ID(PageArgument& args) {
return String(ESP.getChipId());
return String(_getChipId());
}
String AutoConnect::_token_FREE_HEAP(PageArgument& args) {
@ -903,22 +972,21 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
struct station_config entry;
String ssidList = "";
uint8_t* bssid = WiFi.BSSID();
for (uint8_t i = 0; i < credit.entries(); i++) {
credit.load(i, &entry);
AC_DBG("A credential #%d loaded\n", (int)i);
ssidList += String(F("<input id=\"sb\" type=\"submit\" name=\"" AUTOCONNECT_PARAMID_CRED "\" value=\"")) + String((char*)entry.ssid) + String(F("\">"));
ssidList += String(F("<label>"));
if (memcmp(WiFi.BSSID(), entry.bssid, sizeof(station_config::bssid)) == 0) {
if (bssid != NULL && memcmp(bssid, entry.bssid, sizeof(station_config::bssid)) == 0)
ssidList += String(AutoConnect::_toWiFiQuality(WiFi.RSSI())) + String("%");
}
else {
else
ssidList += String("N/A");
}
ssidList += String(F("</label><br>"));
}
if (ssidList.length() == 0) {
ssidList = String(PSTR("<p><b>No credential saved.</b></p>"));
ssidList = String(PSTR("<p><b>No saved credentials.</b></p>"));
}
return ssidList;
}

Loading…
Cancel
Save