├── LICENSE ├── README.md ├── examples ├── all_CompatibilityMode_demo │ └── all_CompatibilityMode_demo.ino ├── all_ConnectFailReset_demo │ └── all_ConnectFailReset_demo.ino ├── all_LittleFS_demo │ └── all_LittleFS_demo.ino ├── all_clearwifi_demo │ └── all_clearwifi_demo.ino ├── all_eeshow_demo │ └── all_eeshow_demo.ino ├── all_ota_only_demo │ └── all_ota_only_demo.ino ├── all_recommend_demo │ └── all_recommend_demo.ino ├── esp32_easy_demo │ └── esp32_easy_demo.ino ├── esp32_olibs_blinker_demo │ └── esp32_olibs_blinker_demo.ino ├── esp32_ota_easy_demo │ └── esp32_ota_easy_demo.ino ├── esp32_ota_zdyhtml_demo │ └── esp32_ota_zdyhtml_demo.ino ├── esp32_umsg_demo │ └── esp32_umsg_demo.ino ├── esp32_zdyhtml_demo │ └── esp32_zdyhtml_demo.ino ├── esp8266_easy_demo │ └── esp8266_easy_demo.ino ├── esp8266_olibs_blinker_demo │ └── esp8266_olibs_blinker_demo.ino ├── esp8266_ota_easy_demo │ └── esp8266_ota_easy_demo.ino ├── esp8266_ota_zdyhtml_demo │ └── esp8266_ota_zdyhtml_demo.ino ├── esp8266_umsg_demo │ └── esp8266_umsg_demo.ino └── esp8266_zdyhtml_demo │ └── esp8266_zdyhtml_demo.ino ├── keywords.txt ├── library.properties └── src ├── BGWiFiConfig.h └── DEFPORT.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BGWiFiConfig 2 | 一个为esp8266和esp32设计的简单易用Arduino配网库,可通过api配置WiFi网络,支持GET和POST请求配置;可通过微信小程序配网(小程序名:配网库);可通过默认网页配置WiFi网络;可自定义配网页面;可通过OTA网页升级程序固件。 3 | 4 | 5 | ## [查看开发文档【必看】](https://www.cbug.top/1app/bgwificonfig/#/) 6 | ### [BGWiFiConfig配置助手【开启和关闭eeshow模式】](https://www.cbug.top/article/25.html) 7 | 8 | ## 配网api 9 | ### 1.由DHCP分配ip信息: 10 | - mode:1 11 | - ssid:你要配置的WiFi名称 12 | - pwd:你要配置的WiFi密码 13 | ### 2.静态ip: 14 | - mode:2 15 | - ssid:你要配置的WiFi名称 16 | - pwd:你要配置的WiFi密码 17 | - ip:你要配置的WiFi的ip 18 | - gateway:你要配置的WiFi的网关 19 | - subnet:你要配置的WiFi的子网掩码 20 | - dns:你要配置的WiFi的dns 21 | 22 | ## 通过api配网: 23 | ``` 24 | 连接开发板生成的WiFi(用户名:WiFi配网,密码为空) 25 | ``` 26 | ### 1. GET请求配网 27 | ``` 28 | GET http://192.168.22.22:2022/api?mode=1&ssid=cam2&pwd=12345678 29 | ``` 30 | ### 2. POST请求配网 31 | ``` 32 | POST http://192.168.22.22:2022/api 33 | Content-Type: application/x-www-form-urlencoded 34 | 35 | mode=2&ssid=cam2&pwd=12345678&ip=192.168.168.69&gateway=192.168.168.219&subnet=255.255.255.0&dns=192.168.168.219 36 | ``` 37 | ## 通过微信小程序配网【推荐】 38 | 微信小程序搜索【配网库】 39 | 40 | ![配网库](https://www.cbug.top/1img/pwkxcx.jpg) 41 | 42 | 43 | ## 通过网页配网 44 | ``` 45 | 连接开发板生成的WiFi(用户名:WiFi配网,密码为空),浏览器进入http://192.168.22.22:2022 46 | ``` 47 | 48 | ## 自定义网页配网 49 | ``` 50 | 见开发文档和参考示例代码 51 | ``` 52 | ## 自定义配网数据组 53 | ``` 54 | UMSG机制共可存取12组自定义数据,在api配网或自定义网页配网下使用,配网存储关键字[umsg1 ~ umsg12], 读取存储值[wifipw.readUMSG(int i)] 55 | ``` 56 | ## eeshow模式 57 | ``` 58 | 实现了连接配网WiFi后自动跳转到配网页面的功能,需使用宏定义或BGWiFiConfig配置助手进行配置(需#define exe)。 59 | ``` 60 | ## 兼容模式 61 | ``` 62 | 优化解决部分手机配网WiFi自动断连问题,启用兼容模式,配网IP将从192.168.22.22变为192.168.22.1 63 | ``` 64 | 65 | ## OTA升级 66 | ``` 67 | 通过OTA网页升级程序固件,可以结合配网使用,也可单独使用(需#define onlyota),主要函数:OTAbegin()、OTALoop(),具体用法请参考开发文档和demo程序。 68 | ``` 69 | ## 宏定义 70 | ``` 71 | #define eeshow //宏定义开启eeshow 72 | #define eeshowM 0 //宏定义指定eeshow弹起页面(0.导航页面,1.默认页面,2.自定义页面) 73 | #define exe //使用BGWiFiConfig配置助手配置eeshow 74 | #define onlyota //只使用OTA功能,不使用配网功能 75 | #include 76 | ``` 77 | ## 友情提示 78 | ``` 79 | 小伙伴们在使用BGWiFiConfig库时,一定要多看文档,为什么呢?因为BGWiFiConfig库很多新功能是根据小伙伴们的需求开发的,只有通过看文档,了解新的功能函数,你才知道哪些需求被采纳并实现了,从而才能更好地实现自己的需求。举例来说,自定义数据储存已经实现了一个多月了?eeshow怎么使用?自定义api返回值用哪个函数?这些你知道吗?? 80 | ``` 81 | ## 补充约定 82 | ``` 83 | 你可以通过BGWiFiConfig库提供的函数(参考开发文档和demo程序)任意使用本库(允许商用),但禁止对除demo程序(.ino结尾的文件)外的其他源代码及文件,进行任何形式的修改及二次开发。 84 | ``` 85 | -------------------------------------------------------------------------------- /examples/all_CompatibilityMode_demo/all_CompatibilityMode_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP32 4 | 实现功能:新增兼容模式,优化解决部分手机配网WiFi自动断连问题, 5 | 启用兼容模式,配网IP将从192.168.22.22变为192.168.22.1。 6 | 开发文档:https://www.cbug.top/1app/bgwificonfig 7 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 8 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 9 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 10 | **/ 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | delay(1000); 17 | wifipw.setConFailReset(3, 10,true); 18 | wifipw.useSpaceWiFi(true); 19 | wifipw.autoStart(true); 20 | /**setCompatibleMode 21 | 1.xCMTag为true:启用兼容模式,配网IP为:192.168.22.1 22 | 2.xCMTag为false:关闭兼容模式,配网IP为:192.168.22.22 23 | ***/ 24 | wifipw.setCompatibleMode(true); 25 | wifipw.begin(); 26 | } 27 | 28 | void loop() { 29 | wifipw.Loop(); 30 | } -------------------------------------------------------------------------------- /examples/all_ConnectFailReset_demo/all_ConnectFailReset_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP32C3 4 | 实现功能:BGWiFiConfig库新增:setConFailReset和useSpaceWiFi函数。 5 | setConFailReset函数:在指定次数及重连时间内,WiFi连接失败,可自动重置配网。 6 | useSpaceWiFi函数:传入true时,配置的WiFi名称和密码将支持空格。 7 | 开发文档:https://www.cbug.top/1app/bgwificonfig 8 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 9 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 10 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 11 | **/ 12 | #include 13 | BGWiFiConfig wifipw; 14 | 15 | void setup() { 16 | Serial.begin(115200); 17 | delay(1000); 18 | /** setConFailReset 19 | 1.xReConNum:重连次数(总次数不记第1次)。 20 | 2.xReConTime:超时时间(单位:秒)。 21 | 3.xIsReboot:重置配网后是否自动重启进入配网程序。 22 | ***/ 23 | wifipw.setConFailReset(3,10,false); 24 | /**useSpaceWiFi 25 | 传入true时,配置的WiFi名称和密码将支持空格。 26 | 传入fasle或不使用该函数,将默认过滤WiFi空格。 27 | ***/ 28 | wifipw.useSpaceWiFi(true); 29 | /**autoStart 30 | 写入配网信息后,将自动重启并连接配置好的WiFi。 31 | ***/ 32 | wifipw.autoStart(true); 33 | wifipw.begin(); 34 | } 35 | 36 | void loop() { 37 | wifipw.Loop(); 38 | } -------------------------------------------------------------------------------- /examples/all_LittleFS_demo/all_LittleFS_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP32S3 4 | 实现功能:使用LittleFS,本demo建议配合微信小程序配网(小程序名:配网库)使用。 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | #define useLittleFS 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | delay(1000); 17 | wifipw.setConFailReset(2, 10,true); 18 | wifipw.useSpaceWiFi(true); 19 | wifipw.autoStart(true); 20 | wifipw.setCompatibleMode(true); 21 | wifipw.begin(); 22 | } 23 | 24 | void loop() { 25 | wifipw.Loop(); 26 | } -------------------------------------------------------------------------------- /examples/all_clearwifi_demo/all_clearwifi_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP8266和ESP32通用 4 | 实现功能:清除已配置的WiFi信息。其实该功能BGWiFiConfig库一直都有,一个函数就能解决问题, 5 | 但是有小伙伴并没有认真阅读文档所以没有发现,此次特意写了个demo,以后就不会写这种 6 | demo了,请小伙伴多看文档,新功能也会在文档告诉你怎么使用,请一定要多看文档!!! 7 | 开发文档:https://www.cbug.top/1app/bgwificonfig 8 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 9 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 10 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 11 | **/ 12 | 13 | #include 14 | BGWiFiConfig wifipw; 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println(); 19 | Serial.println("开始清除配网信息"); 20 | wifipw.clearWiFi(); 21 | Serial.println("配网信息清除成功"); 22 | } 23 | 24 | void loop() { 25 | } 26 | -------------------------------------------------------------------------------- /examples/all_eeshow_demo/all_eeshow_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig的eeshow模式简述 3 | 开发板:esp8266和esp32全系列 4 | 开发文档:https://www.cbug.top/1app/bgwificonfig 5 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 6 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 7 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 8 | -------------------------------------------------------- 9 | 1.eeshow模式的开启和关闭? 10 | 1.1.通过宏定义开启: 11 | #define eeshow 12 | #define eeshowM 0 13 | #include 14 | tag:程序内定义eeshow,再通过eeshowM指定弹起页面(0.导航页面,1.默认页面,2.自定义页面) 15 | 1.2.通过BGWiFiConfig配置助手开启 16 | #define exe 17 | #include 18 | tag:程序内定义exe,再运行配置助手进行配置 19 | 2.BGWiFiConfig配置助手如何下载? 20 | 答:https://www.cbug.top/article/25.html 21 | 3.eeshow模式实现了什么需求? 22 | 答:解决部分手机因自身网络优化造成配网WiFi自动断开的问题,以及实现了连接配网WiFi后自动跳转到配网页面的功能。 23 | 4.开启eeshow模式后功能有什么变化? 24 | 答:开启eeshow模式后,配网链接会发生变化,需要省略2022端口,具体请看串口信息或问题5。 25 | 5.eeshow模式下的配网链接? 26 | 配网页面:http://192.168.22.22/def 27 | 配网接口:http://192.168.22.22/api 28 | 自定义配网页面:http://192.168.22.22/html 29 | 配网导航页面:http://192.168.22.22 30 | ---------------------------------------------------------- 31 | **/ 32 | -------------------------------------------------------------------------------- /examples/all_ota_only_demo/all_ota_only_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP8266和ESP32通用 4 | 实现功能:BGWiFiConfig只使用OTA功能 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | /**setOTAWiFiAP函数,设置AP模式, 12 | 生成一个WiFi名为OTA升级, 13 | 密码为空的WiFi,并等待用户连接;**/ 14 | 15 | /**setOTAWiFiSTA函数,设置STA模式, 16 | 主动连接WiFi名为esp32, 17 | 密码为123456789的WiFi**/ 18 | 19 | /**setOTAWiFiAPSTA函数, 20 | 设置AP模式与STA模式共存**/ 21 | 22 | 23 | #define onlyota /**仅使用OTA功能,必须定义onlyota*/ 24 | #include 25 | BGWiFiConfig wifipw; 26 | 27 | void setup() { 28 | Serial.begin(115200); 29 | /** 以下三种连接方式任选一种即可 */ 30 | wifipw.setOTAWiFiAP("OTA升级","","192.168.33.33"); 31 | //wifipw.setOTAWiFiSTA("esp32","123456789"); 32 | //wifipw.setOTAWiFiAPSTA("OTA升级", "", "esp32", "123456789"); 33 | /*****end*****/ 34 | //wifipw.setOTATimeOut(30); /**设置就绪超时时间,非必须*/ 35 | wifipw.OTAbegin(); 36 | //Serial.println(wifipw.getOTAIP()); /**获取OTA升级IP,非必须*/ 37 | } 38 | 39 | void loop() { 40 | wifipw.OTALoop(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/all_recommend_demo/all_recommend_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: ESP32 4 | 实现功能:提供一个推荐使用的demo,以契合BGWiFiConfig诸多新增库函数, 5 | 本demo建议配合微信小程序配网(小程序名:配网库)使用。 6 | 开发文档:https://www.cbug.top/1app/bgwificonfig 7 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 8 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 9 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 10 | **/ 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | delay(1000); 17 | wifipw.setConFailReset(2, 10,true); 18 | wifipw.useSpaceWiFi(true); 19 | wifipw.autoStart(true); 20 | wifipw.setCompatibleMode(true); 21 | wifipw.begin(); 22 | } 23 | 24 | void loop() { 25 | wifipw.Loop(); 26 | } -------------------------------------------------------------------------------- /examples/esp32_easy_demo/esp32_easy_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU-32S 4 | 实现功能:最简单的BGWiFiConfig库使用 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | pinMode(0, INPUT); 17 | wifipw.begin(); 18 | } 19 | 20 | void loop() { 21 | wifipw.Loop(); 22 | if (!digitalRead(0)) 23 | wifipw.clearWiFi(); 24 | } 25 | -------------------------------------------------------------------------------- /examples/esp32_olibs_blinker_demo/esp32_olibs_blinker_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码Beta 3 | 开发板: NodeMCU-32S 4 | 实现功能:BGWiFiConfig库接入点灯科技示例代码(以blinker示例代码Hello_WiFi为例) 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | Other: 10 | 1.点灯科技(blinker)文档:https://diandeng.tech/doc/getting-start-esp32-wifi 11 | 2.BGWiFiConfig库接入blinker示例代码如下,用的是blinker的Hello_WiFi程序, 12 | 如需使用请确保BGWiFiConfig库在v1.0.6版本及以上,此示例代码为Beta程序,如有问题请反馈,但 13 | 精力有限,只受理BGWiFiConfig库问题,遇到问题,请先看文档!看文档!!看文档!!! 14 | **/ 15 | 16 | #define BLINKER_WIFI 17 | #include 18 | 19 | #include 20 | BGWiFiConfig wifipw; 21 | #define key 0 //按钮清除配网信息,其他esp32/8266开发板改这个中断io口即可。 22 | 23 | String html = String("BGWiFiConfig") 24 | + String("
") 25 | + String("
WiFi名称:
") 26 | + String("
WiFi密码:
") 27 | + String("
auth:
") 28 | + String("
模式选择:mode:1") 29 | + String("  mode:2

