Supports lower RSSI limit.

pull/200/head
Hieromon Ikasamo 4 years ago
parent 0f81aab9db
commit 8eda9af698
  1. 13
      mkdocs/advancedusage.md
  2. 142
      mkdocs/images/process_begin.svg
  3. 8
      mkdocs/lsbegin.md

@ -14,11 +14,11 @@ AutoConnect stores the established WiFi connection in the flash of the ESP8266/E
### <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 but then the reconnect behavior of ESP32 is somewhat different from this.
AutoConnect changes WIFI mode depending on the situation. The [AutoConnect::begin](lsbegin.md) function starts WIFI in STA mode and starts the webserver if the connection is successful by the 1st-WiFi.begin. But if the connection fails with the least recently established access point, AutoConnect will switch the WIFI mode to AP_STA and starts the DNS server to be able to launch a captive portal.
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.
When the captive portal is started, SoftAP starts and the STA is disconnected. At this point, the station configuration information that the ESP module has stored on its own (it is known as the SDK's [station_config](https://github.com/esp8266/Arduino/blob/db75d2c448bfccc6dc308bdeb9fbd3efca7927ff/tools/sdk/include/user_interface.h#L249) structure) is discarded.
If the [**autoReconnect**](apiconfig.md#autoreconnect) option of the [AutoConnectConfig](apiconfig.md) 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 the flash as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun.
AutoConnect can connect to an access point again using saved credential that has disconnected once, and its control is allowed by [**autoReconnect**](apiconfig.md#autoreconnect). [*AutoConnectConfig::autoReconnect*](apiconfig.md#autoreconnect) option specifies to attempt to reconnect to the past established access point that stored in saved credentials. AutoConnect does not start SoftAP immediately even if 1st-WiFi.begin fails when the [**autoReconnct**](apiconfig.md#autoreconnect) is enabled. It will scan the WiFi signal, and if the same BSSID as the detected BSSID is stored in flash as AutoConnect credentials, explicitly apply it and reruns WiFi.begin still WIFI_STA mode. (The autoReconnect works effectively even if the SSID is a hidden access point)
```cpp hl_lines="3"
AutoConnect Portal;
@ -28,10 +28,11 @@ Portal.config(Config);
Portal.begin();
```
An autoReconnect option is available to *AutoConnect::begin* without SSID and pass Passphrase.
An [**autoRecconect**](apiconfig.md#autoreconnect) option is only available for [*AutoConnect::begin*](api.md#begin) without SSID and PASSWORD parameter.
!!! caution "An autoReconnect will work if SSID detection succeeded"
An autoReconnect will not effect if the SSID which stored credential to be connected is a hidden access point.
!!! note "An autoReconnect is not autoreconnect"
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 the arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core.
### <i class="fa fa-caret-right"></i> Autosave Credential

@ -9,12 +9,12 @@
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="109mm"
width="104.57415mm"
height="371.83472mm"
viewBox="0 0 108.99999 371.83472"
viewBox="0 0 104.57414 371.83472"
version="1.1"
id="svg8776"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="process_begin.svg">
<defs
id="defs8770">
@ -248,8 +248,8 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4142136"
inkscape:cx="259.43725"
inkscape:cy="1200.0696"
inkscape:cx="305.90966"
inkscape:cy="637.13379"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
@ -261,23 +261,24 @@
inkscape:snap-smooth-nodes="true"
inkscape:snap-midpoints="false"
inkscape:bbox-paths="true"
inkscape:bbox-nodes="true"
inkscape:bbox-nodes="false"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:snap-bbox-midpoints="true"
inkscape:window-width="1571"
inkscape:window-width="1920"
inkscape:window-height="1013"
inkscape:window-x="1376"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:window-x="2551"
inkscape:window-y="-9"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0">
fit-margin-bottom="0"
showguides="true">
<inkscape:grid
type="xygrid"
id="grid9104"
originx="-23.664512"
originy="15.544259" />
originx="-23.664533"
originy="15.544253" />
</sodipodi:namedview>
<metadata
id="metadata8773">
@ -295,10 +296,10 @@
inkscape:label="レイヤー 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-23.664512,59.290411)">
transform="translate(-23.664535,59.290408)">
<path
style="fill:none;stroke:#000000;stroke-width:0.26458341px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 58.208337,-11.256129 v 3.8405916"
d="M 58.208337,4.6230754 V 8.463667"
id="path9639-8-5-5"
inkscape:connector-curvature="0" />
<path
@ -316,8 +317,8 @@
transform="translate(-15.875002,-48.749459)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="159.70068"
x="238.01735"
height="18.355465"
@ -341,8 +342,8 @@
transform="translate(-42.333331,28.77345)">
<rect
transform="matrix(0.945946,0.32432418,-0.945946,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="50.674988"
x="156.96188"
height="18.355465"
@ -443,8 +444,8 @@
transform="translate(-15.875002,18.719279)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="159.70068"
x="238.01735"
height="18.355465"
@ -608,8 +609,8 @@
transform="translate(-79.374976,29.567202)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="219.95329"
x="365.3985"
height="18.355465"
@ -672,8 +673,8 @@
transform="translate(-15.875002,120.84858)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="159.70068"
x="238.01735"
height="18.355465"
@ -697,8 +698,8 @@
transform="translate(0,31.948452)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="335.73843"
x="397.27298"
height="18.355465"
@ -858,7 +859,7 @@
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458329px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 40.91184,26.461738 23.796883,26.338925 23.878643,163.58402 H 58.274475"
d="m 40.91184,-29.09866 -17.114957,-0.172561 0.08176,192.839591 h 34.395832"
id="path10088-9"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
@ -939,24 +940,24 @@
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="34.062004"
y="25.63336"
x="34.591171"
y="-29.929094"
id="text10760"><tspan
sodipodi:role="line"
id="tspan10758"
x="34.062004"
y="25.63336"
x="34.591171"
y="-29.929094"
style="stroke-width:0.26458332">YES</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="60.544109"
y="35.014442"
x="60.12553"
y="-20.668676"
id="text10760-5"><tspan
sodipodi:role="line"
id="tspan10758-9"
x="60.544109"
y="35.014442"
x="60.12553"
y="-20.668676"
style="stroke-width:0.26458332">NO</tspan></text>
<text
xml:space="preserve"
@ -1095,8 +1096,8 @@
transform="translate(0.132299)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="25.565748"
x="86.960411"
height="18.355465"
@ -1122,11 +1123,11 @@
inkscape:connector-curvature="0" />
<g
id="g9322"
transform="translate(-25.135403,-130.96875)">
transform="translate(-25.135403,-186.53117)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="189.47736"
x="277.58359"
height="18.355465"
@ -1243,7 +1244,7 @@
</g>
<g
id="g1197"
transform="translate(-0.22278483,12.761983)">
transform="translate(-0.22278483,28.641187)">
<rect
ry="0.26458257"
rx="0.26458332"
@ -1265,7 +1266,8 @@
sodipodi:role="line">WiFi.config (STA)</tspan></text>
</g>
<g
id="g1141">
id="g1141"
transform="translate(0,15.879204)">
<rect
ry="0.26458257"
rx="0.26458332"
@ -1288,7 +1290,7 @@
</g>
<path
style="fill:none;stroke:#000000;stroke-width:0.26458341px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 58.208332,-27.002966 v 3.840593"
d="m 58.208332,-11.123762 v 3.8405934"
id="path9639-8-5"
inkscape:connector-curvature="0" />
<path
@ -1298,11 +1300,11 @@
inkscape:connector-curvature="0" />
<g
id="g2166"
transform="translate(-30.682548,-13.096212)">
transform="translate(-30.682548,2.7829924)">
<rect
transform="matrix(0.94594599,0.32432418,-0.94594599,0.32432418,0,0)"
ry="3.6888673e-006"
rx="3.6888673e-006"
ry="3.6888673e-06"
rx="3.6888673e-06"
y="-62.503849"
x="31.466501"
height="18.355465"
@ -1328,22 +1330,22 @@
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458338px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 58.208337,4.6271392 v 3.840592"
d="m 58.208337,20.506344 v 3.840592"
id="path9639-0"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458341px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 58.208337,0.78654773 V 4.6271395"
d="m 58.208333,-23.145787 v 3.840592"
id="path9639-0-5"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458341px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 58.208332,-39.045645 v 3.840594"
d="m 58.208335,-39.045647 v 3.993608"
id="path9639-8-5-6"
inkscape:connector-curvature="0" />
<g
id="g2200"
transform="translate(-37.753577,2.3026717)">
transform="translate(-37.753577,18.181876)">
<rect
ry="0.26458257"
rx="0.26458332"
@ -1366,7 +1368,7 @@
</g>
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 40.84505,-17.209253 -10.258285,-0.0196 0.01789,22.0368617 h 27.461784"
d="m 40.84505,-1.3300486 -10.258285,-0.0196 0.01789,22.0368616 h 27.461784"
id="path10088-9-7-3"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
@ -1374,55 +1376,55 @@
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="35.828152"
y="-18.166817"
y="-2.2876122"
id="text10760-5-3"><tspan
sodipodi:role="line"
id="tspan10758-9-2"
x="35.828152"
y="-18.166817"
y="-2.2876122"
style="stroke-width:0.26458332">NO</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="60.096973"
y="-8.7963543"
y="7.08285"
id="text10760-57"><tspan
sodipodi:role="line"
id="tspan10758-6"
x="60.096973"
y="-8.7963543"
y="7.08285"
style="stroke-width:0.26458332">YES</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:'Times New Roman';-inkscape-font-specification:'Times New Roman, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="79.585876"
y="-32.471371"
x="79.343994"
y="-18.098808"
id="text9138-7-3-9-9-90-9"><tspan
sodipodi:role="line"
id="tspan1283"
x="79.585876"
y="-32.471371">Loads saved credentials from the flash</tspan><tspan
x="79.343994"
y="-18.098808">Loads saved credentials from the flash</tspan><tspan
sodipodi:role="line"
id="tspan1285"
x="79.585876"
y="-28.502621">that matches the last SSID stored in</tspan><tspan
x="79.343994"
y="-14.130058">that matches the last SSID stored in</tspan><tspan
sodipodi:role="line"
id="tspan1287"
x="79.585876"
y="-24.533871">the ESP module. </tspan></text>
x="79.343994"
y="-10.161308">the ESP module. </tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:serif;-inkscape-font-specification:'serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="79.543159"
y="-14.876924"
x="79.354843"
y="-1.560024"
id="text9138-7-3-9-9-90-9-7"><tspan
sodipodi:role="line"
id="tspan1289"
x="79.543159"
y="-14.876924">If that credential has a static IP,</tspan><tspan
x="79.354843"
y="-1.560024">If that credential has a static IP,</tspan><tspan
sodipodi:role="line"
id="tspan1291"
x="79.543159"
y="-10.908174">restore it.</tspan></text>
x="79.354843"
y="2.408726">restore it.</tspan></text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

@ -1,17 +1,17 @@
## AutoConnect::begin logic sequence
Several parameters as follows of [AutoConnectConfig](apiconfig.md) affect the behavior of [AutoConnect::begin](api.md#begin) function. Each parameter affects the behaves in interacted order with the priority and apply to the logic sequence of [AutoConnect::begin](api.md#begin).
The following parameters of [AutoConnectConfig](apiconfig.md) affect the behavior of [AutoConnect::begin](api.md#begin) function and control a logic sequence. They are also evaluated on a case-by-case basis and may not be valid in all situations. The sketch must consider the role of these parameters and the conditions under which they will work as intended. You need to understand what happens when using these parameters in combination.
- [immediateStart](apiconfig.md#immediatestart) : The captive portal start immediately, without first WiFi.begin.
- [immediateStart](apiconfig.md#immediatestart) : The captive portal start immediately, without the 1st-WiFi.begin.
- [autoReconenct](apiconfig.md#autoreconnect) : Attempt re-connect with past SSID by saved credential.
- [portalTimeout](apiconfig.md#portaltimeout) : Time out limit for the portal.
- [retainPortal](apiconfig.md#retainportal) : Keep DNS server functioning for the captive portal.
You can use these parameters in combination with sketch requirements and need to understand correctly the behavior caused by the parameters. The following chart shows the AutoConnect::begin logic sequence including the effect of these parameters.
The following chart shows the AutoConnect::begin logic sequence that contains the control flow with each parameter takes effect.
<img align="center" src="images/process_begin.svg">
For example, [AutoConnect::begin](api.md#begin) will not exits without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. A DNS server that detects the probe of the captive portal is also effective. So, your sketch may work seemingly, but it will close with inside a loop of the [AutoConnect::begin](api.md#begin) function. Especially when invoking [AutoConnect::begin](api.md#begin) in the **setup()**, execution control does not pass to the **loop()**.
For example, [AutoConnect::begin](api.md#begin) will not end without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. And the DNS server also will start to make the captive portal detection to the client. The custom web page now responds correctly with the behavior of the two internally launched servers, and the sketch looks like working. But AutoConnect::begin does not end yet. Especially when invoking AutoConnect::begin in the **setup()**, control flow does not pass to the **loop()**.
As different scenes, you may use the [**immediateStart**](apiconfig.md#immediatestart) effectively. Equipped the external switch to activate the captive portal with the ESP module, combined with the [**portalTime**](apiconfig.md#portaltimeout) and the [**retainPortal**](apiconfig.md#retainportal) it will become WiFi active connection feature. You can start [AutoConnect::begin](api.md#begin) at any point in the **loop()**, which allows your sketch can behave both the offline mode and the online mode.

Loading…
Cancel
Save