├── .github └── workflows │ └── platformio-publish-release.yml ├── LICENSE ├── README.md ├── examples └── simple_server │ └── simple_server.ino ├── library.json ├── library.properties ├── previews ├── arduino.png ├── minimal.png ├── pio.png └── stylized.png ├── scripts ├── codeGenerator.py └── requirements.txt ├── src ├── ESPAsyncHTTPUpdateServer.cpp └── ESPAsyncHTTPUpdateServer.h └── www ├── minimal-flash.html ├── minimal-fs.html ├── minimal.html ├── stylized-flash.html ├── stylized-fs.html └── stylized.html /.github/workflows/platformio-publish-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish PlatformIO - Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | permissions: 9 | contents: write 10 | 11 | jobs: 12 | publish-platformio-release: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - uses: actions/cache@v4 18 | with: 19 | path: | 20 | ~/.cache/pip 21 | ~/.platformio/.cache 22 | key: ${{ runner.os }}-pio 23 | - uses: actions/setup-python@v5 24 | with: 25 | python-version: '3.11' 26 | - name: Install PlatformIO Core 27 | run: pip install --upgrade platformio 28 | 29 | - name: Login to PlatformIO 30 | run: pio account login -u ${{ secrets.PLATFORMIO_USERNAME }} -p ${{ secrets.PLATFORMIO_PASSWORD }} 31 | 32 | - name: Publish Package 33 | run: pio pkg publish --no-interactive 34 | 35 | - name: Create Package 36 | run: pio pkg pack -o ${{ github.event.repository.name }}-${{ github.ref_name }}.tar.gz 37 | 38 | - name: Release 39 | uses: softprops/action-gh-release@v2 40 | with: 41 | prerelease: true 42 | generate_release_notes: true 43 | files: | 44 | ${{ github.event.repository.name }}-${{ github.ref_name }}.tar.gz 45 | 46 | -------------------------------------------------------------------------------- /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 |

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