") 30 | + String("
") 31 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 32 | + String("

BGWiFiConfig接入Blinker示例代码Beta"); 33 | String htmlret = String("配置成功,请打开blinker软件,等待开发板连接WiFi。"); 34 | 35 | // Blinker示例程序Hello_WiFi内容 36 | BlinkerButton Button1("btn-abc"); 37 | BlinkerNumber Number1("num-abc"); 38 | int counter = 0; 39 | void button1_callback(const String & state) 40 | { 41 | BLINKER_LOG("get button state: ", state); 42 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 43 | } 44 | void dataRead(const String & data) 45 | { 46 | BLINKER_LOG("Blinker readString: ", data); 47 | counter++; 48 | Number1.print(counter); 49 | } 50 | 51 | void keyCwifi() { 52 | wifipw.clearWiFi(); 53 | Serial.println("WiFi信息清除成功!"); 54 | } 55 | 56 | void setup() { 57 | Serial.begin(115200); 58 | pinMode(key, INPUT_PULLUP); 59 | attachInterrupt(digitalPinToInterrupt(key), keyCwifi, CHANGE); 60 | 61 | wifipw.offConnectWiFi(true); 62 | wifipw.autoStart(true); 63 | wifipw.setZDYhtml(html); 64 | wifipw.setZDYhtmlret(htmlret); 65 | wifipw.setNumUMSG(1); 66 | wifipw.begin(); 67 | 68 | if (wifipw.OK()) { 69 | Serial.println(">>> blinker start debug <<<"); 70 | Serial.println(wifipw.readUMSG(1)); 71 | Serial.println(wifipw.readWiFi(0)); 72 | Serial.println(wifipw.readWiFi(1)); 73 | Serial.println(">>> end <<<"); 74 | pinMode(LED_BUILTIN, OUTPUT); 75 | digitalWrite(LED_BUILTIN, HIGH); 76 | Blinker.begin( wifipw.readUMSG(1).c_str(), wifipw.readWiFi(0).c_str(), wifipw.readWiFi(1).c_str()); 77 | Blinker.attachData(dataRead); 78 | Button1.attach(button1_callback); 79 | } 80 | 81 | } 82 | 83 | void loop() { 84 | wifipw.Loop(); 85 | if (wifipw.OK()) 86 | Blinker.run(); 87 | } 88 | -------------------------------------------------------------------------------- /examples/esp32_ota_easy_demo/esp32_ota_easy_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU-32S 4 | 实现功能:BGWiFiConfig-OTA结合配网使用 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | #include 11 | BGWiFiConfig wifipw; 12 | 13 | void setup() { 14 | Serial.begin(115200); 15 | pinMode(0, INPUT); 16 | wifipw.begin(); 17 | wifipw.OTAbegin(); 18 | } 19 | 20 | void loop() { 21 | wifipw.Loop(); 22 | wifipw.OTALoop(); 23 | if (!digitalRead(0)) 24 | wifipw.clearWiFi(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/esp32_ota_zdyhtml_demo/esp32_ota_zdyhtml_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU-32S 4 | 实现功能:BGWiFiConfig库自定义OTA页面及结合配网使用及宏定义开启eeshow模式 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #define eeshow 12 | #define eeshowM 0 13 | #include 14 | BGWiFiConfig wifipw; 15 | 16 | String mhtml = 17 | String("") + 18 | String("") + 19 | String("") + 20 | String("BGWiFiConfig自定义OTA

自定义OTA

") + 21 | String("
") + 22 | String("

"); 23 | 24 | void setup() { 25 | Serial.begin(115200); 26 | pinMode(0, INPUT); 27 | wifipw.begin(); 28 | wifipw.setOTAhtml(mhtml); 29 | wifipw.OTAbegin(); 30 | } 31 | 32 | void loop() { 33 | wifipw.Loop(); 34 | wifipw.OTALoop(); 35 | if (!digitalRead(0)) 36 | wifipw.clearWiFi(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/esp32_umsg_demo/esp32_umsg_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU-32S 4 | 实现功能:BGWiFiConfig库UMSG(配网时自定义数据)功能演示。 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | String html = String("BGWiFiConfig") 15 | + String("
") 16 | + String("
WiFi名称:
") 17 | + String("
WiFi密码:
") 18 | + String("
UMSG数据组1:
") 19 | + String("
UMSG数据组2:
") 20 | + String("
UMSG数据组3:
") 21 | + String("
UMSG数据组4:
") 22 | + String("
UMSG数据组5:
") 23 | + String("
UMSG数据组6:
") 24 | + String("
UMSG数据组7:
") 25 | + String("
UMSG数据组8:
") 26 | + String("
UMSG数据组9:
") 27 | + String("
UMSG数据组10:
") 28 | + String("
UMSG数据组11:
") 29 | + String("
UMSG数据组12:
") 30 | + String("
模式选择:mode:1") 31 | + String("  mode:2

") 32 | + String("
") 33 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 34 | + String("

