From 8ad3f52bbfdebe97e7e17d951ad3b4362a30d7f0 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Sun, 6 May 2018 20:16:39 +0900 Subject: [PATCH] Supports autoReconnect --- README.md | 3 ++ docs/advancedusage/index.html | 25 +++++++++++++++ docs/api/index.html | 32 ++++++++++++++++++- docs/changelog/index.html | 22 +++++++++++-- docs/search/search_index.json | 25 ++++++++++++--- docs/sitemap.xml | 20 ++++++------ examples/Simple/Simple.ino | 9 ++++++ mkdocs/advancedusage.md | 15 +++++++++ mkdocs/api.md | 20 +++++++++++- mkdocs/changelog.md | 4 +++ src/AutoConnect.cpp | 60 ++++++++++++++++++++++++----------- src/AutoConnect.h | 12 ++++--- 12 files changed, 206 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 9e0f564..1de6c69 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,9 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some ## Change log +### [0.9.4] May 5, 2018. +- 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. + ### [0.9.3] March 23, 2018. - Supports a static IP address assignment. diff --git a/docs/advancedusage/index.html b/docs/advancedusage/index.html index b794657..a01c634 100644 --- a/docs/advancedusage/index.html +++ b/docs/advancedusage/index.html @@ -365,6 +365,13 @@ 404 handler + + +
  • + + Automatic reconnect + +
  • @@ -578,6 +585,13 @@ 404 handler +
  • + +
  • + + Automatic reconnect + +
  • @@ -711,6 +725,17 @@

    Advanced usage

    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.

    +

    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.
    +If the autoReconnect option of the AutoConnectConfig 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.

    +
    AutoConnect       Portal;
    +AutoConnectConfig Config;
    +Config.autoReconnect = true;
    +Portal.config(Config);
    +Portal.begin();
    +
    + +

    An autoReconnect option is available to AutoConnect::begin without SSID and pass passphrase.

    Auto save Credential

    By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the autoSave parameter specified by AutoConnectConfig.

    AutoConnect       Portal;
    diff --git a/docs/api/index.html b/docs/api/index.html
    index b7ffd52..d803df1 100644
    --- a/docs/api/index.html
    +++ b/docs/api/index.html
    @@ -554,6 +554,13 @@
         apip
       
       
    +
  • + +
  • + + autoReconnect + +
  • @@ -952,6 +959,13 @@ apip +
  • + +
  • + + autoReconnect + +
  • @@ -1186,7 +1200,7 @@ AutoConnect first invokes WiFi.begin. If the case of SSID and Password
    void handleClient()
     
    -

    Process the AutoConnect menu interface. It will be processed the client request too contained in the user sketch handler by calling the host handleClient::ESP8266WebServer from the Autoconnect internally.

    +

    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.

    handleRequest

    void handleRequest()
     
    @@ -1275,6 +1289,21 @@ Register the handler function for undefined URL request detected.
    Type
    IPAddressThe default value is 192.168.244.1

    +

    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.
    +If the connection fails, starts the captive portal in SoftAP + STA mode.
    +

    +
    Type
    +
    bool
    +
    Value
    +
    trueReconnect automatically.
    +
    falseStarts Captive Portal in SoftAP + STA mode without trying to reconnect. This is the default.
    +

    +

    When the autoReconnect option is enabled, an automatic connection will behave if the following conditions are satisfied.

    +

    autoReset

    Reset ESP8266 module automatically after WLAN disconnected.

    @@ -1395,6 +1424,7 @@ The default value is 0. Config.apip = IPAddress(192,168,10,101); // Sets SoftAP IP address Config.gateway = IPAddress(192,168,10,1); // Sets WLAN router IP address Config.netmask = IPAddress(255,255,255,0); // Sets WLAN scope +Config.autoReconnect = true; // Enable auto-reconnect Config.autoSave = AC_SAVECREDENTIAL_NEVER; // No save credential COnfig.boundaryOffet = 64; // Reserve 64 bytes for the user data in EEPROM. Config.homeUri = "/index.html" // Sets home path of the sketch application diff --git a/docs/changelog/index.html b/docs/changelog/index.html index ee582f8..a29afdc 100644 --- a/docs/changelog/index.html +++ b/docs/changelog/index.html @@ -101,7 +101,7 @@ - + Skip to content @@ -400,6 +400,13 @@
      +
    • + + [0.9.4] May 5, 2018. + + +
    • +
    • [0.9.3] March 23, 2018. @@ -462,6 +469,13 @@
        +
      • + + [0.9.4] May 5, 2018. + + +
      • +
      • [0.9.3] March 23, 2018. @@ -502,7 +516,11 @@

        Change log

        -

        [0.9.3] March 23, 2018.

        +

        [0.9.4] May 5, 2018.

        +
          +
        • 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.
        • +
        +

        [0.9.3] March 23, 2018.

        • Supports a static IP address assignment.
        diff --git a/docs/search/search_index.json b/docs/search/search_index.json index ea2faa8..07de4ac 100644 --- a/docs/search/search_index.json +++ b/docs/search/search_index.json @@ -197,7 +197,7 @@ }, { "location": "/advancedusage/index.html", - "text": "Advanced usage\n\u00b6\n\n\n 404 handler\n\u00b6\n\n\nRegistering the \"not found\" handler is a different way than ESP8266WebServer. The \nonNotFound\n of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides \nESP8266WebServer::onNotFound\n to handle a captive portal. To register \"not found\" handler, use \nAutoConnect::onNotFound\n.\n\n\n Auto save Credential\n\u00b6\n\n\nBy default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the \nautoSave\n parameter specified by \nAutoConnectConfig\n.\n\n\nAutoConnect\n \nPortal\n;\n\n\nAutoConnectConfig\n \nConfig\n;\n\n\nConfig\n.\nautoSave\n \n=\n \nAC_SAVECREDENTIAL_NEVER\n;\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n\n\nPortal\n.\nbegin\n();\n\n\n\n\n\n Captive portal start detection\n\u00b6\n\n\nThe captive portal will only be activated if the first \nWiFi::begin\n fails. Sketch can detect with the \nAutoConnect::onDetect\n 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.\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nbool\n \nstartCP\n(\nIPAddress\n \nip\n)\n \n{\n\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nHIGH\n);\n\n \nSerial\n.\nprintln\n(\n\"C.P. started, IP:\"\n \n+\n \nWiFi\n.\nlocalIP\n().\ntoString\n());\n\n \nreturn\n \ntrue\n;\n\n\n}\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nSerial\n.\nbegin\n(\n115200\n);\n\n \npinMode\n(\nBUILTIN_LED\n,\n \nOUTPUT\n);\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nLOW\n);\n\n\n \nPortal\n.\nonDetect\n(\nstartCP\n);\n\n\n \nif\n \n(\nPortal\n.\nbegin\n())\n \n{\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nLOW\n);\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n \nPortal\n.\nhandleClient\n();\n\n\n}\n\n\n\n\n\n Combination with mDNS\n\u00b6\n\n\nWith \nmDNS library\n, you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after \nAutoConnect::begin\n.\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n#include\n \n\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nif\n \n(\nPortal\n.\nbegin\n())\n \n{\n\n\n \nif\n \n(\nMDNS\n.\nbegin\n(\n\"esp8266\"\n))\n \n{\n\n\n \nMDNS\n.\naddService\n(\n\"http\"\n,\n \n\"tcp\"\n,\n \n80\n);\n\n\n \n}\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n \nPortal\n.\nhandleClient\n();\n\n\n}\n\n\n\n\n\n Debug print\n\u00b6\n\n\nYou can output AutoConnect monitor messages to the \nSerial\n. A monitor message activation switch is in an include header file \nAutoConnect.h\n of library source. Define \nAC_DEBUG\n macro to output the monitor messages.\n\n\n#define AC_DEBUG\n\n\n\n\n\n Disable the captive portal\n\u00b6\n\n\nIt can also prevent the captive portal from starting even if the connection at the first \nWiFi.begin\n fails. In this case, \nAutoConnect::begin\n behaves same as \nWiFi.begin\n.\n\n\nFor disabling the captive portal, \nautoRise\n sets to false with \nAutoConnectConfig\n.\n\n\nAutoConnect\n \nportal\n;\n\n\nAutoConnectConfig\n \nacConfig\n;\n\n\n\nacConfig\n.\nautoRaise\n \n=\n \nfalse\n;\n\n\nportal\n.\nconfig\n(\nacConfig\n);\n\n\nportal\n.\nbegin\n();\n\n\n\n\n\n Move the saving area of EEPROM for the credentials\n\u00b6\n\n\nBy default, the credentials saving area is occupied from the beginning of EEPROM area. \nESP8266 Arduino core document\n says that:\n\n\n\n\nThe following diagram illustrates flash layout used in Arduino environment:\n\n\n\n\n\n\n\n \n|--------------|-------|---------------|--|--|--|--|--|\n\n \n^\n \n^\n \n^\n \n^\n \n^\n\n \nSketch\n \nOTA\n \nupdate\n \nFile\n \nsystem\n \nEEPROM\n \nWiFi\n \nconfig\n \n(\nSDK\n)\n\n\n\n\n\n\n\nand\n\n\n\n\nEEPROM library uses one sector of flash located \njust after the SPIFFS\n.\n\n\n\n\nSo 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.\n\n\nThe \nboundaryOffset\n in \nAutoConnectConfig\n specifies the start offset of the credentials storage area. The default value is 0.\n\n\n Refers the hosted ESP8266WebServer\n\u00b6\n\n\nConstructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by \nAutoConnect::host()\n function to access ESP8266WebServer instance as like below.\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nPortal\n.\nbegin\n();\n\n\nESP8266WebServer\n&\n \nserver\n \n=\n \nPortal\n.\nhost\n();\n\n\nserver\n.\nsend\n(\n200\n,\n \n\"text/plain\"\n,\n \n\"Hello, world\"\n);\n\n\n\n\n\n\n\nWhen host() is valid\n\n\nThe host() can be referred at after \nAutoConnect::begin\n.\n\n\n\n\n Usage for automatically instantiated ESP8266WebServer\n\u00b6\n\n\nThe sketch can handle URL requests using ESP8266WebServer that AutoConnect started internally. ESP8266WebServer instantiated dynamically by AutoConnect can be referred to by \nAutoConnect::host\n function. The sketch can use the '\non\n' function, '\nsend\n' function, '\nclient\n' function and others by ESP8266WebServer reference of its return value.\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nvoid\n \nhandleRoot\n()\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\nsend\n(\n200\n,\n \n\"text/html\"\n,\n \n\"Hello, world\"\n);\n\n\n}\n\n\n\nvoid\n \nhandleNotFound\n()\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\nsend\n(\n404\n,\n \n\"text/html\"\n,\n \n\"Unknown.\"\n);\n\n\n}\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nbool\n \nr\n \n=\n \nPortal\n.\nbegin\n();\n\n \nif\n \n(\nr\n)\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\non\n(\n\"/\"\n,\n \nhandleRoot\n);\n\n\n \nPortal\n.\nonNotFound\n(\nhandleNotFound\n);\n \n// For only onNotFound.\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n\n \nPortal\n.\nhost\n().\nhandleClient\n();\n\n\n \nPortal\n.\nhandleRequest\n();\n\n \n/* or following one line code is equ.\n\n\n Portal.handleClient();\n\n\n */\n\n\n}\n\n\n\n\n\n\n\nESP8266WebServer function should be called after AutoConnect::begin\n\n\nThe sketch cannot refer to an instance of ESP8266WebServer until AutoConnect::begin completes successfully.\n\n\n\n\n\n\nDo not use with ESP8266WebServer::begin\n\n\nESP8266WebServer is already running inside the AutoConnect.\n\n\n\n\n Use with the \nPageBuilder\n library\n\u00b6\n\n\nIn ordinary, the URL handler will respond the request by sending some HTML. \nPageBuilder\n 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.\n\n\nAn example sketch used with the PageBuilder as follows and it explains how it aids for the HTML generating. Details for \nGithub repository\n.\n\n\n\n\nConfiguration functions\n\u00b6\n\n\n Configuration for Soft AP\n\u00b6\n\n\nAutoConnect will activate SoftAP at failed the first \nWiFi.begin\n. It SoftAP settings are stored in \nAutoConnectConfig\n as the following parameters. The sketch could be configured SoftAP using these parameters, refer the \nAutoConnectConfig API\n for details.\n\n\n\n\nIP address of SoftAP activated.\n\n\nGateway IP address.\n\n\nSubnet mask.\n\n\nSSID for SoftAP.\n\n\nPassword for SoftAP.\n\n\nChannel.\n\n\nHidden attribute.\n\n\nAuto save credential.\n\n\nOffset address of the credentials storage area in EEPROM.\n\n\nLength of start up time after reset.\n\n\nAutomatic starting the captive portal.\n\n\nAuto reset after connection establishment.\n\n\nHome URL of the user sketch application.\n\n\n\n\n\n\nAutoConnect::config before AutoConnect::begin\n\n\nAutoConnect::config\n must be executed before \nAutoConnect::begin\n.\n\n\n\n\n Assign user sketch's home path\n\u00b6\n\n\n\"\nHOME\n\" for returning to the user's sketch homepage is displayed at the bottom of the AutoConnect menu. It could be set using the \nAutoConnect::home\n function.\n\n\n\n\n Relocate the AutoConnect home path\n\u00b6\n\n\nA home path of AutoConnect is \n/_ac\n by default. You can access from the browser with http://IPADDRESS/_ac. You can change the home path by revising \nAUTOCONNECT_URI\n macro in the include header file as \nAutoConnect.h\n.\n\n\n#define AUTOCONNECT_URI \"/_ac\"\n\n\n\n\n\n Static IP assignment \n1\n\u00b6\n\n\nIt 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 \nWiFi.begin\n.\n\n\nTo assign a static IP to ESP8266 with WIFI_MODE_STA, the following parameters are required:\n\n\n\n\nIP address.\n\n\nGateway address.\n\n\nSubnet mask.\n\n\nPrimary DNS server.\n\n\nSecondary DNS server. (optional)\n\n\n\n\nThe above parameters must be executed before \nAutoConnect::begin\n as \narguments of AutoConnectConfig\n.\n\n\nAutoConnect\n \nportal\n;\n\n\nAutoConnectConfig\n \nConfig\n;\n\n\nConfig\n.\nstaip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n10\n);\n\n\nConfig\n.\nstaGateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n1\n);\n\n\nConfig\n.\nstaNetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n\n\nConfig\n.\ndns1\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n1\n);\n\n\nportal\n.\nconfig\n(\nConfig\n);\n\n\nportal\n.\nbegin\n();\n\n\n\n\n\n\n\n\n\n\n\n\n\nStatic IP address assignment is available from version 0.9.3.\u00a0\n\u21a9", + "text": "Advanced usage\n\u00b6\n\n\n 404 handler\n\u00b6\n\n\nRegistering the \"not found\" handler is a different way than ESP8266WebServer. The \nonNotFound\n of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides \nESP8266WebServer::onNotFound\n to handle a captive portal. To register \"not found\" handler, use \nAutoConnect::onNotFound\n.\n\n\n Automatic reconnect\n\u00b6\n\n\nWhen the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost.\n\nIf the \nautoReconnect\n option of the \nAutoConnectConfig\n 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.\n\n\nAutoConnect\n \nPortal\n;\n\n\nAutoConnectConfig\n \nConfig\n;\n\n\nConfig\n.\nautoReconnect\n \n=\n \ntrue\n;\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n\n\nPortal\n.\nbegin\n();\n\n\n\n\n\nAn autoReconnect option is available to \nAutoConnect::begin\n without SSID and pass passphrase.\n\n\n Auto save Credential\n\u00b6\n\n\nBy default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the \nautoSave\n parameter specified by \nAutoConnectConfig\n.\n\n\nAutoConnect\n \nPortal\n;\n\n\nAutoConnectConfig\n \nConfig\n;\n\n\nConfig\n.\nautoSave\n \n=\n \nAC_SAVECREDENTIAL_NEVER\n;\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n\n\nPortal\n.\nbegin\n();\n\n\n\n\n\n Captive portal start detection\n\u00b6\n\n\nThe captive portal will only be activated if the first \nWiFi::begin\n fails. Sketch can detect with the \nAutoConnect::onDetect\n 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.\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nbool\n \nstartCP\n(\nIPAddress\n \nip\n)\n \n{\n\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nHIGH\n);\n\n \nSerial\n.\nprintln\n(\n\"C.P. started, IP:\"\n \n+\n \nWiFi\n.\nlocalIP\n().\ntoString\n());\n\n \nreturn\n \ntrue\n;\n\n\n}\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nSerial\n.\nbegin\n(\n115200\n);\n\n \npinMode\n(\nBUILTIN_LED\n,\n \nOUTPUT\n);\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nLOW\n);\n\n\n \nPortal\n.\nonDetect\n(\nstartCP\n);\n\n\n \nif\n \n(\nPortal\n.\nbegin\n())\n \n{\n\n \ndigitalWrite\n(\nBUILTIN_LED\n,\n \nLOW\n);\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n \nPortal\n.\nhandleClient\n();\n\n\n}\n\n\n\n\n\n Combination with mDNS\n\u00b6\n\n\nWith \nmDNS library\n, you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after \nAutoConnect::begin\n.\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n#include\n \n\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nif\n \n(\nPortal\n.\nbegin\n())\n \n{\n\n\n \nif\n \n(\nMDNS\n.\nbegin\n(\n\"esp8266\"\n))\n \n{\n\n\n \nMDNS\n.\naddService\n(\n\"http\"\n,\n \n\"tcp\"\n,\n \n80\n);\n\n\n \n}\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n \nPortal\n.\nhandleClient\n();\n\n\n}\n\n\n\n\n\n Debug print\n\u00b6\n\n\nYou can output AutoConnect monitor messages to the \nSerial\n. A monitor message activation switch is in an include header file \nAutoConnect.h\n of library source. Define \nAC_DEBUG\n macro to output the monitor messages.\n\n\n#define AC_DEBUG\n\n\n\n\n\n Disable the captive portal\n\u00b6\n\n\nIt can also prevent the captive portal from starting even if the connection at the first \nWiFi.begin\n fails. In this case, \nAutoConnect::begin\n behaves same as \nWiFi.begin\n.\n\n\nFor disabling the captive portal, \nautoRise\n sets to false with \nAutoConnectConfig\n.\n\n\nAutoConnect\n \nportal\n;\n\n\nAutoConnectConfig\n \nacConfig\n;\n\n\n\nacConfig\n.\nautoRaise\n \n=\n \nfalse\n;\n\n\nportal\n.\nconfig\n(\nacConfig\n);\n\n\nportal\n.\nbegin\n();\n\n\n\n\n\n Move the saving area of EEPROM for the credentials\n\u00b6\n\n\nBy default, the credentials saving area is occupied from the beginning of EEPROM area. \nESP8266 Arduino core document\n says that:\n\n\n\n\nThe following diagram illustrates flash layout used in Arduino environment:\n\n\n\n\n\n\n\n \n|--------------|-------|---------------|--|--|--|--|--|\n\n \n^\n \n^\n \n^\n \n^\n \n^\n\n \nSketch\n \nOTA\n \nupdate\n \nFile\n \nsystem\n \nEEPROM\n \nWiFi\n \nconfig\n \n(\nSDK\n)\n\n\n\n\n\n\n\nand\n\n\n\n\nEEPROM library uses one sector of flash located \njust after the SPIFFS\n.\n\n\n\n\nSo 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.\n\n\nThe \nboundaryOffset\n in \nAutoConnectConfig\n specifies the start offset of the credentials storage area. The default value is 0.\n\n\n Refers the hosted ESP8266WebServer\n\u00b6\n\n\nConstructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by \nAutoConnect::host()\n function to access ESP8266WebServer instance as like below.\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nPortal\n.\nbegin\n();\n\n\nESP8266WebServer\n&\n \nserver\n \n=\n \nPortal\n.\nhost\n();\n\n\nserver\n.\nsend\n(\n200\n,\n \n\"text/plain\"\n,\n \n\"Hello, world\"\n);\n\n\n\n\n\n\n\nWhen host() is valid\n\n\nThe host() can be referred at after \nAutoConnect::begin\n.\n\n\n\n\n Usage for automatically instantiated ESP8266WebServer\n\u00b6\n\n\nThe sketch can handle URL requests using ESP8266WebServer that AutoConnect started internally. ESP8266WebServer instantiated dynamically by AutoConnect can be referred to by \nAutoConnect::host\n function. The sketch can use the '\non\n' function, '\nsend\n' function, '\nclient\n' function and others by ESP8266WebServer reference of its return value.\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n#include\n \n\n\n\n\nAutoConnect\n \nPortal\n;\n\n\n\nvoid\n \nhandleRoot\n()\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\nsend\n(\n200\n,\n \n\"text/html\"\n,\n \n\"Hello, world\"\n);\n\n\n}\n\n\n\nvoid\n \nhandleNotFound\n()\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\nsend\n(\n404\n,\n \n\"text/html\"\n,\n \n\"Unknown.\"\n);\n\n\n}\n\n\n\nvoid\n \nsetup\n()\n \n{\n\n \nbool\n \nr\n \n=\n \nPortal\n.\nbegin\n();\n\n \nif\n \n(\nr\n)\n \n{\n\n\n \nESP8266WebServer\n&\n \nIntServer\n \n=\n \nPortal\n.\nhost\n();\n\n\n \nIntServer\n.\non\n(\n\"/\"\n,\n \nhandleRoot\n);\n\n\n \nPortal\n.\nonNotFound\n(\nhandleNotFound\n);\n \n// For only onNotFound.\n\n \n}\n\n\n}\n\n\n\nvoid\n \nloop\n()\n \n{\n\n\n \nPortal\n.\nhost\n().\nhandleClient\n();\n\n\n \nPortal\n.\nhandleRequest\n();\n\n \n/* or following one line code is equ.\n\n\n Portal.handleClient();\n\n\n */\n\n\n}\n\n\n\n\n\n\n\nESP8266WebServer function should be called after AutoConnect::begin\n\n\nThe sketch cannot refer to an instance of ESP8266WebServer until AutoConnect::begin completes successfully.\n\n\n\n\n\n\nDo not use with ESP8266WebServer::begin\n\n\nESP8266WebServer is already running inside the AutoConnect.\n\n\n\n\n Use with the \nPageBuilder\n library\n\u00b6\n\n\nIn ordinary, the URL handler will respond the request by sending some HTML. \nPageBuilder\n 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.\n\n\nAn example sketch used with the PageBuilder as follows and it explains how it aids for the HTML generating. Details for \nGithub repository\n.\n\n\n\n\nConfiguration functions\n\u00b6\n\n\n Configuration for Soft AP\n\u00b6\n\n\nAutoConnect will activate SoftAP at failed the first \nWiFi.begin\n. It SoftAP settings are stored in \nAutoConnectConfig\n as the following parameters. The sketch could be configured SoftAP using these parameters, refer the \nAutoConnectConfig API\n for details.\n\n\n\n\nIP address of SoftAP activated.\n\n\nGateway IP address.\n\n\nSubnet mask.\n\n\nSSID for SoftAP.\n\n\nPassword for SoftAP.\n\n\nChannel.\n\n\nHidden attribute.\n\n\nAuto save credential.\n\n\nOffset address of the credentials storage area in EEPROM.\n\n\nLength of start up time after reset.\n\n\nAutomatic starting the captive portal.\n\n\nAuto reset after connection establishment.\n\n\nHome URL of the user sketch application.\n\n\n\n\n\n\nAutoConnect::config before AutoConnect::begin\n\n\nAutoConnect::config\n must be executed before \nAutoConnect::begin\n.\n\n\n\n\n Assign user sketch's home path\n\u00b6\n\n\n\"\nHOME\n\" for returning to the user's sketch homepage is displayed at the bottom of the AutoConnect menu. It could be set using the \nAutoConnect::home\n function.\n\n\n\n\n Relocate the AutoConnect home path\n\u00b6\n\n\nA home path of AutoConnect is \n/_ac\n by default. You can access from the browser with http://IPADDRESS/_ac. You can change the home path by revising \nAUTOCONNECT_URI\n macro in the include header file as \nAutoConnect.h\n.\n\n\n#define AUTOCONNECT_URI \"/_ac\"\n\n\n\n\n\n Static IP assignment \n1\n\u00b6\n\n\nIt 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 \nWiFi.begin\n.\n\n\nTo assign a static IP to ESP8266 with WIFI_MODE_STA, the following parameters are required:\n\n\n\n\nIP address.\n\n\nGateway address.\n\n\nSubnet mask.\n\n\nPrimary DNS server.\n\n\nSecondary DNS server. (optional)\n\n\n\n\nThe above parameters must be executed before \nAutoConnect::begin\n as \narguments of AutoConnectConfig\n.\n\n\nAutoConnect\n \nportal\n;\n\n\nAutoConnectConfig\n \nConfig\n;\n\n\nConfig\n.\nstaip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n10\n);\n\n\nConfig\n.\nstaGateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n1\n);\n\n\nConfig\n.\nstaNetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n\n\nConfig\n.\ndns1\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n1\n,\n1\n);\n\n\nportal\n.\nconfig\n(\nConfig\n);\n\n\nportal\n.\nbegin\n();\n\n\n\n\n\n\n\n\n\n\n\n\n\nStatic IP address assignment is available from version 0.9.3.\u00a0\n\u21a9", "title": "Advanced usage" }, { @@ -210,6 +210,11 @@ "text": "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 .", "title": " 404 handler" }, + { + "location": "/advancedusage/index.html#automatic-reconnect", + "text": "When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost. \nIf the autoReconnect option of the AutoConnectConfig 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. AutoConnect Portal ; AutoConnectConfig Config ; Config . autoReconnect = true ; Portal . config ( Config ); Portal . begin (); An autoReconnect option is available to AutoConnect::begin without SSID and pass passphrase.", + "title": " Automatic reconnect" + }, { "location": "/advancedusage/index.html#auto-save-credential", "text": "By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the autoSave parameter specified by AutoConnectConfig . AutoConnect Portal ; AutoConnectConfig Config ; Config . autoSave = AC_SAVECREDENTIAL_NEVER ; Portal . config ( Config ); Portal . begin ();", @@ -282,7 +287,7 @@ }, { "location": "/api/index.html", - "text": "Include headers\n\u00b6\n\n\n AutoConnect.h\n\u00b6\n\n\n#include\n \n\n\n\n\n\n\nDefine macros\n\u00b6\n\n\n#define AC_DEBUG \n// Monitor message output activation\n\n\n#define AC_DEBUG_PORT Serial \n// Default message output device\n\n\n#define AUTOCONNECT_AP_IP 0x01F4A8C0 \n// Default SoftAP IP\n\n\n#define AUTOCONNECT_AP_GW 0x01F4A8C0 \n// Default SoftAP Gateway IP\n\n\n#define AUTOCONNECT_AP_NM 0x00FFFFFF \n// Default subnet mask\n\n\n#define AUTOCONNECT_DNSPORT 53 \n// Default DNS port at captive portal\n\n\n#define AUTOCONNECT_HTTPPORT 80 \n// Default HTTP\n\n\n#define AUTOCONNECT_MENU_TITLE \"AutoConnect\" \n// Default AutoConnect menu title\n\n\n#define AUTOCONNECT_STARTUPTIME 10 \n// Default waiting time[s] for after reset\n\n\n#define AUTOCONNECT_URI \"/_ac\" \n// Default AutoConnect root path\n\n\n#define AUTOCONNECT_TIMEOUT 30000 \n// Default connection timeout[ms]\n\n\n\n\n\nAutoConnect API\n\u00b6\n\n\n Constructors\n\u00b6\n\n\nAutoConnect\n\u00b6\n\n\nAutoConnect\n()\n\n\n\n\n\n\n\nAutoConnect default constructor. This entry internally allocates the ESP8266WebServer and is activated internally.\n\n\nAutoConnect\n(\nESP8266WebServer\n&\n \nwebServer\n)\n\n\n\n\n\nRun the AutoConnect site using the externally ensured ESP8266WebServer.\n\n\nThe \nhandleClient\n function of AutoConnect can include the response of the URI handler added by the user using the \"\non\n\" function of ESP8266WebServer. If ESP8266WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the \nhost\n function.\n\n\n \nParameters\n\n \nwebServer\nA reference of ESP8266WebServer instance.\n\n\n\n\n Public member functions\n\u00b6\n\n\nbegin\n\u00b6\n\n\nbool\n \nbegin\n()\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n)\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n,\n \nunsinged\n \nlong\n \ntimeout\n)\n\n\n\n\nStarts establishing the WiFi connection.\n\nAutoConnect first invokes \nWiFi.begin\n. If the case of SSID and Password missing, its \nWiFi.begin\n has no SSID and Password. The WiFi mode at this time is WIFI_STA. Then ESP8266WebServer will be started immediately after the first \nWiFi.beign\n regardless of the result.\n\n\nThe captive portal will not be started if the connection has been established with first \nWiFi.begin\n. If the connection cannot establish, switch to WIFI_AP_STA mode and activate SoftAP. Then DNS server starts.\n\n\n \nParameters\n\n \nssid\nSSID to be connected.\n\n \npassphrase\nPassword for connection.\n\n \ntimeout\nA time out value in milliseconds for waiting connection.\n\n \nReturn value\n\n \ntrue\nConnection established, AutoConnect service started with WIFI_STA mode.\n\n \nfalse\nCould not connected, Captive portal started with WIFI_AP_STA mode.\n\n\n\n\nconfig\n\u00b6\n\n\nbool\n \nconfig\n(\nAutoConnectConfig\n&\n \nconfig\n)\n\n\n\n\nbool\n \nconfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n \n=\n \nnullptr\n)\n\n\n\n\nSet SoftAP's WiFi configuration and static IP configuration. \n\n\n \nParameters\n\n \nconfig\nReference to \nAutoConnectConfig\n containing SoftAP's parameters and static IP parameters.\n\n \nap\nSSID for SoftAP. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The default value is \n12345678\n.\n\n \nReturn value\n\n \ntrue\nSuccessfully configured.\n\n \nfalse\nConfiguration parameter is invalid, some values out of range.\n\n\n\n\nend\n\u00b6\n\n\nvoid\n \nend\n()\n\n\n\n\n\nStops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer. \n\n\n\n\nAttention to end\n\n\nThe end function releases the instance of ESP8266WebServer and DNSServer. It can not process them after the end function.\n\n\n\n\nhandleClient\n\u00b6\n\n\nvoid\n \nhandleClient\n()\n\n\n\n\n\nProcess the AutoConnect menu interface. It will be processed the client request too contained in the user sketch handler by calling the host \nhandleClient::ESP8266WebServer\n from the Autoconnect internally.\n\n\nhandleRequest\n\u00b6\n\n\nvoid\n \nhandleRequest\n()\n\n\n\n\n\nHandling for the AutoConnect menu request.\n\n\n\n\nAbout used in combination with handleClient\n\n\nThe handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266::handleClient.\n\n\n\n\nhome\n\u00b6\n\n\nvoid\n \nhome\n(\nString\n \nuri\n)\n\n\n\n\n\nPut a user site's home URI. The URI specified by home is linked from \"HOME\" in the AutoConnect menu.\n\n\n \nParameters\n\n \nuri\n A URI string of user site's home path.\n\n\n\n\nhost\n\u00b6\n\n\nReturns the reference of the ESP8266WebServer which is allocated in AutoConnect automatically.\n\n\nESP8266WebServer\n&\n \nhost\n()\n\n\n\n\n\n \nReturn value\n\n \nA reference of the ESP8266WebServer.\n\n\n\n\n\n\n&reference is not a pointer\n\n\nA reference cannot be re-assigned, and must be assigned at initialization. It's like as bind as alias. \n\n\nESP8266WebServer\n&\n \nserver\n \n=\n \nportal\n.\nhost\n();\n\n\nserver\n.\nhandleClient\n();\n\n\n\nor\n\n\nportal\n.\nhost\n().\nhandleClient\n();\n\n\n\n\n\n\nonDetect\n\u00b6\n\n\nvoid\n \nonDetect\n(\nDetectExit_ft\n \nfn\n)\n\n\n\nRegister the function which will call from AutoConnect at the start of the captive portal.\n\n\n \nParameters\n\n \nfn\nFunction called at the captive portal start.\n\n\n\n\n\nAn \nfn\n specifies the function called when the captive portal starts. Its prototype declaration is defined as \"\nDetectExit_ft\n\".\n\n\ntypedef\n \nstd\n::\nfunction\n<\nbool\n(\nIPAddress\n \nsoftapIP\n)\n>\n \nDetectExit_ft\n\n\n\n\n\n \nParameters\n\n \nsoftapIP\nAn IP address of SoftAP for the captive portal.\n\n \nRetuen value\n\n \ntrue\nContinues captive portal handling.\n\n \nfalse\nCancel the captive portal. AutoConnect::begin function will return with a false.\n\n\n\n\nonNotFound\n\u00b6\n\n\nvoid\n \nonNotFound\n(\nESP8266WebServer\n::\nTHandlerFunction\n \nfn\n)\n\n\n\nRegister the handler function for undefined URL request detected.\n\n\n \nParameters\n\n \nfn\nA function of the \"not found\" handler.\n\n\n\n\nAutoConnectConfig API\n\u00b6\n\n\n Constructor\n\u00b6\n\n\nAutoConnectConfig\n\u00b6\n\n\nAutoConnectConfig\n();\n\n\n\n\nAutoConnectConfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n);\n\n\n\n\n\n \nParameters\n\n \nap\nSSID for SoftAP. The length should be up to 31. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n\n\n Public member variables\n\u00b6\n\n\napid\n\u00b6\n\n\nSoftAP's SSID.\n\n\n \nType\n\n \nString\n\n\n\n\napip\n\u00b6\n\n\nSets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n192.168.244.1\n\n\n\n\nautoReset\n\u00b6\n\n\nReset ESP8266 module automatically after WLAN disconnected.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nReset after WiFi disconnected automatically.\n\n \nfalse\nNo reset.\n\n\n\n\nautoRise\n\u00b6\n\n\nCaptive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first \nWiFi.begin\n fails.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nEnable the captive portal. This is the default.\n\n \nfalse\nDisable the captive portal.\n\n\n\n\nautoSave\n\u00b6\n\n\nThe credential saved automatically at the connection establishment.\n\n\n \nType\n\n \nAC_SAVECREDENTIAL_t\n\n \nValue\n\n \nAC_SAVECREDENTIAL_AUTO\nThe credential saved automatically. This is the default.\n\n \nAC_SAVECREDENTIAL_NEVER\nThe credential no saved.\n\n\n\n\nboundaryOffset\n\u00b6\n\n\nSets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)\n\nThe default value is 0.\n\n\n \nType\n\n \nuint16_t\n\n\n\n\n\n\nIt will conflict with user data.\n\n\nIf the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.\n\n\n\n\nchannel\n\u00b6\n\n\nThe channel number of WIFi when SoftAP starts.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n1 ~ 14. The default value is 1.\n\n\n\n\n\n\nHow do I choose Channel\n\n\nEspressif Systems had announced the \napplication note\n about Wi-Fi channel selection.\n\n\n\n\ndns1\n\u00b6\n\n\nSet primary DNS server address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\ndns2\n\u00b6\n\n\nSet secondary DNS server address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\ngateway\n\u00b6\n\n\nSets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n192.168.244.1\n\n\n\n\nhidden\n\u00b6\n\n\nSets SoftAP to hidden SSID.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n0\nSSID will be appeared. This is the default.\n\n \n1\nSSID will be hidden.\n\n\n\n\nhomeUri\n\u00b6\n\n\nSets the home path of user sketch. This path would be linked from 'HOME' in the AutoConnect menu.\n\n\n \nType\n\n \nString\n\n\n\n\nnetmask\n\u00b6\n\n\nSets subnet mask for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n255.255.255.0\n\n\n\n\npsk\n\u00b6\n\n\nSets password for SoftAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n \nType\n\n \nString\n\n\n\n\nstaip\n\u00b6\n\n\nSet a static IP address. The IP will behave with STA mode.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nstaGateway\n\u00b6\n\n\nSet the gateway address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nstaNetmask\n\u00b6\n\n\nSet the subnetmask when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\n AutoConnectConfig example\n\u00b6\n\n\nAutoConenct\n \nPortal\n;\n\n\nAutoConenctConfig\n \nConfig\n(\n\"\"\n,\n \n\"passpass\"\n);\n \n// SoftAp name is determined at runtime\n\n\nConfig\n.\napid\n \n=\n \nESP\n.\nhostname\n();\n \n// Retrieve host name to SotAp identification\n\n\nConfig\n.\napip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n101\n);\n \n// Sets SoftAP IP address\n\n\nConfig\n.\ngateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets WLAN router IP address\n\n\nConfig\n.\nnetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n \n// Sets WLAN scope\n\n\nConfig\n.\nautoSave\n \n=\n \nAC_SAVECREDENTIAL_NEVER\n;\n \n// No save credential\n\n\nCOnfig\n.\nboundaryOffet\n \n=\n \n64\n;\n \n// Reserve 64 bytes for the user data in EEPROM. \n\n\nConfig\n.\nhomeUri\n \n=\n \n\"/index.html\"\n \n// Sets home path of the sketch application\n\n\nConfig\n.\nstaip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n10\n);\n \n// Sets static IP\n\n\nConfig\n.\nstaGateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets WiFi router address\n\n\nConfig\n.\nstaNetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n \n// Sets WLAN scope\n\n\nConfig\n.\ndns1\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets primary DNS address\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n \n// Configure AutoConnect\n\n\nPortal\n.\nbegin\n();\n \n// Starts and behaves captive portal\n\n\n\n\n\n Something extra\n\u00b6\n\n\nThe library presents two PNG icons which can be used to embed a hyperlink to the AutoConnect menu.\n\n\n\n\nBar type \n\n\nCog type \n\n\n\n\nTo reference the icon, use the \nAUTOCONNECT_LINK\n macro in the sketch. It expands into the string literal as an HTML \n\n tag with PNG embedded of the AutoConnect menu hyperlinks. Icon type is specified by the parameter of the macro.\n\n\n\n \nBAR_24\nBars icon, 24x24.\n\n \nBAR_32\nBars icon, 32x32.\n\n \nBAR_48\nBars icon, 48x48.\n\n \nCOG_24\nCog icon, 24x24.\n\n \nCOG_32\nCog icon, 32x32.\n\n\n\n\n\n\n\nUsage\n\n\nString\n \nhtml\n \n=\n \n\"\"\n;\n\n\nhtml\n \n+=\n \nAUTOCONNECT_LINK\n(\nBAR_32\n);\n\n\nhtml\n \n+=\n \n\"\"\n;\n\n\nserver\n.\nsend\n(\n200\n,\n \n\"text/html\"\n,\n \nhtml\n);", + "text": "Include headers\n\u00b6\n\n\n AutoConnect.h\n\u00b6\n\n\n#include\n \n\n\n\n\n\n\nDefine macros\n\u00b6\n\n\n#define AC_DEBUG \n// Monitor message output activation\n\n\n#define AC_DEBUG_PORT Serial \n// Default message output device\n\n\n#define AUTOCONNECT_AP_IP 0x01F4A8C0 \n// Default SoftAP IP\n\n\n#define AUTOCONNECT_AP_GW 0x01F4A8C0 \n// Default SoftAP Gateway IP\n\n\n#define AUTOCONNECT_AP_NM 0x00FFFFFF \n// Default subnet mask\n\n\n#define AUTOCONNECT_DNSPORT 53 \n// Default DNS port at captive portal\n\n\n#define AUTOCONNECT_HTTPPORT 80 \n// Default HTTP\n\n\n#define AUTOCONNECT_MENU_TITLE \"AutoConnect\" \n// Default AutoConnect menu title\n\n\n#define AUTOCONNECT_STARTUPTIME 10 \n// Default waiting time[s] for after reset\n\n\n#define AUTOCONNECT_URI \"/_ac\" \n// Default AutoConnect root path\n\n\n#define AUTOCONNECT_TIMEOUT 30000 \n// Default connection timeout[ms]\n\n\n\n\n\nAutoConnect API\n\u00b6\n\n\n Constructors\n\u00b6\n\n\nAutoConnect\n\u00b6\n\n\nAutoConnect\n()\n\n\n\n\n\n\n\nAutoConnect default constructor. This entry internally allocates the ESP8266WebServer and is activated internally.\n\n\nAutoConnect\n(\nESP8266WebServer\n&\n \nwebServer\n)\n\n\n\n\n\nRun the AutoConnect site using the externally ensured ESP8266WebServer.\n\n\nThe \nhandleClient\n function of AutoConnect can include the response of the URI handler added by the user using the \"\non\n\" function of ESP8266WebServer. If ESP8266WebServer is assigned internally by AutoConnect, the sketch can obtain that reference with the \nhost\n function.\n\n\n \nParameters\n\n \nwebServer\nA reference of ESP8266WebServer instance.\n\n\n\n\n Public member functions\n\u00b6\n\n\nbegin\n\u00b6\n\n\nbool\n \nbegin\n()\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n)\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n,\n \nunsinged\n \nlong\n \ntimeout\n)\n\n\n\n\nStarts establishing the WiFi connection.\n\nAutoConnect first invokes \nWiFi.begin\n. If the case of SSID and Password missing, its \nWiFi.begin\n has no SSID and Password. The WiFi mode at this time is WIFI_STA. Then ESP8266WebServer will be started immediately after the first \nWiFi.beign\n regardless of the result.\n\n\nThe captive portal will not be started if the connection has been established with first \nWiFi.begin\n. If the connection cannot establish, switch to WIFI_AP_STA mode and activate SoftAP. Then DNS server starts.\n\n\n \nParameters\n\n \nssid\nSSID to be connected.\n\n \npassphrase\nPassword for connection.\n\n \ntimeout\nA time out value in milliseconds for waiting connection.\n\n \nReturn value\n\n \ntrue\nConnection established, AutoConnect service started with WIFI_STA mode.\n\n \nfalse\nCould not connected, Captive portal started with WIFI_AP_STA mode.\n\n\n\n\nconfig\n\u00b6\n\n\nbool\n \nconfig\n(\nAutoConnectConfig\n&\n \nconfig\n)\n\n\n\n\nbool\n \nconfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n \n=\n \nnullptr\n)\n\n\n\n\nSet SoftAP's WiFi configuration and static IP configuration. \n\n\n \nParameters\n\n \nconfig\nReference to \nAutoConnectConfig\n containing SoftAP's parameters and static IP parameters.\n\n \nap\nSSID for SoftAP. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The default value is \n12345678\n.\n\n \nReturn value\n\n \ntrue\nSuccessfully configured.\n\n \nfalse\nConfiguration parameter is invalid, some values out of range.\n\n\n\n\nend\n\u00b6\n\n\nvoid\n \nend\n()\n\n\n\n\n\nStops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer. \n\n\n\n\nAttention to end\n\n\nThe end function releases the instance of ESP8266WebServer and DNSServer. It can not process them after the end function.\n\n\n\n\nhandleClient\n\u00b6\n\n\nvoid\n \nhandleClient\n()\n\n\n\n\n\nProcess 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 \nESP8266WebServer::handleClient\n.\n\n\nhandleRequest\n\u00b6\n\n\nvoid\n \nhandleRequest\n()\n\n\n\n\n\nHandling for the AutoConnect menu request.\n\n\n\n\nAbout used in combination with handleClient\n\n\nThe handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266::handleClient.\n\n\n\n\nhome\n\u00b6\n\n\nvoid\n \nhome\n(\nString\n \nuri\n)\n\n\n\n\n\nPut a user site's home URI. The URI specified by home is linked from \"HOME\" in the AutoConnect menu.\n\n\n \nParameters\n\n \nuri\n A URI string of user site's home path.\n\n\n\n\nhost\n\u00b6\n\n\nReturns the reference of the ESP8266WebServer which is allocated in AutoConnect automatically.\n\n\nESP8266WebServer\n&\n \nhost\n()\n\n\n\n\n\n \nReturn value\n\n \nA reference of the ESP8266WebServer.\n\n\n\n\n\n\n&reference is not a pointer\n\n\nA reference cannot be re-assigned, and must be assigned at initialization. It's like as bind as alias. \n\n\nESP8266WebServer\n&\n \nserver\n \n=\n \nportal\n.\nhost\n();\n\n\nserver\n.\nhandleClient\n();\n\n\n\nor\n\n\nportal\n.\nhost\n().\nhandleClient\n();\n\n\n\n\n\n\nonDetect\n\u00b6\n\n\nvoid\n \nonDetect\n(\nDetectExit_ft\n \nfn\n)\n\n\n\nRegister the function which will call from AutoConnect at the start of the captive portal.\n\n\n \nParameters\n\n \nfn\nFunction called at the captive portal start.\n\n\n\n\n\nAn \nfn\n specifies the function called when the captive portal starts. Its prototype declaration is defined as \"\nDetectExit_ft\n\".\n\n\ntypedef\n \nstd\n::\nfunction\n<\nbool\n(\nIPAddress\n \nsoftapIP\n)\n>\n \nDetectExit_ft\n\n\n\n\n\n \nParameters\n\n \nsoftapIP\nAn IP address of SoftAP for the captive portal.\n\n \nRetuen value\n\n \ntrue\nContinues captive portal handling.\n\n \nfalse\nCancel the captive portal. AutoConnect::begin function will return with a false.\n\n\n\n\nonNotFound\n\u00b6\n\n\nvoid\n \nonNotFound\n(\nESP8266WebServer\n::\nTHandlerFunction\n \nfn\n)\n\n\n\nRegister the handler function for undefined URL request detected.\n\n\n \nParameters\n\n \nfn\nA function of the \"not found\" handler.\n\n\n\n\nAutoConnectConfig API\n\u00b6\n\n\n Constructor\n\u00b6\n\n\nAutoConnectConfig\n\u00b6\n\n\nAutoConnectConfig\n();\n\n\n\n\nAutoConnectConfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n);\n\n\n\n\n\n \nParameters\n\n \nap\nSSID for SoftAP. The length should be up to 31. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n\n\n Public member variables\n\u00b6\n\n\napid\n\u00b6\n\n\nSoftAP's SSID.\n\n\n \nType\n\n \nString\n\n\n\n\napip\n\u00b6\n\n\nSets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n192.168.244.1\n\n\n\n\nautoReconnect\n\u00b6\n\n\nAutomatically reconnect to past established access point (BSSID) when the current configured SSID in ESP8266 could not be connected. By enabling this option, \nAutoConnect::begin()\n function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.\n\nIf the connection fails, starts the captive portal in SoftAP + STA mode.\n\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nReconnect automatically.\n\n \nfalse\nStarts Captive Portal in SoftAP + STA mode without trying to reconnect. This is the default.\n\n\n\n\nWhen the autoReconnect option is enabled, an automatic connection will behave if the following conditions are satisfied.\n\n\n\n\nInvokes \nAutoConnect::begin\n without user name and password parameter as \nbegin()\n.\n\n\nIf one of the saved BSSIDs (not the SSID) of the credentials matches the BSSID detected by the network scan.\n\n\n\n\nautoReset\n\u00b6\n\n\nReset ESP8266 module automatically after WLAN disconnected.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nReset after WiFi disconnected automatically.\n\n \nfalse\nNo reset.\n\n\n\n\nautoRise\n\u00b6\n\n\nCaptive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first \nWiFi.begin\n fails.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nEnable the captive portal. This is the default.\n\n \nfalse\nDisable the captive portal.\n\n\n\n\nautoSave\n\u00b6\n\n\nThe credential saved automatically at the connection establishment.\n\n\n \nType\n\n \nAC_SAVECREDENTIAL_t\n\n \nValue\n\n \nAC_SAVECREDENTIAL_AUTO\nThe credential saved automatically. This is the default.\n\n \nAC_SAVECREDENTIAL_NEVER\nThe credential no saved.\n\n\n\n\nboundaryOffset\n\u00b6\n\n\nSets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)\n\nThe default value is 0.\n\n\n \nType\n\n \nuint16_t\n\n\n\n\n\n\nIt will conflict with user data.\n\n\nIf the sketch leaves this offset at zero, it will conflict the storage area of credentials with the user sketch owned data. It needs to use the behind of credential area.\n\n\n\n\nchannel\n\u00b6\n\n\nThe channel number of WIFi when SoftAP starts.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n1 ~ 14. The default value is 1.\n\n\n\n\n\n\nHow do I choose Channel\n\n\nEspressif Systems had announced the \napplication note\n about Wi-Fi channel selection.\n\n\n\n\ndns1\n\u00b6\n\n\nSet primary DNS server address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\ndns2\n\u00b6\n\n\nSet secondary DNS server address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\ngateway\n\u00b6\n\n\nSets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n192.168.244.1\n\n\n\n\nhidden\n\u00b6\n\n\nSets SoftAP to hidden SSID.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n0\nSSID will be appeared. This is the default.\n\n \n1\nSSID will be hidden.\n\n\n\n\nhomeUri\n\u00b6\n\n\nSets the home path of user sketch. This path would be linked from 'HOME' in the AutoConnect menu.\n\n\n \nType\n\n \nString\n\n\n\n\nnetmask\n\u00b6\n\n\nSets subnet mask for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\nThe default value is \n255.255.255.0\n\n\n\n\npsk\n\u00b6\n\n\nSets password for SoftAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n \nType\n\n \nString\n\n\n\n\nstaip\n\u00b6\n\n\nSet a static IP address. The IP will behave with STA mode.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nstaGateway\n\u00b6\n\n\nSet the gateway address when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nstaNetmask\n\u00b6\n\n\nSet the subnetmask when using static IP address.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\n AutoConnectConfig example\n\u00b6\n\n\nAutoConenct\n \nPortal\n;\n\n\nAutoConenctConfig\n \nConfig\n(\n\"\"\n,\n \n\"passpass\"\n);\n \n// SoftAp name is determined at runtime\n\n\nConfig\n.\napid\n \n=\n \nESP\n.\nhostname\n();\n \n// Retrieve host name to SotAp identification\n\n\nConfig\n.\napip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n101\n);\n \n// Sets SoftAP IP address\n\n\nConfig\n.\ngateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets WLAN router IP address\n\n\nConfig\n.\nnetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n \n// Sets WLAN scope\n\n\nConfig\n.\nautoReconnect\n \n=\n \ntrue\n;\n \n// Enable auto-reconnect\n\n\nConfig\n.\nautoSave\n \n=\n \nAC_SAVECREDENTIAL_NEVER\n;\n \n// No save credential\n\n\nCOnfig\n.\nboundaryOffet\n \n=\n \n64\n;\n \n// Reserve 64 bytes for the user data in EEPROM. \n\n\nConfig\n.\nhomeUri\n \n=\n \n\"/index.html\"\n \n// Sets home path of the sketch application\n\n\nConfig\n.\nstaip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n10\n);\n \n// Sets static IP\n\n\nConfig\n.\nstaGateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets WiFi router address\n\n\nConfig\n.\nstaNetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n \n// Sets WLAN scope\n\n\nConfig\n.\ndns1\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets primary DNS address\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n \n// Configure AutoConnect\n\n\nPortal\n.\nbegin\n();\n \n// Starts and behaves captive portal\n\n\n\n\n\n Something extra\n\u00b6\n\n\nThe library presents two PNG icons which can be used to embed a hyperlink to the AutoConnect menu.\n\n\n\n\nBar type \n\n\nCog type \n\n\n\n\nTo reference the icon, use the \nAUTOCONNECT_LINK\n macro in the sketch. It expands into the string literal as an HTML \n\n tag with PNG embedded of the AutoConnect menu hyperlinks. Icon type is specified by the parameter of the macro.\n\n\n\n \nBAR_24\nBars icon, 24x24.\n\n \nBAR_32\nBars icon, 32x32.\n\n \nBAR_48\nBars icon, 48x48.\n\n \nCOG_24\nCog icon, 24x24.\n\n \nCOG_32\nCog icon, 32x32.\n\n\n\n\n\n\n\nUsage\n\n\nString\n \nhtml\n \n=\n \n\"\"\n;\n\n\nhtml\n \n+=\n \nAUTOCONNECT_LINK\n(\nBAR_32\n);\n\n\nhtml\n \n+=\n \n\"\"\n;\n\n\nserver\n.\nsend\n(\n200\n,\n \n\"text/html\"\n,\n \nhtml\n);", "title": "Library APIs" }, { @@ -337,7 +342,7 @@ }, { "location": "/api/index.html#handleclient", - "text": "void handleClient () Process the AutoConnect menu interface. It will be processed the client request too contained in the user sketch handler by calling the host handleClient::ESP8266WebServer from the Autoconnect internally.", + "text": "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 .", "title": "handleClient" }, { @@ -395,6 +400,11 @@ "text": "Sets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this. \n Type \n IPAddress The default value is 192.168.244.1", "title": "apip" }, + { + "location": "/api/index.html#autoreconnect", + "text": "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. \nIf the connection fails, starts the captive portal in SoftAP + STA mode. \n Type \n bool \n Value \n true Reconnect automatically. \n false Starts Captive Portal in SoftAP + STA mode without trying to reconnect. This is the default. When the autoReconnect option is enabled, an automatic connection will behave if the following conditions are satisfied. Invokes AutoConnect::begin without user name and password parameter as begin() . If one of the saved BSSIDs (not the SSID) of the credentials matches the BSSID detected by the network scan.", + "title": "autoReconnect" + }, { "location": "/api/index.html#autoreset", "text": "Reset ESP8266 module automatically after WLAN disconnected. \n Type \n bool \n Value \n true Reset after WiFi disconnected automatically. \n false No reset.", @@ -472,7 +482,7 @@ }, { "location": "/api/index.html#autoconnectconfig-example", - "text": "AutoConenct Portal ; AutoConenctConfig Config ( \"\" , \"passpass\" ); // SoftAp name is determined at runtime Config . apid = ESP . hostname (); // Retrieve host name to SotAp identification Config . apip = IPAddress ( 192 , 168 , 10 , 101 ); // Sets SoftAP IP address Config . gateway = IPAddress ( 192 , 168 , 10 , 1 ); // Sets WLAN router IP address Config . netmask = IPAddress ( 255 , 255 , 255 , 0 ); // Sets WLAN scope Config . autoSave = AC_SAVECREDENTIAL_NEVER ; // No save credential COnfig . boundaryOffet = 64 ; // Reserve 64 bytes for the user data in EEPROM. Config . homeUri = \"/index.html\" // Sets home path of the sketch application Config . staip = IPAddress ( 192 , 168 , 10 , 10 ); // Sets static IP Config . staGateway = IPAddress ( 192 , 168 , 10 , 1 ); // Sets WiFi router address Config . staNetmask = IPAddress ( 255 , 255 , 255 , 0 ); // Sets WLAN scope Config . dns1 = IPAddress ( 192 , 168 , 10 , 1 ); // Sets primary DNS address Portal . config ( Config ); // Configure AutoConnect Portal . begin (); // Starts and behaves captive portal", + "text": "AutoConenct Portal ; AutoConenctConfig Config ( \"\" , \"passpass\" ); // SoftAp name is determined at runtime Config . apid = ESP . hostname (); // Retrieve host name to SotAp identification Config . apip = IPAddress ( 192 , 168 , 10 , 101 ); // Sets SoftAP IP address Config . gateway = IPAddress ( 192 , 168 , 10 , 1 ); // Sets WLAN router IP address Config . netmask = IPAddress ( 255 , 255 , 255 , 0 ); // Sets WLAN scope Config . autoReconnect = true ; // Enable auto-reconnect Config . autoSave = AC_SAVECREDENTIAL_NEVER ; // No save credential COnfig . boundaryOffet = 64 ; // Reserve 64 bytes for the user data in EEPROM. Config . homeUri = \"/index.html\" // Sets home path of the sketch application Config . staip = IPAddress ( 192 , 168 , 10 , 10 ); // Sets static IP Config . staGateway = IPAddress ( 192 , 168 , 10 , 1 ); // Sets WiFi router address Config . staNetmask = IPAddress ( 255 , 255 , 255 , 0 ); // Sets WLAN scope Config . dns1 = IPAddress ( 192 , 168 , 10 , 1 ); // Sets primary DNS address Portal . config ( Config ); // Configure AutoConnect Portal . begin (); // Starts and behaves captive portal", "title": " AutoConnectConfig example" }, { @@ -637,9 +647,14 @@ }, { "location": "/changelog/index.html", - "text": "[0.9.3] March 23, 2018.\n\u00b6\n\n\n\n\nSupports a static IP address assignment.\n\n\n\n\n[0.9.2] March 19, 2018.\n\u00b6\n\n\n\n\nImprovement of string literal declaration with the examples, no library change.\n\n\n\n\n[0.9.1] March 13, 2018.\n\u00b6\n\n\n\n\nA release of the stable.", + "text": "[0.9.4] May 5, 2018.\n\u00b6\n\n\n\n\nSupports 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.\n\n\n\n\n[0.9.3] March 23, 2018.\n\u00b6\n\n\n\n\nSupports a static IP address assignment.\n\n\n\n\n[0.9.2] March 19, 2018.\n\u00b6\n\n\n\n\nImprovement of string literal declaration with the examples, no library change.\n\n\n\n\n[0.9.1] March 13, 2018.\n\u00b6\n\n\n\n\nA release of the stable.", "title": "Change log" }, + { + "location": "/changelog/index.html#094-may-5-2018", + "text": "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.", + "title": "[0.9.4] May 5, 2018." + }, { "location": "/changelog/index.html#093-march-23-2018", "text": "Supports a static IP address assignment.", diff --git a/docs/sitemap.xml b/docs/sitemap.xml index c69c05a..c3e0291 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -4,7 +4,7 @@ https://Hieromon.github.io/AutoConnect//index.html - 2018-03-26 + 2018-05-06 daily @@ -12,7 +12,7 @@ https://Hieromon.github.io/AutoConnect//gettingstarted/index.html - 2018-03-26 + 2018-05-06 daily @@ -20,7 +20,7 @@ https://Hieromon.github.io/AutoConnect//menu/index.html - 2018-03-26 + 2018-05-06 daily @@ -28,7 +28,7 @@ https://Hieromon.github.io/AutoConnect//basicusage/index.html - 2018-03-26 + 2018-05-06 daily @@ -36,7 +36,7 @@ https://Hieromon.github.io/AutoConnect//advancedusage/index.html - 2018-03-26 + 2018-05-06 daily @@ -44,7 +44,7 @@ https://Hieromon.github.io/AutoConnect//api/index.html - 2018-03-26 + 2018-05-06 daily @@ -52,7 +52,7 @@ https://Hieromon.github.io/AutoConnect//examples/index.html - 2018-03-26 + 2018-05-06 daily @@ -60,7 +60,7 @@ https://Hieromon.github.io/AutoConnect//faq/index.html - 2018-03-26 + 2018-05-06 daily @@ -68,7 +68,7 @@ https://Hieromon.github.io/AutoConnect//changelog/index.html - 2018-03-26 + 2018-05-06 daily @@ -76,7 +76,7 @@ https://Hieromon.github.io/AutoConnect//license/index.html - 2018-03-26 + 2018-05-06 daily diff --git a/examples/Simple/Simple.ino b/examples/Simple/Simple.ino index 2ac3f58..160a6ac 100644 --- a/examples/Simple/Simple.ino +++ b/examples/Simple/Simple.ino @@ -14,6 +14,7 @@ ESP8266WebServer Server; AutoConnect Portal(Server); +AutoConnectConfig Config; // Enable autoReconnect supported on v0.9.4 #define TIMEZONE (3600 * 9) // Tokyo #define NTPServer1 "ntp.nict.jp" // NICT japan. @@ -51,7 +52,15 @@ void setup() { Serial.begin(115200); Serial.println(); + // Behavior a root path of ESP8266WebServer. Server.on("/", rootPage); + + // Enable saved past credential by autoReconnect option, + // even once it is disconnected. + Config.autoReconnect = true; + Portal.config(Config); + + // Establish a connection with an autoReconnect option. if (Portal.begin()) { Serial.println("WiFi connected: " + WiFi.localIP().toString()); configTime(TIMEZONE, 0, NTPServer1, NTPServer2); diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md index 65ca172..e749fe0 100644 --- a/mkdocs/advancedusage.md +++ b/mkdocs/advancedusage.md @@ -4,6 +4,21 @@ 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). +### 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. +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" +AutoConnect Portal; +AutoConnectConfig Config; +Config.autoReconnect = true; +Portal.config(Config); +Portal.begin(); +``` + +An autoReconnect option is available to *AutoConnect::begin* without SSID and pass passphrase. + ### Auto save Credential By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the [**autoSave**](api.md#autosave) parameter specified by [**AutoConnectConfig**](api.md#autoconnectconfig). diff --git a/mkdocs/api.md b/mkdocs/api.md index 6ba37b1..c812493 100644 --- a/mkdocs/api.md +++ b/mkdocs/api.md @@ -113,7 +113,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 the host *handleClient::ESP8266WebServer* from the Autoconnect internally. +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*. #### handleRequest @@ -232,6 +232,23 @@ Sets IP address for Soft AP in captive portal. When AutoConnect fails the initia
        IPAddressThe default value is **192.168.244.1**
    +#### 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. +If the connection fails, starts the captive portal in SoftAP + STA mode. +
    +
    **Type**
    +
    bool
    +
    **Value**
    +
    trueReconnect automatically.
    +
    falseStarts Captive Portal in SoftAP + STA mode without trying to reconnect. This is the default.
    +
    + +When the autoReconnect option is enabled, an automatic connection will behave if the following conditions are satisfied. + +- Invokes *AutoConnect::begin* without user name and password parameter as ```begin()```. +- If one of the saved BSSIDs (not the SSID) of the credentials matches the BSSID detected by the network scan. + #### autoReset Reset ESP8266 module automatically after WLAN disconnected. @@ -382,6 +399,7 @@ Config.apid = ESP.hostname(); // Retrieve host name to SotAp ide Config.apip = IPAddress(192,168,10,101); // Sets SoftAP IP address Config.gateway = IPAddress(192,168,10,1); // Sets WLAN router IP address Config.netmask = IPAddress(255,255,255,0); // Sets WLAN scope +Config.autoReconnect = true; // Enable auto-reconnect Config.autoSave = AC_SAVECREDENTIAL_NEVER; // No save credential COnfig.boundaryOffet = 64; // Reserve 64 bytes for the user data in EEPROM. Config.homeUri = "/index.html" // Sets home path of the sketch application diff --git a/mkdocs/changelog.md b/mkdocs/changelog.md index d1a5a43..148f018 100644 --- a/mkdocs/changelog.md +++ b/mkdocs/changelog.md @@ -1,3 +1,7 @@ +#### [0.9.4] May 5, 2018. + +- 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. + #### [0.9.3] March 23, 2018. - Supports a static IP address assignment. diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index b649ab6..cb3adce 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -2,8 +2,8 @@ * AutoConnect class implementation. * @file AutoConnect.cpp * @author hieromon@gmail.com - * @version 0.9.3 - * @date 2018-03-23 + * @version 0.9.4 + * @date 2018-05-05 * @copyright MIT license. */ @@ -69,24 +69,11 @@ bool AutoConnect::begin() { * @retval false Could not connected, Captive portal started with WIFI_AP_STA mode. */ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long timeout) { - _portalTimeout = timeout; - return begin(ssid, passphrase); -} - -/** - * Starts establishing WiFi connection. - * Before establishing, start the Web server and DNS server for the captive - * portal. Then begins connection establishment in WIFI_STA mode. If - * connection can not established with the specified SSID and password, - * switch to WIFI_AP_STA mode and activate SoftAP. - * @param ssid SSID to be connected. - * @param passphrase Password for connection. - * @retval true Connection established, AutoConnect service started with WIFI_STA mode. - * @retval false Could not connected, Captive portal started with WIFI_AP_STA mode. - */ -bool AutoConnect::begin(const char* ssid, const char* passphrase) { bool cs; + // Overwrite for the current timeout value. + _portalTimeout = timeout; + // Start WiFi connection. WiFi.mode(WIFI_STA); delay(100); @@ -113,6 +100,19 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase) { WiFi.begin(ssid, passphrase); AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase); cs = _waitForConnect(_portalTimeout) == WL_CONNECTED; + + // Reconnect with a valid credential as the autoReconnect option is enabled. + if (!cs && _apConfig.autoReconnect && (ssid == nullptr && passphrase == nullptr)) { + // Load a valid credential. + if (_loadAvailCredential()) { + // Try to reconnect with a stored credential. + AC_DBG("Past SSID:%s loaded\n", reinterpret_cast(_credential.ssid)); + const char* psk = strlen(reinterpret_cast(_credential.password)) ? reinterpret_cast(_credential.password) : nullptr; + WiFi.begin(reinterpret_cast(_credential.ssid), psk); + AC_DBG("WiFi.begin(%s%s%s)\n", _credential.ssid, psk == nullptr ? "" : ",", psk == nullptr ? "" : psk); + cs = _waitForConnect(_portalTimeout) == WL_CONNECTED; + } + } _currentHostIP = WiFi.localIP(); // It doesn't matter the connection status for launching the Web server. @@ -373,6 +373,30 @@ void AutoConnect::onNotFound(ESP8266WebServer::THandlerFunction fn) { _notFoundHandler = fn; } +/** + * Load stored credentials that match nearby WLANs. + * @retval true A matched credential of BSSID was loaded. + */ +bool AutoConnect::_loadAvailCredential() { + AutoConnectCredential credential(_apConfig.boundaryOffset); + + if (credential.entries() >= 0) { + // Scan the vicinity only when the saved credentials are existing. + int8_t nn = WiFi.scanNetworks(false, true); + 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++) { + if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config::bssid))) + return true; + } + } + } + } + return false; +} + /** * Disconnect from the AP and stop the AutoConnect portal. * Stops DNS server and flush tcp sending. diff --git a/src/AutoConnect.h b/src/AutoConnect.h index dd50cfe..89f07f8 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -2,8 +2,8 @@ * Declaration of AutoConnect class and accompanying AutoConnectConfig class. * @file AutoConnect.h * @author hieromon@gmail.com - * @version 0.9.3 - * @date 2018-03-23 + * @version 0.9.4 + * @date 2018-05-05 * @copyright MIT license. */ @@ -119,6 +119,7 @@ class AutoConnectConfig { uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), autoReset(true), + autoReconnect(false), homeUri(AUTOCONNECT_HOMEURI), staip(0U), staGateway(0U), @@ -141,6 +142,7 @@ class AutoConnectConfig { uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), autoReset(true), + autoReconnect(false), homeUri(AUTOCONNECT_HOMEURI), staip(0U), staGateway(0U), @@ -163,6 +165,7 @@ class AutoConnectConfig { uptime = o.uptime; autoRise = o.autoRise; autoReset = o.autoReset; + autoReconnect = o.autoReconnect; homeUri = o.homeUri; staip = o.staip; staGateway = o.staGateway; @@ -184,6 +187,7 @@ class AutoConnectConfig { int uptime; /**< Length of start up time */ bool autoRise; /**< Automatic starting the captive portal */ bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */ + bool autoReconnect; /**< Automatic reconnect with past SSID */ String homeUri; /**< A URI of user site */ IPAddress staip; /**< Station static IP address */ IPAddress staGateway; /**< Station gateway address */ @@ -201,8 +205,7 @@ class AutoConnect { bool config(const char* ap, const char* password = nullptr); void home(String uri); bool begin(); - bool begin(const char* ssid, const char* passphrase); - bool begin(const char* ssid, const char* passphrase, unsigned long timeout); + bool begin(const char* ssid, const char* passphrase = nullptr, unsigned long timeout = AUTOCONNECT_TIMEOUT); void end(); void handleClient(); void handleRequest(); @@ -223,6 +226,7 @@ class AutoConnect { void _startWebServer(); void _startDNSServer(); void _handleNotFound(); + bool _loadAvailCredential(); void _stopPortal(); bool _classifyHandle(HTTPMethod mothod, String uri); PageElement* _setupPage(String uri);