10 | 11 | # ESP Async HTTP Update Server 12 | 13 | This is an advanced version [ESP8266HTTPUpdateServer](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266HTTPUpdateServer)/[ESP32's HTTPUpdateServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/HTTPUpdateServer) library, modified to be compatible with [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) and also add optional Styling 🌈 to the page. 14 | 15 | It will provide a webpage for updating the firmware/filesystem of `ESP8266` or `ESP32` microcontrollers. 16 | 17 | > [!IMPORTANT] 18 | > If you found this library helpful, please consider leaving a Star⭐ 19 | > 20 | > It helps a lot in maintaining the project ❤️ 21 | 22 | ## Features 23 | - Supports: 24 | - ESP8266 25 | - ESP32 26 | - Can Update: 27 | - Firmware 28 | - FileSystem 29 | - Styling: 30 | - Stylized (Additional ~350 bytes) 31 | - Minimal 32 | - Update modes: 33 | - Firmware + FileSystem 34 | - Firmware only 35 | - FileSystem only 36 | - Update route customization (default: `/update`) 37 | - Update credentials customization (default: `No credentials`) 38 | - Username 39 | - Password 40 | - Update Events: 41 | - onUpdateBegin 42 | - onUpdateEnd 43 | - Force Aborting Update using events 44 | - FileSystem Options: 45 | - SPIFFS 46 | - LittleFS 47 | 48 | ## HowTo 49 | 50 | ### Install 51 | 52 | This Library is available in `Arduino Library Repository` and `PIO` and you can install it from: 53 | 54 | | Arduino IDE Library Manager | PlatformIO Libraries | 55 | |:---:|:---:| 56 | |Arduino library manager|pltformio library| 57 | 58 | `ipdotsetaf/ESPAsyncHTTPUpdateServer@^3.0.0` 59 | ### Setup 60 | 1. Include the library after `ESPAsyncWebServer.h` 61 | ``` C++ 62 | #include 63 | #include 64 | ``` 65 | 2. Create an object from `ESPAsyncHTTPUpdateServer` 66 | ``` C++ 67 | ESPAsyncHTTPUpdateServer updateServer; 68 | AsyncWebServer server(80); 69 | ``` 70 | 3. Setup the update server before starting the webServer 71 | ``` C++ 72 | updateServer.setup(&server); 73 | server.begin(); 74 | ``` 75 | #### Custom Route 76 | ``` C++ 77 | updateServer.setup(&server, "/customroute"); 78 | ``` 79 | #### Credentials 80 | ``` C++ 81 | updateServer.setup(&server, "username", "password"); 82 | ``` 83 | or 84 | ``` C++ 85 | updateServer.setup(&server, "/customroute", "username", "password"); 86 | ``` 87 | #### Events 88 | ```c++ 89 | updateServer.onUpdateBegin = [](const UpdateType type, int &result) 90 | { 91 | //... 92 | }; 93 | 94 | updateServer.onUpdateEnd = [](const UpdateType type, int &result) 95 | { 96 | //... 97 | }; 98 | ``` 99 | #### Aborting the update 100 | ```c++ 101 | updateServer.onUpdateBegin = [](const UpdateType type, int &result) 102 | { 103 | result = UpdateResult::UPDATE_ABORT; 104 | }; 105 | ``` 106 | 107 | ### Styling and Customizing OTA Page 108 | 109 | | Stylized | Minimal | 110 | |:---:|:---:| 111 | |Stylized OTA Page | Minimal OTA Page | 112 | 113 | > [!IMPORTANT] 114 | > By default styling is disabled to save ~350 bytes of flash memory. 115 | > 116 | > You can enable the styling by adding the `-DESPASYNCHTTPUPDATESERVER_PRETTY` Build Flag to your environment. 117 | 118 | ### Customizing OTA Page 119 | 120 | > [!IMPORTANT] 121 | > Add the `-DESPASYNCHTTPUPDATESERVER_MODE` Build Flag with desired value to choose different update mode. 122 | > Choose the right value based on your needs from bellow table: 123 | > 124 | > | Update mode | value | 125 | > |:---:|:---:| 126 | > |Firmware and FileSystem|0| 127 | > |Firmware only|1| 128 | > |FileSystem only|2| 129 | 130 | #### Modifying Htmls 131 | 132 | in case you liked to modify the html of any of the pages, you need to run the `scripts/codeGenerator.py` afterwards so html contents get processed and placed in the source. 133 | 134 | Instructions: 135 | 1. Make sure you have python installed 136 | 2. In your python environment run the following 137 | 3. `pip install -r requirements.txt` 138 | 4. `python codeGenerator.py` 139 | 140 | ### Selecting FileSystem 141 | > [!IMPORTANT] 142 | > The library's default fileSystem is `SPIFFS` but if you are using `LittleFS` for your FileSystem, make sure to add the `-DESPASYNCHTTPUPDATESERVER_LITTLEFS` Build Flag to your environment. 143 | 144 | ### Debugging 145 | > [!TIP] 146 | > To debug the library functionality, you can add the `-DESPASYNCHTTPUPDATESERVER_DEBUG` Build Flag to your environment. 147 | > 148 | > This will enable the library to print logs to the Serial. 149 | 150 | > [!TIP] 151 | > If you are using another `Serial` port, you can override the default serial by adding the `-DESPASYNCHTTPUPDATESERVER_SerialOutput=Serial1` Build Flag to your environment. 152 | 153 | ### Server Working Example 154 | 155 | Please refer to this [fully working example](examples/simple_server/simple_server.ino) 156 | 157 | ## TODO: 158 | - Custom CSS support 159 | - Synchronous WebServer support 160 | 161 | ## Contribution 162 | - You can open Issues for any bug report or feature request. 163 | - You are free to contribute to this project by following these steps: 164 | 1. Fork this Repo. 165 | 2. Create a new branch for your feature/bugfix in your forked Repo. 166 | 3. Commit your changes to the new branch you just made. 167 | 4. Create a pull request from your branch into the `master` branch of This Repo([https://github.com/IPdotSetAF/ESPAsyncHTTPUpdateServer](https://github.com/IPdotSetAF/ESPAsyncHTTPUpdateServer)). 168 | -------------------------------------------------------------------------------- /examples/simple_server/simple_server.ino: -------------------------------------------------------------------------------- 1 | // 2 | // A simple server implementation showing how to: 3 | // * serve static messages 4 | // * handle missing pages / 404s 5 | // * setup an http update server 6 | // 7 | 8 | #include 9 | #ifdef ESP32 10 | #include 11 | #include 12 | #elif defined(ESP8266) 13 | #include 14 | #include 15 | #endif 16 | #include 17 | #include 18 | 19 | //create an object from the UpdateServer 20 | ESPAsyncHTTPUpdateServer updateServer; 21 | AsyncWebServer server(80); 22 | 23 | const char* ssid = "YOUR_SSID"; 24 | const char* password = "YOUR_PASSWORD"; 25 | 26 | void notFound(AsyncWebServerRequest *request) { 27 | request->send(404, "text/plain", "Not found"); 28 | } 29 | 30 | void setup() { 31 | 32 | Serial.begin(115200); 33 | WiFi.mode(WIFI_STA); 34 | WiFi.begin(ssid, password); 35 | if (WiFi.waitForConnectResult() != WL_CONNECTED) { 36 | Serial.printf("WiFi Failed!\n"); 37 | return; 38 | } 39 | 40 | Serial.print("IP Address: "); 41 | Serial.println(WiFi.localIP()); 42 | 43 | server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ 44 | request->send(200, "text/plain", "Hello, world"); 45 | }); 46 | 47 | server.onNotFound(notFound); 48 | 49 | //setup the updateServer with credentials 50 | updateServer.setup(&server, "admin", "admin"); 51 | //hook to update events if you need to 52 | updateServer.onUpdateBegin = [](const UpdateType type, int &result) 53 | { 54 | //you can force abort the update like this if you need to: 55 | //result = UpdateResult::UPDATE_ABORT; 56 | Serial.println("Update started : " + String(type)); 57 | }; 58 | updateServer.onUpdateEnd = [](const UpdateType type, int &result) 59 | { 60 | Serial.println("Update finished : " + String(type) + " result: " + String(result)); 61 | }; 62 | 63 | server.begin(); 64 | } 65 | 66 | void loop() { 67 | } -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ESPAsyncHTTPUpdateServer", 3 | "version": "3.0.0", 4 | "description": "Simple/Stylized HTTP Update Server for ESPAsyncWebServer(by me-no-dev). This library lets you to update Firmware/FileSystem of ESP32/ESP8266 OTA(Over The Air) from a web page.", 5 | "keywords": 6 | [ 7 | "ESP", 8 | "Async", 9 | "OTA", 10 | "WebServer", 11 | "HTTP", 12 | "UpdateServer", 13 | "FileSystem", 14 | "Firmware", 15 | "Style", 16 | "Event", 17 | "Callback" 18 | ], 19 | "repository": 20 | { 21 | "type": "git", 22 | "url": "https://github.com/IPdotSetAF/ESPAsyncHTTPUpdateServer.git" 23 | }, 24 | "authors": 25 | [ 26 | { 27 | "name": "Mohammad Mahdi Nazari", 28 | "email": "ipdotsetaf@gmail.com", 29 | "url": "https://github.com/IPdotSetAF", 30 | "maintainer": true 31 | } 32 | ], 33 | "license": "LGPL-2.1-only", 34 | "homepage": "https://github.com/IPdotSetAF/ESPAsyncHTTPUpdateServer", 35 | "dependencies": 36 | [ 37 | { 38 | "owner": "ESP32Async", 39 | "name": "ESPAsyncWebServer", 40 | "frameworks": "arduino", 41 | "platforms": 42 | [ 43 | "espressif32", 44 | "espressif8266" 45 | ], 46 | "version": ">=3.7.4" 47 | }, 48 | { 49 | "name": "SPIFFS", 50 | "frameworks": "arduino", 51 | "platforms": "espressif32", 52 | "version": "*" 53 | }, 54 | { 55 | "name": "LittleFS", 56 | "frameworks": "arduino", 57 | "platforms": 58 | [ 59 | "espressif32", 60 | "espressif8266" 61 | ], 62 | "version": "*" 63 | }, 64 | { 65 | "name": "Update", 66 | "frameworks": "arduino", 67 | "platforms": "espressif32", 68 | "version": "*" 69 | } 70 | ], 71 | "frameworks": "arduino", 72 | "platforms": 73 | [ 74 | "espressif32", 75 | "espressif8266" 76 | ] 77 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESPAsyncHTTPUpdateServer 2 | version=3.0.0 3 | author=Mohammad Mahdi Nazari 4 | maintainer=Mohammad Mahdi Nazari 5 | sentence=Simple/Stylized HTTP Update Server for ESPAsyncWebServer(by me-no-dev) 6 | paragraph=This library lets you to update Firmware/FileSystem of ESP32/ESP8266 OTA(Over The Air) from a web page. 7 | category=Other 8 | url=https://github.com/IPdotSetAF/ESPAsyncHTTPUpdateServer 9 | architectures=esp8266, esp32 10 | dot_a_linkage=false 11 | includes=ESPAsyncHTTPUpdateServer.h 12 | depends=ESPAsyncWebServer (>=3.7.4) -------------------------------------------------------------------------------- /previews/arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IPdotSetAF/ESPAsyncHTTPUpdateServer/f32cb7adb67b344abcf6363a026bfe96d65f81f9/previews/arduino.png -------------------------------------------------------------------------------- /previews/minimal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IPdotSetAF/ESPAsyncHTTPUpdateServer/f32cb7adb67b344abcf6363a026bfe96d65f81f9/previews/minimal.png -------------------------------------------------------------------------------- /previews/pio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IPdotSetAF/ESPAsyncHTTPUpdateServer/f32cb7adb67b344abcf6363a026bfe96d65f81f9/previews/pio.png -------------------------------------------------------------------------------- /previews/stylized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IPdotSetAF/ESPAsyncHTTPUpdateServer/f32cb7adb67b344abcf6363a026bfe96d65f81f9/previews/stylized.png -------------------------------------------------------------------------------- /scripts/codeGenerator.py: -------------------------------------------------------------------------------- 1 | import re 2 | import gzip 3 | import htmlmin 4 | import csscompressor 5 | 6 | def minify_html(content): 7 | """Minifies HTML and embedded CSS within " 13 | 14 | # Apply CSS minification to ", minify_css_in_style_tags, content, flags=re.DOTALL) 16 | 17 | # Minify the entire HTML 18 | return htmlmin.minify(content, remove_empty_space=True, remove_all_empty_space=True) 19 | 20 | def gzip_compress(content): 21 | """Gzips the given content.""" 22 | return gzip.compress(content.encode('utf-8')) 23 | 24 | def convert_to_decimal(byte_data): 25 | """Converts bytes to a comma-separated decimal list.""" 26 | return ",".join(str(b) for b in byte_data) 27 | 28 | def process_file(file_path): 29 | """Processes input HTML files and returns minified, gzipped, and decimal-converted data.""" 30 | with open(file_path, "r", encoding="utf-8") as f: 31 | content = f.read() 32 | 33 | minified = minify_html(content) 34 | gzipped = gzip_compress(minified) 35 | decimal_data = convert_to_decimal(gzipped) 36 | 37 | return decimal_data 38 | 39 | def update_cpp_file(destination_file): 40 | """Updates the .cpp file with generated data between the start and end markers.""" 41 | start_marker = "//generated code start" 42 | end_marker = "//generated code end" 43 | 44 | with open(destination_file, "r", encoding="utf-8") as f: 45 | cpp_content = f.read() 46 | 47 | pattern = re.compile(f"{start_marker}.*?{end_marker}", re.DOTALL) 48 | if not pattern.search(cpp_content): 49 | raise ValueError("Start and End markers not found in the destination file.") 50 | 51 | generated_code = f"""{start_marker} 52 | #if ESPASYNCHTTPUPDATESERVER_MODE == 0 53 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 54 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/stylized.html")} }}; 55 | #else 56 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/minimal.html")} }}; 57 | #endif 58 | #elif ESPASYNCHTTPUPDATESERVER_MODE == 1 59 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 60 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/stylized-flash.html")} }}; 61 | #else 62 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/minimal-flash.html")} }}; 63 | #endif 64 | #elif ESPASYNCHTTPUPDATESERVER_MODE == 2 65 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 66 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/stylized-fs.html")} }}; 67 | #else 68 | static const uint8_t serverIndex[] PROGMEM = {{ {process_file("../www/minimal-fs.html")} }}; 69 | #endif 70 | #endif 71 | {end_marker}""" 72 | 73 | updated_content = pattern.sub(generated_code, cpp_content) 74 | 75 | with open(destination_file, "w", encoding="utf-8") as f: 76 | f.write(updated_content) 77 | 78 | if __name__ == "__main__": 79 | destination_file = "../src/ESPAsyncHTTPUpdateServer.cpp" # Change to your actual .cpp file 80 | 81 | update_cpp_file(destination_file) 82 | 83 | print(f"Updated {destination_file} with generated code.") 84 | -------------------------------------------------------------------------------- /scripts/requirements.txt: -------------------------------------------------------------------------------- 1 | htmlmin2 2 | csscompressor -------------------------------------------------------------------------------- /src/ESPAsyncHTTPUpdateServer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "StreamString.h" 3 | #include "ESPAsyncHTTPUpdateServer.h" 4 | #include 5 | 6 | #ifdef ESP32 7 | #ifdef ESPASYNCHTTPUPDATESERVER_LITTLEFS 8 | #include 9 | #else 10 | #include 11 | #endif 12 | #include 13 | #elif defined(ESP8266) 14 | #include 15 | #include 16 | #else 17 | #error "This library only supports boards with an ESP8266 or ESP32 processor." 18 | #endif 19 | 20 | #ifndef ESPASYNCHTTPUPDATESERVER_SerialOutput 21 | #define ESPASYNCHTTPUPDATESERVER_SerialOutput Serial 22 | #endif 23 | 24 | #ifdef ESPASYNCHTTPUPDATESERVER_DEBUG 25 | #define Log(...) ESPASYNCHTTPUPDATESERVER_SerialOutput.printf(__VA_ARGS__) 26 | #else 27 | #define Log(...) 28 | #endif 29 | 30 | #ifndef ESPASYNCHTTPUPDATESERVER_MODE 31 | #define ESPASYNCHTTPUPDATESERVER_MODE 0 32 | #endif 33 | 34 | //generated code start 35 | #if ESPASYNCHTTPUPDATESERVER_MODE == 0 36 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 37 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,157,146,205,110,212,48,16,199,95,197,236,170,82,139,214,221,108,182,133,214,249,64,92,184,22,169,229,132,16,114,236,73,50,224,216,145,237,236,71,87,251,6,28,56,113,230,217,250,36,56,217,13,106,145,64,168,135,140,20,219,243,255,205,127,102,210,23,210,8,191,109,161,246,141,202,211,62,18,197,117,149,129,206,211,6,60,39,162,230,214,129,207,58,95,210,171,241,204,104,15,218,103,147,53,74,95,103,18,86,40,128,14,63,51,212,232,145,43,234,4,87,144,45,38,68,243,6,178,21,194,186,53,214,231,169,243,91,5,249,203,93,25,52,104,201,27,84,91,214,24,109,92,203,5,36,133,177,18,44,181,92,98,231,216,34,106,55,251,58,222,53,220,86,168,169,55,45,139,246,245,98,39,140,50,150,77,1,56,8,158,12,74,14,239,129,93,245,239,11,35,183,187,130,139,175,149,53,157,150,108,26,199,113,82,241,150,45,195,109,114,144,98,81,82,3,86,181,15,136,104,85,239,75,99,155,81,245,85,177,188,188,40,147,71,10,10,53,112,75,171,190,170,96,251,52,126,29,73,168,102,71,62,137,102,211,235,139,162,128,107,18,196,78,206,146,150,75,137,186,26,120,123,212,109,231,119,7,91,44,110,55,196,25,133,146,252,166,152,13,117,53,151,102,205,34,210,219,61,132,254,225,52,138,162,229,88,230,242,114,212,98,172,68,5,212,129,2,225,141,165,69,231,189,209,179,225,238,99,63,201,204,117,69,131,254,211,147,30,28,113,71,139,101,89,62,242,127,146,252,107,22,161,227,231,98,39,209,181,138,111,89,169,96,147,244,129,74,180,161,0,52,154,5,209,174,209,201,151,206,121,44,183,244,184,28,76,132,0,54,225,10,43,77,209,67,227,142,71,251,116,126,88,130,180,31,21,17,138,59,151,137,176,124,139,252,244,225,219,247,135,31,63,63,135,239,140,220,220,189,77,231,225,48,237,167,67,248,0,203,38,111,134,125,42,209,54,107,110,97,50,166,19,208,195,30,103,77,167,60,182,220,250,121,159,70,37,15,251,26,150,182,54,50,123,127,115,123,23,48,113,254,238,152,29,228,227,60,149,184,202,211,161,127,100,80,232,251,27,112,2,90,159,157,23,168,103,125,56,175,238,201,19,242,147,148,67,203,201,138,171,14,178,201,135,54,80,129,140,148,73,158,206,7,198,80,209,95,236,40,112,91,23,154,244,92,67,10,110,135,252,231,89,26,233,255,99,106,36,253,97,235,23,4,247,158,198,74,4,0,0 }; 38 | #else 39 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,149,142,203,106,196,48,12,69,127,197,245,122,50,165,187,82,44,119,215,237,20,166,253,0,197,81,38,2,191,112,148,132,233,215,55,49,77,97,22,133,206,70,160,199,213,57,230,161,75,78,174,153,6,9,222,154,173,42,143,241,2,20,173,9,36,168,220,128,101,36,129,73,250,230,121,159,165,40,20,5,244,194,157,12,208,209,204,142,154,218,28,56,178,48,250,102,116,232,9,158,180,138,24,8,102,166,37,167,34,214,244,169,4,133,78,56,69,208,175,117,217,115,9,11,22,210,138,98,149,129,48,121,225,140,69,30,183,243,166,195,21,186,146,135,212,193,251,233,252,97,223,126,18,47,166,45,214,112,204,147,168,26,236,217,211,250,221,81,22,56,182,28,15,91,57,94,190,212,13,232,38,50,78,109,96,81,51,250,137,64,127,230,21,70,106,7,104,107,170,194,31,222,158,198,235,40,20,238,49,247,116,174,153,187,221,119,216,127,236,119,200,175,255,55,187,114,189,153,233,1,0,0 }; 40 | #endif 41 | #elif ESPASYNCHTTPUPDATESERVER_MODE == 1 42 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 43 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,125,146,75,110,219,48,16,134,175,194,218,8,144,20,102,44,203,73,155,80,143,162,155,110,83,160,233,170,40,10,138,28,73,211,82,36,65,82,126,196,240,13,186,232,170,235,158,45,39,41,37,219,69,188,233,66,3,136,228,252,223,60,254,252,149,52,34,108,45,180,161,83,101,62,68,162,184,110,10,208,101,222,65,224,68,180,220,121,8,69,31,106,122,119,58,51,58,128,14,197,100,141,50,180,133,132,21,10,160,227,207,12,53,6,228,138,122,193,21,20,139,9,209,188,131,98,133,176,182,198,133,50,247,97,171,160,124,189,171,163,6,173,121,135,106,203,58,163,141,183,92,64,86,25,39,193,81,199,37,246,158,45,18,187,217,183,233,174,227,174,65,77,131,177,44,217,183,139,157,48,202,56,54,5,224,32,120,54,42,121,124,2,118,55,188,175,140,220,238,42,46,126,52,206,244,90,178,105,154,166,89,195,45,91,198,219,236,32,197,146,172,5,108,218,16,17,201,170,221,215,198,117,39,213,55,213,242,246,166,206,94,40,40,212,192,29,109,134,170,98,219,151,233,219,68,66,51,59,242,73,50,155,222,223,84,21,220,147,40,118,113,149,89,46,37,234,102,228,237,81,219,62,236,14,109,177,212,110,136,55,10,37,249,71,49,27,234,91,46,205,154,37,100,104,247,16,134,135,211,36,73,150,167,50,151,183,39,45,198,106,84,64,61,40,16,193,56,90,245,33,24,61,27,239,190,12,155,44,124,95,117,24,190,158,205,224,136,59,182,88,215,245,139,254,47,178,255,237,34,78,252,90,236,36,122,171,248,150,213,10,54,217,16,168,68,23,11,64,163,89,20,237,59,157,125,239,125,192,122,75,143,230,96,34,6,112,25,87,216,104,138,1,58,127,60,218,231,243,131,9,242,97,85,68,40,238,125,33,162,249,22,229,229,243,207,95,207,191,255,124,139,223,21,121,120,124,159,207,227,97,62,108,135,240,17,86,76,222,141,126,170,209,117,107,238,96,114,74,39,160,71,31,23,93,175,2,90,238,194,124,72,163,146,71,191,70,211,182,70,22,31,31,62,61,70,76,90,126,56,102,71,249,180,204,37,174,202,124,156,31,25,21,134,249,70,156,0,27,138,235,10,245,108,8,215,205,19,57,35,159,165,28,70,78,86,92,245,80,76,62,219,72,5,114,162,76,202,124,62,50,198,138,202,191,77,16,113,93,115,3,0,0 }; 44 | #else 45 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,85,142,205,78,196,48,12,132,95,37,228,188,93,196,109,133,226,112,227,10,18,203,3,184,137,187,181,148,63,165,78,43,120,122,218,136,61,236,101,36,123,60,254,198,60,249,236,228,167,208,44,49,88,115,168,10,152,110,64,201,154,72,130,202,205,88,23,18,104,50,13,151,251,46,39,161,36,160,55,246,50,131,167,149,29,13,125,56,113,98,97,12,195,226,48,16,188,104,149,48,18,172,76,91,201,85,172,153,114,141,10,157,112,78,160,223,186,57,113,141,27,86,210,138,82,47,3,177,5,225,130,85,158,143,243,193,227,14,221,201,115,246,240,249,241,117,181,239,255,137,87,51,86,107,56,149,38,170,7,39,14,180,127,119,84,4,206,35,167,211,33,231,219,175,122,0,61,68,150,54,70,22,181,98,104,4,250,187,236,48,82,119,128,182,166,87,176,127,120,226,68,109,41,1,0,0 }; 46 | #endif 47 | #elif ESPASYNCHTTPUPDATESERVER_MODE == 2 48 | #ifdef ESPASYNCHTTPUPDATESERVER_PRETTY 49 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,125,146,203,110,19,49,20,134,95,197,36,170,212,162,56,153,76,90,104,61,23,196,134,109,43,181,172,16,66,30,251,204,140,193,99,91,182,39,201,52,202,27,176,96,197,154,103,235,147,96,79,18,104,89,176,152,35,141,237,243,127,231,242,231,175,184,102,126,48,208,250,78,150,121,140,72,82,213,20,160,202,188,3,79,17,107,169,117,224,139,222,215,248,250,116,166,149,7,229,139,201,70,112,223,22,28,214,130,1,30,127,102,66,9,47,168,196,142,81,9,197,114,130,20,237,160,88,11,216,24,109,125,153,59,63,72,40,95,239,234,160,129,107,218,9,57,144,78,43,237,12,101,144,85,218,114,176,216,82,46,122,71,150,137,217,238,219,116,215,81,219,8,133,189,54,36,217,183,203,29,211,82,91,50,5,160,192,104,54,42,57,241,8,228,58,190,175,52,31,118,21,101,223,26,171,123,197,201,52,77,211,172,161,134,172,194,109,118,144,34,73,214,130,104,90,31,16,201,186,221,215,218,118,39,213,55,213,234,234,178,206,158,41,72,161,128,90,220,196,170,66,219,231,233,219,132,67,51,59,242,81,50,155,222,92,86,21,220,160,32,118,118,145,25,202,185,80,205,200,219,11,101,122,191,59,180,69,82,179,69,78,75,193,209,31,138,222,98,215,82,174,55,36,65,177,221,67,136,15,167,73,146,172,78,101,174,174,78,90,132,212,66,2,118,32,129,121,109,113,213,123,175,213,108,188,251,20,55,89,184,190,234,132,255,252,98,6,71,220,177,197,186,174,159,245,127,150,253,111,23,97,226,115,182,227,194,25,73,7,82,75,216,102,49,96,46,108,40,64,104,69,130,104,223,169,236,107,239,188,168,7,124,52,7,97,33,128,205,168,20,141,194,194,67,231,142,71,251,124,113,48,65,30,87,133,152,164,206,21,44,152,111,89,158,63,125,255,241,244,243,215,151,240,93,160,219,135,247,249,34,28,230,113,59,136,142,176,98,242,110,244,83,156,129,27,92,80,157,156,4,16,168,209,201,69,215,75,47,12,181,126,17,19,49,167,193,177,193,182,173,230,197,221,237,253,67,0,165,229,135,144,127,63,230,7,68,90,230,92,172,203,124,156,33,26,53,162,126,64,50,48,190,152,87,66,205,98,152,55,143,232,31,250,139,164,195,224,209,154,202,30,138,201,71,19,200,128,254,146,38,101,190,24,57,99,93,229,111,61,86,236,22,123,3,0,0 }; 50 | #else 51 | static const uint8_t serverIndex[] PROGMEM = { 31,139,8,0,100,145,225,103,2,255,93,142,203,106,3,49,12,69,127,197,245,58,147,210,93,41,150,187,235,54,133,52,31,224,177,53,25,129,95,216,242,132,228,235,235,49,148,210,110,46,72,226,232,92,245,228,146,229,123,198,149,131,215,106,79,225,77,188,2,70,173,2,178,17,118,53,165,34,67,227,101,122,253,217,165,200,24,25,228,141,28,175,224,112,35,139,211,24,14,20,137,201,248,169,90,227,17,94,164,136,38,32,108,132,183,156,10,107,181,164,18,132,177,76,41,130,124,31,199,133,60,214,123,101,12,82,96,28,117,32,52,207,148,77,225,231,29,152,156,233,218,238,94,147,131,207,211,249,75,127,116,230,60,152,55,53,23,173,40,230,198,98,160,251,187,110,176,152,25,142,51,197,195,30,199,235,67,252,147,253,129,106,155,3,177,216,140,111,8,242,146,187,16,197,175,68,106,53,138,232,111,211,36,186,13,49,1,0,0 }; 52 | #endif 53 | #endif 54 | //generated code end 55 | 56 | static const char successResponse[] PROGMEM = 57 | R"(Update Success! Rebooting...)"; 58 | 59 | Ticker restartTimer; 60 | 61 | ESPAsyncHTTPUpdateServer::ESPAsyncHTTPUpdateServer() 62 | { 63 | _server = NULL; 64 | _username = emptyString; 65 | _password = emptyString; 66 | _authenticated = false; 67 | } 68 | 69 | void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path, const String &username, const String &password) 70 | { 71 | _server = server; 72 | _username = username; 73 | _password = password; 74 | 75 | // handler for the /update form page 76 | _server->on(path.c_str(), HTTP_GET, [&](AsyncWebServerRequest *request) 77 | { 78 | if(_username != emptyString && _password != emptyString) 79 | if( !request->authenticate(_username.c_str(), _password.c_str())) 80 | return request->requestAuthentication(); 81 | #ifdef ESP32 82 | AsyncWebServerResponse* response = request->beginResponse(200, "text/html", serverIndex, sizeof(serverIndex)); 83 | #else 84 | AsyncWebServerResponse* response = request->beginResponse_P(200, "text/html", serverIndex, sizeof(serverIndex)); 85 | #endif 86 | response->addHeader("Content-Encoding", "gzip"); 87 | request->send(response); }); 88 | 89 | // handler for the /update form page - preflight options 90 | _server->on(path.c_str(), HTTP_OPTIONS, [&](AsyncWebServerRequest *request) 91 | { 92 | AsyncWebServerResponse* response = request->beginResponse(200,F("text/html"), String(F("y"))); 93 | response->addHeader("Access-Control-Allow-Headers", "*"); 94 | response->addHeader("Access-Control-Allow-Origin", "*"); 95 | request->send(response); 96 | 97 | _authenticated = (_username == emptyString || _password == emptyString || request -> authenticate(_username.c_str(), _password.c_str())); 98 | if (!_authenticated) 99 | { 100 | Log("Unauthenticated Update\n"); 101 | return; 102 | } }); 103 | 104 | // handler for the /update form POST (once file upload finishes) 105 | _server->on( 106 | path.c_str(), HTTP_POST, [&](AsyncWebServerRequest *request) 107 | { 108 | // if requestAuthentication() is false second handler will run, else it wont. 109 | if (!_authenticated) 110 | return request->requestAuthentication(); 111 | 112 | if (_updateResult != UpdateResult::UPDATE_OK) 113 | { 114 | AsyncWebServerResponse *response = request->beginResponse(200, F("text/html"), Update.hasError() ? String(F("Update error: ")) + _updaterError : "Update aborted by server."); 115 | response->addHeader("Access-Control-Allow-Headers", "*"); 116 | response->addHeader("Access-Control-Allow-Origin", "*"); 117 | response->addHeader("Connection", "close"); 118 | request->send(response); 119 | } 120 | else 121 | { 122 | #ifdef ESP32 123 | request->send(200, PSTR("text/html"), successResponse); 124 | #else 125 | request->send_P(200, PSTR("text/html"), successResponse); 126 | #endif 127 | Log("Rebooting...\n"); 128 | restartTimer.once_ms(1000,[]{ ESP.restart(); }); 129 | } }, 130 | [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) 131 | { 132 | // handler for the file upload, gets the sketch bytes, and writes 133 | // them through the Update object 134 | 135 | _updateType = request->getParam("name")->value() == "filesystem"? 136 | UpdateType::FILE_SYSTEM : 137 | UpdateType::FIRMWARE; 138 | 139 | if (!index) 140 | { 141 | _updaterError.clear(); 142 | 143 | #ifdef ESPASYNCHTTPUPDATESERVER_DEBUG 144 | ESPASYNCHTTPUPDATESERVER_SerialOutput.setDebugOutput(true); 145 | #endif 146 | _authenticated = (_username == emptyString || _password == emptyString || request->authenticate(_username.c_str(), _password.c_str())); 147 | if (!_authenticated) 148 | { 149 | Log("Unauthenticated Update\n"); 150 | return; 151 | } 152 | 153 | if (onUpdateBegin) 154 | { 155 | _updateResult = UpdateResult::UPDATE_OK; 156 | onUpdateBegin(_updateType, _updateResult); 157 | if (_updateResult != UpdateResult::UPDATE_OK) 158 | { 159 | Log("Update aborted by server: %d\n", _updateResult); 160 | if(onUpdateEnd) 161 | onUpdateEnd(_updateType, _updateResult); 162 | return; 163 | } 164 | } 165 | 166 | Log("Update: %s\n", filename.c_str()); 167 | #ifdef ESP8266 168 | Update.runAsync(true); 169 | #endif 170 | if (_updateType == UpdateType::FILE_SYSTEM) 171 | { 172 | Log("updating filesystem\n"); 173 | #ifdef ESP8266 174 | int command = U_FS; 175 | size_t fsSize = ((size_t)FS_end - (size_t)FS_start); 176 | close_all_fs(); 177 | #elif defined(ESP32) 178 | int command = U_SPIFFS; 179 | #ifdef ESPASYNCHTTPUPDATESERVER_LITTLEFS 180 | size_t fsSize = LittleFS.totalBytes(); 181 | #else 182 | size_t fsSize = SPIFFS.totalBytes(); 183 | #endif 184 | #endif 185 | if (!Update.begin(fsSize, command)) 186 | { // start with max available size 187 | #ifdef ESPASYNCHTTPUPDATESERVER_DEBUG 188 | Update.printError(ESPASYNCHTTPUPDATESERVER_SerialOutput); 189 | #endif 190 | } 191 | } 192 | else 193 | { 194 | Log("updating flash\n"); 195 | uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; 196 | if (!Update.begin(maxSketchSpace, U_FLASH)) // start with max available size 197 | _setUpdaterError(); 198 | } 199 | } 200 | 201 | if (_authenticated && len && _updateResult == UpdateResult::UPDATE_OK) 202 | { 203 | Log("."); 204 | if (Update.write(data, len) != len) 205 | _setUpdaterError(); 206 | } 207 | 208 | if (_authenticated && final && _updateResult == UpdateResult::UPDATE_OK) 209 | { 210 | if (Update.end(true)) 211 | { // true to set the size to the current progress 212 | Log("Update Success.\n"); 213 | _updateResult = UpdateResult::UPDATE_OK; 214 | if(onUpdateEnd) 215 | onUpdateEnd(_updateType, _updateResult); 216 | } 217 | else 218 | _setUpdaterError(); 219 | #ifdef ESPASYNCHTTPUPDATESERVER_DEBUG 220 | ESPASYNCHTTPUPDATESERVER_SerialOutput.setDebugOutput(false); 221 | #endif 222 | } 223 | else 224 | return; 225 | }); 226 | } 227 | 228 | void ESPAsyncHTTPUpdateServer::_setUpdaterError() 229 | { 230 | #ifdef ESPASYNCHTTPUPDATESERVER_DEBUG 231 | Update.printError(ESPASYNCHTTPUPDATESERVER_SerialOutput); 232 | #endif 233 | StreamString str; 234 | Update.printError(str); 235 | _updaterError = str.c_str(); 236 | 237 | _updateResult = UpdateResult::UPDATE_ERROR; 238 | if(onUpdateEnd) 239 | onUpdateEnd(_updateType, _updateResult); 240 | } -------------------------------------------------------------------------------- /src/ESPAsyncHTTPUpdateServer.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASYNC_HTTP_UPDATE_SERVER_H 2 | #define __ASYNC_HTTP_UPDATE_SERVER_H 3 | 4 | #include 5 | 6 | enum UpdateType 7 | { 8 | FIRMWARE, 9 | FILE_SYSTEM 10 | }; 11 | 12 | enum UpdateResult 13 | { 14 | UPDATE_OK, 15 | UPDATE_ABORT, 16 | UPDATE_ERROR, 17 | }; 18 | 19 | typedef void (*ESPAsyncHTTPUpdateServer_event)(const UpdateType type, int &result); 20 | 21 | class ESPAsyncHTTPUpdateServer 22 | { 23 | public: 24 | ESPAsyncHTTPUpdateServer_event onUpdateBegin = NULL; 25 | ESPAsyncHTTPUpdateServer_event onUpdateEnd = NULL; 26 | 27 | ESPAsyncHTTPUpdateServer(); 28 | 29 | void setup(AsyncWebServer *server) 30 | { 31 | setup(server, emptyString, emptyString); 32 | } 33 | 34 | void setup(AsyncWebServer *server, const String &path) 35 | { 36 | setup(server, path, emptyString, emptyString); 37 | } 38 | 39 | void setup(AsyncWebServer *server, const String &username, const String &password) 40 | { 41 | setup(server, "/update", username, password); 42 | } 43 | 44 | void setup(AsyncWebServer *server, const String &path, const String &username, const String &password); 45 | 46 | void updateCredentials(const String &username, const String &password) 47 | { 48 | _username = username; 49 | _password = password; 50 | } 51 | 52 | protected: 53 | void _setUpdaterError(); 54 | 55 | private: 56 | AsyncWebServer *_server; 57 | String _username; 58 | String _password; 59 | bool _authenticated; 60 | String _updaterError; 61 | UpdateType _updateType; 62 | int _updateResult; 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /www/minimal-flash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
Firmware:
-------------------------------------------------------------------------------- /www/minimal-fs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
FileSystem:
-------------------------------------------------------------------------------- /www/minimal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
Firmware:
7 |
FileSystem:
-------------------------------------------------------------------------------- /www/stylized-flash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 55 | 56 | 57 |

(⌐■_■) OTA

58 |
59 |

Firmware

60 |
61 |
-------------------------------------------------------------------------------- /www/stylized-fs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 55 | 56 | 57 |

(⌐■_■) OTA

58 |
59 |

FileSystem

60 |
61 |
62 |
-------------------------------------------------------------------------------- /www/stylized.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 55 | 56 | 57 |

(⌐■_■) OTA

58 |
59 |

Firmware

60 |
61 |
62 |
63 |

FileSystem

64 |
65 |
66 |
--------------------------------------------------------------------------------