BGWiFiConfig自定义数据组UMSG示例程序"); 35 | String htmlret = String("htmlresult回调"); 36 | 37 | void setup() { 38 | Serial.begin(115200); 39 | pinMode(0, INPUT); 40 | wifipw.setZDYhtml(html); 41 | wifipw.setZDYhtmlret(htmlret); 42 | wifipw.setNumUMSG(12); 43 | wifipw.begin(); 44 | for (int i = 1; i < 13; i++) { 45 | String msg = wifipw.readUMSG(i); 46 | if (msg != "NULL") { 47 | Serial.println(); 48 | Serial.print("打印数据组["); 49 | Serial.print(i); 50 | Serial.print("]-->"); 51 | Serial.println(msg); 52 | } 53 | } 54 | } 55 | 56 | void loop() { 57 | wifipw.Loop(); 58 | if (!digitalRead(0)) 59 | wifipw.clearWiFi(); 60 | } 61 | -------------------------------------------------------------------------------- /examples/esp32_zdyhtml_demo/esp32_zdyhtml_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU-32S 4 | 实现功能:BGWiFiConfig库自定义配网页面的实现 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | String html = String("BGWiFiConfig") 15 | + String("

") 16 | + String("
WiFi名称:
") 17 | + String("
WiFi密码:
") 18 | + String("
模式选择:mode:1") 19 | + String("  mode:2

") 20 | + String("
") 21 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 22 | + String("

BGWiFiConfig自定义页面示例程序"); 23 | String htmlret = String("htmlresult回调"); 24 | 25 | void setup() { 26 | Serial.begin(115200); 27 | pinMode(0, INPUT); 28 | wifipw.setZDYhtml(html); 29 | wifipw.setZDYhtmlret(htmlret); 30 | wifipw.begin(); 31 | } 32 | 33 | void loop() { 34 | wifipw.Loop(); 35 | if (!digitalRead(0)) 36 | wifipw.clearWiFi(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/esp8266_easy_demo/esp8266_easy_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU 4 | 实现功能:最简单的BGWiFiConfig库使用 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | pinMode(D3, INPUT); 17 | wifipw.begin(); 18 | } 19 | 20 | void loop() { 21 | wifipw.Loop(); 22 | if (!digitalRead(D3)) 23 | wifipw.clearWiFi(); 24 | } 25 | -------------------------------------------------------------------------------- /examples/esp8266_olibs_blinker_demo/esp8266_olibs_blinker_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码Beta 3 | 开发板: NodeMCU 4 | 实现功能:BGWiFiConfig库接入点灯科技示例代码(以blinker示例代码Hello_WiFi为例) 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | Other: 10 | 1.点灯科技(blinker)文档:https://diandeng.tech/doc/getting-start-8266 11 | 2.BGWiFiConfig库接入blinker示例代码如下,用的是blinker的Hello_WiFi程序, 12 | 如需使用请确保BGWiFiConfig库在v1.0.6版本及以上,此示例代码为Beta程序,如有问题请反馈,但 13 | 精力有限,只受理BGWiFiConfig库问题,遇到问题,请先看文档!看文档!!看文档!!! 14 | **/ 15 | 16 | #define BLINKER_WIFI 17 | #include 18 | 19 | #include 20 | BGWiFiConfig wifipw; 21 | #define key D3 //按钮清除配网信息,其他esp8266/32开发板改这个中断io口即可。 22 | 23 | String html = String("BGWiFiConfig") 24 | + String("

") 25 | + String("
WiFi名称:
") 26 | + String("
WiFi密码:
") 27 | + String("
auth:
") 28 | + String("
模式选择:mode:1") 29 | + String("  mode:2

") 30 | + String("
") 31 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 32 | + String("

BGWiFiConfig接入Blinker示例代码Beta"); 33 | String htmlret = String("配置成功,请重启开发板并打开blinker软件,等待开发板连接WiFi。"); 34 | 35 | // Blinker示例程序Hello_WiFi内容 36 | BlinkerButton Button1("btn-abc"); 37 | BlinkerNumber Number1("num-abc"); 38 | int counter = 0; 39 | void button1_callback(const String & state) 40 | { 41 | BLINKER_LOG("get button state: ", state); 42 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 43 | } 44 | void dataRead(const String & data) 45 | { 46 | BLINKER_LOG("Blinker readString: ", data); 47 | counter++; 48 | Number1.print(counter); 49 | } 50 | 51 | ICACHE_RAM_ATTR void keyCwifi() { 52 | wifipw.clearWiFi(); 53 | Serial.println("WiFi信息清除成功!"); 54 | } 55 | 56 | void setup() { 57 | Serial.begin(115200); 58 | pinMode(key, INPUT_PULLUP); 59 | attachInterrupt(digitalPinToInterrupt(key), keyCwifi, CHANGE); 60 | 61 | wifipw.offConnectWiFi(true); 62 | wifipw.setZDYhtml(html); 63 | wifipw.setZDYhtmlret(htmlret); 64 | wifipw.setNumUMSG(1); 65 | wifipw.begin(); 66 | 67 | if (wifipw.OK()) { 68 | Serial.println(">>> blinker start debug <<<"); 69 | Serial.println(wifipw.readUMSG(1)); 70 | Serial.println(wifipw.readWiFi(0)); 71 | Serial.println(wifipw.readWiFi(1)); 72 | Serial.println(">>> end <<<"); 73 | pinMode(LED_BUILTIN, OUTPUT); 74 | digitalWrite(LED_BUILTIN, HIGH); 75 | Blinker.begin( wifipw.readUMSG(1).c_str(), wifipw.readWiFi(0).c_str(), wifipw.readWiFi(1).c_str()); 76 | Blinker.attachData(dataRead); 77 | Button1.attach(button1_callback); 78 | } 79 | 80 | } 81 | 82 | void loop() { 83 | wifipw.Loop(); 84 | if (wifipw.OK()) 85 | Blinker.run(); 86 | } 87 | -------------------------------------------------------------------------------- /examples/esp8266_ota_easy_demo/esp8266_ota_easy_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU 4 | 实现功能:BGWiFiConfig-OTA结合配网使用 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | #include 11 | BGWiFiConfig wifipw; 12 | 13 | void setup() { 14 | Serial.begin(115200); 15 | pinMode(D3, INPUT); 16 | wifipw.begin(); 17 | wifipw.OTAbegin(); 18 | } 19 | 20 | void loop() { 21 | wifipw.Loop(); 22 | wifipw.OTALoop(); 23 | if (!digitalRead(D3)) 24 | wifipw.clearWiFi(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/esp8266_ota_zdyhtml_demo/esp8266_ota_zdyhtml_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU 4 | 实现功能:BGWiFiConfig库自定义OTA页面及结合配网使用及宏定义开启eeshow模式 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #define eeshow 12 | #define eeshowM 1 13 | #include 14 | BGWiFiConfig wifipw; 15 | 16 | String mhtml = 17 | String("") + 18 | String("") + 19 | String("") + 20 | String("BGWiFiConfig自定义OTA

自定义OTA

") + 21 | String("
") + 22 | String("

"); 23 | 24 | void setup() { 25 | Serial.begin(115200); 26 | pinMode(D3, INPUT); 27 | wifipw.begin(); 28 | wifipw.setOTAhtml(mhtml); 29 | wifipw.OTAbegin(); 30 | } 31 | 32 | void loop() { 33 | wifipw.Loop(); 34 | wifipw.OTALoop(); 35 | if (!digitalRead(D3)) 36 | wifipw.clearWiFi(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/esp8266_umsg_demo/esp8266_umsg_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU 4 | 实现功能:BGWiFiConfig库UMSG(配网时自定义数据)功能演示。 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | String html = String("BGWiFiConfig") 15 | + String("
") 16 | + String("
WiFi名称:
") 17 | + String("
WiFi密码:
") 18 | + String("
UMSG数据组1:
") 19 | + String("
UMSG数据组2:
") 20 | + String("
UMSG数据组3:
") 21 | + String("
UMSG数据组4:
") 22 | + String("
UMSG数据组5:
") 23 | + String("
UMSG数据组6:
") 24 | + String("
UMSG数据组7:
") 25 | + String("
UMSG数据组8:
") 26 | + String("
UMSG数据组9:
") 27 | + String("
UMSG数据组10:
") 28 | + String("
UMSG数据组11:
") 29 | + String("
UMSG数据组12:
") 30 | + String("
模式选择:mode:1") 31 | + String("  mode:2

") 32 | + String("
") 33 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 34 | + String("

BGWiFiConfig自定义数据组UMSG示例程序"); 35 | String htmlret = String("htmlresult回调"); 36 | 37 | void setup() { 38 | Serial.begin(115200); 39 | pinMode(D3, INPUT); 40 | wifipw.setZDYhtml(html); 41 | wifipw.setZDYhtmlret(htmlret); 42 | wifipw.setNumUMSG(12); 43 | wifipw.begin(); 44 | for (int i = 1; i < 13; i++) { 45 | String msg = wifipw.readUMSG(i); 46 | if (msg != "NULL") { 47 | Serial.println(); 48 | Serial.print("打印数据组["); 49 | Serial.print(i); 50 | Serial.print("]-->"); 51 | Serial.println(msg); 52 | } 53 | } 54 | } 55 | 56 | void loop() { 57 | wifipw.Loop(); 58 | if (!digitalRead(D3)) 59 | wifipw.clearWiFi(); 60 | } 61 | -------------------------------------------------------------------------------- /examples/esp8266_zdyhtml_demo/esp8266_zdyhtml_demo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BGWiFiConfig示例代码 3 | 开发板: NodeMCU 4 | 实现功能:BGWiFiConfig库自定义配网页面的实现 5 | 开发文档:https://www.cbug.top/1app/bgwificonfig 6 | Gitee地址:https://gitee.com/fish_five/BGWiFiConfig 7 | GitHub地址:https://github.com/fish-five/BGWiFiConfig 8 | 微信公众号:蚍蜉荣光 官方网站:www.cbug.top 9 | **/ 10 | 11 | #include 12 | BGWiFiConfig wifipw; 13 | 14 | String html = String("BGWiFiConfig") 15 | + String("

") 16 | + String("
WiFi名称:
") 17 | + String("
WiFi密码:
") 18 | + String("
模式选择:mode:1") 19 | + String("  mode:2

") 20 | + String("
") 21 | + String("

如果你点击提交,表单数据会被发送到htmlresult处理,setZDYhtmlret函数设置回调页面

") 22 | + String("

