adconnection.html 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. <!doctype html>
  2. <html lang="en" class="no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
  7. <link rel="canonical" href="https://Hieromon.github.io/AutoConnect/adconnection.html">
  8. <meta name="author" content="Hieromon Ikasamo">
  9. <link rel="shortcut icon" href="assets/images/favicon.png">
  10. <meta name="generator" content="mkdocs-1.1.2, mkdocs-material-6.1.6">
  11. <title>AutoConnect WiFi connection control - AutoConnect for ESP8266/ESP32</title>
  12. <link rel="stylesheet" href="assets/stylesheets/main.6910b76c.min.css">
  13. <link rel="stylesheet" href="assets/stylesheets/palette.196e0c26.min.css">
  14. <meta name="theme-color" content="#4051b5">
  15. <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
  16. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
  17. <style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style>
  18. <link rel="stylesheet" href="css/paragraph.css">
  19. <link rel="stylesheet" href="css/extra.css">
  20. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
  21. <script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-116150854-1","auto"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}),document.addEventListener("DOMContentSwitch",function(){ga("send","pageview",document.location.pathname)})</script>
  22. <script async src="https://www.google-analytics.com/analytics.js"></script>
  23. </head>
  24. <body dir="ltr" data-md-color-scheme="" data-md-color-primary="indigo" data-md-color-accent="indigo">
  25. <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
  26. <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
  27. <label class="md-overlay" for="__drawer"></label>
  28. <div data-md-component="skip">
  29. <a href="#automatic-reconnect" class="md-skip">
  30. Skip to content
  31. </a>
  32. </div>
  33. <div data-md-component="announce">
  34. </div>
  35. <header class="md-header" data-md-component="header">
  36. <nav class="md-header-nav md-grid" aria-label="Header">
  37. <a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo" aria-label="AutoConnect for ESP8266/ESP32">
  38. <img src="images/arduino-logo.svg" alt="logo">
  39. </a>
  40. <label class="md-header-nav__button md-icon" for="__drawer">
  41. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
  42. </label>
  43. <div class="md-header-nav__title" data-md-component="header-title">
  44. <div class="md-header-nav__ellipsis">
  45. <span class="md-header-nav__topic md-ellipsis">
  46. AutoConnect for ESP8266/ESP32
  47. </span>
  48. <span class="md-header-nav__topic md-ellipsis">
  49. AutoConnect WiFi connection control
  50. </span>
  51. </div>
  52. </div>
  53. <label class="md-header-nav__button md-icon" for="__search">
  54. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
  55. </label>
  56. <div class="md-search" data-md-component="search" role="dialog">
  57. <label class="md-search__overlay" for="__search"></label>
  58. <div class="md-search__inner" role="search">
  59. <form class="md-search__form" name="search">
  60. <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active" required>
  61. <label class="md-search__icon md-icon" for="__search">
  62. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
  63. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  64. </label>
  65. <button type="reset" class="md-search__icon md-icon" aria-label="Clear" data-md-component="search-reset" tabindex="-1">
  66. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
  67. </button>
  68. </form>
  69. <div class="md-search__output">
  70. <div class="md-search__scrollwrap" data-md-scrollfix>
  71. <div class="md-search-result" data-md-component="search-result">
  72. <div class="md-search-result__meta">
  73. Initializing search
  74. </div>
  75. <ol class="md-search-result__list"></ol>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="md-header-nav__source">
  82. <a href="https://github.com/Hieromon/AutoConnect" title="Go to repository" class="md-source">
  83. <div class="md-source__icon md-icon">
  84. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05L244 40.45a28.87 28.87 0 00-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 01-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 000 40.81l195.61 195.6a28.86 28.86 0 0040.8 0l194.69-194.69a28.86 28.86 0 000-40.81z"/></svg>
  85. </div>
  86. <div class="md-source__repository">
  87. Hieromon/AutoConnect
  88. </div>
  89. </a>
  90. </div>
  91. </nav>
  92. </header>
  93. <div class="md-container" data-md-component="container">
  94. <main class="md-main" data-md-component="main">
  95. <div class="md-main__inner md-grid">
  96. <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
  97. <div class="md-sidebar__scrollwrap">
  98. <div class="md-sidebar__inner">
  99. <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  100. <label class="md-nav__title" for="__drawer">
  101. <a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-nav__button md-logo" aria-label="AutoConnect for ESP8266/ESP32">
  102. <img src="images/arduino-logo.svg" alt="logo">
  103. </a>
  104. AutoConnect for ESP8266/ESP32
  105. </label>
  106. <div class="md-nav__source">
  107. <a href="https://github.com/Hieromon/AutoConnect" title="Go to repository" class="md-source">
  108. <div class="md-source__icon md-icon">
  109. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05L244 40.45a28.87 28.87 0 00-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 01-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 000 40.81l195.61 195.6a28.86 28.86 0 0040.8 0l194.69-194.69a28.86 28.86 0 000-40.81z"/></svg>
  110. </div>
  111. <div class="md-source__repository">
  112. Hieromon/AutoConnect
  113. </div>
  114. </a>
  115. </div>
  116. <ul class="md-nav__list" data-md-scrollfix>
  117. <li class="md-nav__item">
  118. <a href="index.html" class="md-nav__link">
  119. Overview
  120. </a>
  121. </li>
  122. <li class="md-nav__item">
  123. <a href="gettingstarted.html" class="md-nav__link">
  124. Getting started
  125. </a>
  126. </li>
  127. <li class="md-nav__item">
  128. <a href="menu.html" class="md-nav__link">
  129. AutoConnect menu
  130. </a>
  131. </li>
  132. <li class="md-nav__item">
  133. <a href="basicusage.html" class="md-nav__link">
  134. Basic usage
  135. </a>
  136. </li>
  137. <li class="md-nav__item md-nav__item--active md-nav__item--nested">
  138. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5" checked>
  139. <label class="md-nav__link" for="nav-5">
  140. Advanced usage
  141. <span class="md-nav__icon md-icon"></span>
  142. </label>
  143. <nav class="md-nav" aria-label="Advanced usage" data-md-level="1">
  144. <label class="md-nav__title" for="nav-5">
  145. <span class="md-nav__icon md-icon"></span>
  146. Advanced usage
  147. </label>
  148. <ul class="md-nav__list" data-md-scrollfix>
  149. <li class="md-nav__item">
  150. <a href="advancedusage.html" class="md-nav__link">
  151. Advanced usage
  152. </a>
  153. </li>
  154. <li class="md-nav__item md-nav__item--active">
  155. <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
  156. <label class="md-nav__link md-nav__link--active" for="__toc">
  157. AutoConnect WiFi connection control
  158. <span class="md-nav__icon md-icon"></span>
  159. </label>
  160. <a href="adconnection.html" class="md-nav__link md-nav__link--active">
  161. AutoConnect WiFi connection control
  162. </a>
  163. <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  164. <label class="md-nav__title" for="__toc">
  165. <span class="md-nav__icon md-icon"></span>
  166. Table of contents
  167. </label>
  168. <ul class="md-nav__list" data-md-scrollfix>
  169. <li class="md-nav__item">
  170. <a href="#automatic-reconnect" class="md-nav__link">
  171. Automatic reconnect
  172. </a>
  173. </li>
  174. <li class="md-nav__item">
  175. <a href="#automatic-reconnect-background" class="md-nav__link">
  176. Automatic reconnect (Background)
  177. </a>
  178. </li>
  179. <li class="md-nav__item">
  180. <a href="#configure-wifi-channel" class="md-nav__link">
  181. Configure WiFi channel
  182. </a>
  183. </li>
  184. <li class="md-nav__item">
  185. <a href="#connects-depending-on-the-wifi-signal-strength" class="md-nav__link">
  186. Connects depending on the WiFi signal strength
  187. </a>
  188. </li>
  189. <li class="md-nav__item">
  190. <a href="#detects-connection-establishment-to-ap" class="md-nav__link">
  191. Detects connection establishment to AP
  192. </a>
  193. </li>
  194. <li class="md-nav__item">
  195. <a href="#match-with-known-access-points-by-ssid" class="md-nav__link">
  196. Match with known access points by SSID
  197. </a>
  198. </li>
  199. <li class="md-nav__item">
  200. <a href="#preserve-ap-mode" class="md-nav__link">
  201. Preserve AP mode
  202. </a>
  203. </li>
  204. <li class="md-nav__item">
  205. <a href="#timeout-settings-for-a-connection-attempt" class="md-nav__link">
  206. Timeout settings for a connection attempt
  207. </a>
  208. </li>
  209. </ul>
  210. </nav>
  211. </li>
  212. <li class="md-nav__item">
  213. <a href="adcpcontrol.html" class="md-nav__link">
  214. Captive portal control
  215. </a>
  216. </li>
  217. <li class="md-nav__item">
  218. <a href="adnetwork.html" class="md-nav__link">
  219. Settings and controls for network and WiFi
  220. </a>
  221. </li>
  222. <li class="md-nav__item">
  223. <a href="adauthentication.html" class="md-nav__link">
  224. Authentication settings
  225. </a>
  226. </li>
  227. <li class="md-nav__item">
  228. <a href="adcredential.html" class="md-nav__link">
  229. Credential accesses
  230. </a>
  231. </li>
  232. <li class="md-nav__item">
  233. <a href="adexterior.html" class="md-nav__link">
  234. Customizing page appearance
  235. </a>
  236. </li>
  237. <li class="md-nav__item">
  238. <a href="adothers.html" class="md-nav__link">
  239. Other operation settings and controls
  240. </a>
  241. </li>
  242. </ul>
  243. </nav>
  244. </li>
  245. <li class="md-nav__item md-nav__item--nested">
  246. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6" >
  247. <label class="md-nav__link" for="nav-6">
  248. Custom Web pages
  249. <span class="md-nav__icon md-icon"></span>
  250. </label>
  251. <nav class="md-nav" aria-label="Custom Web pages" data-md-level="1">
  252. <label class="md-nav__title" for="nav-6">
  253. <span class="md-nav__icon md-icon"></span>
  254. Custom Web pages
  255. </label>
  256. <ul class="md-nav__list" data-md-scrollfix>
  257. <li class="md-nav__item">
  258. <a href="acintro.html" class="md-nav__link">
  259. Custom Web pages with AutoConnect
  260. </a>
  261. </li>
  262. <li class="md-nav__item">
  263. <a href="acelements.html" class="md-nav__link">
  264. AutoConnectElements
  265. </a>
  266. </li>
  267. <li class="md-nav__item">
  268. <a href="acjson.html" class="md-nav__link">
  269. Custom Web pages with JSON
  270. </a>
  271. </li>
  272. <li class="md-nav__item">
  273. <a href="achandling.html" class="md-nav__link">
  274. Handling the custom Web pages
  275. </a>
  276. </li>
  277. </ul>
  278. </nav>
  279. </li>
  280. <li class="md-nav__item md-nav__item--nested">
  281. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7" >
  282. <label class="md-nav__link" for="nav-7">
  283. OTA Updates
  284. <span class="md-nav__icon md-icon"></span>
  285. </label>
  286. <nav class="md-nav" aria-label="OTA Updates" data-md-level="1">
  287. <label class="md-nav__title" for="nav-7">
  288. <span class="md-nav__icon md-icon"></span>
  289. OTA Updates
  290. </label>
  291. <ul class="md-nav__list" data-md-scrollfix>
  292. <li class="md-nav__item">
  293. <a href="otaupdate.html" class="md-nav__link">
  294. OTA Updates
  295. </a>
  296. </li>
  297. <li class="md-nav__item">
  298. <a href="otabrowser.html" class="md-nav__link">
  299. Using Web Browser
  300. </a>
  301. </li>
  302. <li class="md-nav__item">
  303. <a href="otaserver.html" class="md-nav__link">
  304. Using Update Server
  305. </a>
  306. </li>
  307. </ul>
  308. </nav>
  309. </li>
  310. <li class="md-nav__item md-nav__item--nested">
  311. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8" >
  312. <label class="md-nav__link" for="nav-8">
  313. Library APIs
  314. <span class="md-nav__icon md-icon"></span>
  315. </label>
  316. <nav class="md-nav" aria-label="Library APIs" data-md-level="1">
  317. <label class="md-nav__title" for="nav-8">
  318. <span class="md-nav__icon md-icon"></span>
  319. Library APIs
  320. </label>
  321. <ul class="md-nav__list" data-md-scrollfix>
  322. <li class="md-nav__item">
  323. <a href="api.html" class="md-nav__link">
  324. AutoConnect API
  325. </a>
  326. </li>
  327. <li class="md-nav__item">
  328. <a href="apiaux.html" class="md-nav__link">
  329. AutoConnectAux API
  330. </a>
  331. </li>
  332. <li class="md-nav__item">
  333. <a href="apiconfig.html" class="md-nav__link">
  334. AutoConnectConfig API
  335. </a>
  336. </li>
  337. <li class="md-nav__item">
  338. <a href="apielements.html" class="md-nav__link">
  339. AutoConnectElements API
  340. </a>
  341. </li>
  342. <li class="md-nav__item">
  343. <a href="apiupdate.html" class="md-nav__link">
  344. AutoConnectUpdate API
  345. </a>
  346. </li>
  347. <li class="md-nav__item">
  348. <a href="apiextra.html" class="md-nav__link">
  349. Something extra
  350. </a>
  351. </li>
  352. </ul>
  353. </nav>
  354. </li>
  355. <li class="md-nav__item md-nav__item--nested">
  356. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-9" type="checkbox" id="nav-9" >
  357. <label class="md-nav__link" for="nav-9">
  358. Examples
  359. <span class="md-nav__icon md-icon"></span>
  360. </label>
  361. <nav class="md-nav" aria-label="Examples" data-md-level="1">
  362. <label class="md-nav__title" for="nav-9">
  363. <span class="md-nav__icon md-icon"></span>
  364. Examples
  365. </label>
  366. <ul class="md-nav__list" data-md-scrollfix>
  367. <li class="md-nav__item">
  368. <a href="howtoembed.html" class="md-nav__link">
  369. How to embed
  370. </a>
  371. </li>
  372. <li class="md-nav__item">
  373. <a href="datatips.html" class="md-nav__link">
  374. Tips for data conversion
  375. </a>
  376. </li>
  377. <li class="md-nav__item">
  378. <a href="menuize.html" class="md-nav__link">
  379. Attach the menus
  380. </a>
  381. </li>
  382. <li class="md-nav__item">
  383. <a href="wojson.html" class="md-nav__link">
  384. Custom Web pages w/o JSON
  385. </a>
  386. </li>
  387. </ul>
  388. </nav>
  389. </li>
  390. <li class="md-nav__item md-nav__item--nested">
  391. <input class="md-nav__toggle md-toggle" data-md-toggle="nav-10" type="checkbox" id="nav-10" >
  392. <label class="md-nav__link" for="nav-10">
  393. Appendix
  394. <span class="md-nav__icon md-icon"></span>
  395. </label>
  396. <nav class="md-nav" aria-label="Appendix" data-md-level="1">
  397. <label class="md-nav__title" for="nav-10">
  398. <span class="md-nav__icon md-icon"></span>
  399. Appendix
  400. </label>
  401. <ul class="md-nav__list" data-md-scrollfix>
  402. <li class="md-nav__item">
  403. <a href="lsbegin.html" class="md-nav__link">
  404. Inside AutoConnect::begin
  405. </a>
  406. </li>
  407. <li class="md-nav__item">
  408. <a href="credit.html" class="md-nav__link">
  409. Saved credentials access
  410. </a>
  411. </li>
  412. <li class="md-nav__item">
  413. <a href="acupload.html" class="md-nav__link">
  414. File upload handler
  415. </a>
  416. </li>
  417. <li class="md-nav__item">
  418. <a href="colorized.html" class="md-nav__link">
  419. Custom colorized
  420. </a>
  421. </li>
  422. <li class="md-nav__item">
  423. <a href="changelabel.html" class="md-nav__link">
  424. Change label text
  425. </a>
  426. </li>
  427. </ul>
  428. </nav>
  429. </li>
  430. <li class="md-nav__item">
  431. <a href="faq.html" class="md-nav__link">
  432. FAQ
  433. </a>
  434. </li>
  435. <li class="md-nav__item">
  436. <a href="changelog.html" class="md-nav__link">
  437. Change log
  438. </a>
  439. </li>
  440. <li class="md-nav__item">
  441. <a href="license.html" class="md-nav__link">
  442. License
  443. </a>
  444. </li>
  445. </ul>
  446. </nav>
  447. </div>
  448. </div>
  449. </div>
  450. <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
  451. <div class="md-sidebar__scrollwrap">
  452. <div class="md-sidebar__inner">
  453. <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  454. <label class="md-nav__title" for="__toc">
  455. <span class="md-nav__icon md-icon"></span>
  456. Table of contents
  457. </label>
  458. <ul class="md-nav__list" data-md-scrollfix>
  459. <li class="md-nav__item">
  460. <a href="#automatic-reconnect" class="md-nav__link">
  461. Automatic reconnect
  462. </a>
  463. </li>
  464. <li class="md-nav__item">
  465. <a href="#automatic-reconnect-background" class="md-nav__link">
  466. Automatic reconnect (Background)
  467. </a>
  468. </li>
  469. <li class="md-nav__item">
  470. <a href="#configure-wifi-channel" class="md-nav__link">
  471. Configure WiFi channel
  472. </a>
  473. </li>
  474. <li class="md-nav__item">
  475. <a href="#connects-depending-on-the-wifi-signal-strength" class="md-nav__link">
  476. Connects depending on the WiFi signal strength
  477. </a>
  478. </li>
  479. <li class="md-nav__item">
  480. <a href="#detects-connection-establishment-to-ap" class="md-nav__link">
  481. Detects connection establishment to AP
  482. </a>
  483. </li>
  484. <li class="md-nav__item">
  485. <a href="#match-with-known-access-points-by-ssid" class="md-nav__link">
  486. Match with known access points by SSID
  487. </a>
  488. </li>
  489. <li class="md-nav__item">
  490. <a href="#preserve-ap-mode" class="md-nav__link">
  491. Preserve AP mode
  492. </a>
  493. </li>
  494. <li class="md-nav__item">
  495. <a href="#timeout-settings-for-a-connection-attempt" class="md-nav__link">
  496. Timeout settings for a connection attempt
  497. </a>
  498. </li>
  499. </ul>
  500. </nav>
  501. </div>
  502. </div>
  503. </div>
  504. <div class="md-content">
  505. <article class="md-content__inner md-typeset">
  506. <h1>AutoConnect WiFi connection control</h1>
  507. <p>AutoConnect aims to connect the ESP module as a station to a WiFi access point and equips with various APIs to maintain a WiFi connection as possible while sketch running. The main APIs are <a href="api.html#begin">AutoConnect::begin</a> and <a href="api.html#handleclient">AutoConnect::handleClient</a>. You can make sketches with flexible WiFi connection capability by properly using these two APIs and the settings by <a href="apiconfig.html">AutoConnectConfig</a>.</p>
  508. <ul>
  509. <li><a href="#automatic-reconnect">Automatic reconnect</a></li>
  510. <li><a href="#automatic-reconnect-background">Automatic reconnect (Background)</a></li>
  511. <li><a href="#configure-wifi-channel">Configure WiFi channel</a></li>
  512. <li><a href="#connects-depending-on-the-wifi-signal-strength">Connects depending on the WiFi signal strength</a></li>
  513. <li><a href="#detects-connection-establishment-to-ap">Detects connection establishment to AP</a></li>
  514. <li><a href="#match-with-known-access-points-by-ssid">Match with known access points by SSID</a></li>
  515. <li><a href="#preserve-ap-mode">Preserve AP mode</a></li>
  516. <li><a href="#timeout-settings-for-a-connection-attempt">Timeout settings for a connection attempt</a></li>
  517. </ul>
  518. <h2 id="automatic-reconnect">Automatic reconnect<a class="headerlink" href="#automatic-reconnect" title="Permanent link">&para;</a></h2>
  519. <p>AutoConnect will change the WiFi mode depending on the situation. The <a href="lsbegin.html">AutoConnect::begin</a> function starts WiFi mode in <strong>STA</strong> and starts the webserver if the connection is successful by the <a href="lsbegin.html"><strong>1<sup>st</sup>-WiFi.begin</strong></a>. But if it will fail to connect with the least recently established access point, it will switch the WiFi mode to <strong>AP_STA</strong> and starts the DNS server to be able to launch a captive portal.</p>
  520. <p>When the captive portal starts, <strong>SoftAP</strong> starts and STA disconnected. At this point, the station configuration information (it is known as the SDK's <a href="https://github.com/esp8266/Arduino/blob/db75d2c448bfccc6dc308bdeb9fbd3efca7927ff/tools/sdk/include/user_interface.h#L249">station_config</a> structure) that the ESP module has stored on its own is discarded.</p>
  521. <p>AutoConnect can connect to an access point again that has disconnected once, and its control is allowed by <a href="apiconfig.html#autoreconnect"><em>AutoConnectConfig::autoReconnect</em></a> that option specifies to attempt to reconnect to the past established access point using the saved credentials. If the <a href="apiconfig.html#autoreconnect"><strong>autoReconnect</strong></a> is enabled, AutoConnect will not launch SoftAP immediately even if 1<sup>st</sup>-WiFi.begin fails. When AutoConnect fails to connect WiFi, it will scan the WiFi signal to find out which access points it had connected to in the past. Then if it finds the saved BSSID in the broadcasts, AutoConnect will attempt to connect again applying the matched credential explicitly while still in STA mode. (AutoReconnect works well even with hidden SSID access points)</p>
  522. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  523. <span style="color: #f8f8f2">AutoConnectConfig</span> <span style="color: #f8f8f2">Config;</span>
  524. <span style="background-color: #49483e"><span style="color: #f8f8f2">Config.autoReconnect</span> <span style="color: #f92672">=</span> <span style="color: #f8f8f2">true;</span>
  525. </span><span style="color: #f8f8f2">Portal.config(Config);</span>
  526. <span style="color: #f8f8f2">Portal.begin();</span>
  527. </code></pre></div>
  528. <p>The <a href="apiconfig.html#autoreconnect"><strong>autoReconnect</strong></a> option is only available for <a href="api.html#begin">AutoConnect::begin</a> without SSID and PASSWORD parameter. If you use <a href="api.html#begin">AutoConnect::begin</a> with an SSID and PASSWORD, no reconnection attempt will be made if the 1<sup>st</sup>-WiFi.begin fails to connect to that SSID.</p>
  529. <div class="admonition note">
  530. <p class="admonition-title">The autoReconnect is not autoreconnect</p>
  531. <p>The <a href="https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46"><em>WiFiSTAClass::disconnect</em></a> function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the <a href="https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296">ESP8266WiFiSTAClass</a> has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by the arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core.</p>
  532. </div>
  533. <h2 id="automatic-reconnect-background">Automatic reconnect (Background)<a class="headerlink" href="#automatic-reconnect-background" title="Permanent link">&para;</a></h2>
  534. <p>Combining <a href="advancedusage.html#automatic-reconnect"><strong>autoReconnect</strong></a> with <a href="apiconfig.html#reconnectinterval"><em>AutoConnectConfig::reconnectInterval</em></a> allows you to periodically repeat connection attempts to known access points within <a href="api.html#handleclient">AutoConnect::handleClient</a>. This process is pseudo-asynchronous and does not block the Sketch process in the <code>loop()</code> function.</p>
  535. <p>The reconnectInterval specifies the interval time to seek for known access points with saved credentials during the <strong>handleClient</strong> loop and attempt to connect to the AP.</p>
  536. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  537. <span style="color: #f8f8f2">AutoConnectConfig</span> <span style="color: #f8f8f2">Config;</span>
  538. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  539. <span style="background-color: #49483e"> <span style="color: #f8f8f2">Config.autoReconnect</span> <span style="color: #f92672">=</span> <span style="color: #f8f8f2">true;</span> <span style="color: #75715e">// Attempt automatic reconnection.</span>
  540. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Config.reconnectInterval</span> <span style="color: #f92672">=</span> <span style="color: #ae81ff">6</span><span style="color: #f8f8f2">;</span> <span style="color: #75715e">// Seek interval time is 180[s].</span>
  541. </span> <span style="color: #f8f8f2">Portal.config(Config);</span>
  542. <span style="color: #f8f8f2">Portal.begin();</span>
  543. <span style="color: #f8f8f2">}</span>
  544. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  545. <span style="color: #66d9ef">if</span> <span style="color: #f8f8f2">(WiFi.status()</span> <span style="color: #f92672">==</span> <span style="color: #f8f8f2">WL_CONNECTED)</span> <span style="color: #f8f8f2">{</span>
  546. <span style="color: #75715e">// Here to do when WiFi is connected.</span>
  547. <span style="color: #f8f8f2">}</span>
  548. <span style="color: #66d9ef">else</span> <span style="color: #f8f8f2">{</span>
  549. <span style="color: #75715e">// Here to do when WiFi is not connected.</span>
  550. <span style="color: #f8f8f2">}</span>
  551. <span style="color: #f8f8f2">Portal.handleClient();</span>
  552. <span style="color: #f8f8f2">}</span>
  553. </code></pre></div>
  554. <p>Above Sketch shows a configuration example that you want to keep connecting to known access points as long as possible. When the WiFi connection is lost, it will start seeking the WiFi network every 30 seconds during the handleClient loop.</p>
  555. <div class="admonition info">
  556. <p class="admonition-title">Limitation for automatic reconnection to a specific access point</p>
  557. <p>An access point that ESP module to reconnect automatically depends on whether the SSID and password argument existence with <a href="api.html#begin">AutoConnect::begin</a>. If the Sketch calls <a href="api.html#begin">AutoConnect::begin</a> without specifying an SSID or password, the <a href="apiconfig.html#autoreconnect">autoReconnect</a> will connect to one of the detected access points and cannot be pre-determined.<br />
  558. The other one, the case of the Sketch specifies SSID and password with <a href="api.html#begin">AutoConnect::begin</a>, the <a href="apiconfig.html#autoreconnect">autoReconnect</a> will try to reconnect to a specified access point periodically during the handleClient loop.</p>
  559. </div>
  560. <p>Also, you can combine the background automatic reconnect performing inside the loop function by <a href="api.html#handleclient">handleClient</a> with <a href="apiconfig.html#retainportal"><em>AutoConnectConfig::retainPortal</em></a> and <a href="apiconfig.html#autoreset"><em>AutoConnectConfig::autoReset</em></a>, to enable pop up the captive portal automatically on the client device each time the ESP module disconnects from the access point.</p>
  561. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  562. <span style="color: #f8f8f2">AutoConnectConfig</span> <span style="color: #f8f8f2">Config;</span>
  563. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  564. <span style="color: #f8f8f2">Config.autoReset</span> <span style="color: #f92672">=</span> <span style="color: #f8f8f2">false;</span> <span style="color: #75715e">// Not reset the module even by intentional disconnection using AutoConnect menu.</span>
  565. <span style="color: #f8f8f2">Config.autoReconnect</span> <span style="color: #f92672">=</span> <span style="color: #f8f8f2">true;</span> <span style="color: #75715e">// Reconnect to known access points.</span>
  566. <span style="color: #f8f8f2">Config.reconnectInterval</span> <span style="color: #f92672">=</span> <span style="color: #ae81ff">6</span><span style="color: #f8f8f2">;</span> <span style="color: #75715e">// Reconnection attempting interval is 3[min].</span>
  567. <span style="color: #f8f8f2">Config.retainPortal</span> <span style="color: #f92672">=</span> <span style="color: #f8f8f2">true;</span> <span style="color: #75715e">// Keep the captive portal open.</span>
  568. <span style="color: #f8f8f2">Portal.config(Config);</span>
  569. <span style="color: #f8f8f2">Portal.begin();</span>
  570. <span style="color: #f8f8f2">}</span>
  571. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  572. <span style="color: #66d9ef">if</span> <span style="color: #f8f8f2">(WiFi.status()</span> <span style="color: #f92672">==</span> <span style="color: #f8f8f2">WL_CONNECTED)</span> <span style="color: #f8f8f2">{</span>
  573. <span style="color: #75715e">// Here to do when WiFi is connected.</span>
  574. <span style="color: #f8f8f2">}</span>
  575. <span style="color: #66d9ef">else</span> <span style="color: #f8f8f2">{</span>
  576. <span style="color: #75715e">// Here to do when WiFi is not connected.</span>
  577. <span style="color: #f8f8f2">}</span>
  578. <span style="color: #f8f8f2">}</span>
  579. </code></pre></div>
  580. <div class="admonition info">
  581. <p class="admonition-title">The effective range of the <a href="apiconfig.html#reconnectinterval">reconnectInterval</a> depending on the setting value</p>
  582. <p>The range of values that reconnectInterval can take is 0 to 255. (Actual seconds are from 0 to 255&#xd7;AUTOCONNECT_UNITTIME)<br>
  583. Reconnect behavior depends on the setting value. If it is 0, reconnection will work if the 1<sup>st</sup>-WiFi.begin in AutoConnect::begin fails and will suspend during the handleClient loop. If reconnectInterval is greater than 0, AutoConnect will attempt to reconnect both in AutoConnect::begin and during the handleClient loop.</p>
  584. </div>
  585. <h2 id="configure-wifi-channel">Configure WiFi channel<a class="headerlink" href="#configure-wifi-channel" title="Permanent link">&para;</a></h2>
  586. <p>Appropriately specifying the WiFi channel to use for ESP8266 and ESP32 is essential for a stable connection with the access point. AutoConnect remembers the WiFi channel with a credential of the access point once connected and reuses it.</p>
  587. <p>The default channel when a captive portal starts and AutoConnect itself becomes an access point is the <a href="apiconfig.html#channel"><em>AutoConnectConfig::channel</em></a> member. If this channel is different from the channel of the access point you will attempt to connect, WiFi.begin may fail. The cause is that the ESP module shares the same channel in AP mode and STA mode. If the connection attempt is not stable, specifying a proper channel using AutoConnectConfig::channel may result in a stable connection.</p>
  588. <h2 id="connects-depending-on-the-wifi-signal-strength">Connects depending on the WiFi signal strength<a class="headerlink" href="#connects-depending-on-the-wifi-signal-strength" title="Permanent link">&para;</a></h2>
  589. <p>When the ESP module found the multiple available access points (ie. AutoConnect has connected in the past), the default behavior AutoConnect will attempt to connect to the least recent one. However, If the ESP module can operate properly with any access point, it is advantageous to establish a connection with the best one of the reception sensitivity. </p>
  590. <p>The <a href="apiconfig.html#principle"><em>AutoConnectConfig::principle</em></a> parameter has the connection disposition, and specifying <strong>AC_PRINCIPLE_RSSI</strong> will attempt to connect to one of the highest RSSI value among multiple available access points. Also You can expect stable WiFi connection by specifying the lower limit of signal strength using <a href="apiconfig.html#minrssi"><em>AutoConnectConfig::minRSSI</em></a>.<br />
  591. Combining these two parameters allows you to filter the destination AP when multiple available access points are found.</p>
  592. <p><a href="apiconfig.html#principle"><em>AutoConnectConfig::principle</em></a> affects the behavior of both 1<sup>st</sup>-WiFi.begin and <a href="advancedusage.html#automatic-reconnect"><strong>autoReconnect</strong></a>. If you specify <strong>AC_PRINCIPLE_RECENT</strong> for the <a href="apiconfig.html#principle"><strong>principle</strong></a>, it will try according to the conventional connection rules, but if you specify <strong>AC_PRINCIPLE_RSSI</strong>, it will try to connect to the access point that is sending the strongest WiFi signal at that time instead of the last accessed AP. Also, the static IPs will be restored from a saved credential instead of AutoConnectConfig. (The values specified by AutoConnectConfig is ignored)</p>
  593. <table>
  594. <tr>
  595. <th rowspan="2"></th>
  596. <th rowspan="2">SSID &amp;<br>Password</th>
  597. <th rowspan="2">AutoConnectConfig<br>::principle</th>
  598. <th rowspan="2">Which credentials would be selected</th>
  599. <th rowspan="2">Static IPs</th>
  600. </tr>
  601. <tr>
  602. </tr>
  603. <tr>
  604. <td rowspan="3">AutoConnect<br>::begin</td>
  605. <td rowspan="2">NULL specified</td>
  606. <td>AC_PRINCIPLE_RECENT</td>
  607. <td>Nothing, depends on SDK saves</td>
  608. <td>Use the specified value of AutoConnectConfig<br></td>
  609. </tr>
  610. <tr>
  611. <td>AC_PRINCIPLE_RSSI</td>
  612. <td>Auto-selected credentials with max RSSI</td>
  613. <td>Restoring static IPs suitable for the SSID from saved credentials</td>
  614. </tr>
  615. <tr>
  616. <td>Specified with the Sketch</td>
  617. <td>Not effective</td>
  618. <td>By AutoConnect::begin parameters</td>
  619. <td>Use the specified value of AutoConnectConfig</td>
  620. </tr>
  621. <tr>
  622. <td rowspan="2">AutoReconnect</td>
  623. <td rowspan="2">Load from<br>saved credential</td>
  624. <td>AC_PRINCIPLE_RECENT</td>
  625. <td>Recently saved SSID would be chosen</td>
  626. <td rowspan="2">Restoring static IPs suitable for the SSID from saved credentials</td>
  627. </tr>
  628. <tr>
  629. <td>AC_PRINCIPLE_RSSI</td>
  630. <td>Auto-selected credentials with max RSSI</td>
  631. </tr>
  632. </table>
  633. <h2 id="detects-connection-establishment-to-ap">Detects connection establishment to AP<a class="headerlink" href="#detects-connection-establishment-to-ap" title="Permanent link">&para;</a></h2>
  634. <p>The Sketch can detect that the ESP module has established a WiFi connection as a station to the access point. The <a href="api.html#begin">AutoConnect::begin</a> or <a href="api.html#handleclient">AutoConnect::handleClient</a> will transit the control temporarily to the function in the Sketch registered by <a href="api.html#onconnect">AutoConnect::onConnect</a> when the ESP module establish a WiFi connection.<br />
  635. The <strong>ConnectExit</strong> function registered with <a href="api.html#onconnect">AutoConnect::onConnect</a> should have the following types and arguments:</p>
  636. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #66d9ef">void</span> <span style="color: #f8f8f2">ConnectExit(IPAddress</span><span style="color: #f92672">&amp;</span> <span style="color: #f8f8f2">ip)</span>
  637. </code></pre></div>
  638. <p>The <strong>ConnectExit</strong> function is of type <em>void</em>. The argument <em>ip</em> is the IP address assigned to the ESP module by the connected AP. <a href="api.html#onconnect">AutoConnect::onConnect</a> allows the Sketch registers a <strong>ConnectExit</strong> function to AutoConnect. Also, you can make the function using a <a href="https://en.cppreference.com/w/cpp/language/lambda"><strong>lambda expression</strong></a>.</p>
  639. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  640. <span style="background-color: #49483e"><span style="color: #66d9ef">void</span> <span style="color: #a6e22e">onConnect</span><span style="color: #f8f8f2">(IPAddress</span><span style="color: #f92672">&amp;</span> <span style="color: #f8f8f2">ipaddr)</span> <span style="color: #f8f8f2">{</span>
  641. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.print(</span><span style="color: #e6db74">&quot;WiFi connected with &quot;</span><span style="color: #f8f8f2">);</span>
  642. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.print(WiFi.SSID());</span>
  643. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.print(</span><span style="color: #e6db74">&quot;, IP:&quot;</span><span style="color: #f8f8f2">);</span>
  644. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.println(ipaddr.toString());</span>
  645. </span><span style="background-color: #49483e"><span style="color: #f8f8f2">}</span>
  646. </span>
  647. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  648. <span style="color: #f8f8f2">Serial.begin(</span><span style="color: #ae81ff">115200</span><span style="color: #f8f8f2">);</span>
  649. <span style="background-color: #49483e"> <span style="color: #f8f8f2">Portal.onConnect(onConnect);</span> <span style="color: #75715e">// Register the ConnectExit function</span>
  650. </span> <span style="color: #f8f8f2">Portal.begin();</span>
  651. <span style="color: #f8f8f2">}</span>
  652. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  653. <span style="color: #f8f8f2">Portal.handleClient();</span>
  654. <span style="color: #f8f8f2">}</span>
  655. </code></pre></div>
  656. <p>In addition, a sketch that shuts down SoftAP when the ESP module connects to the access point can be described using a lambda expression as follows:</p>
  657. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  658. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  659. <span style="color: #f8f8f2">Serial.begin(</span><span style="color: #ae81ff">115200</span><span style="color: #f8f8f2">);</span>
  660. <span style="background-color: #49483e"> <span style="color: #f8f8f2">Portal.onConnect([](IPAddress</span><span style="color: #f92672">&amp;</span> <span style="color: #f8f8f2">ipaddr){</span>
  661. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.printf(</span><span style="color: #e6db74">&quot;WiiFi connected with %s, IP:%s</span><span style="color: #ae81ff">\n</span><span style="color: #e6db74">&quot;</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">WiFi.SSID().c_str(),</span> <span style="color: #f8f8f2">ipaddr.toString().c_str());</span>
  662. </span><span style="background-color: #49483e"> <span style="color: #66d9ef">if</span> <span style="color: #f8f8f2">(WiFi.getMode()</span> <span style="color: #f92672">&amp;</span> <span style="color: #f8f8f2">WIFI_AP)</span> <span style="color: #f8f8f2">{</span>
  663. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">WiFi.softAPdisconnect(true);</span>
  664. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">WiFi.enableAP(false);</span>
  665. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">Serial.printf(</span><span style="color: #e6db74">&quot;SoftAP:%s shut down</span><span style="color: #ae81ff">\n</span><span style="color: #e6db74">&quot;</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">WiFi.softAPSSID().c_str());</span>
  666. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">}</span>
  667. </span><span style="background-color: #49483e"> <span style="color: #f8f8f2">});</span>
  668. </span> <span style="color: #f8f8f2">Portal.begin();</span>
  669. <span style="color: #f8f8f2">}</span>
  670. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  671. <span style="color: #f8f8f2">Portal.handleClient();</span>
  672. <span style="color: #f8f8f2">}</span>
  673. </code></pre></div>
  674. <div class="admonition note">
  675. <p class="admonition-title">It is not an event</p>
  676. <p>AutoConnect::onConnect has the same effect on the Sketch as the <a href="https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#onevent">WiFi.onStationModeConnected</a>, but AutoConnect does not use the event. Sketch can use <code>WiFi.onEvent</code> independently of AutoConnect.</p>
  677. </div>
  678. <h2 id="match-with-known-access-points-by-ssid">Match with known access points by SSID<a class="headerlink" href="#match-with-known-access-points-by-ssid" title="Permanent link">&para;</a></h2>
  679. <p>By default, AutoConnect uses the <strong>BSSID</strong> to search for known access points. (Usually, it's the MAC address of the device) By using BSSID as the key to finding the WiFi network, AutoConnect can find even if the access point is hidden. However BSSIDs can change on some mobile hotspots, the BSSID-keyed searches may not be able to find known access points.<br />
  680. If you operate inconvenience in aiming at the access point by BSSID, you can change the collation key from BSSID to SSID by uncommenting <code>AUTOCONNECT_APKEY_SSID</code> macro definition in <a href="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L59"><code>AutoConnectDefs.h</code></a> library source code.</p>
  681. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #75715e">#define AUTOCONNECT_APKEY_SSID</span>
  682. </code></pre></div>
  683. <p>Allow you to use <a href="https://platformio.org/platformio-ide">PlatformIO</a> as a build system and give the following description to the <a href="https://docs.platformio.org/en/latest/projectconf/section_env_build.html?highlight=build_flags#build-flags"><code>platformio.ini</code></a>, you can enable <strong>AUTOCONNECT_APKEY_SSID</strong> each build without modifying the library source code:</p>
  684. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #a6e22e">build_flags</span><span style="color: #f92672">=</span><span style="color: #e6db74">-DAUTOCONNECT_APKEY_SSID</span>
  685. </code></pre></div>
  686. <div class="admonition info">
  687. <p class="admonition-title">Can't be found hidden APs in SSID-keyed</p>
  688. <p>The hidden access point's SSID will be blank on the broadcast. So if the seek key is an SSID, AutoConnect will not find it.</p>
  689. </div>
  690. <h2 id="preserve-ap-mode">Preserve AP mode<a class="headerlink" href="#preserve-ap-mode" title="Permanent link">&para;</a></h2>
  691. <p>Sketch using AutoConnect can open a gateway to the Internet by connecting to a WiFi router even through use Espressif's peculiar WiFi protocol (eg. <a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/mesh.html">ESP-MESH</a> or <a href="https://www.espressif.com/en/products/software/esp-now">ESP-NOW</a>). These specific communication protocols require to keeps AP + STA as the WiFi mode. That is, to apply these protocols, it needs to launch SoftAP by a sketch itself and then call <a href="api.html#begin">AutoConnect::begin</a>. But the default behavior of <a href="api.html#begin">AutoConnect::begin</a> will turn off SoftAP always then it will unable to open a connection.</p>
  692. <p><a href="apiconfig.html#preserveAPMode"><em>AutoConnectConfig::preserveAPMode</em></a> setting maintains WIFI_AP mode without disabling SoftAP inside <a href="api.html#begin">AutoConnect::begin</a>. The Sketch can utilize the WiFi connection via AutoConnect with ESP-MESH and ESP-NOW protocol by enabling this option.</p>
  693. <p>The following diagram quoted from the <a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/mesh.html#mesh-building-a-network">ESP-MESH documentation</a> that illustrates the typical topology of the MESH network. The module located at the Root Node bridges between the mesh network and the router by an application that handles two protocols, TCP/IP and ESP-MESH. Its SoftAP communicates with the internal mesh network as an interface of the mesh layer. On the other hand, STA performs station communication with the WiFi router as an interface of the TCP/IP layer. AutoConnect allows assists the connection between the router and the STA of the Root Node using <a href="apiconfig.html#preserveapmode"><em>AutoConnectConfig::preserveAPMode</em></a> and starting the SoftAP via Sketch separately.</p>
  694. <p><img src="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/_images/mesh-bidirectional-data-stream.png"></p>
  695. <p>Also in general, the Sketch should set <strong>false</strong> to <a href="apiconfig.html#autorise"><em>AutoConnectConfig::autoRise</em></a>, <strong>true</strong> to <a href="apiconfig.html#immediatestart"><em>AutoConnectConfig::immediateStart</em></a> when applying to those protocols.</p>
  696. <h2 id="timeout-settings-for-a-connection-attempt">Timeout settings for a connection attempt<a class="headerlink" href="#timeout-settings-for-a-connection-attempt" title="Permanent link">&para;</a></h2>
  697. <p>AutoConnect uses <a href="apiconfig.html#begintimeout"><em>AutoConnectConfig::beginTimeout</em></a> value to limit time to attempt when connecting the ESP module to the access point as a WiFi station. The default value is <strong>AUTOCONNECT_TIMEOUT</strong> defined in <a href="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L132"><code>AutoConnectDefs.h</code></a> and the initial value is 30 seconds. (actually specified in milliseconds)<br />
  698. For example, the following sketch sets the connection timeout to 15 seconds:</p>
  699. <div class="highlight" style="background: #272822"><pre style="line-height: 125%; margin: 0;"><span></span><code><span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">Portal;</span>
  700. <span style="color: #f8f8f2">AutoConnectConfig</span> <span style="color: #f8f8f2">Config;</span>
  701. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  702. <span style="background-color: #49483e"> <span style="color: #f8f8f2">Config.beginTimeout</span> <span style="color: #f92672">=</span> <span style="color: #ae81ff">15000</span><span style="color: #f8f8f2">;</span> <span style="color: #75715e">// Timeout sets to 15[s]</span>
  703. </span> <span style="color: #f8f8f2">Portal.config(Config);</span>
  704. <span style="color: #f8f8f2">Portal.begin();</span>
  705. <span style="color: #f8f8f2">}</span>
  706. <span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span> <span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
  707. <span style="color: #f8f8f2">Portal.handleClient();</span>
  708. <span style="color: #f8f8f2">}</span>
  709. </code></pre></div>
  710. <p>In addition, the limit of the waiting time for connection attempts can be specified by the <a href="api.html#begin">AutoConnect::begin</a> parameter too. The <em>timeout</em> parameter specified in <a href="api.html#begin">AutoConnect::begin</a> takes precedence over <a href="apiconfig.html#begintimeout"><em>AutoConnectConfig::beginTimeout</em></a>.</p>
  711. <div class="admonition note">
  712. <p class="admonition-title">The beginTimeout has an effect on handleClient</p>
  713. <p>The <a href="apiconfig.html#begintimeout"><strong>beginTimeout</strong></a> value will be applied with <a href="api.html#handleclient"><strong>handleClient</strong></a> when requesting a connection from the captive portal and when attempting to reconnect with <a href="apiconfig.html#autoreconnect"><strong>autoReconnect</strong></a>.</p>
  714. </div>
  715. </article>
  716. </div>
  717. </div>
  718. </main>
  719. <footer class="md-footer">
  720. <div class="md-footer-nav">
  721. <nav class="md-footer-nav__inner md-grid" aria-label="Footer">
  722. <a href="advancedusage.html" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
  723. <div class="md-footer-nav__button md-icon">
  724. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  725. </div>
  726. <div class="md-footer-nav__title">
  727. <div class="md-ellipsis">
  728. <span class="md-footer-nav__direction">
  729. Previous
  730. </span>
  731. Advanced usage
  732. </div>
  733. </div>
  734. </a>
  735. <a href="adcpcontrol.html" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
  736. <div class="md-footer-nav__title">
  737. <div class="md-ellipsis">
  738. <span class="md-footer-nav__direction">
  739. Next
  740. </span>
  741. Captive portal control
  742. </div>
  743. </div>
  744. <div class="md-footer-nav__button md-icon">
  745. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
  746. </div>
  747. </a>
  748. </nav>
  749. </div>
  750. <div class="md-footer-meta md-typeset">
  751. <div class="md-footer-meta__inner md-grid">
  752. <div class="md-footer-copyright">
  753. <div class="md-footer-copyright__highlight">
  754. Copyright &copy; 2018-2020 Hieromon Ikasamo
  755. </div>
  756. Made with
  757. <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
  758. Material for MkDocs
  759. </a>
  760. </div>
  761. <div class="md-footer-social">
  762. <a href="https://github.com/Hieromon" target="_blank" rel="noopener" title="github.com" class="md-footer-social__link">
  763. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  764. </a>
  765. <a href="https://twitter.com/hieromon" target="_blank" rel="noopener" title="twitter.com" class="md-footer-social__link">
  766. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"/></svg>
  767. </a>
  768. </div>
  769. </div>
  770. </div>
  771. </footer>
  772. </div>
  773. <script src="assets/javascripts/vendor.fd16492e.min.js"></script>
  774. <script src="assets/javascripts/bundle.7836ba4d.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}</script>
  775. <script>
  776. app = initialize({
  777. base: ".",
  778. features: [],
  779. search: Object.assign({
  780. worker: "assets/javascripts/worker/search.4ac00218.min.js"
  781. }, typeof search !== "undefined" && search)
  782. })
  783. </script>
  784. <script src="js/gifffer.min.js"></script>
  785. </body>
  786. </html>