BGWiFiConfig自定义页面示例程序"); 23 | String htmlret = String("htmlresult回调"); 24 | 25 | void setup() { 26 | Serial.begin(115200); 27 | pinMode(D3, INPUT); 28 | wifipw.setZDYhtml(html); 29 | wifipw.setZDYhtmlret(htmlret); 30 | wifipw.begin(); 31 | } 32 | 33 | void loop() { 34 | wifipw.Loop(); 35 | if (!digitalRead(D3)) 36 | wifipw.clearWiFi(); 37 | } 38 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | 3 | # Syntax Coloring Map For BGWiFiConfig 4 | 5 | ####################################### 6 | 7 | # Class (KEYWORD1) 8 | 9 | ####################################### 10 | 11 | 12 | 13 | BGWiFiConfig KEYWORD1 14 | 15 | 16 | ####################################### 17 | 18 | # Methods and Functions (KEYWORD2) 19 | 20 | ####################################### 21 | 22 | 23 | begin KEYWORD2 24 | Loop KEYWORD2 25 | clearWiFi KEYWORD2 26 | setPWWiFi KEYWORD2 27 | setWiFiTimeOut KEYWORD2 28 | setZDYhtml KEYWORD2 29 | setZDYhtmlret KEYWORD2 30 | outWiFiSET KEYWORD2 31 | offSerial KEYWORD2 32 | retRUNTAG KEYWORD2 33 | retWiFiSET KEYWORD2 34 | autoStart KEYWORD2 35 | setNumUMSG KEYWORD2 36 | readUMSG KEYWORD2 37 | readWiFi KEYWORD2 38 | offConnectWiFi KEYWORD2 39 | setApiRet KEYWORD2 40 | OK KEYWORD2 41 | OTAbegin KEYWORD2 42 | OTALoop KEYWORD2 43 | getOTAIP KEYWORD2 44 | setOTAhtml KEYWORD2 45 | setOTATimeOut KEYWORD2 46 | setOTAWiFiSTA KEYWORD2 47 | setOTAWiFiAP KEYWORD2 48 | setOTAWiFiAPSTA KEYWORD2 49 | setConFailReset KEYWORD2 50 | useSpaceWiFi KEYWORD2 51 | exe KEYWORD2 52 | eeshow KEYWORD2 53 | eeshowM KEYWORD2 54 | onlyota KEYWORD2 55 | setCompatibleMode KEYWORD2 56 | 57 | 58 | ####################################### 59 | # Constants (LITERAL1) 60 | ####################################### 61 | 62 | 63 | wifipw LITERAL1 64 | useLittleFS LITERAL1 65 | 66 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=BGWiFiConfig 2 | version=1.1.1 3 | author=fishfive 4 | maintainer=fishfive 5 | sentence=BGWiFiConfig是一个为esp8266和esp32设计的简单易用Arduino配网库。 6 | paragraph=本库使用方便,可扩展性极强,可通过api配置WiFi网络,支持GET和POST请求配置;可通过微信小程序配网(小程序名:配网库);可通过默认网页配置WiFi网络;可自定义配网页面;可通过OTA网页升级程序固件。 7 | category=Communication 8 | url=https://github.com/fish-five/BGWiFiConfig 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/BGWiFiConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef _BGWiFiConfig_H_ 2 | #define _BGWiFiConfig_H_ 3 | #include 4 | #include 5 | 6 | #ifdef ESP32 7 | #include 8 | #include 9 | #include 10 | #include 11 | #ifdef useLittleFS 12 | #include 13 | #else 14 | #include 15 | #endif 16 | #else 17 | #include 18 | #include 19 | #include 20 | #ifdef useLittleFS 21 | #include 22 | #else 23 | #include 24 | #endif 25 | #endif 26 | 27 | #ifdef useLittleFS 28 | #define FILESYSTEM LittleFS 29 | #else 30 | #ifdef ESP32 31 | #define FILESYSTEM SPIFFS 32 | #else 33 | #define FILESYSTEM SPIFFS 34 | #endif 35 | #endif 36 | 37 | #ifdef exe 38 | #include "DEFPORT.h" 39 | #else 40 | #ifdef eeshow 41 | #define DEFPORT 80 42 | #ifdef eeshowM 43 | #if eeshowM == 1 44 | #define DEFPORTPWMODE 1 45 | #elif eeshowM == 2 46 | #define DEFPORTPWMODE 2 47 | #else 48 | #define DEFPORTPWMODE 0 49 | #endif 50 | #else 51 | #define DEFPORTPWMODE 0 52 | #endif 53 | #define DEFPORTHTML "NULL" 54 | #else 55 | #define DEFPORT 2022 56 | #define DEFPORTPWMODE 0 57 | #define DEFPORTHTML "NULL" 58 | #endif 59 | #endif 60 | 61 | #ifdef onlyota 62 | #define onlyotaTAG true 63 | #else 64 | #define onlyotaTAG false 65 | #endif 66 | 67 | class BGWiFiConfig { 68 | private: 69 | String TAG, MODE, SSID, PWD, IP, GATEWAY, SUBNET, DNS; 70 | String APssid, APpwd; 71 | static String StrsUMSG[13]; 72 | static String StrApiRet[2]; 73 | static String mhtml, mhtmlresult, runTAG, OTAserverIndex; 74 | int SECtime = 30; 75 | int OTASECtime = 3600; 76 | int gReConNum = 0; 77 | static int UMSGnum; 78 | static int gICompatibleM; 79 | bool booloutwifiset = false; 80 | bool booloffconnectwifi = false; 81 | bool OTASECtimeTAG = false; 82 | bool boolConFailResetTag = false; 83 | bool boolConFailResetIsReboot = false; 84 | static bool boolSpaceWiFiTag; 85 | static bool boolautostart; 86 | static bool booloffSerial; 87 | static void mySerial(String str, bool nend); 88 | IPAddress otapip[3]; 89 | void debugPZ(); 90 | void APstart(); 91 | void StrCL(String str); 92 | void StrCL_UMSG(String str); 93 | void STA_M1(String Mname, String Mssid); 94 | void STA_M2(String Mname, String Mssid, String Mlocal_IP, String Mgateway, String Msubnet, String Mdns); 95 | static void delay_rst(); 96 | static void WRhtml(); 97 | static void WRhtmlresult(); 98 | static void WRindex(); 99 | static void WRresult(); 100 | static void WRapi(); 101 | static void WRindexDH(); 102 | IPAddress StrToIP(String str); 103 | static bool FS_W(String str); 104 | String FS_R(); 105 | static bool FS_W_UMSG(String str); 106 | String FS_R_UMSG(); 107 | void clOTAPIP(String ip); 108 | void STA_M3_FailReset(); 109 | IPAddress getPWIP(); 110 | static String getPWIPDH(); 111 | 112 | public: 113 | void begin(); 114 | void Loop(); 115 | void clearWiFi(); 116 | void setPWWiFi(String ssid, String pwd); 117 | void setWiFiTimeOut(int sectime); 118 | void setZDYhtml(String html); 119 | void setZDYhtmlret(String html); 120 | void outWiFiSET(bool tag); 121 | void offSerial(bool tag); 122 | void autoStart(bool tag); 123 | void offConnectWiFi(bool tag); 124 | void setNumUMSG(int i); 125 | String readUMSG(int i); 126 | String readWiFi(int i); 127 | String retRUNTAG(); 128 | String retWiFiSET(); 129 | bool OK(bool tag = false); 130 | String& setApiRet(int i); 131 | void OTAbegin(); 132 | void OTALoop(); 133 | String getOTAIP(); 134 | void setOTAhtml(String html); 135 | void setOTATimeOut(int sectime); 136 | void setOTAWiFiSTA(String ssid, String pwd); 137 | void setOTAWiFiAP(String ssid, String pwd, String ip = "192.168.33.33"); 138 | void setOTAWiFiAPSTA(String APssid, String APpwd, String STAssid, String STApwd, String ip = "192.168.33.33"); 139 | void setConFailReset(int xReConNum = 0, int xReConTime = 30, bool xIsReboot = false); 140 | void useSpaceWiFi(bool xSpaceWiFiTag = false); 141 | void setCompatibleMode(bool xCMTag = true); 142 | void setCompatibleModeTest(bool xCMTag = true); 143 | }; 144 | #endif 145 | 146 | 147 | /**- 148 | cpp function ach 149 | -**/ 150 | DNSServer WFconfigDNSserver; 151 | #ifdef ESP32 152 | #if DEFPORT == 80 153 | WebServer WFconfigserver(80); 154 | #else 155 | WebServer WFconfigserver(2022); 156 | #endif 157 | #else 158 | #if DEFPORT == 80 159 | ESP8266WebServer WFconfigserver(80); 160 | #else 161 | ESP8266WebServer WFconfigserver(2022); 162 | #endif 163 | #endif 164 | 165 | #ifdef ESP32 166 | WebServer OTAserver(80); 167 | #else 168 | ESP8266WebServer OTAserver(80); 169 | #endif 170 | 171 | int BGWiFiConfig::gICompatibleM = 1; 172 | bool BGWiFiConfig::booloffSerial = false; 173 | bool BGWiFiConfig::boolautostart = false; 174 | bool BGWiFiConfig::boolSpaceWiFiTag = false; 175 | String BGWiFiConfig::mhtml = ""; 176 | String BGWiFiConfig::mhtmlresult = ""; 177 | String BGWiFiConfig::runTAG = ""; 178 | String BGWiFiConfig::StrsUMSG[13] = { "NULL" }; 179 | String BGWiFiConfig::StrApiRet[2] = { "NULL" }; 180 | int BGWiFiConfig::UMSGnum = 0; 181 | String BGWiFiConfig::OTAserverIndex = 182 | String("") + String("") + String("") + String("BGWiFiConfigOTA") + String("

OTA在线升级(bin文件)

") + String("
") + String("

"); 183 | 184 | 185 | void BGWiFiConfig::Loop() { 186 | if (TAG != "OFF") { 187 | WFconfigserver.handleClient(); 188 | WFconfigDNSserver.processNextRequest(); 189 | } 190 | } 191 | 192 | /* 193 | void BGWiFiConfig::clearWiFi() { 194 | //SPIFFS.format(); 195 | SPIFFS.remove("/bgwificonfig/wifiset.txt"); 196 | SPIFFS.remove("/bgwificonfig/umsg.txt"); 197 | WiFi.disconnect(); 198 | }*/ 199 | void BGWiFiConfig::clearWiFi() { 200 | FILESYSTEM.remove("/bgwificonfig/wifiset.txt"); 201 | FILESYSTEM.remove("/bgwificonfig/umsg.txt"); 202 | WiFi.disconnect(); 203 | } 204 | 205 | void BGWiFiConfig::setPWWiFi(String ssid, String pwd) { 206 | APssid = ssid; 207 | APpwd = pwd; 208 | } 209 | 210 | void BGWiFiConfig::setWiFiTimeOut(int sectime) { 211 | SECtime = sectime; 212 | } 213 | 214 | void BGWiFiConfig::setNumUMSG(int umsgnum) { 215 | UMSGnum = umsgnum; 216 | } 217 | 218 | void BGWiFiConfig::setZDYhtml(String html) { 219 | mhtml = html; 220 | } 221 | 222 | void BGWiFiConfig::setZDYhtmlret(String html) { 223 | mhtmlresult = html; 224 | } 225 | 226 | void BGWiFiConfig::outWiFiSET(bool tag) { 227 | booloutwifiset = tag; 228 | } 229 | 230 | void BGWiFiConfig::offSerial(bool tag) { 231 | booloffSerial = tag; 232 | } 233 | 234 | void BGWiFiConfig::autoStart(bool tag) { 235 | boolautostart = tag; 236 | } 237 | 238 | void BGWiFiConfig::delay_rst() { 239 | /** 240 | #ifdef ESP32 241 | unsigned long onetime=millis(); 242 | while (true) { 243 | unsigned long times=millis(); 244 | if (times - onetime > 2000) 245 | break; 246 | } 247 | #else 248 | delay(2000); 249 | #endif 250 | */ 251 | delay(2000); 252 | } 253 | 254 | String BGWiFiConfig::retRUNTAG() { 255 | if (runTAG != "") { 256 | return runTAG; 257 | } 258 | return "获取失败,该函数必需放于begin()函数之后"; 259 | } 260 | 261 | String BGWiFiConfig::retWiFiSET() { 262 | String str = FS_R(); 263 | str.trim(); 264 | if (str.length() > 8) 265 | return str.substring(8); 266 | return "未查询到配置信息"; 267 | } 268 | 269 | void BGWiFiConfig::begin() { 270 | Serial.println(); 271 | Serial.println(); 272 | if (FILESYSTEM.begin()) { 273 | StrCL(FS_R()); 274 | if (TAG == "OFF" && !booloffconnectwifi) { 275 | if (UMSGnum > 0 && UMSGnum < 13) 276 | StrCL_UMSG(FS_R_UMSG()); 277 | if (boolConFailResetTag) { 278 | STA_M3_FailReset(); 279 | debugPZ(); 280 | } else { 281 | if (MODE == "2") { 282 | STA_M2(SSID, PWD, IP, GATEWAY, SUBNET, DNS); 283 | debugPZ(); 284 | } else { 285 | STA_M1(SSID, PWD); 286 | debugPZ(); 287 | } 288 | } 289 | } else if (TAG == "OFF" && booloffconnectwifi) { 290 | mySerial("....user wificode start....", true); 291 | if (UMSGnum > 0 && UMSGnum < 13) 292 | StrCL_UMSG(FS_R_UMSG()); 293 | debugPZ(); 294 | } else { 295 | mySerial("欢迎使用BGWiFiConfig配网程序!!", true); 296 | Serial.println(); 297 | APstart(); 298 | Serial.println(); 299 | #if DEFPORT == 80 300 | WFconfigserver.on("/result", HTTP_GET, WRresult); 301 | WFconfigserver.on("/result", HTTP_POST, WRresult); 302 | WFconfigserver.on("/api", HTTP_POST, WRapi); 303 | WFconfigserver.on("/api", HTTP_GET, WRapi); 304 | WFconfigserver.on("/html", HTTP_GET, WRhtml); 305 | WFconfigserver.on("/html", HTTP_POST, WRhtml); 306 | WFconfigserver.on("/htmlresult", HTTP_GET, WRhtmlresult); 307 | WFconfigserver.on("/htmlresult", HTTP_POST, WRhtmlresult); 308 | WFconfigserver.on("/def", HTTP_GET, WRindex); 309 | WFconfigserver.on("/def", HTTP_POST, WRindex); 310 | if (DEFPORTPWMODE == 1) { 311 | WFconfigserver.on("/", HTTP_GET, WRindex); 312 | WFconfigserver.on("/", HTTP_POST, WRindex); 313 | WFconfigserver.onNotFound(WRindex); 314 | mySerial(">>当前为eeshow模式1", true); 315 | } else if (DEFPORTPWMODE == 2) { 316 | WFconfigserver.on("/", HTTP_GET, WRhtml); 317 | WFconfigserver.on("/", HTTP_POST, WRhtml); 318 | WFconfigserver.onNotFound(WRhtml); 319 | mySerial(">>当前为eeshow模式2", true); 320 | } else { 321 | WFconfigserver.on("/", HTTP_GET, WRindexDH); 322 | WFconfigserver.on("/", HTTP_POST, WRindexDH); 323 | WFconfigserver.onNotFound(WRindexDH); 324 | mySerial(">>当前为eeshow模式0", true); 325 | } 326 | WFconfigserver.begin(); 327 | if (WFconfigDNSserver.start(53, "*", getPWIP())) { 328 | mySerial(">>eeshow模式启动成功", true); 329 | } else { 330 | mySerial(">>eeshow模式启动失败", true); 331 | } 332 | #else 333 | WFconfigserver.on("/result", WRresult); 334 | WFconfigserver.on("/api", WRapi); 335 | WFconfigserver.on("/html", WRhtml); 336 | WFconfigserver.on("/htmlresult", WRhtmlresult); 337 | WFconfigserver.on("/", WRindex); 338 | WFconfigserver.begin(); 339 | mySerial(">>当前为默认模式", true); 340 | #endif 341 | #ifdef useLittleFS 342 | mySerial("配网系统已就绪,预计配网时间为3秒,可以开始配网了<<<", true); 343 | #else 344 | #ifdef ESP32 345 | mySerial("配网系统已就绪,预计配网时间为3秒,可以开始配网了<<<", true); 346 | #else 347 | mySerial("配网系统已就绪,预计配网时间为3秒,可以开始配网了<<<", true); 348 | #endif 349 | #endif 350 | runTAG = "配网程序开始运行"; 351 | if (TAG != "OFF" && onlyotaTAG) { 352 | Serial.println("[err:宏定义onlyota错误,用了配网函数就不能定义onlyota,请修改程序BUG]"); 353 | delay(5000); 354 | ESP.restart(); 355 | } 356 | while (WiFi.softAPgetStationNum() < 1) { 357 | delay(1000); 358 | } 359 | } 360 | } else { 361 | mySerial("配网挂载初始化中ing..", true); 362 | mySerial("正在初始化挂载,请保持等待...", true); 363 | /* 364 | #ifdef ESP32 365 | if (!SPIFFS.begin(true)) { 366 | mySerial("配网程序启动失败!!", true); 367 | } else { 368 | ESP.restart(); 369 | } 370 | #else 371 | SPIFFS.format(); 372 | delay(1000); 373 | ESP.restart(); 374 | #endif 375 | */ 376 | #ifdef ESP32 377 | if (!FILESYSTEM.begin(true)) { 378 | mySerial("配网程序启动失败!!", true); 379 | } else { 380 | ESP.restart(); 381 | } 382 | #else 383 | FILESYSTEM.format(); 384 | delay(1000); 385 | ESP.restart(); 386 | #endif 387 | } 388 | } 389 | 390 | void BGWiFiConfig::mySerial(String str, bool nend) { 391 | if (!booloffSerial) { 392 | if (nend) 393 | Serial.println(str); 394 | else 395 | Serial.print(str); 396 | } 397 | } 398 | 399 | void BGWiFiConfig::debugPZ() { 400 | if (booloutwifiset) { 401 | Serial.println("WiFi配网信息:>>>"); 402 | Serial.print("TAG:"); 403 | Serial.println(TAG); 404 | Serial.print("MODE:"); 405 | Serial.println(MODE); 406 | Serial.print("SSID:"); 407 | Serial.println(SSID); 408 | Serial.print("PWD:"); 409 | Serial.println(PWD); 410 | Serial.print("IP:"); 411 | Serial.println(IP); 412 | Serial.print("GATEWAY:"); 413 | Serial.println(GATEWAY); 414 | Serial.print("SUBNET:"); 415 | Serial.println(SUBNET); 416 | Serial.print("DNS:"); 417 | Serial.println(DNS); 418 | Serial.println("<<>>", true); 439 | mySerial("配网WiFi:", false); 440 | mySerial(WiFi.softAPSSID(), true); 441 | #if DEFPORT == 80 442 | mySerial("配网页面:", false); 443 | mySerial(WiFi.softAPIP().toString(), false); 444 | mySerial("/def", true); 445 | mySerial("配网接口:", false); 446 | mySerial(WiFi.softAPIP().toString(), false); 447 | mySerial("/api", true); 448 | mySerial("自定义配网页面:", false); 449 | mySerial(WiFi.softAPIP().toString(), false); 450 | mySerial("/html", true); 451 | #else 452 | mySerial("配网页面:", false); 453 | mySerial(WiFi.softAPIP().toString(), false); 454 | mySerial(":2022", true); 455 | mySerial("配网接口:", false); 456 | mySerial(WiFi.softAPIP().toString(), false); 457 | mySerial(":2022/api", true); 458 | mySerial("自定义配网页面:", false); 459 | mySerial(WiFi.softAPIP().toString(), false); 460 | mySerial(":2022/html", true); 461 | #endif 462 | mySerial("<<<< SECtime - 1) { 506 | Serial.println(); 507 | if (!boolConFailResetTag) { 508 | runTAG = "连接失败,未成功连接WiFi[" + SSID + "]"; 509 | mySerial("WiFi连接超时,请重试", true); 510 | } 511 | break; 512 | } 513 | } 514 | if (WiFi.isConnected()) { 515 | Serial.println(); 516 | runTAG = "已成功连接WiFi[" + SSID + "]"; 517 | mySerial("连接成功", true); 518 | mySerial("本机IP:", false); 519 | mySerial(WiFi.localIP().toString(), true); 520 | } 521 | mySerial(">>>>> end <<<<<", true); 522 | Serial.println(); 523 | } 524 | 525 | void BGWiFiConfig::STA_M2(String Mname, String Mssid, String Mlocal_IP, String Mgateway, String Msubnet, String Mdns) { 526 | WiFi.disconnect(); 527 | if (!WiFi.config(StrToIP(Mlocal_IP), StrToIP(Mgateway), StrToIP(Msubnet), StrToIP(Mdns))) { 528 | mySerial("WiFi设置失败", true); 529 | } 530 | WiFi.mode(WIFI_STA); 531 | WiFi.begin(Mname.c_str(), Mssid.c_str()); 532 | runTAG = "开始连接WiFi[" + SSID + "]"; 533 | mySerial("Mode2模式:", true); 534 | mySerial("开始连接WiFi[", false); 535 | mySerial(SSID, false); 536 | mySerial("]:", false); 537 | int i = 0; 538 | while (WiFi.status() != WL_CONNECTED) { 539 | delay(1000); 540 | mySerial(",", false); 541 | i++; 542 | mySerial(String(i), false); 543 | if (i > SECtime - 1) { 544 | Serial.println(); 545 | if (!boolConFailResetTag) { 546 | runTAG = "连接失败,未成功连接WiFi[" + SSID + "]"; 547 | mySerial("WiFi连接超时,请重试", true); 548 | } 549 | break; 550 | } 551 | } 552 | if (WiFi.isConnected()) { 553 | Serial.println(); 554 | runTAG = "已成功连接WiFi[" + SSID + "]"; 555 | mySerial("连接成功", true); 556 | mySerial("本机IP:", false); 557 | mySerial(WiFi.localIP().toString(), true); 558 | } 559 | mySerial(">>>>> end <<<<<", true); 560 | Serial.println(); 561 | } 562 | 563 | 564 | void BGWiFiConfig::WRindexDH() { 565 | /* 566 | String dhhtml = String("") 567 | + String("BGWiFiConfig配网 ") 569 | + String("") 570 | + String("

BGWiFiConfig

") 571 | + String("

请选择配网模式

") 572 | + String("默认网页配网
") 573 | + String("自定义网页配网") 574 | + String("

api配网和微信小程序配网默认已支持,无需选择。

") 575 | + String("");*/ 576 | 577 | String dhhtml = String("") 578 | + String("BGWiFiConfig配网 ") 580 | + String("") 581 | + String("

BGWiFiConfig

") 582 | + String("

请选择配网模式

") 583 | + String("默认网页配网
") 584 | + String("自定义网页配网") 585 | + String("

api配网和微信小程序配网默认已支持,无需选择。

") 586 | + String(""); 587 | 588 | if (DEFPORTHTML != "" && DEFPORTHTML != "NULL" && DEFPORTHTML != NULL) { 589 | WFconfigserver.send(200, "text/html", DEFPORTHTML); 590 | } else { 591 | WFconfigserver.send(200, "text/html", dhhtml); 592 | } 593 | } 594 | 595 | void BGWiFiConfig::WRhtml() { 596 | WFconfigserver.send(200, "text/html", mhtml); 597 | } 598 | void BGWiFiConfig::WRhtmlresult() { 599 | String retStr; 600 | String mode = WFconfigserver.arg("mode"); 601 | String ssid = WFconfigserver.arg("ssid"); 602 | String pwd = WFconfigserver.arg("pwd"); 603 | if (mode == "2") { 604 | String ip = WFconfigserver.arg("ip"); 605 | String gateway = WFconfigserver.arg("gateway"); 606 | String subnet = WFconfigserver.arg("subnet"); 607 | String dns = WFconfigserver.arg("dns"); 608 | retStr = "tag=OFF,mode=" + mode + ",ssid=" + ssid + ",pwd=" + pwd + ",ip=" + ip 609 | + ",gateway=" + gateway + ",subnet=" + subnet + ",dns=" + dns; 610 | } else { 611 | retStr = "tag=OFF,mode=" + mode + ",ssid=" + ssid + ",pwd=" + pwd; 612 | } 613 | 614 | if (UMSGnum > 0) { 615 | String UMSGNAME[12] = { "umsg1", "umsg2", "umsg3", "umsg4", "umsg5", "umsg6", 616 | "umsg7", "umsg8", "umsg9", "umsg10", "umsg11", "umsg12" }; 617 | String retStr2 = ""; 618 | for (int i = 0; i < UMSGnum; i++) { 619 | StrsUMSG[i] = WFconfigserver.arg(UMSGNAME[i]); 620 | StrsUMSG[i].trim(); 621 | if (StrsUMSG[i] != "" && StrsUMSG[i] != " " && StrsUMSG[i] != NULL && StrsUMSG[i] != "NULL") { 622 | retStr2 += UMSGNAME[i] + "=" + StrsUMSG[i]; 623 | } else { 624 | retStr2 += UMSGNAME[i] + "=" + "[err:7000]设置的数据组与实际数据组数量不等!!"; 625 | } 626 | } 627 | retStr2.trim(); 628 | retStr2 = retStr2 + "=umsg="; 629 | retStr2.replace(" ", ""); 630 | if (FS_W_UMSG(retStr2)) { 631 | mySerial(">> UMSG Write OK", true); 632 | mySerial(">> 自定义信息已写入:", false); 633 | mySerial(String(UMSGnum), false); 634 | mySerial("条", true); 635 | runTAG = "自定义信息已写入:" + String(UMSGnum) + "条"; 636 | } 637 | } 638 | 639 | if (ssid != "" && ssid != NULL) { 640 | if (!boolSpaceWiFiTag) { 641 | retStr.replace(" ", ""); 642 | } 643 | if (FS_W(retStr)) { 644 | if (mhtmlresult != "") { 645 | WFconfigserver.send(200, "text/html", mhtmlresult); 646 | if (boolautostart) { 647 | delay_rst(); 648 | ESP.restart(); 649 | } 650 | } else { 651 | if (boolautostart) { 652 | WFconfigserver.send(200, "text/plain", "ok, zdyhtml, mode=" + mode + ", The board has rebooted!"); 653 | delay_rst(); 654 | ESP.restart(); 655 | } else { 656 | WFconfigserver.send(200, "text/plain", "ok, zdyhtml, mode=" + mode + ", Please restart the board!"); 657 | } 658 | } 659 | } 660 | } 661 | } 662 | 663 | void BGWiFiConfig::WRindex() { 664 | String time = ""; 665 | #ifdef ESP32 666 | time = "3"; 667 | #else 668 | time = "3"; 669 | #endif 670 | /** 671 | String ret2=String(" BGWiFiConfig配网") 672 | + String("
") 673 | + String( "

配网

") 674 | + String( "

WiFi名称:

") 675 | + String( "

WiFi密码:

") 676 | + String( "

  >>预计需要" + time + "秒

") 677 | + String( "
"); 678 | **/ 679 | String ret = String(" BGWiFiConfig配网") 680 | + String("") 681 | + String("
") 682 | + String("

配网

") 683 | + String("

WiFi名称:

") 684 | + String("

WiFi密码:

") 685 | + String("

  >>预计需要" + time + "秒

") 686 | + String("
"); 687 | WFconfigserver.send(200, "text/html", ret); 688 | } 689 | void BGWiFiConfig::WRresult() { 690 | String ssid = WFconfigserver.arg("ssid"); 691 | String pwd = WFconfigserver.arg("pwd"); 692 | String retStr = "tag=OFF,mode=1,ssid=" + ssid + ",pwd=" + pwd; 693 | String ret = String("BGWiFiConfig配网") 694 | + String("
") 695 | + String("

配网写入结果

") 696 | + String("

已配置WiFi名称:" + ssid + "

") 697 | + String("

已配置WiFi密码:" + pwd + "

") 698 | + String("

确认无误后,请退出页面,并重启开发板

") 699 | + String("
"); 700 | 701 | String ret2 = String("BGWiFiConfig配网") 702 | + String("
") 703 | + String("

配网写入结果

") 704 | + String("

已配置WiFi名称:" + ssid + "

") 705 | + String("

已配置WiFi密码:" + pwd + "

") 706 | + String("

已调用autoStart()函数,已自动重启开发板,请观察串口输出!!

") 707 | + String("
"); 708 | if (ssid != "" && ssid != NULL) { 709 | if (!boolSpaceWiFiTag) { 710 | retStr.replace(" ", ""); 711 | } 712 | if (FS_W(retStr)) { 713 | if (boolautostart) { 714 | WFconfigserver.send(200, "text/html", ret2); 715 | delay_rst(); 716 | ESP.restart(); 717 | } else { 718 | WFconfigserver.send(200, "text/html", ret); 719 | } 720 | } 721 | } 722 | } 723 | 724 | void BGWiFiConfig::WRapi() { 725 | String retStr = ""; 726 | String mode = WFconfigserver.arg("mode"); 727 | String ssid = WFconfigserver.arg("ssid"); 728 | String pwd = WFconfigserver.arg("pwd"); 729 | if (mode == "2") { 730 | String ip = WFconfigserver.arg("ip"); 731 | String gateway = WFconfigserver.arg("gateway"); 732 | String subnet = WFconfigserver.arg("subnet"); 733 | String dns = WFconfigserver.arg("dns"); 734 | retStr = "tag=OFF,mode=" + mode + ",ssid=" + ssid + ",pwd=" + pwd + ",ip=" + ip 735 | + ",gateway=" + gateway + ",subnet=" + subnet + ",dns=" + dns; 736 | } else { 737 | retStr = "tag=OFF,mode=" + mode + ",ssid=" + ssid + ",pwd=" + pwd; 738 | } 739 | 740 | if (UMSGnum > 0) { 741 | String UMSGNAME[12] = { "umsg1", "umsg2", "umsg3", "umsg4", "umsg5", "umsg6", 742 | "umsg7", "umsg8", "umsg9", "umsg10", "umsg11", "umsg12" }; 743 | String retStr2 = ""; 744 | for (int i = 0; i < UMSGnum; i++) { 745 | StrsUMSG[i] = WFconfigserver.arg(UMSGNAME[i]); 746 | StrsUMSG[i].trim(); 747 | if (StrsUMSG[i] != "" && StrsUMSG[i] != " " && StrsUMSG[i] != NULL && StrsUMSG[i] != "NULL") { 748 | retStr2 += UMSGNAME[i] + "=" + StrsUMSG[i]; 749 | } else { 750 | retStr2 += UMSGNAME[i] + "=" + "[err:7000]设置的数据组与实际数据组数量不等!!"; 751 | } 752 | } 753 | retStr2.trim(); 754 | retStr2 = retStr2 + "=umsg="; 755 | retStr2.replace(" ", ""); 756 | if (FS_W_UMSG(retStr2)) { 757 | mySerial(">>UMSG Write OK", true); 758 | mySerial(">>自定义信息已写入:", false); 759 | mySerial(String(UMSGnum), false); 760 | mySerial("条", true); 761 | runTAG = "自定义信息已写入:" + String(UMSGnum) + "条"; 762 | } 763 | } 764 | 765 | if (!boolSpaceWiFiTag) { 766 | retStr.replace(" ", ""); 767 | } 768 | if (FS_W(retStr)) { 769 | if (StrApiRet[0] != NULL && StrApiRet[0] != "NULL" && StrApiRet[0] != "") { 770 | if (StrApiRet[1] == "addWiFi") { 771 | if (boolautostart) { 772 | WFconfigserver.send(200, "text/plain", StrApiRet[0] + ">>[" + mode + "," + ssid + "," + pwd + "]<<"); 773 | delay_rst(); 774 | ESP.restart(); 775 | } else { 776 | WFconfigserver.send(200, "text/plain", StrApiRet[0] + ">>[" + mode + "," + ssid + "," + pwd + "]<<"); 777 | } 778 | } else { 779 | if (boolautostart) { 780 | WFconfigserver.send(200, "text/plain", StrApiRet[0]); 781 | delay_rst(); 782 | ESP.restart(); 783 | } else { 784 | WFconfigserver.send(200, "text/plain", StrApiRet[0]); 785 | } 786 | } 787 | } else { 788 | if (boolautostart) { 789 | WFconfigserver.send(200, "text/plain", "ok,mode=" + mode + ",The board has rebooted!"); 790 | delay_rst(); 791 | ESP.restart(); 792 | } else { 793 | WFconfigserver.send(200, "text/plain", "ok,mode=" + mode + ",Please restart the board!"); 794 | } 795 | } 796 | } 797 | } 798 | 799 | 800 | IPAddress BGWiFiConfig::StrToIP(String str) { 801 | IPAddress ipadd; 802 | ipadd.fromString(str); 803 | return ipadd; 804 | } 805 | 806 | bool BGWiFiConfig::FS_W(String str) { 807 | /* if (UMSGnum < 1) 808 | //SPIFFS.format(); 809 | SPIFFS.remove("/bgwificonfig/wifiset.txt"); 810 | File dataFile = SPIFFS.open("/bgwificonfig/wifiset.txt", "w"); 811 | dataFile.print(str); 812 | dataFile.close();*/ 813 | #ifdef useLittleFS 814 | if (!FILESYSTEM.exists("/bgwificonfig")) { 815 | FILESYSTEM.mkdir("/bgwificonfig"); 816 | } 817 | if (UMSGnum < 1) 818 | FILESYSTEM.remove("/bgwificonfig/wifiset.txt"); 819 | File lsfile = FILESYSTEM.open("/bgwificonfig/wifiset.txt", "w"); 820 | lsfile.print(str); 821 | lsfile.close(); 822 | #else 823 | if (UMSGnum < 1) 824 | FILESYSTEM.remove("/bgwificonfig/wifiset.txt"); 825 | File dataFile = FILESYSTEM.open("/bgwificonfig/wifiset.txt", "w"); 826 | dataFile.print(str); 827 | dataFile.close(); 828 | #endif 829 | Serial.println(); 830 | mySerial(">>", true); 831 | if (boolautostart) { 832 | mySerial(">>配网信息已写入,开发板将自动重启并连接WiFi,请观察串口信息!!", true); 833 | } else { 834 | mySerial(">>配网信息已写入,请重启开发板,连接WiFi!!", true); 835 | } 836 | runTAG = "配网信息已写入"; 837 | return true; 838 | } 839 | 840 | String BGWiFiConfig::FS_R() { 841 | /* if (!SPIFFS.exists("/bgwificonfig/wifiset.txt")) { 842 | return "NULL"; 843 | } 844 | File dataFile = SPIFFS.open("/bgwificonfig/wifiset.txt", "r");*/ 845 | if (!FILESYSTEM.exists("/bgwificonfig/wifiset.txt")) { 846 | return "NULL"; 847 | } 848 | File dataFile = FILESYSTEM.open("/bgwificonfig/wifiset.txt", "r"); 849 | String retStr; 850 | for (int i = 0; i < dataFile.size(); i++) { 851 | retStr += (char)dataFile.read(); 852 | } 853 | dataFile.close(); 854 | return retStr; 855 | } 856 | 857 | bool BGWiFiConfig::FS_W_UMSG(String str) { 858 | //SPIFFS.format(); 859 | /*SPIFFS.remove("/bgwificonfig/umsg.txt"); 860 | File dataFile = SPIFFS.open("/bgwificonfig/umsg.txt", "w"); 861 | */ 862 | #ifdef useLittleFS 863 | if (!FILESYSTEM.exists("/bgwificonfig")) { 864 | FILESYSTEM.mkdir("/bgwificonfig"); 865 | } 866 | FILESYSTEM.remove("/bgwificonfig/umsg.txt"); 867 | File lsfile = FILESYSTEM.open("/bgwificonfig/umsg.txt", "w"); 868 | lsfile.print(str); 869 | lsfile.close(); 870 | #else 871 | FILESYSTEM.remove("/bgwificonfig/umsg.txt"); 872 | File dataFile = FILESYSTEM.open("/bgwificonfig/umsg.txt", "w"); 873 | dataFile.print(str); 874 | dataFile.close(); 875 | #endif 876 | Serial.println(); 877 | mySerial(">>", true); 878 | return true; 879 | } 880 | 881 | String BGWiFiConfig::FS_R_UMSG() { 882 | /* if (!SPIFFS.exists("/bgwificonfig/umsg.txt")) { 883 | return "NULL"; 884 | } 885 | File dataFile = SPIFFS.open("/bgwificonfig/umsg.txt", "r");*/ 886 | if (!FILESYSTEM.exists("/bgwificonfig/umsg.txt")) { 887 | return "NULL"; 888 | } 889 | File dataFile = FILESYSTEM.open("/bgwificonfig/umsg.txt", "r"); 890 | String retStr; 891 | for (int i = 0; i < dataFile.size(); i++) { 892 | retStr += (char)dataFile.read(); 893 | } 894 | dataFile.close(); 895 | return retStr; 896 | } 897 | 898 | void BGWiFiConfig::StrCL_UMSG(String str) { 899 | if (str != "NULL" && str != "" && str != NULL && UMSGnum > 0 && UMSGnum < 13) { 900 | str.trim(); 901 | String umsgname[13] = { 902 | "umsg1=", "umsg2=", "umsg3=", 903 | "umsg4=", "umsg5=", "umsg6=", 904 | "umsg7=", "umsg8=", "umsg9=", 905 | "umsg10=", "umsg11=", "umsg12=", "=umsg=" 906 | }; 907 | int umsgkey[13] = { -1 }; 908 | for (int i = 0; i < UMSGnum + 1; i++) { 909 | umsgkey[i] = str.indexOf(umsgname[i]); 910 | } 911 | for (int j = 0; j < UMSGnum - 1; j++) { 912 | StrsUMSG[j] = str.substring(umsgkey[j] + umsgname[j].length(), umsgkey[j + 1]); 913 | } 914 | StrsUMSG[UMSGnum - 1] = str.substring(umsgkey[UMSGnum - 1] + umsgname[UMSGnum - 1].length(), str.indexOf(umsgname[12])); 915 | } 916 | } 917 | 918 | String BGWiFiConfig::readUMSG(int i) { 919 | if (UMSGnum > 0 && i < 13 && i > 0 && TAG == "OFF") { 920 | StrsUMSG[i - 1].trim(); 921 | if (StrsUMSG[i - 1] != NULL && StrsUMSG[i - 1] != "" && StrsUMSG[i - 1] != "NULL") 922 | return StrsUMSG[i - 1]; 923 | } 924 | return "NULL"; 925 | } 926 | 927 | void BGWiFiConfig::offConnectWiFi(bool tag) { 928 | booloffconnectwifi = tag; 929 | } 930 | 931 | String BGWiFiConfig::readWiFi(int i) { 932 | String str = FS_R(); 933 | if (i == 0) { 934 | return str.substring(str.indexOf(",ssid=") + 6, str.indexOf(",pwd=")); 935 | } else if (i == 1) { 936 | return str.substring(str.indexOf(",pwd=") + 5, str.indexOf(",ip=")); 937 | } else if (i == 2) { 938 | if (WiFi.isConnected()) 939 | return "wifiok"; 940 | else 941 | return "wifibad"; 942 | } 943 | return "NULL"; 944 | } 945 | 946 | String& BGWiFiConfig::setApiRet(int i) { 947 | String& str = StrApiRet[i]; 948 | return str; 949 | } 950 | 951 | bool BGWiFiConfig::OK(bool tag) { 952 | String str = ""; 953 | str = FS_R(); 954 | str = str.substring(str.indexOf(",ssid=") + 6, str.indexOf(",pwd=")); 955 | if (str != "" && str != "NULL" && str != NULL) { 956 | if (tag) { 957 | if (WiFi.isConnected()) 958 | return true; 959 | else 960 | return false; 961 | } else { 962 | return true; 963 | } 964 | } else { 965 | return false; 966 | } 967 | return false; 968 | } 969 | 970 | 971 | void BGWiFiConfig::setOTAhtml(String html) { 972 | if (html.length() > 15) { 973 | OTAserverIndex = html; 974 | } 975 | } 976 | 977 | void BGWiFiConfig::setOTATimeOut(int sectime) { 978 | if (sectime > 1) { 979 | OTASECtimeTAG = true; 980 | OTASECtime = sectime; 981 | } 982 | } 983 | 984 | String BGWiFiConfig::getOTAIP() { 985 | if (onlyotaTAG) { 986 | if ((WiFi.softAPgetStationNum() > 0) && WiFi.isConnected()) 987 | return "[{AP:" + WiFi.softAPIP().toString() + "},{STA:" + WiFi.localIP().toString() + "}]"; 988 | else if (WiFi.isConnected()) 989 | return WiFi.localIP().toString(); 990 | else if (WiFi.softAPgetStationNum() > 0) 991 | return WiFi.softAPIP().toString(); 992 | } else { 993 | if (OK(true)) 994 | return WiFi.localIP().toString(); 995 | } 996 | return "WiFi就绪后,才能获取"; 997 | } 998 | 999 | void BGWiFiConfig::OTAbegin() { 1000 | if (TAG == "OFF" || onlyotaTAG) { 1001 | Serial.println(); 1002 | mySerial("欢迎使用BGWiFiConfig-OTA程序!!", true); 1003 | int ii = 0; 1004 | if (onlyotaTAG == true) { 1005 | while ((WiFi.status() != WL_CONNECTED) && (WiFi.softAPgetStationNum() < 1)) { 1006 | delay(1000); 1007 | Serial.println("OTA等待WiFi就绪..."); 1008 | ii++; 1009 | if ((ii > OTASECtime) && OTASECtimeTAG) { 1010 | Serial.println("WiFi就绪超时~~"); 1011 | break; 1012 | } 1013 | } 1014 | } else { 1015 | while (!OK(true) && TAG == "OFF") { 1016 | delay(1000); 1017 | Serial.println("OTA等待WiFi就绪..."); 1018 | ii++; 1019 | if ((ii > OTASECtime) && OTASECtimeTAG) { 1020 | Serial.println("WiFi就绪超时~~"); 1021 | break; 1022 | } 1023 | } 1024 | } 1025 | runTAG = "OTA启动成功"; 1026 | if ((WiFi.waitForConnectResult() == WL_CONNECTED) || (WiFi.softAPgetStationNum() > 0)) { 1027 | OTAserver.on("/", HTTP_GET, []() { 1028 | OTAserver.sendHeader("Connection", "close"); 1029 | OTAserver.send(200, "text/html", OTAserverIndex); 1030 | }); 1031 | OTAserver.on( 1032 | "/otaupdate", HTTP_POST, []() { 1033 | OTAserver.sendHeader("Connection", "close"); 1034 | OTAserver.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); 1035 | ESP.restart(); 1036 | }, 1037 | []() { 1038 | HTTPUpload& upload = OTAserver.upload(); 1039 | if (upload.status == UPLOAD_FILE_START) { 1040 | Serial.printf("OTA上传文件名: %s\n", upload.filename.c_str()); 1041 | uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; 1042 | if (!Update.begin(maxSketchSpace)) { 1043 | } 1044 | } else if (upload.status == UPLOAD_FILE_WRITE) { 1045 | if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { 1046 | } 1047 | } else if (upload.status == UPLOAD_FILE_END) { 1048 | if (Update.end(true)) { 1049 | OTAserver.send(200, "text/plain", "Upload successfully: " + String(upload.totalSize) + "byte\nRestart to run the new program..."); 1050 | Serial.printf("成功上传: %u字节\n正在重启运行上传的程序...\n", upload.totalSize); 1051 | } else { 1052 | OTAserver.send(200, "text/plain", "ota update failed, please try again"); 1053 | Serial.printf("OTA上传失败,请重试!!"); 1054 | } 1055 | } 1056 | yield(); 1057 | }); 1058 | OTAserver.begin(); 1059 | String Tmsg = ""; 1060 | mySerial("BGWiFiConfig-OTA启动成功~~~", true); 1061 | if (WiFi.waitForConnectResult() == WL_CONNECTED) { 1062 | Tmsg = "请访问http://" + WiFi.localIP().toString() + "进行OTA升级"; 1063 | Serial.println(Tmsg); 1064 | } 1065 | if (WiFi.softAPgetStationNum() > 0) { 1066 | Tmsg = "请访问http://" + WiFi.softAPIP().toString() + "进行OTA升级"; 1067 | Serial.println(Tmsg); 1068 | } 1069 | } else { 1070 | mySerial("BGWiFiConfig-OTA启动失败~~~", true); 1071 | } 1072 | } 1073 | } 1074 | 1075 | void BGWiFiConfig::OTALoop() { 1076 | if (TAG == "OFF" || onlyotaTAG) { 1077 | OTAserver.handleClient(); 1078 | } 1079 | } 1080 | 1081 | void BGWiFiConfig::setOTAWiFiSTA(String ssid, String pwd) { 1082 | WiFi.mode(WIFI_STA); 1083 | WiFi.begin(ssid.c_str(), pwd.c_str()); 1084 | } 1085 | 1086 | void BGWiFiConfig::clOTAPIP(String ip) { 1087 | String ipstrs[4]; 1088 | ipstrs[0] = ip.substring(0, ip.indexOf(".")); 1089 | ipstrs[1] = ip.substring(ipstrs[0].length() + 1, ip.indexOf(".", ipstrs[0].length() + 1)); 1090 | ipstrs[2] = ip.substring(ipstrs[0].length() + ipstrs[1].length() + 2, ip.indexOf(".", ipstrs[0].length() + ipstrs[1].length() + 2)); 1091 | ipstrs[3] = ip.substring(ipstrs[0].length() + ipstrs[1].length() + ipstrs[2].length() + 3, ip.indexOf(".", ipstrs[0].length() + ipstrs[1].length() + ipstrs[2].length() + 3)); 1092 | String mip = ip; 1093 | mip.replace(" ", ""); 1094 | String gateway = "192.168.33.33"; 1095 | gateway = ipstrs[0] + "." + ipstrs[1] + " ." + ipstrs[2] + ".1"; 1096 | gateway.replace(" ", ""); 1097 | String subnet = "255.255.255.0"; 1098 | ipstrs[0].replace(" ", ""); 1099 | if (ipstrs[0].toInt() >= 0 && ipstrs[0].toInt() <= 127) 1100 | subnet = "255.0.0.0"; 1101 | else if (ipstrs[0].toInt() >= 128 && ipstrs[0].toInt() <= 191) 1102 | subnet = "255.255.0.0"; 1103 | else 1104 | subnet = "255.255.255.0"; 1105 | 1106 | otapip[0] = StrToIP(mip); 1107 | otapip[1] = StrToIP(gateway); 1108 | otapip[2] = StrToIP(subnet); 1109 | } 1110 | 1111 | void BGWiFiConfig::setOTAWiFiAP(String ssid, String pwd, String ip) { 1112 | if (onlyotaTAG) { 1113 | clOTAPIP(ip); 1114 | WiFi.mode(WIFI_AP); 1115 | WiFi.softAPConfig(otapip[0], otapip[1], otapip[2]); 1116 | WiFi.softAP(ssid.c_str(), pwd.c_str()); 1117 | } else { 1118 | Serial.println(); 1119 | Serial.println("[未定义onlyota,不能使用setOTAWiFiAP函数]"); 1120 | } 1121 | } 1122 | 1123 | void BGWiFiConfig::setOTAWiFiAPSTA(String APssid, String APpwd, String STAssid, String STApwd, String ip) { 1124 | if (onlyotaTAG) { 1125 | clOTAPIP(ip); 1126 | WiFi.mode(WIFI_AP_STA); 1127 | WiFi.softAPConfig(otapip[0], otapip[1], otapip[2]); 1128 | WiFi.softAP(APssid.c_str(), APpwd.c_str()); 1129 | WiFi.begin(STAssid.c_str(), STApwd.c_str()); 1130 | } else { 1131 | Serial.println(); 1132 | Serial.println("[未定义onlyota,不能使用setOTAWiFiAPSTA函数]"); 1133 | } 1134 | } 1135 | 1136 | void BGWiFiConfig::setConFailReset(int xReConNum, int xReConTime, bool xIsReboot) { 1137 | boolConFailResetTag = true; 1138 | gReConNum = xReConNum; 1139 | SECtime = xReConTime; 1140 | boolConFailResetIsReboot = xIsReboot; 1141 | } 1142 | 1143 | void BGWiFiConfig::STA_M3_FailReset() { 1144 | int iReConNum = 0; 1145 | while (WiFi.status() != WL_CONNECTED) { 1146 | if (MODE == "2") { 1147 | STA_M2(SSID, PWD, IP, GATEWAY, SUBNET, DNS); 1148 | } else { 1149 | STA_M1(SSID, PWD); 1150 | } 1151 | iReConNum++; 1152 | if (WiFi.isConnected()) { 1153 | break; 1154 | } else if (iReConNum > gReConNum) { 1155 | boolConFailResetTag = false; 1156 | mySerial(">>重置配网信息中,请等待...", true); 1157 | runTAG = "重连仍失败,重置配网信息中,请等待"; 1158 | clearWiFi(); 1159 | runTAG = "连接失败,未成功连接WiFi[" + SSID + "],已重置配网"; 1160 | if (boolConFailResetIsReboot) { 1161 | mySerial("WiFi连接失败,已重置配网并将重启,请重新配网<<<", true); 1162 | ESP.restart(); 1163 | } else { 1164 | mySerial("WiFi连接失败,已重置配网,请重启开发板并配网<<<", true); 1165 | } 1166 | break; 1167 | } 1168 | runTAG = "连接失败,正在第[ " + String(iReConNum + 1) + " ]次连接WiFi[" + SSID + "]"; 1169 | mySerial("连接失败,正在第[ " + String(iReConNum + 1) + " ]次连接WiFi[" + SSID + "]", true); 1170 | } 1171 | } 1172 | 1173 | void BGWiFiConfig::useSpaceWiFi(bool xSpaceWiFiTag) { 1174 | boolSpaceWiFiTag = xSpaceWiFiTag; 1175 | } 1176 | 1177 | IPAddress BGWiFiConfig::getPWIP() { 1178 | IPAddress rtIP = StrToIP("192.168.22.22"); 1179 | switch (gICompatibleM) { 1180 | case 0: 1181 | rtIP = StrToIP("192.168.22.1"); 1182 | break; 1183 | case 1: 1184 | rtIP = StrToIP("192.168.22.22"); 1185 | break; 1186 | case 2: 1187 | rtIP = StrToIP("192.168.4.1"); 1188 | break; 1189 | case 3: 1190 | rtIP = WiFi.softAPIP(); 1191 | break; 1192 | } 1193 | return rtIP; 1194 | } 1195 | 1196 | String BGWiFiConfig::getPWIPDH() { 1197 | String rtIP = "192.168.22.22"; 1198 | switch (gICompatibleM) { 1199 | case 0: 1200 | rtIP = "192.168.22.1"; 1201 | break; 1202 | case 1: 1203 | rtIP = "192.168.22.22"; 1204 | break; 1205 | case 2: 1206 | rtIP = "192.168.4.1"; 1207 | break; 1208 | case 3: 1209 | rtIP = WiFi.softAPIP().toString(); 1210 | break; 1211 | } 1212 | return rtIP; 1213 | } 1214 | 1215 | void BGWiFiConfig::setCompatibleModeTest(bool xCMTag) { 1216 | if (xCMTag) 1217 | gICompatibleM = 2; 1218 | else 1219 | gICompatibleM = 3; 1220 | } 1221 | 1222 | void BGWiFiConfig::setCompatibleMode(bool xCMTag) { 1223 | if (xCMTag) 1224 | gICompatibleM = 0; 1225 | else 1226 | gICompatibleM = 1; 1227 | } 1228 | -------------------------------------------------------------------------------- /src/DEFPORT.h: -------------------------------------------------------------------------------- 1 | #define DEFPORT 2022 2 | #define DEFPORTPWMODE 0 3 | #define DEFPORTHTML "NULL" 4 | --------------------------------------------------------------------------------