mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-05 05:38:54 +00:00
Other ETH lib
This commit is contained in:
parent
3ce1df2136
commit
c295017495
70 changed files with 21645 additions and 67 deletions
7
lib/AsyncWebServer_ESP32_W5500/.codespellrc
Normal file
7
lib/AsyncWebServer_ESP32_W5500/.codespellrc
Normal file
|
@ -0,0 +1,7 @@
|
|||
# See: https://github.com/codespell-project/codespell#using-a-config-file
|
||||
[codespell]
|
||||
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
|
||||
ignore-words-list = ,
|
||||
check-filenames =
|
||||
check-hidden =
|
||||
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches
|
32
lib/AsyncWebServer_ESP32_W5500/.gitignore
vendored
Normal file
32
lib/AsyncWebServer_ESP32_W5500/.gitignore
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
79
lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md
Normal file
79
lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md
Normal file
|
@ -0,0 +1,79 @@
|
|||
## Contributing to AsyncWebServer_ESP32_W5500
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
Please report bugs in AsyncWebServer_ESP32_W5500 if you find them.
|
||||
|
||||
However, before reporting a bug please check through the following:
|
||||
|
||||
* [Existing Open Issues](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues) - someone might have already encountered this.
|
||||
|
||||
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues/new).
|
||||
|
||||
### How to submit a bug report
|
||||
|
||||
Please ensure to specify the following:
|
||||
|
||||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
||||
* Board Core Version (e.g. ESP32 core v2.0.6)
|
||||
* Contextual information (e.g. what you were trying to achieve)
|
||||
* Simplest possible steps to reproduce
|
||||
* Anything that might be relevant in your opinion, such as:
|
||||
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
|
||||
* Network configuration
|
||||
|
||||
|
||||
Please be educated, civilized and constructive. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted.
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
Arduino IDE version: 1.8.19
|
||||
ESP32_DEV board
|
||||
ESP32 core v2.0.6
|
||||
OS: Ubuntu 20.04 LTS
|
||||
Linux xy-Inspiron-3593 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
Context:
|
||||
I encountered a crash while using this library
|
||||
Steps to reproduce:
|
||||
1. ...
|
||||
2. ...
|
||||
3. ...
|
||||
4. ...
|
||||
```
|
||||
|
||||
### Additional context
|
||||
|
||||
Add any other context about the problem here.
|
||||
|
||||
---
|
||||
|
||||
### Sending Feature Requests
|
||||
|
||||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
||||
|
||||
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
||||
|
||||
---
|
||||
|
||||
### Sending Pull Requests
|
||||
|
||||
Pull Requests with changes and fixes are also welcome!
|
||||
|
||||
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
|
||||
|
||||
1. Change directory to the library GitHub
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub/
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub$
|
||||
```
|
||||
|
||||
2. Issue astyle command
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub$ bash utils/restyle.sh
|
||||
```
|
||||
|
674
lib/AsyncWebServer_ESP32_W5500/LICENSE
Normal file
674
lib/AsyncWebServer_ESP32_W5500/LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
1952
lib/AsyncWebServer_ESP32_W5500/README.md
Normal file
1952
lib/AsyncWebServer_ESP32_W5500/README.md
Normal file
File diff suppressed because it is too large
Load diff
43
lib/AsyncWebServer_ESP32_W5500/changelog.md
Normal file
43
lib/AsyncWebServer_ESP32_W5500/changelog.md
Normal file
|
@ -0,0 +1,43 @@
|
|||
# AsyncWebServer_ESP32_W5500 Library
|
||||
|
||||
[](https://www.ardu-badge.com/AsyncWebServer_ESP32_W5500)
|
||||
[](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/releases)
|
||||
[](#Contributing)
|
||||
[](http://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues)
|
||||
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Changelog](#changelog)
|
||||
* [Releases v1.6.4](#releases-v164)
|
||||
* [Releases v1.6.3](#releases-v163)
|
||||
* [Releases v1.6.2](#releases-v162)
|
||||
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Changelog
|
||||
|
||||
#### Releases v1.6.4
|
||||
|
||||
1. Remove unused variable to avoid compiler warning and error
|
||||
|
||||
#### Releases v1.6.3
|
||||
|
||||
1. Add `Async_WebSocketsServer`, `Async_HttpBasicAuth` and `MQTT` examples
|
||||
|
||||
#### Releases v1.6.2
|
||||
|
||||
1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using `LwIP W5500 Ethernet`.
|
||||
2. Bump up to `v1.6.2` to sync with [AsyncWebServer_WT32_ETH01 v1.6.2](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01).
|
||||
3. Use `allman astyle`
|
||||
|
||||
|
530
lib/AsyncWebServer_ESP32_W5500/keywords.txt
Normal file
530
lib/AsyncWebServer_ESP32_W5500/keywords.txt
Normal file
|
@ -0,0 +1,530 @@
|
|||
###############################################
|
||||
# Syntax Coloring Map For AsyncWebServer_STM32
|
||||
###############################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
ESP32_ENC KEYWORD1
|
||||
|
||||
AsyncWebServer KEYWORD1
|
||||
AsyncWebServerRequest KEYWORD1
|
||||
AsyncWebServerResponse KEYWORD1
|
||||
AsyncWebHeader KEYWORD1
|
||||
AsyncWebParameter KEYWORD1
|
||||
AsyncWebRewrite KEYWORD1
|
||||
AsyncWebHandler KEYWORD1
|
||||
AsyncStaticWebHandler KEYWORD1
|
||||
AsyncCallbackWebHandler KEYWORD1
|
||||
AsyncResponseStream KEYWORD1
|
||||
|
||||
AsyncWebSocketMessageBuffer
|
||||
AsyncWebSocketMessage
|
||||
AsyncWebSocketBasicMessage
|
||||
AsyncWebSocketMultiMessage
|
||||
AsyncWebSocket KEYWORD1
|
||||
AsyncWebSocketResponse KEYWORD1
|
||||
AsyncWebSocketClient KEYWORD1
|
||||
AsyncWebSocketControl KEYWORD1
|
||||
|
||||
AsyncEventSourceMessage KEYWORD1
|
||||
AsyncEventSourceClient KEYWORD1
|
||||
AsyncEventSource KEYWORD1
|
||||
AsyncEventSourceResponse KEYWORD1
|
||||
ChunkPrint KEYWORD1
|
||||
|
||||
AsyncJsonResponse KEYWORD1
|
||||
PrettyAsyncJsonResponse KEYWORD1
|
||||
AsyncCallbackJsonWebHandler KEYWORD1
|
||||
|
||||
AsyncBasicResponse KEYWORD1
|
||||
AsyncAbstractResponse KEYWORD1
|
||||
AsyncStreamResponse KEYWORD1
|
||||
AsyncCallbackResponse KEYWORD1
|
||||
AsyncChunkedResponse KEYWORD1
|
||||
AsyncResponseStream KEYWORD1
|
||||
|
||||
AsyncWebLock KEYWORD1
|
||||
AsyncWebLockGuard KEYWORD1
|
||||
|
||||
LinkedListNode KEYWORD1
|
||||
LinkedList KEYWORD1
|
||||
StringArray KEYWORD1
|
||||
|
||||
WebRequestMethod KEYWORD1
|
||||
WebRequestMethodComposite KEYWORD1
|
||||
ArDisconnectHandler KEYWORD1
|
||||
|
||||
RequestedConnectionType KEYWORD1
|
||||
AwsResponseFiller KEYWORD1
|
||||
AwsTemplateProcessor KEYWORD1
|
||||
ArRequestFilterFunction KEYWORD1
|
||||
|
||||
WebResponseState KEYWORD1
|
||||
ArRequestHandlerFunction KEYWORD1
|
||||
ArUploadHandlerFunction KEYWORD1
|
||||
ArBodyHandlerFunction KEYWORD1
|
||||
|
||||
ArJsonRequestHandlerFunction KEYWORD1
|
||||
|
||||
AwsFrameInfo KEYWORD1
|
||||
AwsClientStatus KEYWORD1
|
||||
AwsFrameType KEYWORD1
|
||||
AwsMessageStatus KEYWORD1
|
||||
AwsEventType KEYWORD1
|
||||
AwsEventHandler KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
###################
|
||||
# AsyncWebParameter
|
||||
###################
|
||||
|
||||
name KEYWORD2
|
||||
value KEYWORD2
|
||||
size KEYWORD2
|
||||
isPost KEYWORD2
|
||||
isFile KEYWORD2
|
||||
|
||||
###################
|
||||
# AsyncWebHeader
|
||||
###################
|
||||
|
||||
name KEYWORD2
|
||||
value KEYWORD2
|
||||
toString KEYWORD2
|
||||
|
||||
########################
|
||||
# AsyncWebServerRequest
|
||||
########################
|
||||
|
||||
client KEYWORD2
|
||||
version KEYWORD2
|
||||
method KEYWORD2
|
||||
url KEYWORD2
|
||||
host KEYWORD2
|
||||
contentType KEYWORD2
|
||||
contentLength KEYWORD2
|
||||
multipart KEYWORD2
|
||||
methodToString KEYWORD2
|
||||
requestedConnType KEYWORD2
|
||||
isExpectedRequestedConnType KEYWORD2
|
||||
onDisconnect KEYWORD2
|
||||
authenticate KEYWORD2
|
||||
requestAuthentication KEYWORD2
|
||||
setHandler KEYWORD2
|
||||
addInterestingHeader KEYWORD2
|
||||
redirect KEYWORD2
|
||||
send KEYWORD2
|
||||
sendChunked KEYWORD2
|
||||
beginResponse KEYWORD2
|
||||
beginChunkedResponse KEYWORD2
|
||||
beginResponseStream KEYWORD2
|
||||
headers KEYWORD2
|
||||
hasHeader KEYWORD2
|
||||
getHeader KEYWORD2
|
||||
params KEYWORD2
|
||||
hasParam KEYWORD2
|
||||
getParam KEYWORD2
|
||||
arg KEYWORD2
|
||||
argName KEYWORD2
|
||||
hasArg KEYWORD2
|
||||
header KEYWORD2
|
||||
headerName KEYWORD2
|
||||
urlDecode KEYWORD2
|
||||
|
||||
###################
|
||||
# AsyncWebRewrite
|
||||
###################
|
||||
|
||||
filter KEYWORD2
|
||||
from KEYWORD2
|
||||
toUrl KEYWORD2
|
||||
params KEYWORD2
|
||||
match KEYWORD2
|
||||
|
||||
########################
|
||||
# AsyncWebHandler
|
||||
########################
|
||||
|
||||
setFilter KEYWORD2
|
||||
setAuthentication KEYWORD2
|
||||
filter KEYWORD2
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
handleUpload KEYWORD2
|
||||
handleBody KEYWORD2
|
||||
isRequestHandlerTrivial KEYWORD2
|
||||
|
||||
#########################
|
||||
# AsyncWebServerResponse
|
||||
#########################
|
||||
|
||||
setCode KEYWORD2
|
||||
setContentLength KEYWORD2
|
||||
setContentType KEYWORD2
|
||||
addHeader KEYWORD2
|
||||
_assembleHead KEYWORD2
|
||||
_started KEYWORD2
|
||||
_finished KEYWORD2
|
||||
_failed KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
_respond KEYWORD2
|
||||
_ack KEYWORD2
|
||||
|
||||
#########################
|
||||
# AsyncWebServer
|
||||
#########################
|
||||
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
addRewrite KEYWORD2
|
||||
removeRewrite KEYWORD2
|
||||
addHandler KEYWORD2
|
||||
removeHandler KEYWORD2
|
||||
on KEYWORD2
|
||||
onNotFound KEYWORD2
|
||||
onRequestBody KEYWORD2
|
||||
reset KEYWORD2
|
||||
_handleDisconnect KEYWORD2
|
||||
_attachHandler KEYWORD2
|
||||
_rewriteRequest KEYWORD2
|
||||
|
||||
#########################
|
||||
# DefaultHeaders
|
||||
#########################
|
||||
|
||||
addHeader KEYWORD2
|
||||
end KEYWORD2
|
||||
begin KEYWORD2
|
||||
Instance KEYWORD2
|
||||
|
||||
#########################
|
||||
# AsyncEventSourceMessage
|
||||
#########################
|
||||
|
||||
ack KEYWORD2
|
||||
send KEYWORD2
|
||||
finished KEYWORD2
|
||||
sent KEYWORD2
|
||||
|
||||
#########################
|
||||
# AsyncEventSourceClient
|
||||
#########################
|
||||
|
||||
client KEYWORD2
|
||||
close KEYWORD2
|
||||
write KEYWORD2
|
||||
send KEYWORD2
|
||||
connected KEYWORD2
|
||||
lastId KEYWORD2
|
||||
packetsWaiting KEYWORD2
|
||||
_onAck KEYWORD2
|
||||
_onPoll KEYWORD2
|
||||
_onTimeout KEYWORD2
|
||||
_onDisconnect KEYWORD2
|
||||
|
||||
###########################
|
||||
# AsyncEventSource
|
||||
###########################
|
||||
|
||||
url KEYWORD2
|
||||
close KEYWORD2
|
||||
onConnect KEYWORD2
|
||||
send KEYWORD2
|
||||
count KEYWORD2
|
||||
avgPacketsWaiting KEYWORD2
|
||||
_addClient KEYWORD2
|
||||
_handleDisconnect KEYWORD2
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
|
||||
###########################
|
||||
# AsyncEventSourceResponse
|
||||
###########################
|
||||
|
||||
_respond KEYWORD2
|
||||
_ack KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
|
||||
###########################
|
||||
# ChunkPrint
|
||||
###########################
|
||||
|
||||
write KEYWORD2
|
||||
|
||||
###########################
|
||||
# AsyncJsonResponse
|
||||
###########################
|
||||
|
||||
getRoot KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
setLength KEYWORD2
|
||||
getSize KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
###########################
|
||||
# PrettyAsyncJsonResponse
|
||||
###########################
|
||||
|
||||
setLength KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncCallbackJsonWebHandler
|
||||
##############################
|
||||
|
||||
setMethod KEYWORD2
|
||||
setMaxContentLength KEYWORD2
|
||||
|
||||
onRequest KEYWORD2
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
handleUpload KEYWORD2
|
||||
handleBody KEYWORD2
|
||||
isRequestHandlerTrivial KEYWORD2
|
||||
|
||||
###########################
|
||||
# AsyncStaticWebHandler
|
||||
###########################
|
||||
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
setIsDir KEYWORD2
|
||||
setCacheControl KEYWORD2
|
||||
setLastModified KEYWORD2
|
||||
setTemplateProcessor KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncCallbackWebHandler
|
||||
##############################
|
||||
|
||||
setUri KEYWORD2
|
||||
setMethod KEYWORD2
|
||||
onRequest KEYWORD2
|
||||
onUpload KEYWORD2
|
||||
onBody KEYWORD2
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
handleBody KEYWORD2
|
||||
isRequestHandlerTrivial KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncBasicResponse
|
||||
##############################
|
||||
|
||||
_respond KEYWORD2
|
||||
_ack KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncAbstractResponse
|
||||
##############################
|
||||
|
||||
_respond KEYWORD2
|
||||
_ack KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncStreamResponse
|
||||
##############################
|
||||
|
||||
_sourceValid KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncCallbackResponse
|
||||
##############################
|
||||
|
||||
_sourceValid KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncChunkedResponse
|
||||
##############################
|
||||
|
||||
_sourceValid KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncResponseStream
|
||||
##############################
|
||||
|
||||
_sourceValid KEYWORD2
|
||||
_fillBuffer KEYWORD2
|
||||
write KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocketMessage
|
||||
##############################
|
||||
|
||||
ack KEYWORD2
|
||||
send KEYWORD2
|
||||
finished KEYWORD2
|
||||
betweenFrames KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocketBasicMessage
|
||||
##############################
|
||||
|
||||
ack KEYWORD2
|
||||
send KEYWORD2
|
||||
betweenFrames KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocketMultiMessage
|
||||
##############################
|
||||
|
||||
ack KEYWORD2
|
||||
send KEYWORD2
|
||||
betweenFrames KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocketClient
|
||||
##############################
|
||||
|
||||
id KEYWORD2
|
||||
status KEYWORD2
|
||||
client KEYWORD2
|
||||
server KEYWORD2
|
||||
pinfo KEYWORD2
|
||||
remoteIP KEYWORD2
|
||||
remotePort KEYWORD2
|
||||
close KEYWORD2
|
||||
ping KEYWORD2
|
||||
keepAlivePeriod KEYWORD2
|
||||
message KEYWORD2
|
||||
queueIsFull KEYWORD2
|
||||
printf KEYWORD2
|
||||
text KEYWORD2
|
||||
binary KEYWORD2
|
||||
canSend KEYWORD2
|
||||
_onAck KEYWORD2
|
||||
_onError KEYWORD2
|
||||
_onPoll KEYWORD2
|
||||
_onTimeout KEYWORD2
|
||||
_onDisconnect KEYWORD2
|
||||
_onData KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocket
|
||||
##############################
|
||||
|
||||
url KEYWORD2
|
||||
enable KEYWORD2
|
||||
enabled KEYWORD2
|
||||
availableForWriteAll KEYWORD2
|
||||
availableForWrite KEYWORD2
|
||||
count KEYWORD2
|
||||
client KEYWORD2
|
||||
hasClient KEYWORD2
|
||||
close KEYWORD2
|
||||
closeAll KEYWORD2
|
||||
cleanupClients KEYWORD2
|
||||
|
||||
ping KEYWORD2
|
||||
pingAll KEYWORD2
|
||||
text KEYWORD2
|
||||
textAll KEYWORD2
|
||||
binary KEYWORD2
|
||||
binaryAll KEYWORD2
|
||||
message KEYWORD2
|
||||
messageAll KEYWORD2
|
||||
printf KEYWORD2
|
||||
printfAll KEYWORD2
|
||||
onEvent KEYWORD2
|
||||
_getNextId KEYWORD2
|
||||
_addClient KEYWORD2
|
||||
_handleDisconnect KEYWORD2
|
||||
_handleEvent KEYWORD2
|
||||
canHandle KEYWORD2
|
||||
handleRequest KEYWORD2
|
||||
makeBuffer KEYWORD2
|
||||
_cleanBuffers KEYWORD2
|
||||
getClients KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebSocketResponse
|
||||
##############################
|
||||
|
||||
_respond KEYWORD2
|
||||
_ack KEYWORD2
|
||||
_sourceValid KEYWORD2
|
||||
|
||||
##############################
|
||||
# AsyncWebLock
|
||||
##############################
|
||||
|
||||
lock KEYWORD2
|
||||
unlock KEYWORD2
|
||||
|
||||
##############################
|
||||
# LinkedListNode
|
||||
##############################
|
||||
|
||||
value KEYWORD2
|
||||
|
||||
##############################
|
||||
# LinkedList
|
||||
##############################
|
||||
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
add KEYWORD2
|
||||
front KEYWORD2
|
||||
isEmpty KEYWORD2
|
||||
length KEYWORD2
|
||||
count_if KEYWORD2
|
||||
nth KEYWORD2
|
||||
remove KEYWORD2
|
||||
remove_first KEYWORD2
|
||||
free KEYWORD2
|
||||
|
||||
##############################
|
||||
# StringArray
|
||||
##############################
|
||||
|
||||
containsIgnoreCase KEYWORD2
|
||||
|
||||
##############################
|
||||
# General
|
||||
##############################
|
||||
|
||||
memchr KEYWORD2
|
||||
webSocketSendFrameWindow KEYWORD2
|
||||
webSocketSendFrame KEYWORD2
|
||||
generateEventMessage KEYWORD2
|
||||
|
||||
##############################
|
||||
# ESP32_ENC
|
||||
##############################
|
||||
|
||||
begin KEYWORD2
|
||||
config KEYWORD2
|
||||
getHostname KEYWORD2
|
||||
setHostname KEYWORD2
|
||||
fullDuplex KEYWORD2
|
||||
linkUp KEYWORD2
|
||||
linkSpeed KEYWORD2
|
||||
enableIpV6 KEYWORD2
|
||||
localIPv6 KEYWORD2
|
||||
localIP KEYWORD2
|
||||
subnetMask KEYWORD2
|
||||
gatewayIP KEYWORD2
|
||||
dnsIP KEYWORD2
|
||||
broadcastIP KEYWORD2
|
||||
networkID KEYWORD2
|
||||
subnetCIDR KEYWORD2
|
||||
macAddress KEYWORD2
|
||||
macAddress KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
# LITERAL1
|
||||
ENC28J60_Default_Mac LITERAL1
|
38
lib/AsyncWebServer_ESP32_W5500/library.json
Normal file
38
lib/AsyncWebServer_ESP32_W5500/library.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name":"AsyncWebServer_ESP32_W5500",
|
||||
"version": "1.6.4",
|
||||
"description":"Asynchronous HTTP and WebSocket Server Library for (ESP32 + LwIP W5500). Now supporting using CString to save heap to send very large data and with examples to demo how to use beginChunkedResponse() to send large html in chunks",
|
||||
"keywords":"http, async, async-webserver, websocket, webserver, esp32, w5500, lwip",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Hristo Gochkov",
|
||||
"url": "https://github.com/me-no-dev"
|
||||
},
|
||||
{
|
||||
"name": "Khoi Hoang",
|
||||
"url": "https://github.com/khoih-prog",
|
||||
"email": "khoih.prog@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500"
|
||||
},
|
||||
"dependencies":
|
||||
[
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "AsyncTCP",
|
||||
"version": "^1.1.1",
|
||||
"platforms": "espressif32"
|
||||
}
|
||||
],
|
||||
"license": "LGPL-3.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["espressif32"],
|
||||
"examples": "examples/*/*/*.ino",
|
||||
"headers": ["AsyncWebServer_ESP32_W5500.h"]
|
||||
}
|
12
lib/AsyncWebServer_ESP32_W5500/library.properties
Normal file
12
lib/AsyncWebServer_ESP32_W5500/library.properties
Normal file
|
@ -0,0 +1,12 @@
|
|||
name=AsyncWebServer_ESP32_W5500
|
||||
version=1.6.4
|
||||
author=Hristo Gochkov,Khoi Hoang
|
||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||
license=GPLv3
|
||||
sentence=AsyncWebServer for (ESP32 + LwIP W5500)
|
||||
paragraph=This is Asynchronous HTTP and WebSocket Server Library for (ESP32 + LwIP W5500). Now supporting using CString to save heap to send very large data and with examples to demo how to use beginChunkedResponse() to send large html in chunks
|
||||
category=Communication
|
||||
url=https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
architectures=esp32
|
||||
depends=AsyncTCP
|
||||
includes=AsyncWebServer_ESP32_W5500.h
|
566
lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp
Normal file
566
lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp
Normal file
|
@ -0,0 +1,566 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncEventSource.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "AsyncEventSource.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect)
|
||||
{
|
||||
String ev = "";
|
||||
|
||||
if (reconnect)
|
||||
{
|
||||
ev += "retry: ";
|
||||
ev += String(reconnect);
|
||||
ev += "\r\n";
|
||||
}
|
||||
|
||||
if (id)
|
||||
{
|
||||
ev += "id: ";
|
||||
ev += String(id);
|
||||
ev += "\r\n";
|
||||
}
|
||||
|
||||
if (event != NULL)
|
||||
{
|
||||
ev += "event: ";
|
||||
ev += String(event);
|
||||
ev += "\r\n";
|
||||
}
|
||||
|
||||
if (message != NULL)
|
||||
{
|
||||
size_t messageLen = strlen(message);
|
||||
char * lineStart = (char *)message;
|
||||
char * lineEnd;
|
||||
|
||||
do
|
||||
{
|
||||
char * nextN = strchr(lineStart, '\n');
|
||||
char * nextR = strchr(lineStart, '\r');
|
||||
|
||||
if (nextN == NULL && nextR == NULL)
|
||||
{
|
||||
size_t llen = ((char *)message + messageLen) - lineStart;
|
||||
char * ldata = (char *)malloc(llen + 1);
|
||||
|
||||
if (ldata != NULL)
|
||||
{
|
||||
memcpy(ldata, lineStart, llen);
|
||||
ldata[llen] = 0;
|
||||
ev += "data: ";
|
||||
ev += ldata;
|
||||
ev += "\r\n\r\n";
|
||||
free(ldata);
|
||||
}
|
||||
|
||||
lineStart = (char *)message + messageLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
char * nextLine = NULL;
|
||||
|
||||
if (nextN != NULL && nextR != NULL)
|
||||
{
|
||||
if (nextR < nextN)
|
||||
{
|
||||
lineEnd = nextR;
|
||||
|
||||
if (nextN == (nextR + 1))
|
||||
nextLine = nextN + 1;
|
||||
else
|
||||
nextLine = nextR + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lineEnd = nextN;
|
||||
|
||||
if (nextR == (nextN + 1))
|
||||
nextLine = nextR + 1;
|
||||
else
|
||||
nextLine = nextN + 1;
|
||||
}
|
||||
}
|
||||
else if (nextN != NULL)
|
||||
{
|
||||
lineEnd = nextN;
|
||||
nextLine = nextN + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lineEnd = nextR;
|
||||
nextLine = nextR + 1;
|
||||
}
|
||||
|
||||
size_t llen = lineEnd - lineStart;
|
||||
char * ldata = (char *)malloc(llen + 1);
|
||||
|
||||
if (ldata != NULL)
|
||||
{
|
||||
memcpy(ldata, lineStart, llen);
|
||||
ldata[llen] = 0;
|
||||
ev += "data: ";
|
||||
ev += ldata;
|
||||
ev += "\r\n";
|
||||
free(ldata);
|
||||
}
|
||||
|
||||
lineStart = nextLine;
|
||||
|
||||
if (lineStart == ((char *)message + messageLen))
|
||||
ev += "\r\n";
|
||||
}
|
||||
} while (lineStart < ((char *)message + messageLen));
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Message
|
||||
|
||||
AsyncEventSourceMessage::AsyncEventSourceMessage(const char * data, size_t len)
|
||||
: _data(nullptr), _len(len), _sent(0), _acked(0)
|
||||
{
|
||||
_data = (uint8_t*)malloc(_len + 1);
|
||||
|
||||
if (_data == nullptr)
|
||||
{
|
||||
_len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(_data, data, len);
|
||||
_data[_len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncEventSourceMessage::~AsyncEventSourceMessage()
|
||||
{
|
||||
if (_data != NULL)
|
||||
free(_data);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t AsyncEventSourceMessage::ack(size_t len, uint32_t time)
|
||||
{
|
||||
ESP32_W5500_AWS_UNUSED(time);
|
||||
|
||||
// If the whole message is now acked...
|
||||
if (_acked + len > _len)
|
||||
{
|
||||
// Return the number of extra bytes acked (they will be carried on to the next message)
|
||||
const size_t extra = _acked + len - _len;
|
||||
_acked = _len;
|
||||
return extra;
|
||||
}
|
||||
|
||||
// Return that no extra bytes left.
|
||||
_acked += len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t AsyncEventSourceMessage::send(AsyncClient *client)
|
||||
{
|
||||
const size_t len = _len - _sent;
|
||||
|
||||
if (client->space() < len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t sent = client->add((const char *)_data, len);
|
||||
|
||||
if (client->canSend())
|
||||
client->send();
|
||||
|
||||
_sent += sent;
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Client
|
||||
|
||||
AsyncEventSourceClient::AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server)
|
||||
: _messageQueue(LinkedList<AsyncEventSourceMessage * >([](AsyncEventSourceMessage * m)
|
||||
{
|
||||
delete m;
|
||||
}))
|
||||
{
|
||||
_client = request->client();
|
||||
_server = server;
|
||||
_lastId = 0;
|
||||
|
||||
if (request->hasHeader("Last-Event-ID"))
|
||||
_lastId = atoi(request->getHeader("Last-Event-ID")->value().c_str());
|
||||
|
||||
_client->setRxTimeout(0);
|
||||
_client->onError(NULL, NULL);
|
||||
|
||||
_client->onAck([](void *r, AsyncClient * c, size_t len, uint32_t time)
|
||||
{
|
||||
ESP32_W5500_AWS_UNUSED(c);
|
||||
((AsyncEventSourceClient*)(r))->_onAck(len, time);
|
||||
}, this);
|
||||
|
||||
_client->onPoll([](void *r, AsyncClient * c)
|
||||
{
|
||||
ESP32_W5500_AWS_UNUSED(c);
|
||||
((AsyncEventSourceClient*)(r))->_onPoll();
|
||||
}, this);
|
||||
|
||||
_client->onData(NULL, NULL);
|
||||
|
||||
_client->onTimeout([this](void *r, AsyncClient * c __attribute__((unused)), uint32_t time)
|
||||
{
|
||||
((AsyncEventSourceClient*)(r))->_onTimeout(time);
|
||||
}, this);
|
||||
|
||||
_client->onDisconnect([this](void *r, AsyncClient * c)
|
||||
{
|
||||
((AsyncEventSourceClient*)(r))->_onDisconnect();
|
||||
delete c;
|
||||
}, this);
|
||||
|
||||
_server->_addClient(this);
|
||||
|
||||
delete request;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncEventSourceClient::~AsyncEventSourceClient()
|
||||
{
|
||||
_messageQueue.free();
|
||||
close();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage)
|
||||
{
|
||||
if (dataMessage == NULL)
|
||||
return;
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
delete dataMessage;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES)
|
||||
{
|
||||
AWS_LOGERROR(F("[AsyncEventSourceClient::_queueMessage] ERROR: Too many messages queued"));
|
||||
|
||||
delete dataMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
_messageQueue.add(dataMessage);
|
||||
}
|
||||
|
||||
if (_client->canSend())
|
||||
_runQueue();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_onAck(size_t len, uint32_t time)
|
||||
{
|
||||
while (len && !_messageQueue.isEmpty())
|
||||
{
|
||||
len = _messageQueue.front()->ack(len, time);
|
||||
|
||||
if (_messageQueue.front()->finished())
|
||||
_messageQueue.remove(_messageQueue.front());
|
||||
}
|
||||
|
||||
_runQueue();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_onPoll()
|
||||
{
|
||||
if (!_messageQueue.isEmpty())
|
||||
{
|
||||
_runQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_onTimeout(uint32_t time __attribute__((unused)))
|
||||
{
|
||||
_client->close(true);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_onDisconnect()
|
||||
{
|
||||
_client = NULL;
|
||||
_server->_handleDisconnect(this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::close()
|
||||
{
|
||||
if (_client != NULL)
|
||||
_client->close();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::write(const char * message, size_t len)
|
||||
{
|
||||
_queueMessage(new AsyncEventSourceMessage(message, len));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::send(const char *message, const char *event, uint32_t id, uint32_t reconnect)
|
||||
{
|
||||
String ev = generateEventMessage(message, event, id, reconnect);
|
||||
_queueMessage(new AsyncEventSourceMessage(ev.c_str(), ev.length()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceClient::_runQueue()
|
||||
{
|
||||
while (!_messageQueue.isEmpty() && _messageQueue.front()->finished())
|
||||
{
|
||||
_messageQueue.remove(_messageQueue.front());
|
||||
}
|
||||
|
||||
for (auto i = _messageQueue.begin(); i != _messageQueue.end(); ++i)
|
||||
{
|
||||
if (!(*i)->sent())
|
||||
(*i)->send(_client);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Handler
|
||||
|
||||
AsyncEventSource::AsyncEventSource(const String& url)
|
||||
: _url(url)
|
||||
, _clients(LinkedList<AsyncEventSourceClient * >([](AsyncEventSourceClient * c)
|
||||
{
|
||||
delete c;
|
||||
}))
|
||||
, _connectcb(NULL)
|
||||
{}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncEventSource::~AsyncEventSource()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::onConnect(ArEventHandlerFunction cb)
|
||||
{
|
||||
_connectcb = cb;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::_addClient(AsyncEventSourceClient * client)
|
||||
{
|
||||
/*char * temp = (char *)malloc(2054);
|
||||
if(temp != NULL){
|
||||
memset(temp+1,' ',2048);
|
||||
temp[0] = ':';
|
||||
temp[2049] = '\r';
|
||||
temp[2050] = '\n';
|
||||
temp[2051] = '\r';
|
||||
temp[2052] = '\n';
|
||||
temp[2053] = 0;
|
||||
client->write((const char *)temp, 2053);
|
||||
free(temp);
|
||||
}*/
|
||||
|
||||
_clients.add(client);
|
||||
|
||||
if (_connectcb)
|
||||
_connectcb(client);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient * client)
|
||||
{
|
||||
_clients.remove(client);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::close()
|
||||
{
|
||||
for (const auto &c : _clients)
|
||||
{
|
||||
if (c->connected())
|
||||
c->close();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// pmb fix
|
||||
size_t AsyncEventSource::avgPacketsWaiting() const
|
||||
{
|
||||
if (_clients.isEmpty())
|
||||
return 0;
|
||||
|
||||
size_t aql = 0;
|
||||
uint32_t nConnectedClients = 0;
|
||||
|
||||
for (const auto &c : _clients)
|
||||
{
|
||||
if (c->connected())
|
||||
{
|
||||
aql += c->packetsWaiting();
|
||||
++nConnectedClients;
|
||||
}
|
||||
}
|
||||
|
||||
// return aql / nConnectedClients;
|
||||
return ((aql) + (nConnectedClients / 2)) / (nConnectedClients); // round up
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::send(const char *message, const char *event, uint32_t id, uint32_t reconnect)
|
||||
{
|
||||
String ev = generateEventMessage(message, event, id, reconnect);
|
||||
|
||||
for (const auto &c : _clients)
|
||||
{
|
||||
if (c->connected())
|
||||
{
|
||||
c->write(ev.c_str(), ev.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t AsyncEventSource::count() const
|
||||
{
|
||||
return _clients.count_if([](AsyncEventSourceClient * c)
|
||||
{
|
||||
return c->connected();
|
||||
});
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncEventSource::canHandle(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->method() != HTTP_GET || !request->url().equals(_url))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
request->addInterestingHeader("Last-Event-ID");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSource::handleRequest(AsyncWebServerRequest *request)
|
||||
{
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
request->send(new AsyncEventSourceResponse(this));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Response
|
||||
|
||||
AsyncEventSourceResponse::AsyncEventSourceResponse(AsyncEventSource *server)
|
||||
{
|
||||
_server = server;
|
||||
_code = 200;
|
||||
_contentType = "text/event-stream";
|
||||
_sendContentLength = false;
|
||||
addHeader("Cache-Control", "no-cache");
|
||||
addHeader("Connection", "keep-alive");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncEventSourceResponse::_respond(AsyncWebServerRequest *request)
|
||||
{
|
||||
String out = _assembleHead(request->version());
|
||||
request->client()->write(out.c_str(), _headLength);
|
||||
_state = RESPONSE_WAIT_ACK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t AsyncEventSourceResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time __attribute__((unused)))
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
new AsyncEventSourceClient(request, _server);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
208
lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h
Normal file
208
lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h
Normal file
|
@ -0,0 +1,208 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncEventSource.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ASYNCEVENTSOURCE_H_
|
||||
#define ASYNCEVENTSOURCE_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
#define SSE_MAX_QUEUED_MESSAGES 32
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
#include "AsyncWebSynchronization.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define DEFAULT_MAX_SSE_CLIENTS 8
|
||||
|
||||
class AsyncEventSource;
|
||||
class AsyncEventSourceResponse;
|
||||
class AsyncEventSourceClient;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef std::function<void(AsyncEventSourceClient *client)> ArEventHandlerFunction;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncEventSourceMessage
|
||||
{
|
||||
private:
|
||||
uint8_t * _data;
|
||||
size_t _len;
|
||||
size_t _sent;
|
||||
size_t _acked;
|
||||
|
||||
public:
|
||||
AsyncEventSourceMessage(const char * data, size_t len);
|
||||
~AsyncEventSourceMessage();
|
||||
size_t ack(size_t len, uint32_t time __attribute__((unused)));
|
||||
size_t send(AsyncClient *client);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool finished()
|
||||
{
|
||||
return _acked == _len;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool sent()
|
||||
{
|
||||
return _sent == _len;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncEventSourceClient
|
||||
{
|
||||
private:
|
||||
AsyncClient *_client;
|
||||
AsyncEventSource *_server;
|
||||
uint32_t _lastId;
|
||||
LinkedList<AsyncEventSourceMessage *> _messageQueue;
|
||||
void _queueMessage(AsyncEventSourceMessage *dataMessage);
|
||||
void _runQueue();
|
||||
|
||||
public:
|
||||
|
||||
AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server);
|
||||
~AsyncEventSourceClient();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncClient* client()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void close();
|
||||
void write(const char * message, size_t len);
|
||||
void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool connected() const
|
||||
{
|
||||
return (_client != NULL) && _client->connected();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline uint32_t lastId() const
|
||||
{
|
||||
return _lastId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t packetsWaiting() const
|
||||
{
|
||||
return _messageQueue.length();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//system callbacks (do not call)
|
||||
void _onAck(size_t len, uint32_t time);
|
||||
void _onPoll();
|
||||
void _onTimeout(uint32_t time);
|
||||
void _onDisconnect();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncEventSource: public AsyncWebHandler
|
||||
{
|
||||
private:
|
||||
String _url;
|
||||
LinkedList<AsyncEventSourceClient *> _clients;
|
||||
ArEventHandlerFunction _connectcb;
|
||||
|
||||
public:
|
||||
AsyncEventSource(const String& url);
|
||||
~AsyncEventSource();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const char * url() const
|
||||
{
|
||||
return _url.c_str();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void close();
|
||||
void onConnect(ArEventHandlerFunction cb);
|
||||
void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0);
|
||||
size_t count() const; //number clinets connected
|
||||
size_t avgPacketsWaiting() const;
|
||||
|
||||
//system callbacks (do not call)
|
||||
void _addClient(AsyncEventSourceClient * client);
|
||||
void _handleDisconnect(AsyncEventSourceClient * client);
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final;
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncEventSourceResponse: public AsyncWebServerResponse
|
||||
{
|
||||
private:
|
||||
String _content;
|
||||
AsyncEventSource *_server;
|
||||
|
||||
public:
|
||||
AsyncEventSourceResponse(AsyncEventSource *server);
|
||||
void _respond(AsyncWebServerRequest *request);
|
||||
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif /* ASYNCEVENTSOURCE_H_ */
|
||||
|
447
lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h
Normal file
447
lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h
Normal file
|
@ -0,0 +1,447 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncJson.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Async Response to use with ArduinoJson and AsyncWebServer
|
||||
Written by Andrew Melvin (SticilFace) with help from me-no-dev and BBlanchon.
|
||||
|
||||
Example of callback in use
|
||||
|
||||
server.on("/json", HTTP_ANY, [](AsyncWebServerRequest * request) {
|
||||
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse();
|
||||
JsonObject& root = response->getRoot();
|
||||
root["key1"] = "key number one";
|
||||
JsonObject& nested = root.createNestedObject("nested");
|
||||
nested["key1"] = "key number one";
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
--------------------
|
||||
|
||||
Async Request to use with ArduinoJson and AsyncWebServer
|
||||
Written by Arsène von Wyss (avonwyss)
|
||||
|
||||
Example
|
||||
|
||||
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint");
|
||||
handler->onRequest([](AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
JsonObject& jsonObj = json.as<JsonObject>();
|
||||
// ...
|
||||
});
|
||||
server.addHandler(handler);
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ASYNC_JSON_H_
|
||||
#define ASYNC_JSON_H_
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
#include <Print.h>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#if ARDUINOJSON_VERSION_MAJOR == 5
|
||||
#define ARDUINOJSON_5_COMPATIBILITY
|
||||
#else
|
||||
#ifndef DYNAMIC_JSON_DOCUMENT_SIZE
|
||||
#define DYNAMIC_JSON_DOCUMENT_SIZE 1024
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
constexpr const char* JSON_MIMETYPE = "application/json";
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
Json Response
|
||||
* */
|
||||
|
||||
class ChunkPrint : public Print
|
||||
{
|
||||
private:
|
||||
uint8_t* _destination;
|
||||
size_t _to_skip;
|
||||
size_t _to_write;
|
||||
size_t _pos;
|
||||
|
||||
public:
|
||||
ChunkPrint(uint8_t* destination, size_t from, size_t len)
|
||||
: _destination(destination), _to_skip(from), _to_write(len), _pos{0} {}
|
||||
|
||||
virtual ~ChunkPrint() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t write(uint8_t c)
|
||||
{
|
||||
if (_to_skip > 0)
|
||||
{
|
||||
_to_skip--;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (_to_write > 0)
|
||||
{
|
||||
_to_write--;
|
||||
_destination[_pos++] = c;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
return this->Print::write(buffer, size);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncJsonResponse: public AsyncAbstractResponse
|
||||
{
|
||||
protected:
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
DynamicJsonBuffer _jsonBuffer;
|
||||
#else
|
||||
DynamicJsonDocument _jsonBuffer;
|
||||
#endif
|
||||
|
||||
JsonVariant _root;
|
||||
bool _isValid;
|
||||
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
AsyncJsonResponse(bool isArray = false): _isValid {false}
|
||||
{
|
||||
_code = 200;
|
||||
_contentType = JSON_MIMETYPE;
|
||||
|
||||
if (isArray)
|
||||
_root = _jsonBuffer.createArray();
|
||||
else
|
||||
_root = _jsonBuffer.createObject();
|
||||
}
|
||||
#else
|
||||
AsyncJsonResponse(bool isArray = false,
|
||||
size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid {false}
|
||||
{
|
||||
_code = 200;
|
||||
_contentType = JSON_MIMETYPE;
|
||||
|
||||
if (isArray)
|
||||
_root = _jsonBuffer.createNestedArray();
|
||||
else
|
||||
_root = _jsonBuffer.createNestedObject();
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
~AsyncJsonResponse() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline JsonVariant & getRoot()
|
||||
{
|
||||
return _root;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return _isValid;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t setLength()
|
||||
{
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_contentLength = _root.measureLength();
|
||||
#else
|
||||
_contentLength = measureJson(_root);
|
||||
#endif
|
||||
|
||||
if (_contentLength)
|
||||
{
|
||||
_isValid = true;
|
||||
}
|
||||
|
||||
return _contentLength;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t getSize()
|
||||
{
|
||||
return _jsonBuffer.size();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t _fillBuffer(uint8_t *data, size_t len)
|
||||
{
|
||||
ChunkPrint dest(data, _sentLength, len);
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_root.printTo( dest ) ;
|
||||
#else
|
||||
serializeJson(_root, dest);
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class PrettyAsyncJsonResponse: public AsyncJsonResponse
|
||||
{
|
||||
public:
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
PrettyAsyncJsonResponse (bool isArray = false) : AsyncJsonResponse {isArray} {}
|
||||
#else
|
||||
PrettyAsyncJsonResponse (bool isArray = false,
|
||||
size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : AsyncJsonResponse {isArray, maxJsonBufferSize} {}
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t setLength ()
|
||||
{
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_contentLength = _root.measurePrettyLength ();
|
||||
#else
|
||||
_contentLength = measureJsonPretty(_root);
|
||||
#endif
|
||||
|
||||
if (_contentLength)
|
||||
{
|
||||
_isValid = true;
|
||||
}
|
||||
|
||||
return _contentLength;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t _fillBuffer (uint8_t *data, size_t len)
|
||||
{
|
||||
ChunkPrint dest (data, _sentLength, len);
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_root.prettyPrintTo (dest);
|
||||
#else
|
||||
serializeJsonPretty(_root, dest);
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef std::function<void(AsyncWebServerRequest *request, JsonVariant &json)> ArJsonRequestHandlerFunction;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncCallbackJsonWebHandler: public AsyncWebHandler
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
const String _uri;
|
||||
WebRequestMethodComposite _method;
|
||||
ArJsonRequestHandlerFunction _onRequest;
|
||||
size_t _contentLength;
|
||||
|
||||
#ifndef ARDUINOJSON_5_COMPATIBILITY
|
||||
const size_t maxJsonBufferSize;
|
||||
#endif
|
||||
|
||||
size_t _maxContentLength;
|
||||
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest)
|
||||
: _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
||||
#else
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest,
|
||||
size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
|
||||
: _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize),
|
||||
_maxContentLength(16384) {}
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void setMethod(WebRequestMethodComposite method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void setMaxContentLength(int maxContentLength)
|
||||
{
|
||||
_maxContentLength = maxContentLength;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void onRequest(ArJsonRequestHandlerFunction fn)
|
||||
{
|
||||
_onRequest = fn;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final
|
||||
{
|
||||
if (!_onRequest)
|
||||
return false;
|
||||
|
||||
if (!(_method & request->method()))
|
||||
return false;
|
||||
|
||||
if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
|
||||
return false;
|
||||
|
||||
if ( !request->contentType().equalsIgnoreCase(JSON_MIMETYPE) )
|
||||
return false;
|
||||
|
||||
request->addInterestingHeader("ANY");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final
|
||||
{
|
||||
if (_onRequest)
|
||||
{
|
||||
if (request->_tempObject != NULL)
|
||||
{
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonVariant json = jsonBuffer.parse((uint8_t*)(request->_tempObject));
|
||||
|
||||
if (json.success())
|
||||
{
|
||||
#else
|
||||
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize);
|
||||
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject));
|
||||
|
||||
if (!error)
|
||||
{
|
||||
JsonVariant json = jsonBuffer.as<JsonVariant>();
|
||||
#endif
|
||||
|
||||
_onRequest(request, json);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
request->send(_contentLength > _maxContentLength ? 413 : 400);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(500);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
|
||||
size_t len, bool final) override final
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
|
||||
size_t total) override final
|
||||
{
|
||||
if (_onRequest)
|
||||
{
|
||||
_contentLength = total;
|
||||
|
||||
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength)
|
||||
{
|
||||
request->_tempObject = malloc(total);
|
||||
}
|
||||
|
||||
if (request->_tempObject != NULL)
|
||||
{
|
||||
memcpy((uint8_t*)(request->_tempObject) + index, data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool isRequestHandlerTrivial() override final
|
||||
{
|
||||
return _onRequest ? false : true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncWebServer_ESP32_W5500.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500_eth_connected = false;
|
||||
|
||||
void ESP32_W5500_onEvent()
|
||||
{
|
||||
WiFi.onEvent(ESP32_W5500_event);
|
||||
}
|
||||
|
||||
void ESP32_W5500_waitForConnect()
|
||||
{
|
||||
while (!ESP32_W5500_eth_connected)
|
||||
delay(100);
|
||||
}
|
||||
|
||||
bool ESP32_W5500_isConnected()
|
||||
{
|
||||
return ESP32_W5500_eth_connected;
|
||||
}
|
||||
|
||||
void ESP32_W5500_event(WiFiEvent_t event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
//#if USING_CORE_ESP32_CORE_V200_PLUS
|
||||
#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) )
|
||||
// For breaking core v2.0.0
|
||||
// Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h
|
||||
// compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h
|
||||
// You can preserve the old enum order and just adding new items to do no harm
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
AWS_LOG(F("\nETH Started"));
|
||||
//set eth hostname here
|
||||
ETH.setHostname("ESP32_W5500");
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
AWS_LOG(F("ETH Connected"));
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
if (!ESP32_W5500_eth_connected)
|
||||
{
|
||||
AWS_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP());
|
||||
|
||||
if (ETH.fullDuplex())
|
||||
{
|
||||
AWS_LOG0(F("FULL_DUPLEX, "));
|
||||
}
|
||||
else
|
||||
{
|
||||
AWS_LOG0(F("HALF_DUPLEX, "));
|
||||
}
|
||||
|
||||
AWS_LOG1(ETH.linkSpeed(), F("Mbps"));
|
||||
|
||||
ESP32_W5500_eth_connected = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
AWS_LOG("ETH Disconnected");
|
||||
ESP32_W5500_eth_connected = false;
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
AWS_LOG("\nETH Stopped");
|
||||
ESP32_W5500_eth_connected = false;
|
||||
break;
|
||||
|
||||
#else
|
||||
|
||||
// For old core v1.0.6-
|
||||
// Core v2.0.0 defines a stupid enum arduino_event_id_t, breaking any code for ESP32_W5500 written for previous core
|
||||
// Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h
|
||||
// compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h
|
||||
// You can preserve the old enum order and just adding new items to do no harm
|
||||
case SYSTEM_EVENT_ETH_START:
|
||||
AWS_LOG(F("\nETH Started"));
|
||||
//set eth hostname here
|
||||
ETH.setHostname("ESP32_W5500");
|
||||
break;
|
||||
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
AWS_LOG(F("ETH Connected"));
|
||||
break;
|
||||
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
if (!ESP32_W5500_eth_connected)
|
||||
{
|
||||
AWS_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP());
|
||||
|
||||
if (ETH.fullDuplex())
|
||||
{
|
||||
AWS_LOG0(F("FULL_DUPLEX, "));
|
||||
}
|
||||
else
|
||||
{
|
||||
AWS_LOG0(F("HALF_DUPLEX, "));
|
||||
}
|
||||
|
||||
AWS_LOG1(ETH.linkSpeed(), F("Mbps"));
|
||||
|
||||
ESP32_W5500_eth_connected = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
AWS_LOG("ETH Disconnected");
|
||||
ESP32_W5500_eth_connected = false;
|
||||
break;
|
||||
|
||||
case SYSTEM_EVENT_ETH_STOP:
|
||||
AWS_LOG("\nETH Stopped");
|
||||
ESP32_W5500_eth_connected = false;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
938
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h
Normal file
938
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h
Normal file
|
@ -0,0 +1,938 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncWebServer_ESP32_W5500.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef _AsyncWebServer_ESP32_W5500_H_
|
||||
#define _AsyncWebServer_ESP32_W5500_H_
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#if ESP32
|
||||
|
||||
#if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 )
|
||||
#warning Using ESP32 architecture for WebServer_ESP32_W5500
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error This code is designed for ESP32_W5500 to run on ESP32 platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) )
|
||||
#define USING_CORE_ESP32_CORE_V200_PLUS true
|
||||
|
||||
#if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 )
|
||||
#warning Using code for ESP32 core v2.0.0+ in AsyncWebServer_ESP32_W5500.h
|
||||
#endif
|
||||
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION "AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+"
|
||||
#else
|
||||
|
||||
#if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 )
|
||||
#warning Using code for ESP32 core v1.0.6- in AsyncWebServer_ESP32_W5500.h
|
||||
#endif
|
||||
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION "AsyncWebServer_ESP32_W5500 v1.6.4 for core v1.0.6-"
|
||||
#endif
|
||||
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_MAJOR 1
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_MINOR 6
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_PATCH 4
|
||||
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_INT 1006004
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifndef ESP32_W5500_AWS_UNUSED
|
||||
#define ESP32_W5500_AWS_UNUSED(x) (void)(x)
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <functional>
|
||||
#include "FS.h"
|
||||
|
||||
#include "StringArray.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// ESP32_W5500 related code
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
#if 1
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h> // Introduce corresponding libraries
|
||||
|
||||
#include "w5500/esp32_w5500.h"
|
||||
|
||||
#include <hal/spi_types.h>
|
||||
|
||||
#if !defined(ETH_SPI_HOST)
|
||||
#define ETH_SPI_HOST SPI3_HOST
|
||||
#endif
|
||||
|
||||
#if !defined(SPI_CLOCK_MHZ)
|
||||
// Using 25MHz for W5500, 14MHz for W5100
|
||||
#define SPI_CLOCK_MHZ 25
|
||||
#endif
|
||||
|
||||
#if !defined(INT_GPIO)
|
||||
#define INT_GPIO 4
|
||||
#endif
|
||||
|
||||
#if !defined(MISO_GPIO)
|
||||
#define MISO_GPIO 19
|
||||
#endif
|
||||
|
||||
#if !defined(MOSI_GPIO)
|
||||
#define MOSI_GPIO 23
|
||||
#endif
|
||||
|
||||
#if !defined(SCK_GPIO)
|
||||
#define SCK_GPIO 18
|
||||
#endif
|
||||
|
||||
#if !defined(CS_GPIO)
|
||||
#define CS_GPIO 5
|
||||
#endif
|
||||
|
||||
#ifndef SHIELD_TYPE
|
||||
#define SHIELD_TYPE "ESP32_W5500"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
//#include <WebServer_ESP32_W5500.hpp>
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
extern bool ESP32_W5500_eth_connected;
|
||||
|
||||
extern void ESP32_W5500_onEvent();
|
||||
|
||||
extern void ESP32_W5500_waitForConnect();
|
||||
|
||||
extern bool ESP32_W5500_isConnected();
|
||||
|
||||
extern void ESP32_W5500_event(WiFiEvent_t event);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
|
||||
#ifdef ASYNCWEBSERVER_REGEX
|
||||
#define ASYNCWEBSERVER_REGEX_ATTRIBUTE
|
||||
#else
|
||||
#define ASYNCWEBSERVER_REGEX_ATTRIBUTE __attribute__((warning("ASYNCWEBSERVER_REGEX not defined")))
|
||||
#endif
|
||||
|
||||
#define DEBUGF(...) //Serial.printf(__VA_ARGS__)
|
||||
|
||||
class AsyncWebServer;
|
||||
class AsyncWebServerRequest;
|
||||
class AsyncWebServerResponse;
|
||||
class AsyncWebHeader;
|
||||
class AsyncWebParameter;
|
||||
class AsyncWebRewrite;
|
||||
class AsyncWebHandler;
|
||||
class AsyncStaticWebHandler;
|
||||
class AsyncCallbackWebHandler;
|
||||
class AsyncResponseStream;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifndef WEBSERVER_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_GET = 0b00000001,
|
||||
HTTP_POST = 0b00000010,
|
||||
HTTP_DELETE = 0b00000100,
|
||||
HTTP_PUT = 0b00001000,
|
||||
HTTP_PATCH = 0b00010000,
|
||||
HTTP_HEAD = 0b00100000,
|
||||
HTTP_OPTIONS = 0b01000000,
|
||||
HTTP_ANY = 0b01111111,
|
||||
} WebRequestMethod;
|
||||
|
||||
#endif
|
||||
|
||||
//if this value is returned when asked for data, packet will not be sent and you will be asked for data again
|
||||
#define RESPONSE_TRY_AGAIN 0xFFFFFFFF
|
||||
|
||||
typedef uint8_t WebRequestMethodComposite;
|
||||
typedef std::function<void(void)> ArDisconnectHandler;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
PARAMETER :: Chainable object to hold GET/POST and FILE parameters
|
||||
* */
|
||||
|
||||
class AsyncWebParameter
|
||||
{
|
||||
private:
|
||||
String _name;
|
||||
String _value;
|
||||
size_t _size;
|
||||
bool _isForm;
|
||||
bool _isFile;
|
||||
|
||||
public:
|
||||
|
||||
AsyncWebParameter(const String& name, const String& value, bool form = false, bool file = false,
|
||||
size_t size = 0): _name(name), _value(value), _size(size), _isForm(form), _isFile(file) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool isPost() const
|
||||
{
|
||||
return _isForm;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool isFile() const
|
||||
{
|
||||
return _isFile;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
HEADER :: Chainable object to hold the headers
|
||||
* */
|
||||
|
||||
class AsyncWebHeader
|
||||
{
|
||||
private:
|
||||
String _name;
|
||||
String _value;
|
||||
|
||||
public:
|
||||
AsyncWebHeader(const String& name, const String& value): _name(name), _value(value) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebHeader(const String& data): _name(), _value()
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
int index = data.indexOf(':');
|
||||
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
_name = data.substring(0, index);
|
||||
_value = data.substring(index + 2);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
~AsyncWebHeader() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline String toString() const
|
||||
{
|
||||
return String(_name + ": " + _value + "\r\n");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
REQUEST :: Each incoming Client is wrapped inside a Request and both live together until disconnect
|
||||
* */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RCT_NOT_USED = -1,
|
||||
RCT_DEFAULT = 0,
|
||||
RCT_HTTP,
|
||||
RCT_WS,
|
||||
RCT_EVENT,
|
||||
RCT_MAX
|
||||
} RequestedConnectionType;
|
||||
|
||||
typedef std::function<size_t(uint8_t*, size_t, size_t)> AwsResponseFiller;
|
||||
typedef std::function<String(const String&)> AwsTemplateProcessor;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebServerRequest
|
||||
{
|
||||
using File = fs::File;
|
||||
using FS = fs::FS;
|
||||
friend class AsyncWebServer;
|
||||
friend class AsyncCallbackWebHandler;
|
||||
|
||||
private:
|
||||
AsyncClient* _client;
|
||||
AsyncWebServer* _server;
|
||||
AsyncWebHandler* _handler;
|
||||
AsyncWebServerResponse* _response;
|
||||
StringArray _interestingHeaders;
|
||||
ArDisconnectHandler _onDisconnectfn;
|
||||
|
||||
String _temp;
|
||||
uint8_t _parseState;
|
||||
|
||||
uint8_t _version;
|
||||
WebRequestMethodComposite _method;
|
||||
String _url;
|
||||
String _host;
|
||||
String _contentType;
|
||||
String _boundary;
|
||||
String _authorization;
|
||||
RequestedConnectionType _reqconntype;
|
||||
void _removeNotInterestingHeaders();
|
||||
bool _isDigest;
|
||||
bool _isMultipart;
|
||||
bool _isPlainPost;
|
||||
bool _expectingContinue;
|
||||
size_t _contentLength;
|
||||
size_t _parsedLength;
|
||||
|
||||
LinkedList<AsyncWebHeader *> _headers;
|
||||
LinkedList<AsyncWebParameter *> _params;
|
||||
LinkedList<String *> _pathParams;
|
||||
|
||||
uint8_t _multiParseState;
|
||||
uint8_t _boundaryPosition;
|
||||
size_t _itemStartIndex;
|
||||
size_t _itemSize;
|
||||
String _itemName;
|
||||
String _itemFilename;
|
||||
String _itemType;
|
||||
String _itemValue;
|
||||
uint8_t *_itemBuffer;
|
||||
size_t _itemBufferIndex;
|
||||
bool _itemIsFile;
|
||||
|
||||
void _onPoll();
|
||||
void _onAck(size_t len, uint32_t time);
|
||||
void _onError(int8_t error);
|
||||
void _onTimeout(uint32_t time);
|
||||
void _onDisconnect();
|
||||
void _onData(void *buf, size_t len);
|
||||
|
||||
void _addParam(AsyncWebParameter*);
|
||||
void _addPathParam(const char *param);
|
||||
|
||||
bool _parseReqHead();
|
||||
bool _parseReqHeader();
|
||||
void _parseLine();
|
||||
void _parsePlainPostChar(uint8_t data);
|
||||
void _parseMultipartPostByte(uint8_t data, bool last);
|
||||
void _addGetParams(const String& params);
|
||||
|
||||
void _handleUploadStart();
|
||||
void _handleUploadByte(uint8_t data, bool last);
|
||||
void _handleUploadEnd();
|
||||
|
||||
public:
|
||||
File _tempFile;
|
||||
void *_tempObject;
|
||||
|
||||
AsyncWebServerRequest(AsyncWebServer*, AsyncClient*);
|
||||
~AsyncWebServerRequest();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncClient* client()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline uint8_t version() const
|
||||
{
|
||||
return _version;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline WebRequestMethodComposite method() const
|
||||
{
|
||||
return _method;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& url() const
|
||||
{
|
||||
return _url;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& host() const
|
||||
{
|
||||
return _host;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& contentType() const
|
||||
{
|
||||
return _contentType;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t contentLength() const
|
||||
{
|
||||
return _contentLength;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool multipart() const
|
||||
{
|
||||
return _isMultipart;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
const char * methodToString() const;
|
||||
const char * requestedConnTypeToString() const;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline RequestedConnectionType requestedConnType() const
|
||||
{
|
||||
return _reqconntype;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED,
|
||||
RequestedConnectionType erct3 = RCT_NOT_USED);
|
||||
void onDisconnect (ArDisconnectHandler fn);
|
||||
|
||||
//hash is the string representation of:
|
||||
// base64(user:pass) for basic or
|
||||
// user:realm:md5(user:realm:pass) for digest
|
||||
bool authenticate(const char * hash);
|
||||
bool authenticate(const char * username, const char * password, const char * realm = NULL, bool passwordIsHash = false);
|
||||
void requestAuthentication(const char * realm = NULL, bool isDigest = true);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void setHandler(AsyncWebHandler *handler)
|
||||
{
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void addInterestingHeader(const String& name);
|
||||
|
||||
void redirect(const String& url);
|
||||
|
||||
void send(AsyncWebServerResponse *response);
|
||||
void send(int code, const String& contentType = String(), const String& content = String());
|
||||
|
||||
void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD
|
||||
|
||||
void send(FS &fs, const String& path, const String& contentType = String(), bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
void send(File content, const String& path, const String& contentType = String(), bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
|
||||
void send(const String& contentType, size_t len, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
|
||||
void sendChunked(const String& contentType, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
|
||||
void send_P(int code, const String& contentType, const uint8_t * content, size_t len,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback = nullptr);
|
||||
|
||||
AsyncWebServerResponse *beginResponse(int code, const String& contentType = String(), const String& content = String());
|
||||
|
||||
AsyncWebServerResponse *beginResponse(int code, const String& contentType, const char * content = nullptr); // RSMOD
|
||||
|
||||
// KH add
|
||||
AsyncWebServerResponse *beginResponse(int code, const String& contentType, const uint8_t * content, size_t len,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
//////
|
||||
|
||||
|
||||
AsyncWebServerResponse *beginResponse(FS &fs, const String& path, const String& contentType = String(),
|
||||
bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
AsyncWebServerResponse *beginResponse(File content, const String& path, const String& contentType = String(),
|
||||
bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
AsyncWebServerResponse *beginResponse(const String& contentType, size_t len, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
|
||||
AsyncWebServerResponse *beginChunkedResponse(const String& contentType, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
AsyncResponseStream *beginResponseStream(const String& contentType, size_t bufferSize = 1460);
|
||||
|
||||
AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, const uint8_t * content, size_t len,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, PGM_P content,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
|
||||
size_t headers() const; // get header count
|
||||
bool hasHeader(const String& name) const; // check if header exists
|
||||
bool hasHeader(const __FlashStringHelper * data) const; // check if header exists
|
||||
|
||||
AsyncWebHeader* getHeader(const String& name) const;
|
||||
AsyncWebHeader* getHeader(const __FlashStringHelper * data) const;
|
||||
AsyncWebHeader* getHeader(size_t num) const;
|
||||
|
||||
size_t params() const; // get arguments count
|
||||
bool hasParam(const String& name, bool post = false, bool file = false) const;
|
||||
bool hasParam(const __FlashStringHelper * data, bool post = false, bool file = false) const;
|
||||
|
||||
AsyncWebParameter* getParam(const String& name, bool post = false, bool file = false) const;
|
||||
AsyncWebParameter* getParam(const __FlashStringHelper * data, bool post, bool file) const;
|
||||
AsyncWebParameter* getParam(size_t num) const;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t args() const
|
||||
{
|
||||
return params(); // get arguments count
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
const String& arg(const String& name) const; // get request argument value by name
|
||||
const String& arg(const __FlashStringHelper * data) const; // get request argument value by F(name)
|
||||
const String& arg(size_t i) const; // get request argument value by number
|
||||
const String& argName(size_t i) const; // get request argument name by number
|
||||
bool hasArg(const char* name) const; // check if argument exists
|
||||
bool hasArg(const __FlashStringHelper * data) const; // check if F(argument) exists
|
||||
|
||||
const String& ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(size_t i) const;
|
||||
|
||||
const String& header(const char* name) const;// get request header value by name
|
||||
const String& header(const __FlashStringHelper * data) const;// get request header value by F(name)
|
||||
const String& header(size_t i) const; // get request header value by number
|
||||
const String& headerName(size_t i) const; // get request header name by number
|
||||
String urlDecode(const String& text) const;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
FILTER :: Callback to filter AsyncWebRewrite and AsyncWebHandler (done by the Server)
|
||||
* */
|
||||
|
||||
typedef std::function<bool(AsyncWebServerRequest *request)> ArRequestFilterFunction;
|
||||
|
||||
bool ON_STA_FILTER(AsyncWebServerRequest *request);
|
||||
|
||||
bool ON_AP_FILTER(AsyncWebServerRequest *request);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
REWRITE :: One instance can be handle any Request (done by the Server)
|
||||
* */
|
||||
|
||||
class AsyncWebRewrite
|
||||
{
|
||||
protected:
|
||||
String _from;
|
||||
String _toUrl;
|
||||
String _params;
|
||||
ArRequestFilterFunction _filter;
|
||||
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebRewrite(const char* from, const char* to): _from(from), _toUrl(to), _params(String()), _filter(NULL)
|
||||
{
|
||||
int index = _toUrl.indexOf('?');
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
_params = _toUrl.substring(index + 1);
|
||||
_toUrl = _toUrl.substring(0, index);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual ~AsyncWebRewrite() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncWebRewrite& setFilter(ArRequestFilterFunction fn)
|
||||
{
|
||||
_filter = fn;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool filter(AsyncWebServerRequest *request) const
|
||||
{
|
||||
return _filter == NULL || _filter(request);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& from() const
|
||||
{
|
||||
return _from;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& toUrl() const
|
||||
{
|
||||
return _toUrl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const String& params() const
|
||||
{
|
||||
return _params;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool match(AsyncWebServerRequest *request)
|
||||
{
|
||||
return from() == request->url() && filter(request);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
HANDLER :: One instance can be attached to any Request (done by the Server)
|
||||
* */
|
||||
|
||||
class AsyncWebHandler
|
||||
{
|
||||
protected:
|
||||
ArRequestFilterFunction _filter;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
public:
|
||||
AsyncWebHandler(): _username(""), _password("") {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncWebHandler& setFilter(ArRequestFilterFunction fn)
|
||||
{
|
||||
_filter = fn;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncWebHandler& setAuthentication(const char *username, const char *password)
|
||||
{
|
||||
_username = String(username);
|
||||
_password = String(password);
|
||||
return *this;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool filter(AsyncWebServerRequest *request)
|
||||
{
|
||||
return _filter == NULL || _filter(request);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual ~AsyncWebHandler() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool canHandle(AsyncWebServerRequest *request __attribute__((unused)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleRequest(AsyncWebServerRequest *request __attribute__((unused))) {}
|
||||
virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)),
|
||||
const String& filename __attribute__((unused)),
|
||||
size_t index __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)),
|
||||
bool final __attribute__((unused))) {}
|
||||
virtual void handleBody(AsyncWebServerRequest *request __attribute__((unused)), uint8_t *data __attribute__((unused)),
|
||||
size_t len __attribute__((unused)), size_t index __attribute__((unused)), size_t total __attribute__((unused))) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool isRequestHandlerTrivial()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
RESPONSE :: One instance is created for each Request (attached by the Handler)
|
||||
* */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RESPONSE_SETUP,
|
||||
RESPONSE_HEADERS,
|
||||
RESPONSE_CONTENT,
|
||||
RESPONSE_WAIT_ACK,
|
||||
RESPONSE_END,
|
||||
RESPONSE_FAILED
|
||||
} WebResponseState;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebServerResponse
|
||||
{
|
||||
protected:
|
||||
int _code;
|
||||
LinkedList<AsyncWebHeader *> _headers;
|
||||
String _contentType;
|
||||
size_t _contentLength;
|
||||
bool _sendContentLength;
|
||||
bool _chunked;
|
||||
size_t _headLength;
|
||||
size_t _sentLength;
|
||||
size_t _ackedLength;
|
||||
size_t _writtenLength;
|
||||
WebResponseState _state;
|
||||
const char* _responseCodeToString(int code);
|
||||
|
||||
public:
|
||||
AsyncWebServerResponse();
|
||||
virtual ~AsyncWebServerResponse();
|
||||
virtual void setCode(int code);
|
||||
virtual void setContentLength(size_t len);
|
||||
virtual void setContentType(const String& type);
|
||||
virtual void addHeader(const String& name, const String& value);
|
||||
virtual String _assembleHead(uint8_t version);
|
||||
virtual bool _started() const;
|
||||
virtual bool _finished() const;
|
||||
virtual bool _failed() const;
|
||||
virtual bool _sourceValid() const;
|
||||
virtual void _respond(AsyncWebServerRequest *request);
|
||||
virtual size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
SERVER :: One instance
|
||||
* */
|
||||
|
||||
typedef std::function<void(AsyncWebServerRequest *request)> ArRequestHandlerFunction;
|
||||
typedef std::function<void(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final)>
|
||||
ArUploadHandlerFunction;
|
||||
typedef std::function<void(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)>
|
||||
ArBodyHandlerFunction;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebServer
|
||||
{
|
||||
protected:
|
||||
AsyncServer _server;
|
||||
LinkedList<AsyncWebRewrite*> _rewrites;
|
||||
LinkedList<AsyncWebHandler*> _handlers;
|
||||
AsyncCallbackWebHandler* _catchAllHandler;
|
||||
|
||||
public:
|
||||
AsyncWebServer(uint16_t port);
|
||||
~AsyncWebServer();
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
|
||||
#if ASYNC_TCP_SSL_ENABLED
|
||||
void onSslFileRequest(AcSSlFileHandler cb, void* arg);
|
||||
void beginSecure(const char *cert, const char *private_key_file, const char *password);
|
||||
#endif
|
||||
|
||||
AsyncWebRewrite& addRewrite(AsyncWebRewrite* rewrite);
|
||||
bool removeRewrite(AsyncWebRewrite* rewrite);
|
||||
AsyncWebRewrite& rewrite(const char* from, const char* to);
|
||||
|
||||
AsyncWebHandler& addHandler(AsyncWebHandler* handler);
|
||||
bool removeHandler(AsyncWebHandler* handler);
|
||||
|
||||
AsyncCallbackWebHandler& on(const char* uri, ArRequestHandlerFunction onRequest);
|
||||
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest);
|
||||
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest,
|
||||
ArUploadHandlerFunction onUpload);
|
||||
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest,
|
||||
ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody);
|
||||
|
||||
AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL);
|
||||
|
||||
void onNotFound(ArRequestHandlerFunction fn); //called when handler is not assigned
|
||||
void onFileUpload(ArUploadHandlerFunction fn); //handle file uploads
|
||||
void onRequestBody(ArBodyHandlerFunction
|
||||
fn); //handle posts with plain body content (JSON often transmitted this way as a request)
|
||||
|
||||
void reset(); //remove all writers and handlers, with onNotFound/onFileUpload/onRequestBody
|
||||
|
||||
void _handleDisconnect(AsyncWebServerRequest *request);
|
||||
void _attachHandler(AsyncWebServerRequest *request);
|
||||
void _rewriteRequest(AsyncWebServerRequest *request);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class DefaultHeaders
|
||||
{
|
||||
using headers_t = LinkedList<AsyncWebHeader *>;
|
||||
headers_t _headers;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
DefaultHeaders()
|
||||
: _headers(headers_t([](AsyncWebHeader * h)
|
||||
{
|
||||
delete h;
|
||||
}))
|
||||
{}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
using ConstIterator = headers_t::ConstIterator;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void addHeader(const String& name, const String& value)
|
||||
{
|
||||
_headers.add(new AsyncWebHeader(name, value));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline ConstIterator begin() const
|
||||
{
|
||||
return _headers.begin();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline ConstIterator end() const
|
||||
{
|
||||
return _headers.end();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
DefaultHeaders(DefaultHeaders const &) = delete;
|
||||
DefaultHeaders &operator=(DefaultHeaders const &) = delete;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static DefaultHeaders &Instance()
|
||||
{
|
||||
static DefaultHeaders instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#include "WebResponseImpl.h"
|
||||
#include "WebHandlerImpl.h"
|
||||
#include "AsyncWebSocket.h"
|
||||
#include "AsyncEventSource.h"
|
||||
|
||||
#endif /* _AsyncWebServer_ESP32_W5500_H_ */
|
|
@ -0,0 +1,115 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncWebServer_ESP32_W5500_Debug.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H
|
||||
#define ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef DEBUG_ASYNC_WEBSERVER_PORT
|
||||
#define AWS_DEBUG_OUTPUT DEBUG_ASYNC_WEBSERVER_PORT
|
||||
#else
|
||||
#define AWS_DEBUG_OUTPUT Serial
|
||||
#endif
|
||||
|
||||
// Change _ASYNC_WEBSERVER_LOGLEVEL_ to set tracing and logging verbosity
|
||||
// 0: DISABLED: no logging
|
||||
// 1: ERROR: errors
|
||||
// 2: WARN: errors and warnings
|
||||
// 3: INFO: errors, warnings and informational (default)
|
||||
// 4: DEBUG: errors, warnings, informational and debug
|
||||
|
||||
#ifndef _ASYNC_WEBSERVER_LOGLEVEL_
|
||||
#define _ASYNC_WEBSERVER_LOGLEVEL_ 1
|
||||
#endif
|
||||
|
||||
const char AWS_MARK[] = "[AWS] ";
|
||||
const char AWS_SPACE[] = " ";
|
||||
const char AWS_LINE[] = "========================================\n";
|
||||
|
||||
#define AWS_PRINT_MARK AWS_PRINT(AWS_MARK)
|
||||
#define AWS_PRINT_SP AWS_PRINT(AWS_SPACE)
|
||||
#define AWS_PRINT_LINE AWS_PRINT(AWS_LINE)
|
||||
|
||||
#define AWS_PRINT AWS_DEBUG_OUTPUT.print
|
||||
#define AWS_PRINTLN AWS_DEBUG_OUTPUT.println
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define AWS_LOG(x) { AWS_PRINTLN(x); }
|
||||
#define AWS_LOG0(x) { AWS_PRINT(x); }
|
||||
#define AWS_LOG1(x,y) { AWS_PRINT(x); AWS_PRINTLN(y); }
|
||||
#define AWS_LOG2(x,y,z) { AWS_PRINT(x); AWS_PRINT(y); AWS_PRINTLN(z); }
|
||||
#define AWS_LOG3(x,y,z,w) { AWS_PRINT(x); AWS_PRINT(y); AWS_PRINT(z); AWS_PRINTLN(w); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define AWS_LOGERROR(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINTLN(x); }
|
||||
#define AWS_LOGERROR_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; }
|
||||
#define AWS_LOGERROR0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT(x); }
|
||||
#define AWS_LOGERROR1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); }
|
||||
#define AWS_LOGERROR2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); }
|
||||
#define AWS_LOGERROR3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define AWS_LOGWARN(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINTLN(x); }
|
||||
#define AWS_LOGWARN_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; }
|
||||
#define AWS_LOGWARN0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT(x); }
|
||||
#define AWS_LOGWARN1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); }
|
||||
#define AWS_LOGWARN2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); }
|
||||
#define AWS_LOGWARN3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define AWS_LOGINFO(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINTLN(x); }
|
||||
#define AWS_LOGINFO_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; }
|
||||
#define AWS_LOGINFO0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT(x); }
|
||||
#define AWS_LOGINFO1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); }
|
||||
#define AWS_LOGINFO2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); }
|
||||
#define AWS_LOGINFO3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define AWS_LOGDEBUG(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINTLN(x); }
|
||||
#define AWS_LOGDEBUG_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; }
|
||||
#define AWS_LOGDEBUG0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT(x); }
|
||||
#define AWS_LOGDEBUG1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); }
|
||||
#define AWS_LOGDEBUG2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); }
|
||||
#define AWS_LOGDEBUG3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); }
|
||||
|
||||
#endif // ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H
|
||||
|
||||
|
1929
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp
Normal file
1929
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp
Normal file
File diff suppressed because it is too large
Load diff
611
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h
Normal file
611
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h
Normal file
|
@ -0,0 +1,611 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncWebSocket.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ASYNCWEBSOCKET_H_
|
||||
#define ASYNCWEBSOCKET_H_
|
||||
|
||||
#include "mbedtls/version.h"
|
||||
|
||||
#if (MBEDTLS_VERSION_NUMBER >= 0x02070000)
|
||||
//#error Must use ESP32 core v1.0.6-, with MBEDTLS_VERSION_NUMBER < v2.7.0
|
||||
#endif
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
#define WS_MAX_QUEUED_MESSAGES 32
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
#include "AsyncWebSynchronization.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define DEFAULT_MAX_WS_CLIENTS 8
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocket;
|
||||
class AsyncWebSocketResponse;
|
||||
class AsyncWebSocketClient;
|
||||
class AsyncWebSocketControl;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/** Message type as defined by enum AwsFrameType.
|
||||
Note: Applications will only see WS_TEXT and WS_BINARY.
|
||||
All other types are handled by the library. */
|
||||
uint8_t message_opcode;
|
||||
/** Frame number of a fragmented message. */
|
||||
uint32_t num;
|
||||
/** Is this the last frame in a fragmented message ?*/
|
||||
uint8_t final;
|
||||
/** Is this frame masked? */
|
||||
uint8_t masked;
|
||||
/** Message type as defined by enum AwsFrameType.
|
||||
This value is the same as message_opcode for non-fragmented
|
||||
messages, but may also be WS_CONTINUATION in a fragmented message. */
|
||||
uint8_t opcode;
|
||||
/** Length of the current frame.
|
||||
This equals the total length of the message if num == 0 && final == true */
|
||||
uint64_t len;
|
||||
/** Mask key */
|
||||
uint8_t mask[4];
|
||||
/** Offset of the data inside the current frame. */
|
||||
uint64_t index;
|
||||
} AwsFrameInfo;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WS_DISCONNECTED,
|
||||
WS_CONNECTED,
|
||||
WS_DISCONNECTING
|
||||
} AwsClientStatus;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WS_CONTINUATION,
|
||||
WS_TEXT,
|
||||
WS_BINARY,
|
||||
WS_DISCONNECT = 0x08,
|
||||
WS_PING,
|
||||
WS_PONG
|
||||
} AwsFrameType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WS_MSG_SENDING,
|
||||
WS_MSG_SENT,
|
||||
WS_MSG_ERROR
|
||||
} AwsMessageStatus;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WS_EVT_CONNECT,
|
||||
WS_EVT_DISCONNECT,
|
||||
WS_EVT_PONG,
|
||||
WS_EVT_ERROR,
|
||||
WS_EVT_DATA
|
||||
} AwsEventType;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocketMessageBuffer
|
||||
{
|
||||
private:
|
||||
uint8_t * _data;
|
||||
size_t _len;
|
||||
bool _lock;
|
||||
uint32_t _count;
|
||||
|
||||
public:
|
||||
AsyncWebSocketMessageBuffer();
|
||||
AsyncWebSocketMessageBuffer(size_t size);
|
||||
AsyncWebSocketMessageBuffer(uint8_t * data, size_t size);
|
||||
AsyncWebSocketMessageBuffer(const AsyncWebSocketMessageBuffer &);
|
||||
AsyncWebSocketMessageBuffer(AsyncWebSocketMessageBuffer &&);
|
||||
~AsyncWebSocketMessageBuffer();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void operator ++(int i)
|
||||
{
|
||||
ESP32_W5500_AWS_UNUSED(i);
|
||||
_count++;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void operator --(int i)
|
||||
{
|
||||
ESP32_W5500_AWS_UNUSED(i);
|
||||
|
||||
if (_count > 0)
|
||||
{
|
||||
_count--;
|
||||
} ;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool reserve(size_t size);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void lock()
|
||||
{
|
||||
_lock = true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void unlock()
|
||||
{
|
||||
_lock = false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline uint8_t * get()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline size_t length()
|
||||
{
|
||||
return _len;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline uint32_t count()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool canDelete()
|
||||
{
|
||||
return (!_count && !_lock);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
friend AsyncWebSocket;
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocketMessage
|
||||
{
|
||||
protected:
|
||||
uint8_t _opcode;
|
||||
bool _mask;
|
||||
AwsMessageStatus _status;
|
||||
|
||||
public:
|
||||
AsyncWebSocketMessage(): _opcode(WS_TEXT), _mask(false), _status(WS_MSG_ERROR) {}
|
||||
virtual ~AsyncWebSocketMessage() {}
|
||||
virtual void ack(size_t len __attribute__((unused)), uint32_t time __attribute__((unused))) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t send(AsyncClient *client __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool finished()
|
||||
{
|
||||
return _status != WS_MSG_SENDING;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool betweenFrames() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocketBasicMessage: public AsyncWebSocketMessage
|
||||
{
|
||||
private:
|
||||
size_t _len;
|
||||
size_t _sent;
|
||||
size_t _ack;
|
||||
size_t _acked;
|
||||
uint8_t * _data;
|
||||
|
||||
public:
|
||||
AsyncWebSocketBasicMessage(const char * data, size_t len, uint8_t opcode = WS_TEXT, bool mask = false);
|
||||
AsyncWebSocketBasicMessage(uint8_t opcode = WS_TEXT, bool mask = false);
|
||||
virtual ~AsyncWebSocketBasicMessage() override;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool betweenFrames() const override
|
||||
{
|
||||
return _acked == _ack;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void ack(size_t len, uint32_t time) override ;
|
||||
virtual size_t send(AsyncClient *client) override ;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocketMultiMessage: public AsyncWebSocketMessage
|
||||
{
|
||||
private:
|
||||
uint8_t * _data;
|
||||
size_t _len;
|
||||
size_t _sent;
|
||||
size_t _ack;
|
||||
size_t _acked;
|
||||
AsyncWebSocketMessageBuffer * _WSbuffer;
|
||||
|
||||
public:
|
||||
AsyncWebSocketMultiMessage(AsyncWebSocketMessageBuffer * buffer, uint8_t opcode = WS_TEXT, bool mask = false);
|
||||
virtual ~AsyncWebSocketMultiMessage() override;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool betweenFrames() const override
|
||||
{
|
||||
return _acked == _ack;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void ack(size_t len, uint32_t time) override ;
|
||||
virtual size_t send(AsyncClient *client) override ;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebSocketClient
|
||||
{
|
||||
private:
|
||||
AsyncClient *_client;
|
||||
AsyncWebSocket *_server;
|
||||
uint32_t _clientId;
|
||||
AwsClientStatus _status;
|
||||
|
||||
LinkedList<AsyncWebSocketControl *> _controlQueue;
|
||||
LinkedList<AsyncWebSocketMessage *> _messageQueue;
|
||||
|
||||
uint8_t _pstate;
|
||||
AwsFrameInfo _pinfo;
|
||||
|
||||
uint32_t _lastMessageTime;
|
||||
uint32_t _keepAlivePeriod;
|
||||
|
||||
void _queueMessage(AsyncWebSocketMessage *dataMessage);
|
||||
void _queueControl(AsyncWebSocketControl *controlMessage);
|
||||
void _runQueue();
|
||||
|
||||
public:
|
||||
void *_tempObject;
|
||||
|
||||
AsyncWebSocketClient(AsyncWebServerRequest *request, AsyncWebSocket *server);
|
||||
~AsyncWebSocketClient();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//client id increments for the given server
|
||||
inline uint32_t id()
|
||||
{
|
||||
return _clientId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AwsClientStatus status()
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncClient* client()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AsyncWebSocket *server()
|
||||
{
|
||||
return _server;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline AwsFrameInfo const &pinfo() const
|
||||
{
|
||||
return _pinfo;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
IPAddress remoteIP();
|
||||
uint16_t remotePort();
|
||||
|
||||
//control frames
|
||||
void close(uint16_t code = 0, const char * message = NULL);
|
||||
void ping(uint8_t *data = NULL, size_t len = 0);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//set auto-ping period in seconds. disabled if zero (default)
|
||||
inline void keepAlivePeriod(uint16_t seconds)
|
||||
{
|
||||
_keepAlivePeriod = seconds * 1000;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline uint16_t keepAlivePeriod()
|
||||
{
|
||||
return (uint16_t)(_keepAlivePeriod / 1000);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//data packets
|
||||
inline void message(AsyncWebSocketMessage *message)
|
||||
{
|
||||
_queueMessage(message);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool queueIsFull();
|
||||
|
||||
size_t printf(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
void text(const char * message, size_t len);
|
||||
void text(const char * message);
|
||||
void text(uint8_t * message, size_t len);
|
||||
void text(char * message);
|
||||
void text(const String &message);
|
||||
void text(const __FlashStringHelper *data);
|
||||
void text(AsyncWebSocketMessageBuffer *buffer);
|
||||
|
||||
void binary(const char * message, size_t len);
|
||||
void binary(const char * message);
|
||||
void binary(uint8_t * message, size_t len);
|
||||
void binary(char * message);
|
||||
void binary(const String &message);
|
||||
void binary(const __FlashStringHelper *data, size_t len);
|
||||
void binary(AsyncWebSocketMessageBuffer *buffer);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool canSend()
|
||||
{
|
||||
return _messageQueue.length() < WS_MAX_QUEUED_MESSAGES;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//system callbacks (do not call)
|
||||
void _onAck(size_t len, uint32_t time);
|
||||
void _onError(int8_t);
|
||||
void _onPoll();
|
||||
void _onTimeout(uint32_t time);
|
||||
void _onDisconnect();
|
||||
void _onData(void *pbuf, size_t plen);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef std::function<void(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)>
|
||||
AwsEventHandler;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//WebServer Handler implementation that plays the role of a socket server
|
||||
class AsyncWebSocket: public AsyncWebHandler
|
||||
{
|
||||
public:
|
||||
typedef LinkedList<AsyncWebSocketClient *> AsyncWebSocketClientLinkedList;
|
||||
|
||||
private:
|
||||
String _url;
|
||||
AsyncWebSocketClientLinkedList _clients;
|
||||
uint32_t _cNextId;
|
||||
AwsEventHandler _eventHandler;
|
||||
bool _enabled;
|
||||
AsyncWebLock _lock;
|
||||
|
||||
public:
|
||||
AsyncWebSocket(const String& url);
|
||||
~AsyncWebSocket();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const char * url() const
|
||||
{
|
||||
return _url.c_str();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void enable(bool e)
|
||||
{
|
||||
_enabled = e;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool enabled() const
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool availableForWriteAll();
|
||||
bool availableForWrite(uint32_t id);
|
||||
|
||||
size_t count() const;
|
||||
AsyncWebSocketClient * client(uint32_t id);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool hasClient(uint32_t id)
|
||||
{
|
||||
return client(id) != NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void close(uint32_t id, uint16_t code = 0, const char * message = NULL);
|
||||
void closeAll(uint16_t code = 0, const char * message = NULL);
|
||||
void cleanupClients(uint16_t maxClients = DEFAULT_MAX_WS_CLIENTS);
|
||||
|
||||
void ping(uint32_t id, uint8_t *data = NULL, size_t len = 0);
|
||||
void pingAll(uint8_t *data = NULL, size_t len = 0); // done
|
||||
|
||||
void text(uint32_t id, const char * message, size_t len);
|
||||
void text(uint32_t id, const char * message);
|
||||
void text(uint32_t id, uint8_t * message, size_t len);
|
||||
void text(uint32_t id, char * message);
|
||||
void text(uint32_t id, const String &message);
|
||||
void text(uint32_t id, const __FlashStringHelper *message);
|
||||
|
||||
void textAll(const char * message, size_t len);
|
||||
void textAll(const char * message);
|
||||
void textAll(uint8_t * message, size_t len);
|
||||
void textAll(char * message);
|
||||
void textAll(const String &message);
|
||||
void textAll(const __FlashStringHelper *message); // need to convert
|
||||
void textAll(AsyncWebSocketMessageBuffer * buffer);
|
||||
|
||||
void binary(uint32_t id, const char * message, size_t len);
|
||||
void binary(uint32_t id, const char * message);
|
||||
void binary(uint32_t id, uint8_t * message, size_t len);
|
||||
void binary(uint32_t id, char * message);
|
||||
void binary(uint32_t id, const String &message);
|
||||
void binary(uint32_t id, const __FlashStringHelper *message, size_t len);
|
||||
|
||||
void binaryAll(const char * message, size_t len);
|
||||
void binaryAll(const char * message);
|
||||
void binaryAll(uint8_t * message, size_t len);
|
||||
void binaryAll(char * message);
|
||||
void binaryAll(const String &message);
|
||||
void binaryAll(const __FlashStringHelper *message, size_t len);
|
||||
void binaryAll(AsyncWebSocketMessageBuffer * buffer);
|
||||
|
||||
void message(uint32_t id, AsyncWebSocketMessage *message);
|
||||
void messageAll(AsyncWebSocketMultiMessage *message);
|
||||
|
||||
size_t printf(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
size_t printfAll(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
size_t printfAll_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//event listener
|
||||
inline void onEvent(AwsEventHandler handler)
|
||||
{
|
||||
_eventHandler = handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//system callbacks (do not call)
|
||||
inline uint32_t _getNextId()
|
||||
{
|
||||
return _cNextId++;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void _addClient(AsyncWebSocketClient * client);
|
||||
void _handleDisconnect(AsyncWebSocketClient * client);
|
||||
void _handleEvent(AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final;
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final;
|
||||
|
||||
// messagebuffer functions/objects.
|
||||
AsyncWebSocketMessageBuffer * makeBuffer(size_t size = 0);
|
||||
AsyncWebSocketMessageBuffer * makeBuffer(uint8_t * data, size_t size);
|
||||
LinkedList<AsyncWebSocketMessageBuffer *> _buffers;
|
||||
void _cleanBuffers();
|
||||
|
||||
AsyncWebSocketClientLinkedList getClients() const;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//WebServer response to authenticate the socket and detach the tcp client from the web server request
|
||||
class AsyncWebSocketResponse: public AsyncWebServerResponse
|
||||
{
|
||||
private:
|
||||
String _content;
|
||||
AsyncWebSocket *_server;
|
||||
|
||||
public:
|
||||
AsyncWebSocketResponse(const String& key, AsyncWebSocket *server);
|
||||
void _respond(AsyncWebServerRequest *request);
|
||||
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif /* ASYNCWEBSOCKET_H_ */
|
124
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h
Normal file
124
lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h
Normal file
|
@ -0,0 +1,124 @@
|
|||
/****************************************************************************************************************************
|
||||
AsyncWebSynchronization.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ASYNCWEBSYNCHRONIZATION_H_
|
||||
#define ASYNCWEBSYNCHRONIZATION_H_
|
||||
|
||||
// Synchronisation is only available on ESP32, as the ESP8266 isn't using FreeRTOS by default
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore
|
||||
class AsyncWebLock
|
||||
{
|
||||
private:
|
||||
SemaphoreHandle_t _lock;
|
||||
mutable void *_lockedBy;
|
||||
|
||||
public:
|
||||
AsyncWebLock()
|
||||
{
|
||||
_lock = xSemaphoreCreateBinary();
|
||||
_lockedBy = NULL;
|
||||
xSemaphoreGive(_lock);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
~AsyncWebLock()
|
||||
{
|
||||
vSemaphoreDelete(_lock);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool lock() const
|
||||
{
|
||||
extern void *pxCurrentTCB;
|
||||
|
||||
if (_lockedBy != pxCurrentTCB)
|
||||
{
|
||||
xSemaphoreTake(_lock, portMAX_DELAY);
|
||||
_lockedBy = pxCurrentTCB;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void unlock() const
|
||||
{
|
||||
_lockedBy = NULL;
|
||||
xSemaphoreGive(_lock);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncWebLockGuard
|
||||
{
|
||||
private:
|
||||
const AsyncWebLock *_lock;
|
||||
|
||||
public:
|
||||
AsyncWebLockGuard(const AsyncWebLock &l)
|
||||
{
|
||||
if (l.lock())
|
||||
{
|
||||
_lock = &l;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
~AsyncWebLockGuard()
|
||||
{
|
||||
if (_lock)
|
||||
{
|
||||
_lock->unlock();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif // ASYNCWEBSYNCHRONIZATION_H_
|
109
lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp
Normal file
109
lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
@file Hash.cpp
|
||||
@date 20.05.2015
|
||||
@author Markus Sattler
|
||||
|
||||
Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "bearssl_hash.h"
|
||||
|
||||
#include "Hash.h"
|
||||
|
||||
/**
|
||||
create a sha1 hash from data
|
||||
@param data uint8_t
|
||||
@param size uint32_t
|
||||
@param hash uint8_t[HASH_BUFFER_SIZE]
|
||||
*/
|
||||
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE])
|
||||
{
|
||||
br_sha1_context ctx;
|
||||
|
||||
AWS_LOGDEBUG0("DATA:");
|
||||
|
||||
for (uint16_t i = 0; i < size; i++)
|
||||
{
|
||||
AWS_LOGDEBUG0(data[i]);
|
||||
}
|
||||
|
||||
AWS_LOGDEBUG0("\nDATA:");
|
||||
|
||||
for (uint16_t i = 0; i < size; i++)
|
||||
{
|
||||
AWS_LOGDEBUG0((char) data[i]);
|
||||
|
||||
}
|
||||
|
||||
AWS_LOGDEBUG0("\n");
|
||||
|
||||
br_sha1_init(&ctx);
|
||||
br_sha1_update(&ctx, data, size);
|
||||
br_sha1_out(&ctx, hash);
|
||||
|
||||
AWS_LOGDEBUG0("SHA1:");
|
||||
|
||||
for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++)
|
||||
{
|
||||
AWS_LOGDEBUG0(hash[i]);
|
||||
}
|
||||
|
||||
AWS_LOGDEBUG0("\n");
|
||||
}
|
||||
|
||||
void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE])
|
||||
{
|
||||
sha1((const uint8_t *) data, size, hash);
|
||||
}
|
||||
|
||||
void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE])
|
||||
{
|
||||
sha1(data.c_str(), data.length(), hash);
|
||||
}
|
||||
|
||||
String sha1(const uint8_t* data, uint32_t size)
|
||||
{
|
||||
uint8_t hash[HASH_BUFFER_SIZE];
|
||||
|
||||
String hashStr((const char*)nullptr);
|
||||
hashStr.reserve(HASH_BUFFER_SIZE * 2 + 1);
|
||||
|
||||
sha1(&data[0], size, &hash[0]);
|
||||
|
||||
for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++)
|
||||
{
|
||||
char hex[3];
|
||||
snprintf(hex, sizeof(hex), "%02x", hash[i]);
|
||||
hashStr += hex;
|
||||
}
|
||||
|
||||
return hashStr;
|
||||
}
|
||||
|
||||
String sha1(const char* data, uint32_t size)
|
||||
{
|
||||
return sha1((const uint8_t*) data, size);
|
||||
}
|
||||
|
||||
String sha1(const String& data)
|
||||
{
|
||||
return sha1(data.c_str(), data.length());
|
||||
}
|
||||
|
46
lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h
Normal file
46
lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
@file Hash.h
|
||||
@date 20.05.2015
|
||||
@author Markus Sattler
|
||||
|
||||
Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HASH_H_
|
||||
#define HASH_H_
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
#ifdef HASH_BUFFER_SIZE
|
||||
#undef HASH_BUFFER_SIZE
|
||||
#endif
|
||||
|
||||
#define HASH_BUFFER_SIZE 20
|
||||
|
||||
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]);
|
||||
void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]);
|
||||
void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE]);
|
||||
|
||||
String sha1(const uint8_t* data, uint32_t size);
|
||||
String sha1(const char* data, uint32_t size);
|
||||
String sha1(const String& data);
|
||||
|
||||
#endif /* HASH_H_ */
|
1357
lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h
Normal file
1357
lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h
Normal file
File diff suppressed because it is too large
Load diff
95
lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h
Normal file
95
lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
\file md5.h
|
||||
|
||||
Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
|
||||
Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LWIP_INCLUDED_POLARSSL_MD5_H
|
||||
#define LWIP_INCLUDED_POLARSSL_MD5_H
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
/**
|
||||
\brief MD5 context structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned long total[2]; /*!< number of bytes processed */
|
||||
unsigned long state[4]; /*!< intermediate digest state */
|
||||
unsigned char buffer[64]; /*!< data block being processed */
|
||||
}
|
||||
md5_context;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief MD5 context setup
|
||||
|
||||
\param ctx context to be initialized
|
||||
*/
|
||||
void md5_starts( md5_context *ctx );
|
||||
|
||||
/**
|
||||
\brief MD5 process buffer
|
||||
|
||||
\param ctx MD5 context
|
||||
\param input buffer holding the data
|
||||
\param ilen length of the input data
|
||||
*/
|
||||
void md5_update( md5_context *ctx, const unsigned char *input, int ilen );
|
||||
|
||||
/**
|
||||
\brief MD5 final digest
|
||||
|
||||
\param ctx MD5 context
|
||||
\param output MD5 checksum result
|
||||
*/
|
||||
void md5_finish( md5_context *ctx, unsigned char output[16] );
|
||||
|
||||
/**
|
||||
\brief Output = MD5( input buffer )
|
||||
|
||||
\param input buffer holding the data
|
||||
\param ilen length of the input data
|
||||
\param output MD5 checksum result
|
||||
*/
|
||||
void md5( unsigned char *input, int ilen, unsigned char output[16] );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_INCLUDED_POLARSSL_MD5_H */
|
330
lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c
Normal file
330
lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c
Normal file
|
@ -0,0 +1,330 @@
|
|||
/*
|
||||
FIPS-180-1 compliant SHA-1 implementation
|
||||
|
||||
Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
|
||||
Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
The SHA-1 standard was published by NIST in 1993.
|
||||
|
||||
http://www.itl.nist.gov/fipspubs/fip180-1.htm
|
||||
*/
|
||||
|
||||
#include "sha1.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
SHA-1 context setup
|
||||
*/
|
||||
void sha1_starts( sha1_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long temp, W[16], A, B, C, D, E;
|
||||
|
||||
GET_ULONG_BE( W[ 0], data, 0 );
|
||||
GET_ULONG_BE( W[ 1], data, 4 );
|
||||
GET_ULONG_BE( W[ 2], data, 8 );
|
||||
GET_ULONG_BE( W[ 3], data, 12 );
|
||||
GET_ULONG_BE( W[ 4], data, 16 );
|
||||
GET_ULONG_BE( W[ 5], data, 20 );
|
||||
GET_ULONG_BE( W[ 6], data, 24 );
|
||||
GET_ULONG_BE( W[ 7], data, 28 );
|
||||
GET_ULONG_BE( W[ 8], data, 32 );
|
||||
GET_ULONG_BE( W[ 9], data, 36 );
|
||||
GET_ULONG_BE( W[10], data, 40 );
|
||||
GET_ULONG_BE( W[11], data, 44 );
|
||||
GET_ULONG_BE( W[12], data, 48 );
|
||||
GET_ULONG_BE( W[13], data, 52 );
|
||||
GET_ULONG_BE( W[14], data, 56 );
|
||||
GET_ULONG_BE( W[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
|
||||
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
|
||||
( W[t & 0x0F] = S(temp,1) ) \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,x) \
|
||||
{ \
|
||||
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define K 0x5A827999
|
||||
|
||||
P( A, B, C, D, E, W[0] );
|
||||
P( E, A, B, C, D, W[1] );
|
||||
P( D, E, A, B, C, W[2] );
|
||||
P( C, D, E, A, B, W[3] );
|
||||
P( B, C, D, E, A, W[4] );
|
||||
P( A, B, C, D, E, W[5] );
|
||||
P( E, A, B, C, D, W[6] );
|
||||
P( D, E, A, B, C, W[7] );
|
||||
P( C, D, E, A, B, W[8] );
|
||||
P( B, C, D, E, A, W[9] );
|
||||
P( A, B, C, D, E, W[10] );
|
||||
P( E, A, B, C, D, W[11] );
|
||||
P( D, E, A, B, C, W[12] );
|
||||
P( C, D, E, A, B, W[13] );
|
||||
P( B, C, D, E, A, W[14] );
|
||||
P( A, B, C, D, E, W[15] );
|
||||
P( E, A, B, C, D, R(16) );
|
||||
P( D, E, A, B, C, R(17) );
|
||||
P( C, D, E, A, B, R(18) );
|
||||
P( B, C, D, E, A, R(19) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0x6ED9EBA1
|
||||
|
||||
P( A, B, C, D, E, R(20) );
|
||||
P( E, A, B, C, D, R(21) );
|
||||
P( D, E, A, B, C, R(22) );
|
||||
P( C, D, E, A, B, R(23) );
|
||||
P( B, C, D, E, A, R(24) );
|
||||
P( A, B, C, D, E, R(25) );
|
||||
P( E, A, B, C, D, R(26) );
|
||||
P( D, E, A, B, C, R(27) );
|
||||
P( C, D, E, A, B, R(28) );
|
||||
P( B, C, D, E, A, R(29) );
|
||||
P( A, B, C, D, E, R(30) );
|
||||
P( E, A, B, C, D, R(31) );
|
||||
P( D, E, A, B, C, R(32) );
|
||||
P( C, D, E, A, B, R(33) );
|
||||
P( B, C, D, E, A, R(34) );
|
||||
P( A, B, C, D, E, R(35) );
|
||||
P( E, A, B, C, D, R(36) );
|
||||
P( D, E, A, B, C, R(37) );
|
||||
P( C, D, E, A, B, R(38) );
|
||||
P( B, C, D, E, A, R(39) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define K 0x8F1BBCDC
|
||||
|
||||
P( A, B, C, D, E, R(40) );
|
||||
P( E, A, B, C, D, R(41) );
|
||||
P( D, E, A, B, C, R(42) );
|
||||
P( C, D, E, A, B, R(43) );
|
||||
P( B, C, D, E, A, R(44) );
|
||||
P( A, B, C, D, E, R(45) );
|
||||
P( E, A, B, C, D, R(46) );
|
||||
P( D, E, A, B, C, R(47) );
|
||||
P( C, D, E, A, B, R(48) );
|
||||
P( B, C, D, E, A, R(49) );
|
||||
P( A, B, C, D, E, R(50) );
|
||||
P( E, A, B, C, D, R(51) );
|
||||
P( D, E, A, B, C, R(52) );
|
||||
P( C, D, E, A, B, R(53) );
|
||||
P( B, C, D, E, A, R(54) );
|
||||
P( A, B, C, D, E, R(55) );
|
||||
P( E, A, B, C, D, R(56) );
|
||||
P( D, E, A, B, C, R(57) );
|
||||
P( C, D, E, A, B, R(58) );
|
||||
P( B, C, D, E, A, R(59) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0xCA62C1D6
|
||||
|
||||
P( A, B, C, D, E, R(60) );
|
||||
P( E, A, B, C, D, R(61) );
|
||||
P( D, E, A, B, C, R(62) );
|
||||
P( C, D, E, A, B, R(63) );
|
||||
P( B, C, D, E, A, R(64) );
|
||||
P( A, B, C, D, E, R(65) );
|
||||
P( E, A, B, C, D, R(66) );
|
||||
P( D, E, A, B, C, R(67) );
|
||||
P( C, D, E, A, B, R(68) );
|
||||
P( B, C, D, E, A, R(69) );
|
||||
P( A, B, C, D, E, R(70) );
|
||||
P( E, A, B, C, D, R(71) );
|
||||
P( D, E, A, B, C, R(72) );
|
||||
P( C, D, E, A, B, R(73) );
|
||||
P( B, C, D, E, A, R(74) );
|
||||
P( A, B, C, D, E, R(75) );
|
||||
P( E, A, B, C, D, R(76) );
|
||||
P( D, E, A, B, C, R(77) );
|
||||
P( C, D, E, A, B, R(78) );
|
||||
P( B, C, D, E, A, R(79) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
}
|
||||
|
||||
/*
|
||||
SHA-1 process buffer
|
||||
*/
|
||||
void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if ( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if ( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if ( left && ilen >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
sha1_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while ( ilen >= 64 )
|
||||
{
|
||||
sha1_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if ( ilen > 0 )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char sha1_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
SHA-1 final digest
|
||||
*/
|
||||
void sha1_finish( sha1_context *ctx, unsigned char output[SHA1_BUFFER_SIZE] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_BE( high, msglen, 0 );
|
||||
PUT_ULONG_BE( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
sha1_update( ctx, sha1_padding, padn );
|
||||
sha1_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_BE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_BE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_BE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_BE( ctx->state[3], output, 12 );
|
||||
PUT_ULONG_BE( ctx->state[4], output, 16 );
|
||||
}
|
||||
|
||||
/*
|
||||
output = SHA-1( input buffer )
|
||||
*/
|
||||
void sha1( unsigned char *input, int ilen, unsigned char output[SHA1_BUFFER_SIZE] )
|
||||
{
|
||||
sha1_context ctx;
|
||||
|
||||
sha1_starts( &ctx );
|
||||
sha1_update( &ctx, input, ilen );
|
||||
sha1_finish( &ctx, output );
|
||||
}
|
101
lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h
Normal file
101
lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
\file sha1.h
|
||||
|
||||
Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
|
||||
Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LWIP_INCLUDED_POLARSSL_SHA1_H
|
||||
#define LWIP_INCLUDED_POLARSSL_SHA1_H
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
#ifdef SHA1_BUFFER_SIZE
|
||||
#undef SHA1_BUFFER_SIZE
|
||||
#endif
|
||||
|
||||
#define SHA1_BUFFER_SIZE 20
|
||||
|
||||
/**
|
||||
\brief SHA-1 context structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned long total[2]; /*!< number of bytes processed */
|
||||
unsigned long state[5]; /*!< intermediate digest state */
|
||||
unsigned char buffer[64]; /*!< data block being processed */
|
||||
}
|
||||
sha1_context;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief SHA-1 context setup
|
||||
|
||||
\param ctx context to be initialized
|
||||
*/
|
||||
void sha1_starts( sha1_context *ctx );
|
||||
|
||||
/**
|
||||
\brief SHA-1 process buffer
|
||||
|
||||
\param ctx SHA-1 context
|
||||
\param input buffer holding the data
|
||||
\param ilen length of the input data
|
||||
*/
|
||||
void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
|
||||
|
||||
/**
|
||||
\brief SHA-1 final digest
|
||||
|
||||
\param ctx SHA-1 context
|
||||
\param output SHA-1 checksum result
|
||||
*/
|
||||
void sha1_finish( sha1_context *ctx, unsigned char output[SHA1_BUFFER_SIZE] );
|
||||
|
||||
/**
|
||||
\brief Output = SHA-1( input buffer )
|
||||
|
||||
\param input buffer holding the data
|
||||
\param ilen length of the input data
|
||||
\param output SHA-1 checksum result
|
||||
*/
|
||||
void sha1( unsigned char *input, int ilen, unsigned char output[SHA1_BUFFER_SIZE] );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */
|
689
lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp
Normal file
689
lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp
Normal file
|
@ -0,0 +1,689 @@
|
|||
/****************************************************************************************************************************
|
||||
ESP32_W5500_SPIFFSEditor.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "ESP32_W5500_SPIFFSEditor.h"
|
||||
#include <FS.h>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
//File: edit.htm.gz, Size: 4151
|
||||
#define edit_htm_gz_len 4151
|
||||
|
||||
const uint8_t edit_htm_gz[] PROGMEM =
|
||||
{
|
||||
0x1F, 0x8B, 0x08, 0x08, 0xB8, 0x94, 0xB1, 0x59, 0x00, 0x03, 0x65, 0x64, 0x69, 0x74, 0x2E, 0x68,
|
||||
0x74, 0x6D, 0x00, 0xB5, 0x3A, 0x0B, 0x7B, 0xDA, 0xB8, 0xB2, 0x7F, 0xC5, 0x71, 0xCF, 0x66, 0xED,
|
||||
0x83, 0x31, 0x90, 0xA4, 0xD9, 0xD6, 0xC4, 0xC9, 0x42, 0x92, 0x36, 0x6D, 0xF3, 0x6A, 0x80, 0xB6,
|
||||
0x69, 0x4F, 0xEE, 0x7E, 0xC2, 0x16, 0xA0, 0xC6, 0x96, 0x5D, 0x5B, 0x0E, 0x49, 0x59, 0xFE, 0xFB,
|
||||
0x9D, 0x91, 0x6C, 0xB0, 0x09, 0x69, 0x77, 0xCF, 0xBD, 0xBB, 0xD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,
|
||||
0x85, 0x78, 0xD4, 0x46, 0xD6, 0x80, 0xFD, 0xDC, 0xBD, 0x73, 0x33, 0xDE, 0x90, 0x68, 0x09, 0x56,
|
||||
0x36, 0x3D, 0x9A, 0xA6, 0x52, 0x5C, 0x54, 0xC7, 0x19, 0xF8, 0xA8, 0xA1, 0x03, 0x5A, 0x23, 0x84,
|
||||
0x11, 0x1E, 0x84, 0x8A, 0x01, 0x40, 0x7F, 0x42, 0xC3, 0x1C, 0x22, 0x70, 0x08, 0x20, 0x82, 0xA0,
|
||||
0x7F, 0x49, 0x0D, 0xF7, 0x64, 0x05, 0xC9, 0xF8, 0xD8, 0x6D, 0x35, 0xF0, 0x9D, 0x66, 0x95, 0xEC,
|
||||
0x20, 0xA5, 0xBD, 0x68, 0x24, 0xFA, 0x64, 0x98, 0x1A, 0x50, 0x00, 0xAC, 0xD9, 0x01, 0xA0, 0x1E,
|
||||
0x24, 0x5E, 0x63, 0x2B, 0x3F, 0xEF, 0x04, 0x2A, 0xBB, 0x00, 0xAB, 0xBB, 0x8E, 0x87, 0x5F, 0x39,
|
||||
0x4F, 0x19, 0xA7, 0x39, 0x26, 0x00, 0x7B, 0x93, 0x68, 0x7A, 0x99, 0x30, 0x2E, 0xCE, 0x64, 0x1B,
|
||||
0x6A, 0x6C, 0xB4, 0xE4, 0xF5, 0xA9, 0x87, 0x15, 0x79, 0x3F, 0xC5, 0x8B, 0xCB, 0x0C, 0xF3, 0xBA,
|
||||
0x53, 0x79, 0x77, 0xB1, 0x86, 0x70, 0x21, 0x50, 0x66, 0x38, 0xB3, 0x29, 0x74, 0xB0, 0xFA, 0xA1,
|
||||
0x48, 0x82, 0x7A, 0x4F, 0xB7, 0x42, 0xE2, 0xC1, 0x44, 0xED, 0x81, 0xF9, 0xDC, 0xC2, 0xD8, 0xE1,
|
||||
0x94, 0x83, 0x5A, 0x0A, 0xB5, 0x02, 0x45, 0xC6, 0x95, 0xCD, 0x98, 0x35, 0x1D, 0x6A, 0x58, 0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x60, 0xD4, 0x31, 0xBA, 0x95, 0x2F, 0x92, 0xF4, 0x81, 0x7B, 0x18, 0x5B, 0x17,
|
||||
0x54, 0x26, 0x70, 0x49, 0xD5, 0x87, 0x34, 0xB9, 0xD3, 0x9C, 0x2F, 0x39, 0xC3, 0xB7, 0x3C, 0xA8,
|
||||
0x03, 0xE4, 0x37, 0x9C, 0x72, 0x39, 0xB0, 0xBF, 0x07, 0x5D, 0x33, 0x2A, 0x41, 0x79, 0xB1, 0x26,
|
||||
0x9B, 0xE6, 0x7C, 0x02, 0x82, 0x01, 0x70, 0xB1, 0xA3, 0x48, 0xCD, 0x2B, 0xCB, 0x98, 0x9B, 0x57,
|
||||
0x96, 0x54, 0xE2, 0x5F, 0x59, 0xCC, 0xDB, 0x9F, 0xFC, 0xDB, 0x4C, 0xF9, 0x7F, 0x5B, 0x28, 0x36,
|
||||
0x32, 0xF9, 0xE1, 0x09, 0xF7, 0x56, 0x3F, 0x45, 0xAD, 0x47, 0x51, 0xBB, 0xF7, 0xFF, 0x17, 0x53,
|
||||
0xE8, 0x9D, 0x36, 0x92, 0x29, 0x00, 0x00
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define SPIFFS_MAXLENGTH_FILEPATH 32
|
||||
|
||||
const char *excludeListFile = "/.exclude.files";
|
||||
|
||||
typedef struct ExcludeListS
|
||||
{
|
||||
char *item;
|
||||
ExcludeListS *next;
|
||||
} ExcludeList;
|
||||
|
||||
static ExcludeList *excludes = NULL;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static bool matchWild(const char *pattern, const char *testee)
|
||||
{
|
||||
const char *nxPat = NULL, *nxTst = NULL;
|
||||
|
||||
while (*testee)
|
||||
{
|
||||
if (( *pattern == '?' ) || (*pattern == *testee))
|
||||
{
|
||||
pattern++;
|
||||
testee++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*pattern == '*')
|
||||
{
|
||||
nxPat = pattern++;
|
||||
nxTst = testee;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nxPat)
|
||||
{
|
||||
pattern = nxPat + 1;
|
||||
testee = ++nxTst;
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
while (*pattern == '*')
|
||||
{
|
||||
pattern++;
|
||||
}
|
||||
|
||||
return (*pattern == 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static bool addExclude(const char *item)
|
||||
{
|
||||
size_t len = strlen(item);
|
||||
|
||||
if (!len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ExcludeList *e = (ExcludeList *)malloc(sizeof(ExcludeList));
|
||||
|
||||
if (!e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
e->item = (char *)malloc(len + 1);
|
||||
|
||||
if (!e->item)
|
||||
{
|
||||
free(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(e->item, item, len + 1);
|
||||
e->next = excludes;
|
||||
excludes = e;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static void loadExcludeList(fs::FS &_fs, const char *filename)
|
||||
{
|
||||
static char linebuf[SPIFFS_MAXLENGTH_FILEPATH];
|
||||
fs::File excludeFile = _fs.open(filename, "r");
|
||||
|
||||
if (!excludeFile)
|
||||
{
|
||||
//addExclude("/*.js.gz");
|
||||
return;
|
||||
}
|
||||
|
||||
if (excludeFile.isDirectory())
|
||||
{
|
||||
excludeFile.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (excludeFile.size() > 0)
|
||||
{
|
||||
uint8_t idx;
|
||||
bool isOverflowed = false;
|
||||
|
||||
while (excludeFile.available())
|
||||
{
|
||||
linebuf[0] = '\0';
|
||||
idx = 0;
|
||||
int lastChar;
|
||||
|
||||
do
|
||||
{
|
||||
lastChar = excludeFile.read();
|
||||
|
||||
if (lastChar != '\r')
|
||||
{
|
||||
linebuf[idx++] = (char) lastChar;
|
||||
}
|
||||
} while ((lastChar >= 0) && (lastChar != '\n') && (idx < SPIFFS_MAXLENGTH_FILEPATH));
|
||||
|
||||
if (isOverflowed)
|
||||
{
|
||||
isOverflowed = (lastChar != '\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
isOverflowed = (idx >= SPIFFS_MAXLENGTH_FILEPATH);
|
||||
linebuf[idx - 1] = '\0';
|
||||
|
||||
if (!addExclude(linebuf))
|
||||
{
|
||||
excludeFile.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
excludeFile.close();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static bool isExcluded(fs::FS &_fs, const char *filename)
|
||||
{
|
||||
if (excludes == NULL)
|
||||
{
|
||||
loadExcludeList(_fs, excludeListFile);
|
||||
}
|
||||
|
||||
ExcludeList *e = excludes;
|
||||
|
||||
while (e)
|
||||
{
|
||||
if (matchWild(e->item, filename))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// WEB HANDLER IMPLEMENTATION
|
||||
|
||||
SPIFFSEditor::SPIFFSEditor(const fs::FS& fs, const String& username, const String& password)
|
||||
: _fs(fs)
|
||||
, _username(username)
|
||||
, _password(password)
|
||||
, _authenticated(false)
|
||||
, _startTime(0)
|
||||
{}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool SPIFFSEditor::canHandle(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->url().equalsIgnoreCase("/edit"))
|
||||
{
|
||||
if (request->method() == HTTP_GET)
|
||||
{
|
||||
if (request->hasParam("list"))
|
||||
return true;
|
||||
|
||||
if (request->hasParam("edit"))
|
||||
{
|
||||
request->_tempFile = _fs.open(request->arg("edit"), "r");
|
||||
|
||||
if (!request->_tempFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request->_tempFile.isDirectory())
|
||||
{
|
||||
request->_tempFile.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request->hasParam("download"))
|
||||
{
|
||||
request->_tempFile = _fs.open(request->arg("download"), "r");
|
||||
|
||||
if (!request->_tempFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request->_tempFile.isDirectory())
|
||||
{
|
||||
request->_tempFile.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
request->addInterestingHeader("If-Modified-Since");
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (request->method() == HTTP_POST)
|
||||
return true;
|
||||
else if (request->method() == HTTP_DELETE)
|
||||
return true;
|
||||
else if (request->method() == HTTP_PUT)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (request->method() == HTTP_GET)
|
||||
{
|
||||
if (request->hasParam("list"))
|
||||
{
|
||||
String path = request->getParam("list")->value();
|
||||
File dir = _fs.open(path);
|
||||
path = String();
|
||||
String output = "[";
|
||||
|
||||
File entry = dir.openNextFile();
|
||||
|
||||
while (entry)
|
||||
{
|
||||
if (isExcluded(_fs, entry.name()))
|
||||
{
|
||||
entry = dir.openNextFile();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (output != "[")
|
||||
output += ',';
|
||||
|
||||
output += "{\"type\":\"";
|
||||
output += "file";
|
||||
output += "\",\"name\":\"";
|
||||
output += String(entry.name());
|
||||
output += "\",\"size\":";
|
||||
output += String(entry.size());
|
||||
output += "}";
|
||||
|
||||
entry = dir.openNextFile();
|
||||
}
|
||||
|
||||
dir.close();
|
||||
output += "]";
|
||||
request->send(200, "application/json", output);
|
||||
output = String();
|
||||
}
|
||||
else if (request->hasParam("edit") || request->hasParam("download"))
|
||||
{
|
||||
request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download"));
|
||||
}
|
||||
else
|
||||
{
|
||||
const char * buildTime = __DATE__ " " __TIME__ " GMT";
|
||||
|
||||
if (request->header("If-Modified-Since").equals(buildTime))
|
||||
{
|
||||
request->send(304);
|
||||
}
|
||||
else
|
||||
{
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", edit_htm_gz, edit_htm_gz_len);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
response->addHeader("Last-Modified", buildTime);
|
||||
request->send(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (request->method() == HTTP_DELETE)
|
||||
{
|
||||
if (request->hasParam("path", true))
|
||||
{
|
||||
_fs.remove(request->getParam("path", true)->value());
|
||||
request->send(200, "", "DELETE: " + request->getParam("path", true)->value());
|
||||
}
|
||||
else
|
||||
request->send(404);
|
||||
}
|
||||
else if (request->method() == HTTP_POST)
|
||||
{
|
||||
if (request->hasParam("data", true, true) && _fs.exists(request->getParam("data", true, true)->value()))
|
||||
request->send(200, "", "UPLOADED: " + request->getParam("data", true, true)->value());
|
||||
else
|
||||
request->send(500);
|
||||
}
|
||||
else if (request->method() == HTTP_PUT)
|
||||
{
|
||||
if (request->hasParam("path", true))
|
||||
{
|
||||
String filename = request->getParam("path", true)->value();
|
||||
|
||||
if (_fs.exists(filename))
|
||||
{
|
||||
request->send(200);
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::File f = _fs.open(filename, "w");
|
||||
|
||||
if (f)
|
||||
{
|
||||
f.write((uint8_t)0x00);
|
||||
f.close();
|
||||
request->send(200, "", "CREATE: " + filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
request->send(400);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void SPIFFSEditor::handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
|
||||
size_t len, bool final)
|
||||
{
|
||||
if (!index)
|
||||
{
|
||||
if (!_username.length() || request->authenticate(_username.c_str(), _password.c_str()))
|
||||
{
|
||||
_authenticated = true;
|
||||
request->_tempFile = _fs.open(filename, "w");
|
||||
_startTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
if (_authenticated && request->_tempFile)
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
request->_tempFile.write(data, len);
|
||||
}
|
||||
|
||||
if (final)
|
||||
{
|
||||
request->_tempFile.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************************************************************
|
||||
ESP32_W5500_SPIFFSEditor.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ESP32_W5500_SPIFFSEditor_H_
|
||||
#define ESP32_W5500_SPIFFSEditor_H_
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class SPIFFSEditor: public AsyncWebHandler
|
||||
{
|
||||
private:
|
||||
fs::FS _fs;
|
||||
String _username;
|
||||
String _password;
|
||||
bool _authenticated;
|
||||
uint32_t _startTime;
|
||||
|
||||
public:
|
||||
SPIFFSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final;
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final;
|
||||
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
|
||||
size_t len, bool final) override final;
|
||||
|
||||
virtual bool isRequestHandlerTrivial() override final
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif // SPIFFSEditor_H_
|
353
lib/AsyncWebServer_ESP32_W5500/src/StringArray.h
Normal file
353
lib/AsyncWebServer_ESP32_W5500/src/StringArray.h
Normal file
|
@ -0,0 +1,353 @@
|
|||
/****************************************************************************************************************************
|
||||
StringArray.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef STRINGARRAY_H_
|
||||
#define STRINGARRAY_H_
|
||||
|
||||
#include "stddef.h"
|
||||
#include "WString.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
template <typename T>
|
||||
class LinkedListNode
|
||||
{
|
||||
T _value;
|
||||
|
||||
public:
|
||||
LinkedListNode<T>* next;
|
||||
LinkedListNode(const T val): _value(val), next(nullptr) {}
|
||||
~LinkedListNode() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const T& value() const
|
||||
{
|
||||
return _value;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline T& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
template <typename T, template<typename> class Item = LinkedListNode>
|
||||
class LinkedList
|
||||
{
|
||||
public:
|
||||
typedef Item<T> ItemType;
|
||||
typedef std::function<void(const T&)> OnRemove;
|
||||
typedef std::function<bool(const T&)> Predicate;
|
||||
|
||||
private:
|
||||
ItemType* _root;
|
||||
OnRemove _onRemove;
|
||||
|
||||
class Iterator
|
||||
{
|
||||
ItemType* _node;
|
||||
|
||||
public:
|
||||
Iterator(ItemType* current = nullptr) : _node(current) {}
|
||||
Iterator(const Iterator& i) : _node(i._node) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline Iterator& operator ++()
|
||||
{
|
||||
_node = _node->next;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool operator != (const Iterator& i) const
|
||||
{
|
||||
return _node != i._node;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const T& operator * () const
|
||||
{
|
||||
return _node->value();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline const T* operator -> () const
|
||||
{
|
||||
return &_node->value();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
typedef const Iterator ConstIterator;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline ConstIterator begin() const
|
||||
{
|
||||
return ConstIterator(_root);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline ConstIterator end() const
|
||||
{
|
||||
return ConstIterator(nullptr);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
LinkedList(OnRemove onRemove) : _root(nullptr), _onRemove(onRemove) {}
|
||||
~LinkedList() {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void add(const T& t)
|
||||
{
|
||||
auto it = new ItemType(t);
|
||||
|
||||
if (!_root)
|
||||
{
|
||||
_root = it;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto i = _root;
|
||||
|
||||
while (i->next)
|
||||
i = i->next;
|
||||
|
||||
i->next = it;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline T& front() const
|
||||
{
|
||||
return _root->value();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool isEmpty() const
|
||||
{
|
||||
return _root == nullptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t length() const
|
||||
{
|
||||
size_t i = 0;
|
||||
auto it = _root;
|
||||
|
||||
while (it)
|
||||
{
|
||||
i++;
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
size_t count_if(Predicate predicate) const
|
||||
{
|
||||
size_t i = 0;
|
||||
auto it = _root;
|
||||
|
||||
while (it)
|
||||
{
|
||||
if (!predicate)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else if (predicate(it->value()))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
const T* nth(size_t N) const
|
||||
{
|
||||
size_t i = 0;
|
||||
auto it = _root;
|
||||
|
||||
while (it)
|
||||
{
|
||||
if (i++ == N)
|
||||
return &(it->value());
|
||||
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool remove(const T& t)
|
||||
{
|
||||
auto it = _root;
|
||||
auto pit = _root;
|
||||
|
||||
while (it)
|
||||
{
|
||||
if (it->value() == t)
|
||||
{
|
||||
if (it == _root)
|
||||
{
|
||||
_root = _root->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
pit->next = it->next;
|
||||
}
|
||||
|
||||
if (_onRemove)
|
||||
{
|
||||
_onRemove(it->value());
|
||||
}
|
||||
|
||||
delete it;
|
||||
return true;
|
||||
}
|
||||
|
||||
pit = it;
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool remove_first(Predicate predicate)
|
||||
{
|
||||
auto it = _root;
|
||||
auto pit = _root;
|
||||
|
||||
while (it)
|
||||
{
|
||||
if (predicate(it->value()))
|
||||
{
|
||||
if (it == _root)
|
||||
{
|
||||
_root = _root->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
pit->next = it->next;
|
||||
}
|
||||
|
||||
if (_onRemove)
|
||||
{
|
||||
_onRemove(it->value());
|
||||
}
|
||||
|
||||
delete it;
|
||||
return true;
|
||||
}
|
||||
|
||||
pit = it;
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void free()
|
||||
{
|
||||
while (_root != nullptr)
|
||||
{
|
||||
auto it = _root;
|
||||
_root = _root->next;
|
||||
|
||||
if (_onRemove)
|
||||
{
|
||||
_onRemove(it->value());
|
||||
}
|
||||
|
||||
delete it;
|
||||
}
|
||||
|
||||
_root = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class StringArray : public LinkedList<String>
|
||||
{
|
||||
public:
|
||||
|
||||
StringArray() : LinkedList(nullptr) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool containsIgnoreCase(const String& str)
|
||||
{
|
||||
for (const auto& s : *this)
|
||||
{
|
||||
if (str.equalsIgnoreCase(s))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* STRINGARRAY_H_ */
|
360
lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp
Normal file
360
lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp
Normal file
|
@ -0,0 +1,360 @@
|
|||
/****************************************************************************************************************************
|
||||
WebAuthentication.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "WebAuthentication.h"
|
||||
#include <libb64/cencode.h>
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/version.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Basic Auth hash = base64("username:password")
|
||||
|
||||
bool checkBasicAuthentication(const char * hash, const char * username, const char * password)
|
||||
{
|
||||
if (username == NULL || password == NULL || hash == NULL)
|
||||
return false;
|
||||
|
||||
size_t toencodeLen = strlen(username) + strlen(password) + 1;
|
||||
size_t encodedLen = base64_encode_expected_len(toencodeLen);
|
||||
|
||||
if (strlen(hash) != encodedLen)
|
||||
return false;
|
||||
|
||||
char *toencode = new char[toencodeLen + 1];
|
||||
|
||||
if (toencode == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char *encoded = new char[base64_encode_expected_len(toencodeLen) + 1];
|
||||
|
||||
if (encoded == NULL)
|
||||
{
|
||||
delete[] toencode;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
sprintf(toencode, "%s:%s", username, password);
|
||||
|
||||
if (base64_encode_chars(toencode, toencodeLen, encoded) > 0 && memcmp(hash, encoded, encodedLen) == 0)
|
||||
{
|
||||
delete[] toencode;
|
||||
delete[] encoded;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
delete[] toencode;
|
||||
delete[] encoded;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static bool getMD5(uint8_t * data, uint16_t len, char * output)
|
||||
{
|
||||
//33 bytes or more
|
||||
mbedtls_md5_context _ctx;
|
||||
uint8_t i;
|
||||
uint8_t * _buf = (uint8_t*)malloc(16);
|
||||
|
||||
if (_buf == NULL)
|
||||
return false;
|
||||
|
||||
memset(_buf, 0x00, 16);
|
||||
|
||||
mbedtls_md5_init(&_ctx);
|
||||
|
||||
#if (MBEDTLS_VERSION_NUMBER < 0x02070000)
|
||||
// Superseded from v2.7.0
|
||||
mbedtls_md5_starts(&_ctx);
|
||||
mbedtls_md5_update(&_ctx, data, len);
|
||||
mbedtls_md5_finish(&_ctx, _buf);
|
||||
#else
|
||||
mbedtls_md5_starts_ret(&_ctx);
|
||||
mbedtls_md5_update_ret(&_ctx, data, len);
|
||||
mbedtls_md5_finish_ret(&_ctx, _buf);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
sprintf(output + (i * 2), "%02x", _buf[i]);
|
||||
}
|
||||
|
||||
free(_buf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static String genRandomMD5()
|
||||
{
|
||||
uint32_t r = rand();
|
||||
char * out = (char*)malloc(33);
|
||||
|
||||
if (out == NULL || !getMD5((uint8_t*)(&r), 4, out))
|
||||
return "";
|
||||
|
||||
String res = String(out);
|
||||
free(out);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
static String stringMD5(const String& in)
|
||||
{
|
||||
char * out = (char*)malloc(33);
|
||||
|
||||
if (out == NULL || !getMD5((uint8_t*)(in.c_str()), in.length(), out))
|
||||
return "";
|
||||
|
||||
String res = String(out);
|
||||
free(out);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
String generateDigestHash(const char * username, const char * password, const char * realm)
|
||||
{
|
||||
if (username == NULL || password == NULL || realm == NULL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
char * out = (char*)malloc(33);
|
||||
String res = String(username);
|
||||
res.concat(":");
|
||||
res.concat(realm);
|
||||
res.concat(":");
|
||||
String in = res;
|
||||
in.concat(password);
|
||||
|
||||
if (out == NULL || !getMD5((uint8_t*)(in.c_str()), in.length(), out))
|
||||
return "";
|
||||
|
||||
res.concat(out);
|
||||
free(out);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
String requestDigestAuthentication(const char * realm)
|
||||
{
|
||||
String header = "realm=\"";
|
||||
|
||||
if (realm == NULL)
|
||||
header.concat("asyncesp");
|
||||
else
|
||||
header.concat(realm);
|
||||
|
||||
header.concat( "\", qop=\"auth\", nonce=\"");
|
||||
header.concat(genRandomMD5());
|
||||
header.concat("\", opaque=\"");
|
||||
header.concat(genRandomMD5());
|
||||
header.concat("\"");
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool checkDigestAuthentication(const char * header, const char * method, const char * username, const char * password,
|
||||
const char * realm,
|
||||
bool passwordIsHash, const char * nonce, const char * opaque, const char * uri)
|
||||
{
|
||||
if (username == NULL || password == NULL || header == NULL || method == NULL)
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, missing required fields"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String myHeader = String(header);
|
||||
int nextBreak = myHeader.indexOf(",");
|
||||
|
||||
if (nextBreak < 0)
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, no variables"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String myUsername = String();
|
||||
String myRealm = String();
|
||||
String myNonce = String();
|
||||
String myUri = String();
|
||||
String myResponse = String();
|
||||
String myQop = String();
|
||||
String myNc = String();
|
||||
String myCnonce = String();
|
||||
|
||||
myHeader += ", ";
|
||||
|
||||
do
|
||||
{
|
||||
String avLine = myHeader.substring(0, nextBreak);
|
||||
avLine.trim();
|
||||
myHeader = myHeader.substring(nextBreak + 1);
|
||||
nextBreak = myHeader.indexOf(",");
|
||||
|
||||
int eqSign = avLine.indexOf("=");
|
||||
|
||||
if (eqSign < 0)
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, no = sign"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String varName = avLine.substring(0, eqSign);
|
||||
avLine = avLine.substring(eqSign + 1);
|
||||
|
||||
if (avLine.startsWith("\""))
|
||||
{
|
||||
avLine = avLine.substring(1, avLine.length() - 1);
|
||||
}
|
||||
|
||||
if (varName.equals("username"))
|
||||
{
|
||||
if (!avLine.equals(username))
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, username"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myUsername ="), myUsername);
|
||||
|
||||
myUsername = avLine;
|
||||
}
|
||||
else if (varName.equals("realm"))
|
||||
{
|
||||
if (realm != NULL && !avLine.equals(realm))
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, realm"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myRealm ="), myRealm);
|
||||
|
||||
myRealm = avLine;
|
||||
}
|
||||
else if (varName.equals("nonce"))
|
||||
{
|
||||
if (nonce != NULL && !avLine.equals(nonce))
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, nonce"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myNonce ="), myNonce);
|
||||
|
||||
myNonce = avLine;
|
||||
}
|
||||
else if (varName.equals("opaque"))
|
||||
{
|
||||
if (opaque != NULL && !avLine.equals(opaque))
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, opaque"));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (varName.equals("uri"))
|
||||
{
|
||||
if (uri != NULL && !avLine.equals(uri))
|
||||
{
|
||||
AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, uri"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myUri ="), myUri);
|
||||
|
||||
myUri = avLine;
|
||||
}
|
||||
else if (varName.equals("response"))
|
||||
{
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myResponse ="), myResponse);
|
||||
|
||||
myResponse = avLine;
|
||||
}
|
||||
else if (varName.equals("qop"))
|
||||
{
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myQop ="), myQop);
|
||||
|
||||
myQop = avLine;
|
||||
}
|
||||
else if (varName.equals("nc"))
|
||||
{
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myNc ="), myNc);
|
||||
|
||||
myNc = avLine;
|
||||
}
|
||||
else if (varName.equals("cnonce"))
|
||||
{
|
||||
AWS_LOGINFO1(F("checkDigestAuthentication: myCnonce ="), myCnonce);
|
||||
|
||||
myCnonce = avLine;
|
||||
}
|
||||
} while (nextBreak > 0);
|
||||
|
||||
String ha1 = (passwordIsHash) ? String(password) : stringMD5(myUsername + ":" + myRealm + ":" + String(password));
|
||||
String ha2 = String(method) + ":" + myUri;
|
||||
String response = ha1 + ":" + myNonce + ":" + myNc + ":" + myCnonce + ":" + myQop + ":" + stringMD5(ha2);
|
||||
|
||||
if (myResponse.equals(stringMD5(response)))
|
||||
{
|
||||
AWS_LOGINFO(F("AUTH SUCCESS"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AWS_LOGINFO(F("AUTH FAIL: password"));
|
||||
|
||||
return false;
|
||||
}
|
55
lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h
Normal file
55
lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/****************************************************************************************************************************
|
||||
WebAuthentication.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef WEB_AUTHENTICATION_H_
|
||||
#define WEB_AUTHENTICATION_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool checkBasicAuthentication(const char * header, const char * username, const char * password);
|
||||
String requestDigestAuthentication(const char * realm);
|
||||
|
||||
bool checkDigestAuthentication(const char * header, const char * method, const char * username, const char * password,
|
||||
const char * realm,
|
||||
bool passwordIsHash, const char * nonce, const char * opaque, const char * uri);
|
||||
|
||||
//for storing hashed versions on the device that can be authenticated against
|
||||
String generateDigestHash(const char * username, const char * password, const char * realm);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif // WEB_AUTHENTICATION_H_
|
245
lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h
Normal file
245
lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h
Normal file
|
@ -0,0 +1,245 @@
|
|||
/****************************************************************************************************************************
|
||||
WebHandlerImpl.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ASYNCWEBSERVERHANDLERIMPL_H_
|
||||
#define ASYNCWEBSERVERHANDLERIMPL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef ASYNCWEBSERVER_REGEX
|
||||
#include <regex>
|
||||
#endif
|
||||
|
||||
#include "stddef.h"
|
||||
#include <time.h>
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncStaticWebHandler: public AsyncWebHandler
|
||||
{
|
||||
using File = fs::File;
|
||||
using FS = fs::FS;
|
||||
|
||||
private:
|
||||
bool _getFile(AsyncWebServerRequest *request);
|
||||
bool _fileExists(AsyncWebServerRequest *request, const String& path);
|
||||
uint8_t _countBits(const uint8_t value) const;
|
||||
|
||||
protected:
|
||||
FS _fs;
|
||||
String _uri;
|
||||
String _path;
|
||||
String _default_file;
|
||||
String _cache_control;
|
||||
String _last_modified;
|
||||
AwsTemplateProcessor _callback;
|
||||
bool _isDir;
|
||||
bool _gzipFirst;
|
||||
uint8_t _gzipStats;
|
||||
|
||||
public:
|
||||
AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control);
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final;
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final;
|
||||
AsyncStaticWebHandler& setIsDir(bool isDir);
|
||||
AsyncStaticWebHandler& setDefaultFile(const char* filename);
|
||||
AsyncStaticWebHandler& setCacheControl(const char* cache_control);
|
||||
AsyncStaticWebHandler& setLastModified(const char* last_modified);
|
||||
AsyncStaticWebHandler& setLastModified(struct tm* last_modified);
|
||||
|
||||
AsyncStaticWebHandler& setTemplateProcessor(AwsTemplateProcessor newCallback)
|
||||
{
|
||||
_callback = newCallback;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncCallbackWebHandler: public AsyncWebHandler
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
String _uri;
|
||||
WebRequestMethodComposite _method;
|
||||
ArRequestHandlerFunction _onRequest;
|
||||
ArUploadHandlerFunction _onUpload;
|
||||
ArBodyHandlerFunction _onBody;
|
||||
bool _isRegex;
|
||||
|
||||
public:
|
||||
AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL),
|
||||
_isRegex(false) {}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void setUri(const String& uri)
|
||||
{
|
||||
_uri = uri;
|
||||
_isRegex = uri.startsWith("^") && uri.endsWith("$");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void setMethod(WebRequestMethodComposite method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void onRequest(ArRequestHandlerFunction fn)
|
||||
{
|
||||
_onRequest = fn;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void onUpload(ArUploadHandlerFunction fn)
|
||||
{
|
||||
_onUpload = fn;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline void onBody(ArBodyHandlerFunction fn)
|
||||
{
|
||||
_onBody = fn;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool canHandle(AsyncWebServerRequest *request) override final
|
||||
{
|
||||
if (!_onRequest)
|
||||
return false;
|
||||
|
||||
if (!(_method & request->method()))
|
||||
return false;
|
||||
|
||||
#ifdef ASYNCWEBSERVER_REGEX
|
||||
|
||||
if (_isRegex)
|
||||
{
|
||||
std::regex pattern(_uri.c_str());
|
||||
std::smatch matches;
|
||||
std::string s(request->url().c_str());
|
||||
|
||||
if (std::regex_search(s, matches, pattern))
|
||||
{
|
||||
for (size_t i = 1; i < matches.size(); ++i)
|
||||
{
|
||||
// start from 1
|
||||
request->_addPathParam(matches[i].str().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (_uri.length() && _uri.startsWith("/*."))
|
||||
{
|
||||
String uriTemplate = String (_uri);
|
||||
uriTemplate = uriTemplate.substring(uriTemplate.lastIndexOf("."));
|
||||
|
||||
if (!request->url().endsWith(uriTemplate))
|
||||
return false;
|
||||
}
|
||||
else if (_uri.length() && _uri.endsWith("*"))
|
||||
{
|
||||
String uriTemplate = String(_uri);
|
||||
uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1);
|
||||
|
||||
if (!request->url().startsWith(uriTemplate))
|
||||
return false;
|
||||
}
|
||||
else if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
|
||||
return false;
|
||||
|
||||
request->addInterestingHeader("ANY");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final
|
||||
{
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (_onRequest)
|
||||
_onRequest(request);
|
||||
else
|
||||
request->send(500);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
|
||||
size_t len, bool final) override final
|
||||
{
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (_onUpload)
|
||||
_onUpload(request, filename, index, data, len, final);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
|
||||
size_t total) override final
|
||||
{
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (_onBody)
|
||||
_onBody(request, data, len, index, total);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual bool isRequestHandlerTrivial() override final
|
||||
{
|
||||
return _onRequest ? false : true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ASYNCWEBSERVERHANDLERIMPL_H_ */
|
294
lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp
Normal file
294
lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp
Normal file
|
@ -0,0 +1,294 @@
|
|||
/****************************************************************************************************************************
|
||||
WebHandlers.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
|
||||
#include "WebHandlerImpl.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control)
|
||||
: _fs(fs), _uri(uri), _path(path), _default_file("index.htm"), _cache_control(cache_control), _last_modified(""),
|
||||
_callback(nullptr)
|
||||
{
|
||||
// Ensure leading '/'
|
||||
if (_uri.length() == 0 || _uri[0] != '/')
|
||||
_uri = "/" + _uri;
|
||||
|
||||
if (_path.length() == 0 || _path[0] != '/')
|
||||
_path = "/" + _path;
|
||||
|
||||
// If path ends with '/' we assume a hint that this is a directory to improve performance.
|
||||
// However - if it does not end with '/' we, can't assume a file, path can still be a directory.
|
||||
_isDir = _path[_path.length() - 1] == '/';
|
||||
|
||||
// Remove the trailing '/' so we can handle default file
|
||||
// Notice that root will be "" not "/"
|
||||
if (_uri[_uri.length() - 1] == '/')
|
||||
_uri = _uri.substring(0, _uri.length() - 1);
|
||||
|
||||
if (_path[_path.length() - 1] == '/')
|
||||
_path = _path.substring(0, _path.length() - 1);
|
||||
|
||||
// Reset stats
|
||||
_gzipFirst = false;
|
||||
_gzipStats = 0xF8;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setIsDir(bool isDir)
|
||||
{
|
||||
_isDir = isDir;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setDefaultFile(const char* filename)
|
||||
{
|
||||
_default_file = String(filename);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setCacheControl(const char* cache_control)
|
||||
{
|
||||
_cache_control = String(cache_control);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const char* last_modified)
|
||||
{
|
||||
_last_modified = String(last_modified);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(struct tm* last_modified)
|
||||
{
|
||||
char result[30];
|
||||
strftime (result, 30, "%a, %d %b %Y %H:%M:%S %Z", last_modified);
|
||||
|
||||
return setLastModified((const char *)result);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->method() != HTTP_GET || !request->url().startsWith(_uri)
|
||||
|| !request->isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_getFile(request))
|
||||
{
|
||||
// We interested in "If-Modified-Since" header to check if file was modified
|
||||
if (_last_modified.length())
|
||||
request->addInterestingHeader("If-Modified-Since");
|
||||
|
||||
if (_cache_control.length())
|
||||
request->addInterestingHeader("If-None-Match");
|
||||
|
||||
AWS_LOGDEBUG("[AsyncStaticWebHandler::canHandle] TRUE");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncStaticWebHandler::_getFile(AsyncWebServerRequest *request)
|
||||
{
|
||||
// Remove the found uri
|
||||
String path = request->url().substring(_uri.length());
|
||||
|
||||
// We can skip the file check and look for default if request is to the root of a directory or that request path ends with '/'
|
||||
bool canSkipFileCheck = (_isDir && path.length() == 0) || (path.length() && path[path.length() - 1] == '/');
|
||||
|
||||
path = _path + path;
|
||||
|
||||
// Do we have a file or .gz file
|
||||
if (!canSkipFileCheck && _fileExists(request, path))
|
||||
return true;
|
||||
|
||||
// Can't handle if not default file
|
||||
if (_default_file.length() == 0)
|
||||
return false;
|
||||
|
||||
// Try to add default file, ensure there is a trailing '/' ot the path.
|
||||
if (path.length() == 0 || path[path.length() - 1] != '/')
|
||||
path += "/";
|
||||
|
||||
path += _default_file;
|
||||
|
||||
return _fileExists(request, path);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define FILE_IS_REAL(f) (f == true && !f.isDirectory())
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest *request, const String& path)
|
||||
{
|
||||
bool fileFound = false;
|
||||
bool gzipFound = false;
|
||||
|
||||
String gzip = path + ".gz";
|
||||
|
||||
if (_gzipFirst)
|
||||
{
|
||||
request->_tempFile = _fs.open(gzip, "r");
|
||||
gzipFound = FILE_IS_REAL(request->_tempFile);
|
||||
|
||||
if (!gzipFound)
|
||||
{
|
||||
request->_tempFile = _fs.open(path, "r");
|
||||
fileFound = FILE_IS_REAL(request->_tempFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->_tempFile = _fs.open(path, "r");
|
||||
fileFound = FILE_IS_REAL(request->_tempFile);
|
||||
|
||||
if (!fileFound)
|
||||
{
|
||||
request->_tempFile = _fs.open(gzip, "r");
|
||||
gzipFound = FILE_IS_REAL(request->_tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
bool found = fileFound || gzipFound;
|
||||
|
||||
if (found)
|
||||
{
|
||||
// Extract the file name from the path and keep it in _tempObject
|
||||
size_t pathLen = path.length();
|
||||
char * _tempPath = (char*)malloc(pathLen + 1);
|
||||
snprintf(_tempPath, pathLen + 1, "%s", path.c_str());
|
||||
request->_tempObject = (void*)_tempPath;
|
||||
|
||||
// Calculate gzip statistic
|
||||
_gzipStats = (_gzipStats << 1) + (gzipFound ? 1 : 0);
|
||||
|
||||
if (_gzipStats == 0x00)
|
||||
_gzipFirst = false; // All files are not gzip
|
||||
else if (_gzipStats == 0xFF)
|
||||
_gzipFirst = true; // All files are gzip
|
||||
else
|
||||
_gzipFirst = _countBits(_gzipStats) > 4; // IF we have more gzip files - try gzip first
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
uint8_t AsyncStaticWebHandler::_countBits(const uint8_t value) const
|
||||
{
|
||||
uint8_t w = value;
|
||||
uint8_t n;
|
||||
|
||||
for (n = 0; w != 0; n++)
|
||||
w &= w - 1;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request)
|
||||
{
|
||||
// Get the filename from request->_tempObject and free it
|
||||
String filename = String((char*)request->_tempObject);
|
||||
free(request->_tempObject);
|
||||
request->_tempObject = NULL;
|
||||
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (request->_tempFile == true)
|
||||
{
|
||||
String etag = String(request->_tempFile.size());
|
||||
|
||||
if (_last_modified.length() && _last_modified == request->header("If-Modified-Since"))
|
||||
{
|
||||
request->_tempFile.close();
|
||||
request->send(304); // Not modified
|
||||
}
|
||||
else if (_cache_control.length() && request->hasHeader("If-None-Match")
|
||||
&& request->header("If-None-Match").equals(etag))
|
||||
{
|
||||
request->_tempFile.close();
|
||||
AsyncWebServerResponse * response = new AsyncBasicResponse(304); // Not modified
|
||||
|
||||
response->addHeader("Cache-Control", _cache_control);
|
||||
response->addHeader("ETag", etag);
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
AsyncWebServerResponse * response = new AsyncFileResponse(request->_tempFile, filename, String(), false, _callback);
|
||||
|
||||
if (_last_modified.length())
|
||||
response->addHeader("Last-Modified", _last_modified);
|
||||
|
||||
if (_cache_control.length())
|
||||
{
|
||||
response->addHeader("Cache-Control", _cache_control);
|
||||
response->addHeader("ETag", etag);
|
||||
}
|
||||
|
||||
request->send(response);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(404);
|
||||
}
|
||||
}
|
1753
lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp
Normal file
1753
lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp
Normal file
File diff suppressed because it is too large
Load diff
278
lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h
Normal file
278
lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h
Normal file
|
@ -0,0 +1,278 @@
|
|||
/****************************************************************************************************************************
|
||||
WebResponseImpl.h - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef ASYNCWEBSERVERRESPONSEIMPL_H_
|
||||
#define ASYNCWEBSERVERRESPONSEIMPL_H_
|
||||
|
||||
#ifdef Arduino_h
|
||||
// arduino is not compatible with std::vector
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max.
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncBasicResponse: public AsyncWebServerResponse
|
||||
{
|
||||
private:
|
||||
String _content;
|
||||
|
||||
char *_contentCstr; // RSMOD
|
||||
String _partialHeader;
|
||||
|
||||
public:
|
||||
AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String());
|
||||
|
||||
AsyncBasicResponse(int code, const String& contentType, const char *content = nullptr); // RSMOD
|
||||
|
||||
void _respond(AsyncWebServerRequest *request);
|
||||
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncAbstractResponse: public AsyncWebServerResponse
|
||||
{
|
||||
private:
|
||||
String _head;
|
||||
// Data is inserted into cache at begin().
|
||||
// This is inefficient with vector, but if we use some other container,
|
||||
// we won't be able to access it as contiguous array of bytes when reading from it,
|
||||
// so by gaining performance in one place, we'll lose it in another.
|
||||
std::vector<uint8_t> _cache;
|
||||
size_t _readDataFromCacheOrContent(uint8_t* data, const size_t len);
|
||||
size_t _fillBufferAndProcessTemplates(uint8_t* buf, size_t maxLen);
|
||||
|
||||
protected:
|
||||
AwsTemplateProcessor _callback;
|
||||
|
||||
public:
|
||||
AsyncAbstractResponse(AwsTemplateProcessor callback = nullptr);
|
||||
void _respond(AsyncWebServerRequest *request);
|
||||
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifndef TEMPLATE_PLACEHOLDER
|
||||
#define TEMPLATE_PLACEHOLDER '%'
|
||||
#endif
|
||||
|
||||
#define TEMPLATE_PARAM_NAME_LENGTH 32
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncFileResponse: public AsyncAbstractResponse
|
||||
{
|
||||
using File = fs::File;
|
||||
using FS = fs::FS;
|
||||
|
||||
private:
|
||||
File _content;
|
||||
String _path;
|
||||
void _setContentType(const String& path);
|
||||
|
||||
public:
|
||||
AsyncFileResponse(FS &fs, const String& path, const String& contentType = String(), bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
AsyncFileResponse(File content, const String& path, const String& contentType = String(), bool download = false,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
|
||||
~AsyncFileResponse();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return !!(_content);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncStreamResponse: public AsyncAbstractResponse
|
||||
{
|
||||
private:
|
||||
Stream *_content;
|
||||
|
||||
public:
|
||||
AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return !!(_content);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncCallbackResponse: public AsyncAbstractResponse
|
||||
{
|
||||
private:
|
||||
AwsResponseFiller _content;
|
||||
size_t _filledLength;
|
||||
|
||||
public:
|
||||
AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return !!(_content);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncChunkedResponse: public AsyncAbstractResponse
|
||||
{
|
||||
private:
|
||||
AwsResponseFiller _content;
|
||||
size_t _filledLength;
|
||||
|
||||
public:
|
||||
AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback,
|
||||
AwsTemplateProcessor templateCallback = nullptr);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return !!(_content);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncProgmemResponse: public AsyncAbstractResponse
|
||||
{
|
||||
private:
|
||||
const uint8_t * _content;
|
||||
size_t _readLength;
|
||||
|
||||
public:
|
||||
AsyncProgmemResponse(int code, const String& contentType, const uint8_t * content, size_t len,
|
||||
AwsTemplateProcessor callback = nullptr);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class cbuf;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class AsyncResponseStream: public AsyncAbstractResponse, public Print
|
||||
{
|
||||
private:
|
||||
cbuf *_content;
|
||||
|
||||
public:
|
||||
AsyncResponseStream(const String& contentType, size_t bufferSize);
|
||||
~AsyncResponseStream();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
inline bool _sourceValid() const
|
||||
{
|
||||
return (_state < RESPONSE_END);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
|
||||
size_t write(const uint8_t *data, size_t len);
|
||||
size_t write(uint8_t data);
|
||||
using Print::write;
|
||||
};
|
||||
|
||||
#endif /* ASYNCWEBSERVERRESPONSEIMPL_H_ */
|
1300
lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp
Normal file
1300
lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp
Normal file
File diff suppressed because it is too large
Load diff
315
lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp
Normal file
315
lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp
Normal file
|
@ -0,0 +1,315 @@
|
|||
/****************************************************************************************************************************
|
||||
WebServer.cpp - Dead simple Ethernet AsyncWebServer.
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
|
||||
Original author: Hristo Gochkov
|
||||
|
||||
Copyright (c) 2016 Hristo Gochkov. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along with this library;
|
||||
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version: 1.6.4
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2
|
||||
1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples
|
||||
1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
#include "WebHandlerImpl.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool ON_STA_FILTER(AsyncWebServerRequest *request)
|
||||
{
|
||||
return ETH.localIP() == request->client()->localIP();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool ON_AP_FILTER(AsyncWebServerRequest *request)
|
||||
{
|
||||
return ETH.localIP() != request->client()->localIP();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebServer::AsyncWebServer(uint16_t port)
|
||||
: _server(port),
|
||||
_rewrites(LinkedList<AsyncWebRewrite * >([](AsyncWebRewrite * r)
|
||||
{
|
||||
delete r;
|
||||
})),
|
||||
_handlers(LinkedList<AsyncWebHandler*>([](AsyncWebHandler* h)
|
||||
{
|
||||
delete h;
|
||||
}))
|
||||
{
|
||||
_catchAllHandler = new AsyncCallbackWebHandler();
|
||||
|
||||
if (_catchAllHandler == NULL)
|
||||
return;
|
||||
|
||||
_server.onClient([](void *s, AsyncClient * c)
|
||||
{
|
||||
if (c == NULL)
|
||||
return;
|
||||
|
||||
c->setRxTimeout(3);
|
||||
AsyncWebServerRequest *r = new AsyncWebServerRequest((AsyncWebServer*)s, c);
|
||||
|
||||
if (r == NULL)
|
||||
{
|
||||
c->close(true);
|
||||
c->free();
|
||||
delete c;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebServer::~AsyncWebServer()
|
||||
{
|
||||
reset();
|
||||
end();
|
||||
|
||||
if (_catchAllHandler)
|
||||
delete _catchAllHandler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebRewrite& AsyncWebServer::addRewrite(AsyncWebRewrite* rewrite)
|
||||
{
|
||||
_rewrites.add(rewrite);
|
||||
|
||||
return *rewrite;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncWebServer::removeRewrite(AsyncWebRewrite *rewrite)
|
||||
{
|
||||
return _rewrites.remove(rewrite);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebRewrite& AsyncWebServer::rewrite(const char* from, const char* to)
|
||||
{
|
||||
return addRewrite(new AsyncWebRewrite(from, to));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncWebHandler& AsyncWebServer::addHandler(AsyncWebHandler* handler)
|
||||
{
|
||||
_handlers.add(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
bool AsyncWebServer::removeHandler(AsyncWebHandler *handler)
|
||||
{
|
||||
return _handlers.remove(handler);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::begin()
|
||||
{
|
||||
_server.setNoDelay(true);
|
||||
_server.begin();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::end()
|
||||
{
|
||||
_server.end();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#if ASYNC_TCP_SSL_ENABLED
|
||||
|
||||
void AsyncWebServer::onSslFileRequest(AcSSlFileHandler cb, void* arg)
|
||||
{
|
||||
_server.onSslFileRequest(cb, arg);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::beginSecure(const char *cert, const char *key, const char *password)
|
||||
{
|
||||
_server.beginSecure(cert, key, password);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::_handleDisconnect(AsyncWebServerRequest *request)
|
||||
{
|
||||
delete request;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::_rewriteRequest(AsyncWebServerRequest *request)
|
||||
{
|
||||
for (const auto& r : _rewrites)
|
||||
{
|
||||
if (r->match(request))
|
||||
{
|
||||
request->_url = r->toUrl();
|
||||
request->_addGetParams(r->params());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::_attachHandler(AsyncWebServerRequest *request)
|
||||
{
|
||||
for (const auto& h : _handlers)
|
||||
{
|
||||
if (h->filter(request) && h->canHandle(request))
|
||||
{
|
||||
request->setHandler(h);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
request->addInterestingHeader("ANY");
|
||||
request->setHandler(_catchAllHandler);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method,
|
||||
ArRequestHandlerFunction onRequest,
|
||||
ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody)
|
||||
{
|
||||
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
|
||||
handler->setUri(uri);
|
||||
handler->setMethod(method);
|
||||
handler->onRequest(onRequest);
|
||||
handler->onUpload(onUpload);
|
||||
handler->onBody(onBody);
|
||||
addHandler(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method,
|
||||
ArRequestHandlerFunction onRequest,
|
||||
ArUploadHandlerFunction onUpload)
|
||||
{
|
||||
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
|
||||
handler->setUri(uri);
|
||||
handler->setMethod(method);
|
||||
handler->onRequest(onRequest);
|
||||
handler->onUpload(onUpload);
|
||||
addHandler(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method,
|
||||
ArRequestHandlerFunction onRequest)
|
||||
{
|
||||
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
|
||||
handler->setUri(uri);
|
||||
handler->setMethod(method);
|
||||
handler->onRequest(onRequest);
|
||||
addHandler(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, ArRequestHandlerFunction onRequest)
|
||||
{
|
||||
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
|
||||
handler->setUri(uri);
|
||||
handler->onRequest(onRequest);
|
||||
addHandler(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path,
|
||||
const char* cache_control)
|
||||
{
|
||||
AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control);
|
||||
addHandler(handler);
|
||||
|
||||
return *handler;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::onNotFound(ArRequestHandlerFunction fn)
|
||||
{
|
||||
_catchAllHandler->onRequest(fn);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::onFileUpload(ArUploadHandlerFunction fn)
|
||||
{
|
||||
_catchAllHandler->onUpload(fn);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::onRequestBody(ArBodyHandlerFunction fn)
|
||||
{
|
||||
_catchAllHandler->onBody(fn);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void AsyncWebServer::reset()
|
||||
{
|
||||
_rewrites.free();
|
||||
_handlers.free();
|
||||
|
||||
if (_catchAllHandler != NULL)
|
||||
{
|
||||
_catchAllHandler->onRequest(NULL);
|
||||
_catchAllHandler->onUpload(NULL);
|
||||
_catchAllHandler->onBody(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
|
627
lib/AsyncWebServer_ESP32_W5500/src/edit.htm
Normal file
627
lib/AsyncWebServer_ESP32_W5500/src/edit.htm
Normal file
|
@ -0,0 +1,627 @@
|
|||
<!--This is the plain html source of the hex encoded Editor-Page embedded in SPIFFSEditor.cpp -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>ESP Editor</title>
|
||||
<style type="text/css" media="screen">
|
||||
.cm {
|
||||
z-index: 300;
|
||||
position: absolute;
|
||||
left: 5px;
|
||||
border: 1px solid #444;
|
||||
background-color: #F5F5F5;
|
||||
display: none;
|
||||
box-shadow: 0 0 10px rgba( 0, 0, 0, .4 );
|
||||
font-size: 12px;
|
||||
font-family: sans-serif;
|
||||
font-weight:bold;
|
||||
}
|
||||
.cm ul {
|
||||
list-style: none;
|
||||
top: 0;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.cm li {
|
||||
position: relative;
|
||||
min-width: 60px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.cm span {
|
||||
color: #444;
|
||||
display: inline-block;
|
||||
padding: 6px;
|
||||
}
|
||||
.cm li:hover { background: #444; }
|
||||
.cm li:hover span { color: #EEE; }
|
||||
.tvu ul, .tvu li {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.tvu input {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
}
|
||||
.tvu {
|
||||
font: normal 12px Verdana, Arial, Sans-serif;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
color: #444;
|
||||
line-height: 16px;
|
||||
}
|
||||
.tvu span {
|
||||
margin-bottom:5px;
|
||||
padding: 0 0 0 18px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
height: 16px;
|
||||
vertical-align: middle;
|
||||
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADoSURBVBgZBcExblNBGAbA2ceegTRBuIKOgiihSZNTcC5LUHAihNJR0kGKCDcYJY6D3/77MdOinTvzAgCw8ysThIvn/VojIyMjIyPP+bS1sUQIV2s95pBDDvmbP/mdkft83tpYguZq5Jh/OeaYh+yzy8hTHvNlaxNNczm+la9OTlar1UdA/+C2A4trRCnD3jS8BB1obq2Gk6GU6QbQAS4BUaYSQAf4bhhKKTFdAzrAOwAxEUAH+KEM01SY3gM6wBsEAQB0gJ+maZoC3gI6iPYaAIBJsiRmHU0AALOeFC3aK2cWAACUXe7+AwO0lc9eTHYTAAAAAElFTkSuQmCC') no-repeat;
|
||||
background-position: 0px 0px;
|
||||
}
|
||||
.tvu span:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
@media screen and (-webkit-min-device-pixel-ratio:0){
|
||||
.tvu{
|
||||
-webkit-animation: webkit-adjacent-element-selector-bugfix infinite 1s;
|
||||
}
|
||||
|
||||
@-webkit-keyframes webkit-adjacent-element-selector-bugfix {
|
||||
from {
|
||||
padding: 0;
|
||||
}
|
||||
to {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#uploader {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
height:28px;
|
||||
line-height: 24px;
|
||||
padding-left: 10px;
|
||||
background-color: #444;
|
||||
color:#EEE;
|
||||
}
|
||||
#tree {
|
||||
position: absolute;
|
||||
top: 28px;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width:160px;
|
||||
padding: 8px;
|
||||
}
|
||||
#editor, #preview {
|
||||
position: absolute;
|
||||
top: 28px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 160px;
|
||||
border-left:1px solid #EEE;
|
||||
}
|
||||
#preview {
|
||||
background-color: #EEE;
|
||||
padding:5px;
|
||||
}
|
||||
#loader {
|
||||
position: absolute;
|
||||
top: 36%;
|
||||
right: 40%;
|
||||
}
|
||||
.loader {
|
||||
z-index: 10000;
|
||||
border: 8px solid #b5b5b5; /* Grey */
|
||||
border-top: 8px solid #3498db; /* Blue */
|
||||
border-bottom: 8px solid #3498db; /* Blue */
|
||||
border-radius: 50%;
|
||||
width: 240px;
|
||||
height: 240px;
|
||||
animation: spin 2s linear infinite;
|
||||
display:none;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
if (typeof XMLHttpRequest === "undefined") {
|
||||
XMLHttpRequest = function () {
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
|
||||
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
|
||||
throw new Error("This browser does not support XMLHttpRequest.");
|
||||
};
|
||||
}
|
||||
|
||||
function ge(a){
|
||||
return document.getElementById(a);
|
||||
}
|
||||
function ce(a){
|
||||
return document.createElement(a);
|
||||
}
|
||||
|
||||
function sortByKey(array, key) {
|
||||
return array.sort(function(a, b) {
|
||||
var x = a[key]; var y = b[key];
|
||||
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var QueuedRequester = function () {
|
||||
this.queue = [];
|
||||
this.running = false;
|
||||
this.xmlhttp = null;
|
||||
}
|
||||
QueuedRequester.prototype = {
|
||||
_request: function(req){
|
||||
this.running = true;
|
||||
if(!req instanceof Object) return;
|
||||
var that = this;
|
||||
|
||||
function ajaxCb(x,d){ return function(){
|
||||
if (x.readyState == 4){
|
||||
ge("loader").style.display = "none";
|
||||
d.callback(x.status, x.responseText);
|
||||
if(that.queue.length === 0) that.running = false;
|
||||
if(that.running) that._request(that.queue.shift());
|
||||
}
|
||||
}}
|
||||
|
||||
ge("loader").style.display = "block";
|
||||
|
||||
var p = "";
|
||||
if(req.params instanceof FormData){
|
||||
p = req.params;
|
||||
} else if(req.params instanceof Object){
|
||||
for (var key in req.params) {
|
||||
if(p === "")
|
||||
p += (req.method === "GET")?"?":"";
|
||||
else
|
||||
p += "&";
|
||||
p += encodeURIComponent(key)+"="+encodeURIComponent(req.params[key]);
|
||||
};
|
||||
}
|
||||
|
||||
this.xmlhttp = new XMLHttpRequest();
|
||||
this.xmlhttp.onreadystatechange = ajaxCb(this.xmlhttp, req);
|
||||
if(req.method === "GET"){
|
||||
this.xmlhttp.open(req.method, req.url+p, true);
|
||||
this.xmlhttp.send();
|
||||
} else {
|
||||
this.xmlhttp.open(req.method, req.url, true);
|
||||
if(p instanceof String)
|
||||
this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
this.xmlhttp.send(p);
|
||||
}
|
||||
},
|
||||
stop: function(){
|
||||
if(this.running) this.running = false;
|
||||
if(this.xmlhttp && this.xmlhttp.readyState < 4){
|
||||
this.xmlhttp.abort();
|
||||
}
|
||||
},
|
||||
add: function(method, url, params, callback){
|
||||
this.queue.push({url:url,method:method,params:params,callback:callback});
|
||||
if(!this.running){
|
||||
this._request(this.queue.shift());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var requests = new QueuedRequester();
|
||||
|
||||
function createFileUploader(element, tree, editor){
|
||||
var xmlHttp;
|
||||
|
||||
var refresh = ce("button");
|
||||
refresh.innerHTML = 'Refresh List';
|
||||
ge(element).appendChild(refresh);
|
||||
|
||||
var input = ce("input");
|
||||
input.type = "file";
|
||||
input.multiple = false;
|
||||
input.name = "data";
|
||||
input.id="upload-select";
|
||||
ge(element).appendChild(input);
|
||||
|
||||
var path = ce("input");
|
||||
path.id = "upload-path";
|
||||
path.type = "text";
|
||||
path.name = "path";
|
||||
path.defaultValue = "/";
|
||||
ge(element).appendChild(path);
|
||||
|
||||
var button = ce("button");
|
||||
button.innerHTML = 'Upload';
|
||||
ge(element).appendChild(button);
|
||||
|
||||
var mkfile = ce("button");
|
||||
mkfile.innerHTML = 'Create';
|
||||
ge(element).appendChild(mkfile);
|
||||
|
||||
var filename = ce("input");
|
||||
filename.id = "editor-filename";
|
||||
filename.type = "text";
|
||||
filename.disabled= true;
|
||||
filename.size = 20;
|
||||
ge(element).appendChild(filename);
|
||||
|
||||
var savefile = ce("button");
|
||||
savefile.innerHTML = ' Save ' ;
|
||||
ge(element).appendChild(savefile);
|
||||
|
||||
function httpPostProcessRequest(status, responseText){
|
||||
if(status != 200)
|
||||
alert("ERROR["+status+"]: "+responseText);
|
||||
else
|
||||
tree.refreshPath(path.value);
|
||||
}
|
||||
function createPath(p){
|
||||
var formData = new FormData();
|
||||
formData.append("path", p);
|
||||
requests.add("PUT", "/edit", formData, httpPostProcessRequest);
|
||||
}
|
||||
|
||||
mkfile.onclick = function(e){
|
||||
createPath(path.value);
|
||||
editor.loadUrl(path.value);
|
||||
path.value="/";
|
||||
};
|
||||
|
||||
savefile.onclick = function(e){
|
||||
editor.execCommand('saveCommand');
|
||||
};
|
||||
|
||||
refresh.onclick = function(e){
|
||||
tree.refreshPath(path.value);
|
||||
};
|
||||
|
||||
button.onclick = function(e){
|
||||
if(input.files.length === 0){
|
||||
return;
|
||||
}
|
||||
var formData = new FormData();
|
||||
formData.append("data", input.files[0], path.value);
|
||||
requests.add("POST", "/edit", formData, httpPostProcessRequest);
|
||||
var uploadPath= ge("upload-path");
|
||||
uploadPath.value="/";
|
||||
var uploadSelect= ge("upload-select");
|
||||
uploadSelect.value="";
|
||||
};
|
||||
input.onchange = function(e){
|
||||
if(input.files.length === 0) return;
|
||||
var filename = input.files[0].name;
|
||||
var ext = /(?:\.([^.]+))?$/.exec(filename)[1];
|
||||
var name = /(.*)\.[^.]+$/.exec(filename)[1];
|
||||
if(typeof name !== undefined){
|
||||
filename = name;
|
||||
}
|
||||
path.value = "/"+filename+"."+ext;
|
||||
};
|
||||
}
|
||||
|
||||
function createTree(element, editor){
|
||||
var preview = ge("preview");
|
||||
var treeRoot = ce("div");
|
||||
treeRoot.className = "tvu";
|
||||
ge(element).appendChild(treeRoot);
|
||||
|
||||
function loadDownload(path){
|
||||
ge('download-frame').src = "/edit?download="+path;
|
||||
}
|
||||
|
||||
function loadPreview(path){
|
||||
var edfname = ge("editor-filename");
|
||||
edfname.value=path;
|
||||
ge("editor").style.display = "none";
|
||||
preview.style.display = "block";
|
||||
preview.innerHTML = '<img src="/edit?edit='+path+'&_cb='+Date.now()+'" style="max-width:100%; max-height:100%; margin:auto; display:block;" />';
|
||||
}
|
||||
|
||||
function fillFileMenu(el, path){
|
||||
var list = ce("ul");
|
||||
el.appendChild(list);
|
||||
var action = ce("li");
|
||||
list.appendChild(action);
|
||||
if(isImageFile(path)){
|
||||
action.innerHTML = "<span>Preview</span>";
|
||||
action.onclick = function(e){
|
||||
loadPreview(path);
|
||||
if(document.body.getElementsByClassName('cm').length > 0) document.body.removeChild(el);
|
||||
};
|
||||
} else if(isTextFile(path)){
|
||||
action.innerHTML = "<span>Edit</span>";
|
||||
action.onclick = function(e){
|
||||
editor.loadUrl(path);
|
||||
if(document.body.getElementsByClassName('cm').length > 0) document.body.removeChild(el);
|
||||
};
|
||||
}
|
||||
var download = ce("li");
|
||||
list.appendChild(download);
|
||||
download.innerHTML = "<span>Download</span>";
|
||||
download.onclick = function(e){
|
||||
loadDownload(path);
|
||||
if(document.body.getElementsByClassName('cm').length > 0) document.body.removeChild(el);
|
||||
};
|
||||
var delFile = ce("li");
|
||||
list.appendChild(delFile);
|
||||
delFile.innerHTML = "<span>Delete</span>";
|
||||
delFile.onclick = function(e){
|
||||
httpDelete(path);
|
||||
if(document.body.getElementsByClassName('cm').length > 0) document.body.removeChild(el);
|
||||
};
|
||||
}
|
||||
|
||||
function showContextMenu(event, path, isfile){
|
||||
var divContext = ce("div");
|
||||
var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
|
||||
var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
|
||||
var left = event.clientX + scrollLeft;
|
||||
var top = event.clientY + scrollTop;
|
||||
divContext.className = 'cm';
|
||||
divContext.style.display = 'block';
|
||||
divContext.style.left = left + 'px';
|
||||
divContext.style.top = top + 'px';
|
||||
fillFileMenu(divContext, path);
|
||||
document.body.appendChild(divContext);
|
||||
var width = divContext.offsetWidth;
|
||||
var height = divContext.offsetHeight;
|
||||
divContext.onmouseout = function(e){
|
||||
if(e.clientX < left || e.clientX > (left + width) || e.clientY < top || e.clientY > (top + height)){
|
||||
if(document.body.getElementsByClassName('cm').length > 0) document.body.removeChild(divContext);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createTreeLeaf(path, name, size){
|
||||
var leaf = ce("li");
|
||||
leaf.id = name;
|
||||
var label = ce("span");
|
||||
label.innerHTML = name;
|
||||
leaf.appendChild(label);
|
||||
leaf.onclick = function(e){
|
||||
if(isTextFile(leaf.id.toLowerCase())){
|
||||
editor.loadUrl(leaf.id);
|
||||
} else if(isImageFile(leaf.id.toLowerCase())){
|
||||
loadPreview(leaf.id);
|
||||
}
|
||||
};
|
||||
leaf.oncontextmenu = function(e){
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
showContextMenu(e, leaf.id, true);
|
||||
};
|
||||
return leaf;
|
||||
}
|
||||
|
||||
function addList(parent, path, items){
|
||||
sortByKey(items, 'name');
|
||||
var list = ce("ul");
|
||||
parent.appendChild(list);
|
||||
var ll = items.length;
|
||||
for(var i = 0; i < ll; i++){
|
||||
if(items[i].type === "file")
|
||||
list.appendChild(createTreeLeaf(path, items[i].name, items[i].size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isTextFile(path){
|
||||
var ext = /(?:\.([^.]+))?$/.exec(path)[1];
|
||||
if(typeof ext !== undefined){
|
||||
switch(ext){
|
||||
case "txt":
|
||||
case "htm":
|
||||
case "html":
|
||||
case "js":
|
||||
case "css":
|
||||
case "xml":
|
||||
case "json":
|
||||
case "conf":
|
||||
case "ini":
|
||||
case "h":
|
||||
case "c":
|
||||
case "cpp":
|
||||
case "php":
|
||||
case "hex":
|
||||
case "ino":
|
||||
case "pde":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isImageFile(path){
|
||||
var ext = /(?:\.([^.]+))?$/.exec(path)[1];
|
||||
if(typeof ext !== undefined){
|
||||
switch(ext){
|
||||
case "png":
|
||||
case "jpg":
|
||||
case "gif":
|
||||
case "bmp":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.refreshPath = function(path){
|
||||
treeRoot.removeChild(treeRoot.childNodes[0]);
|
||||
httpGet(treeRoot, "/");
|
||||
};
|
||||
|
||||
function delCb(path){
|
||||
return function(status, responseText){
|
||||
if(status != 200){
|
||||
alert("ERROR["+status+"]: "+responseText);
|
||||
} else {
|
||||
treeRoot.removeChild(treeRoot.childNodes[0]);
|
||||
httpGet(treeRoot, "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function httpDelete(filename){
|
||||
var formData = new FormData();
|
||||
formData.append("path", filename);
|
||||
requests.add("DELETE", "/edit", formData, delCb(filename));
|
||||
}
|
||||
|
||||
function getCb(parent, path){
|
||||
return function(status, responseText){
|
||||
if(status == 200)
|
||||
addList(parent, path, JSON.parse(responseText));
|
||||
}
|
||||
}
|
||||
|
||||
function httpGet(parent, path){
|
||||
requests.add("GET", "/edit", { list: path }, getCb(parent, path));
|
||||
}
|
||||
|
||||
httpGet(treeRoot, "/");
|
||||
return this;
|
||||
}
|
||||
|
||||
function createEditor(element, file, lang, theme, type){
|
||||
function getLangFromFilename(filename){
|
||||
var lang = "plain";
|
||||
var ext = /(?:\.([^.]+))?$/.exec(filename)[1];
|
||||
if(typeof ext !== undefined){
|
||||
switch(ext){
|
||||
case "txt": lang = "plain"; break;
|
||||
case "hex": lang = "plain"; break;
|
||||
case "conf": lang = "plain"; break;
|
||||
case "htm": lang = "html"; break;
|
||||
case "js": lang = "javascript"; break;
|
||||
case "h": lang = "c_cpp"; break;
|
||||
case "c": lang = "c_cpp"; break;
|
||||
case "cpp": lang = "c_cpp"; break;
|
||||
case "css":
|
||||
case "scss":
|
||||
case "php":
|
||||
case "html":
|
||||
case "json":
|
||||
case "xml":
|
||||
case "ini": lang = ext;
|
||||
}
|
||||
}
|
||||
return lang;
|
||||
}
|
||||
|
||||
if(typeof file === "undefined") file = "/index.html";
|
||||
|
||||
if(typeof lang === "undefined"){
|
||||
lang = getLangFromFilename(file);
|
||||
}
|
||||
|
||||
if(typeof theme === "undefined") theme = "textmate";
|
||||
|
||||
if(typeof type === "undefined"){
|
||||
type = "text/"+lang;
|
||||
if(lang === "c_cpp") type = "text/plain";
|
||||
}
|
||||
|
||||
var editor = ace.edit(element);
|
||||
function httpPostProcessRequest(status, responseText){
|
||||
if(status != 200) alert("ERROR["+status+"]: "+responseText);
|
||||
}
|
||||
function httpPost(filename, data, type){
|
||||
var formData = new FormData();
|
||||
formData.append("data", new Blob([data], { type: type }), filename);
|
||||
requests.add("POST", "/edit", formData, httpPostProcessRequest);
|
||||
}
|
||||
function httpGetProcessRequest(status, responseText){
|
||||
ge("preview").style.display = "none";
|
||||
ge("editor").style.display = "block";
|
||||
if(status == 200)
|
||||
editor.setValue(responseText);
|
||||
else
|
||||
editor.setValue("");
|
||||
editor.clearSelection();
|
||||
}
|
||||
function httpGet(theUrl){
|
||||
requests.add("GET", "/edit", { edit: theUrl }, httpGetProcessRequest);
|
||||
}
|
||||
|
||||
if(lang !== "plain") editor.getSession().setMode("ace/mode/"+lang);
|
||||
editor.setTheme("ace/theme/"+theme);
|
||||
editor.$blockScrolling = Infinity;
|
||||
editor.getSession().setUseSoftTabs(true);
|
||||
editor.getSession().setTabSize(2);
|
||||
editor.setHighlightActiveLine(true);
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.commands.addCommand({
|
||||
name: 'saveCommand',
|
||||
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
|
||||
exec: function(editor) {
|
||||
httpPost(file, editor.getValue()+"", type);
|
||||
},
|
||||
readOnly: false
|
||||
});
|
||||
editor.commands.addCommand({
|
||||
name: 'undoCommand',
|
||||
bindKey: {win: 'Ctrl-Z', mac: 'Command-Z'},
|
||||
exec: function(editor) {
|
||||
editor.getSession().getUndoManager().undo(false);
|
||||
},
|
||||
readOnly: false
|
||||
});
|
||||
editor.commands.addCommand({
|
||||
name: 'redoCommand',
|
||||
bindKey: {win: 'Ctrl-Shift-Z', mac: 'Command-Shift-Z'},
|
||||
exec: function(editor) {
|
||||
editor.getSession().getUndoManager().redo(false);
|
||||
},
|
||||
readOnly: false
|
||||
});
|
||||
editor.loadUrl = function(filename){
|
||||
var edfname = ge("editor-filename");
|
||||
edfname.value=filename;
|
||||
file = filename;
|
||||
lang = getLangFromFilename(file);
|
||||
type = "text/"+lang;
|
||||
if(lang !== "plain") editor.getSession().setMode("ace/mode/"+lang);
|
||||
httpGet(file);
|
||||
};
|
||||
return editor;
|
||||
}
|
||||
function onBodyLoad(){
|
||||
var vars = {};
|
||||
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; });
|
||||
var editor = createEditor("editor", vars.file, vars.lang, vars.theme);
|
||||
var tree = createTree("tree", editor);
|
||||
createFileUploader("uploader", tree, editor);
|
||||
if(typeof vars.file === "undefined") vars.file = "/index.htm";
|
||||
editor.loadUrl(vars.file);
|
||||
};
|
||||
</script>
|
||||
<script id='ace' src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script>
|
||||
if (typeof ace.edit == "undefined") {
|
||||
var script = document.createElement('script');
|
||||
script.src = "/ace.js";
|
||||
script.async = false;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onBodyLoad();">
|
||||
<div id="loader" class="loader"></div>
|
||||
<div id="uploader"></div>
|
||||
<div id="tree"></div>
|
||||
<div id="editor"></div>
|
||||
<div id="preview" style="display:none;"></div>
|
||||
<iframe id=download-frame style='display:none;'></iframe>
|
||||
</body>
|
||||
</html>
|
150
lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c
Normal file
150
lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c
Normal file
|
@ -0,0 +1,150 @@
|
|||
/****************************************************************************************************************************
|
||||
cdecode.c - c source to a base64 decoding algorithm implementation
|
||||
|
||||
This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "cdecode.h"
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_decode_value(int value_in)
|
||||
{
|
||||
static const char decoding[] =
|
||||
{
|
||||
62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2,
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1,
|
||||
-1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
|
||||
47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
static const char decoding_size = sizeof(decoding);
|
||||
value_in -= 43;
|
||||
|
||||
if (value_in < 0 || value_in > decoding_size)
|
||||
return -1;
|
||||
|
||||
return decoding[(int)value_in];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void base64_init_decodestate(base64_decodestate* state_in)
|
||||
{
|
||||
state_in->step = step_a;
|
||||
state_in->plainchar = 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in)
|
||||
{
|
||||
const char* codechar = code_in;
|
||||
char* plainchar = plaintext_out;
|
||||
int fragment;
|
||||
|
||||
*plainchar = state_in->plainchar;
|
||||
|
||||
switch (state_in->step)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
case step_a:
|
||||
do
|
||||
{
|
||||
if (codechar == code_in + length_in)
|
||||
{
|
||||
state_in->step = step_a;
|
||||
state_in->plainchar = *plainchar;
|
||||
return plainchar - plaintext_out;
|
||||
}
|
||||
|
||||
fragment = base64_decode_value(*codechar++);
|
||||
} while (fragment < 0);
|
||||
|
||||
*plainchar = (fragment & 0x03f) << 2;
|
||||
|
||||
// fall through
|
||||
|
||||
case step_b:
|
||||
do
|
||||
{
|
||||
if (codechar == code_in + length_in)
|
||||
{
|
||||
state_in->step = step_b;
|
||||
state_in->plainchar = *plainchar;
|
||||
return plainchar - plaintext_out;
|
||||
}
|
||||
|
||||
fragment = base64_decode_value(*codechar++);
|
||||
} while (fragment < 0);
|
||||
|
||||
*plainchar++ |= (fragment & 0x030) >> 4;
|
||||
*plainchar = (fragment & 0x00f) << 4;
|
||||
|
||||
// fall through
|
||||
|
||||
case step_c:
|
||||
do
|
||||
{
|
||||
if (codechar == code_in + length_in)
|
||||
{
|
||||
state_in->step = step_c;
|
||||
state_in->plainchar = *plainchar;
|
||||
return plainchar - plaintext_out;
|
||||
}
|
||||
|
||||
fragment = base64_decode_value(*codechar++);
|
||||
} while (fragment < 0);
|
||||
|
||||
*plainchar++ |= (fragment & 0x03c) >> 2;
|
||||
*plainchar = (fragment & 0x003) << 6;
|
||||
|
||||
// fall through
|
||||
|
||||
case step_d:
|
||||
do
|
||||
{
|
||||
if (codechar == code_in + length_in)
|
||||
{
|
||||
state_in->step = step_d;
|
||||
state_in->plainchar = *plainchar;
|
||||
return plainchar - plaintext_out;
|
||||
}
|
||||
|
||||
fragment = base64_decode_value(*codechar++);
|
||||
} while (fragment < 0);
|
||||
|
||||
*plainchar++ |= (fragment & 0x03f);
|
||||
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
/* control should not reach here */
|
||||
return plainchar - plaintext_out;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out)
|
||||
{
|
||||
|
||||
base64_decodestate _state;
|
||||
base64_init_decodestate(&_state);
|
||||
int len = base64_decode_block(code_in, length_in, plaintext_out, &_state);
|
||||
|
||||
if (len > 0)
|
||||
plaintext_out[len] = 0;
|
||||
|
||||
return len;
|
||||
}
|
62
lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h
Normal file
62
lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/****************************************************************************************************************************
|
||||
cdecode.h - c header for a base64 decoding algorithm
|
||||
|
||||
This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Reintroduce to prevent duplication compile error if other lib/core already has LIB64
|
||||
// pragma once can't prevent that
|
||||
#ifndef BASE64_CDECODE_H
|
||||
#define BASE64_CDECODE_H
|
||||
|
||||
#define base64_decode_expected_len(n) ((n * 3) / 4)
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef enum
|
||||
{
|
||||
step_a, step_b, step_c, step_d
|
||||
} base64_decodestep;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
base64_decodestep step;
|
||||
char plainchar;
|
||||
} base64_decodestate;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void base64_init_decodestate(base64_decodestate* state_in);
|
||||
|
||||
int base64_decode_value(int value_in);
|
||||
|
||||
int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in);
|
||||
|
||||
int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif /* BASE64_CDECODE_H */
|
154
lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c
Normal file
154
lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c
Normal file
|
@ -0,0 +1,154 @@
|
|||
/****************************************************************************************************************************
|
||||
cencode.c - c source to a base64 encoding algorithm implementation
|
||||
|
||||
This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "cencode.h"
|
||||
|
||||
const int CHARS_PER_LINE = 72;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void base64_init_encodestate(base64_encodestate* state_in)
|
||||
{
|
||||
state_in->step = step_A;
|
||||
state_in->result = 0;
|
||||
state_in->stepcount = 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
char base64_encode_value(char value_in)
|
||||
{
|
||||
static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
if (value_in > 63)
|
||||
return '=';
|
||||
|
||||
return encoding[(unsigned int)value_in];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in)
|
||||
{
|
||||
const char* plainchar = plaintext_in;
|
||||
const char* const plaintextend = plaintext_in + length_in;
|
||||
char* codechar = code_out;
|
||||
char result;
|
||||
char fragment;
|
||||
|
||||
result = state_in->result;
|
||||
|
||||
switch (state_in->step)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
case step_A:
|
||||
if (plainchar == plaintextend)
|
||||
{
|
||||
state_in->result = result;
|
||||
state_in->step = step_A;
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
||||
fragment = *plainchar++;
|
||||
result = (fragment & 0x0fc) >> 2;
|
||||
*codechar++ = base64_encode_value(result);
|
||||
result = (fragment & 0x003) << 4;
|
||||
|
||||
// fall through
|
||||
|
||||
case step_B:
|
||||
if (plainchar == plaintextend)
|
||||
{
|
||||
state_in->result = result;
|
||||
state_in->step = step_B;
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
||||
fragment = *plainchar++;
|
||||
result |= (fragment & 0x0f0) >> 4;
|
||||
*codechar++ = base64_encode_value(result);
|
||||
result = (fragment & 0x00f) << 2;
|
||||
|
||||
// fall through
|
||||
|
||||
case step_C:
|
||||
if (plainchar == plaintextend)
|
||||
{
|
||||
state_in->result = result;
|
||||
state_in->step = step_C;
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
||||
fragment = *plainchar++;
|
||||
result |= (fragment & 0x0c0) >> 6;
|
||||
*codechar++ = base64_encode_value(result);
|
||||
result = (fragment & 0x03f) >> 0;
|
||||
*codechar++ = base64_encode_value(result);
|
||||
|
||||
++(state_in->stepcount);
|
||||
|
||||
if (state_in->stepcount == CHARS_PER_LINE / 4)
|
||||
{
|
||||
*codechar++ = '\n';
|
||||
state_in->stepcount = 0;
|
||||
}
|
||||
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
/* control should not reach here */
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
|
||||
{
|
||||
char* codechar = code_out;
|
||||
|
||||
switch (state_in->step)
|
||||
{
|
||||
case step_B:
|
||||
*codechar++ = base64_encode_value(state_in->result);
|
||||
*codechar++ = '=';
|
||||
*codechar++ = '=';
|
||||
break;
|
||||
|
||||
case step_C:
|
||||
*codechar++ = base64_encode_value(state_in->result);
|
||||
*codechar++ = '=';
|
||||
break;
|
||||
|
||||
case step_A:
|
||||
break;
|
||||
}
|
||||
|
||||
*codechar = 0x00;
|
||||
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out)
|
||||
{
|
||||
base64_encodestate _state;
|
||||
base64_init_encodestate(&_state);
|
||||
int len = base64_encode_block(plaintext_in, length_in, code_out, &_state);
|
||||
|
||||
return len + base64_encode_blockend((code_out + len), &_state);
|
||||
}
|
65
lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h
Normal file
65
lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************************************************************
|
||||
cencode.h - c header for a base64 encoding algorithm
|
||||
|
||||
This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Reintroduce to prevent duplication compile error if other lib/core already has LIB64
|
||||
// pragma once can't prevent that
|
||||
#ifndef BASE64_CENCODE_H
|
||||
#define BASE64_CENCODE_H
|
||||
|
||||
#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3)
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef enum
|
||||
{
|
||||
step_A, step_B, step_C
|
||||
} base64_encodestep;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
base64_encodestep step;
|
||||
char result;
|
||||
int stepcount;
|
||||
} base64_encodestate;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void base64_init_encodestate(base64_encodestate* state_in);
|
||||
|
||||
char base64_encode_value(char value_in);
|
||||
|
||||
int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
|
||||
|
||||
int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
|
||||
|
||||
int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif /* BASE64_CENCODE_H */
|
412
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp
Normal file
412
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp
Normal file
|
@ -0,0 +1,412 @@
|
|||
/****************************************************************************************************************************
|
||||
esp32_w5500.cpp
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncWebServer_ESP32_W5500_Debug.h"
|
||||
#include "esp32_w5500.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
esp_eth_mac_t* w5500_begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ,
|
||||
int SPIHOST);
|
||||
#include "esp_eth/esp_eth_w5500.h"
|
||||
}
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "esp_eth_phy.h"
|
||||
#include "esp_eth_mac.h"
|
||||
#include "esp_eth_com.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "soc/emac_ext_struct.h"
|
||||
#include "soc/rtc.h"
|
||||
#endif
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
extern void tcpipInit();
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
ESP32_W5500::ESP32_W5500()
|
||||
: initialized(false)
|
||||
, staticIP(false)
|
||||
, eth_handle(NULL)
|
||||
, started(false)
|
||||
, eth_link(ETH_LINK_DOWN)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
ESP32_W5500::~ESP32_W5500()
|
||||
{}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ, int SPIHOST,
|
||||
uint8_t *W5500_Mac)
|
||||
{
|
||||
tcpipInit();
|
||||
|
||||
esp_base_mac_addr_set( W5500_Mac );
|
||||
|
||||
tcpip_adapter_set_default_eth_handlers();
|
||||
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t *eth_netif = esp_netif_new(&cfg);
|
||||
|
||||
esp_eth_mac_t *eth_mac = w5500_begin(MISO, MOSI, SCLK, CS, INT, SPICLOCK_MHZ, SPIHOST);
|
||||
|
||||
if (eth_mac == NULL)
|
||||
{
|
||||
AWS_LOGERROR("esp_eth_mac_new_esp32 failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
phy_config.autonego_timeout_ms = 0; // W5500 doesn't support auto-negotiation
|
||||
phy_config.reset_gpio_num = -1; // W5500 doesn't have a pin to reset internal PHY
|
||||
esp_eth_phy_t *eth_phy = esp_eth_phy_new_w5500(&phy_config);
|
||||
|
||||
if (eth_phy == NULL)
|
||||
{
|
||||
AWS_LOGERROR("esp_eth_phy_new failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
eth_handle = NULL;
|
||||
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy);
|
||||
|
||||
if (esp_eth_driver_install(ð_config, ð_handle) != ESP_OK || eth_handle == NULL)
|
||||
{
|
||||
AWS_LOG("esp_eth_driver_install failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
eth_mac->set_addr(eth_mac, W5500_Mac);
|
||||
|
||||
#if 1
|
||||
|
||||
if ( (SPICLOCK_MHZ < 14) || (SPICLOCK_MHZ > 25) )
|
||||
{
|
||||
AWS_LOGERROR("SPI Clock must be >= 8 and <= 25 MHz for W5500");
|
||||
ESP_ERROR_CHECK(ESP_FAIL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* attach Ethernet driver to TCP/IP stack */
|
||||
if (esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)) != ESP_OK)
|
||||
{
|
||||
AWS_LOGERROR("esp_netif_attach failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_eth_start(eth_handle) != ESP_OK)
|
||||
{
|
||||
AWS_LOG("esp_eth_start failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// holds a few microseconds to let DHCP start and enter into a good state
|
||||
// FIX ME -- addresses issue https://github.com/espressif/arduino-esp32/issues/5733
|
||||
delay(50);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
tcpip_adapter_ip_info_t info;
|
||||
|
||||
if (static_cast<uint32_t>(local_ip) != 0)
|
||||
{
|
||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||
info.netmask.addr = static_cast<uint32_t>(subnet);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.ip.addr = 0;
|
||||
info.gw.addr = 0;
|
||||
info.netmask.addr = 0;
|
||||
}
|
||||
|
||||
err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
|
||||
|
||||
if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED)
|
||||
{
|
||||
AWS_LOGERROR1("DHCP could not be stopped! Error =", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &info);
|
||||
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
AWS_LOGERROR1("STA IP could not be configured! Error = ", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.ip.addr)
|
||||
{
|
||||
staticIP = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_ETH);
|
||||
|
||||
if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED)
|
||||
{
|
||||
AWS_LOGWARN1("DHCP could not be started! Error =", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
staticIP = false;
|
||||
}
|
||||
|
||||
ip_addr_t d;
|
||||
d.type = IPADDR_TYPE_V4;
|
||||
|
||||
if (static_cast<uint32_t>(dns1) != 0)
|
||||
{
|
||||
// Set DNS1-Server
|
||||
d.u_addr.ip4.addr = static_cast<uint32_t>(dns1);
|
||||
dns_setserver(0, &d);
|
||||
}
|
||||
|
||||
if (static_cast<uint32_t>(dns2) != 0)
|
||||
{
|
||||
// Set DNS2-Server
|
||||
d.u_addr.ip4.addr = static_cast<uint32_t>(dns2);
|
||||
dns_setserver(1, &d);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::localIP()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
AWS_LOGDEBUG("localIP NULL");
|
||||
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
AWS_LOGDEBUG1("localIP =", IPAddress(ip.ip.addr));
|
||||
|
||||
return IPAddress(ip.ip.addr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::subnetMask()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
return IPAddress(ip.netmask.addr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::gatewayIP()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
return IPAddress(ip.gw.addr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::dnsIP(uint8_t dns_no)
|
||||
{
|
||||
const ip_addr_t * dns_ip = dns_getserver(dns_no);
|
||||
|
||||
return IPAddress(dns_ip->u_addr.ip4.addr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::broadcastIP()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPAddress ESP32_W5500::networkID()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
uint8_t ESP32_W5500::subnetCIDR()
|
||||
{
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip))
|
||||
{
|
||||
return (uint8_t)0;
|
||||
}
|
||||
|
||||
return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
const char * ESP32_W5500::getHostname()
|
||||
{
|
||||
const char * hostname;
|
||||
|
||||
if (tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_ETH, &hostname))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::setHostname(const char * hostname)
|
||||
{
|
||||
return tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_ETH, hostname) == 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::fullDuplex()
|
||||
{
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
return true;//todo: do not see an API for this
|
||||
#else
|
||||
return eth_config.phy_get_duplex_mode();
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::linkUp()
|
||||
{
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
return eth_link == ETH_LINK_UP;
|
||||
#else
|
||||
return eth_config.phy_check_link();
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
uint8_t ESP32_W5500::linkSpeed()
|
||||
{
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
eth_speed_t link_speed;
|
||||
esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed);
|
||||
return (link_speed == ETH_SPEED_10M) ? 10 : 100;
|
||||
#else
|
||||
return eth_config.phy_get_speed_mode() ? 100 : 10;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
bool ESP32_W5500::enableIpV6()
|
||||
{
|
||||
return tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_ETH) == 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IPv6Address ESP32_W5500::localIPv6()
|
||||
{
|
||||
static ip6_addr_t addr;
|
||||
|
||||
if (tcpip_adapter_get_ip6_linklocal(TCPIP_ADAPTER_IF_ETH, &addr))
|
||||
{
|
||||
return IPv6Address();
|
||||
}
|
||||
|
||||
return IPv6Address(addr.addr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
uint8_t * ESP32_W5500::macAddress(uint8_t* mac)
|
||||
{
|
||||
if (!mac)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac);
|
||||
#else
|
||||
esp_eth_get_mac(mac);
|
||||
#endif
|
||||
|
||||
return mac;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
String ESP32_W5500::macAddress()
|
||||
{
|
||||
uint8_t mac[6] = {0, 0, 0, 0, 0, 0};
|
||||
char macStr[18] = { 0 };
|
||||
macAddress(mac);
|
||||
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
return String(macStr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
ESP32_W5500 ETH;
|
94
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h
Normal file
94
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/****************************************************************************************************************************
|
||||
esp32_w5500.h
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#ifndef _ESP32_W5500_H_
|
||||
#define _ESP32_W5500_H_
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
#include <hal/spi_types.h>
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR < 4 || ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,4,0)
|
||||
#error "This version of Arduino is too old"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static uint8_t W5500_Default_Mac[] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF };
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
class ESP32_W5500
|
||||
{
|
||||
private:
|
||||
bool initialized;
|
||||
bool staticIP;
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR > 3
|
||||
esp_eth_handle_t eth_handle;
|
||||
|
||||
protected:
|
||||
bool started;
|
||||
eth_link_t eth_link;
|
||||
static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
#else
|
||||
bool started;
|
||||
eth_config_t eth_config;
|
||||
#endif
|
||||
|
||||
public:
|
||||
ESP32_W5500();
|
||||
~ESP32_W5500();
|
||||
|
||||
bool begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ = 25, int SPIHOST = SPI3_HOST,
|
||||
uint8_t *W5500_Mac = W5500_Default_Mac);
|
||||
|
||||
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000,
|
||||
IPAddress dns2 = (uint32_t)0x00000000);
|
||||
|
||||
const char * getHostname();
|
||||
bool setHostname(const char * hostname);
|
||||
|
||||
bool fullDuplex();
|
||||
bool linkUp();
|
||||
uint8_t linkSpeed();
|
||||
|
||||
bool enableIpV6();
|
||||
IPv6Address localIPv6();
|
||||
|
||||
IPAddress localIP();
|
||||
IPAddress subnetMask();
|
||||
IPAddress gatewayIP();
|
||||
IPAddress dnsIP(uint8_t dns_no = 0);
|
||||
|
||||
IPAddress broadcastIP();
|
||||
IPAddress networkID();
|
||||
uint8_t subnetCIDR();
|
||||
|
||||
uint8_t * macAddress(uint8_t* mac);
|
||||
String macAddress();
|
||||
|
||||
friend class WiFiClient;
|
||||
friend class WiFiServer;
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
extern ESP32_W5500 ETH;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#endif /* _ESP32_W5500_H_ */
|
|
@ -0,0 +1,950 @@
|
|||
/****************************************************************************************************************************
|
||||
esp_eth_mac_w5500.c
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "hal/cpu_hal.h"
|
||||
#include "w5500.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static const char *TAG = "w5500.mac";
|
||||
|
||||
#define W5500_SPI_LOCK_TIMEOUT_MS (50)
|
||||
#define W5500_TX_MEM_SIZE (0x4000)
|
||||
#define W5500_RX_MEM_SIZE (0x4000)
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
esp_eth_mac_t parent;
|
||||
esp_eth_mediator_t *eth;
|
||||
spi_device_handle_t spi_hdl;
|
||||
SemaphoreHandle_t spi_lock;
|
||||
TaskHandle_t rx_task_hdl;
|
||||
uint32_t sw_reset_timeout_ms;
|
||||
int int_gpio_num;
|
||||
uint8_t addr[6];
|
||||
bool packets_remain;
|
||||
} emac_w5500_t;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static inline bool w5500_lock(emac_w5500_t *emac)
|
||||
{
|
||||
return xSemaphoreTake(emac->spi_lock, pdMS_TO_TICKS(W5500_SPI_LOCK_TIMEOUT_MS)) == pdTRUE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static inline bool w5500_unlock(emac_w5500_t *emac)
|
||||
{
|
||||
return xSemaphoreGive(emac->spi_lock) == pdTRUE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_write(emac_w5500_t *emac, uint32_t address, const void *value, uint32_t len)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
spi_transaction_t trans =
|
||||
{
|
||||
.cmd = (address >> W5500_ADDR_OFFSET),
|
||||
.addr = ((address & 0xFFFF) | (W5500_ACCESS_MODE_WRITE << W5500_RWB_OFFSET) | W5500_SPI_OP_MODE_VDM),
|
||||
.length = 8 * len,
|
||||
.tx_buffer = value
|
||||
};
|
||||
|
||||
if (w5500_lock(emac))
|
||||
{
|
||||
if (spi_device_polling_transmit(emac->spi_hdl, &trans) != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s(%d): SPI transmit failed", __FUNCTION__, __LINE__);
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
w5500_unlock(emac);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_read(emac_w5500_t *emac, uint32_t address, void *value, uint32_t len)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
spi_transaction_t trans =
|
||||
{
|
||||
// use direct reads for registers to prevent overwrites by 4-byte boundary writes
|
||||
.flags = len <= 4 ? SPI_TRANS_USE_RXDATA : 0,
|
||||
.cmd = (address >> W5500_ADDR_OFFSET),
|
||||
.addr = ((address & 0xFFFF) | (W5500_ACCESS_MODE_READ << W5500_RWB_OFFSET) | W5500_SPI_OP_MODE_VDM),
|
||||
.length = 8 * len,
|
||||
.rx_buffer = value
|
||||
};
|
||||
|
||||
if (w5500_lock(emac))
|
||||
{
|
||||
if (spi_device_polling_transmit(emac->spi_hdl, &trans) != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s(%d): SPI transmit failed", __FUNCTION__, __LINE__);
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
w5500_unlock(emac);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
if ((trans.flags & SPI_TRANS_USE_RXDATA) && len <= 4)
|
||||
{
|
||||
memcpy(value, trans.rx_data, len); // copy register values to output
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_send_command(emac_w5500_t *emac, uint8_t command, uint32_t timeout_ms)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_CR(0), &command, sizeof(command)), err, TAG, "Write SCR failed");
|
||||
|
||||
// after W5500 accepts the command, the command register will be cleared automatically
|
||||
uint32_t to = 0;
|
||||
|
||||
for (to = 0; to < timeout_ms / 10; to++)
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_CR(0), &command, sizeof(command)), err, TAG, "Read SCR failed");
|
||||
|
||||
if (!command)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_FALSE(to < timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "Send command timeout");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_get_tx_free_size(emac_w5500_t *emac, uint16_t *size)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint16_t free0, free1 = 0;
|
||||
|
||||
// read TX_FSR register more than once, until we get the same value
|
||||
// this is a trick because we might be interrupted between reading the high/low part of the TX_FSR register (16 bits in length)
|
||||
do
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_FSR(0), &free0, sizeof(free0)), err, TAG, "Read TX FSR failed");
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_FSR(0), &free1, sizeof(free1)), err, TAG, "Read TX FSR failed");
|
||||
} while (free0 != free1);
|
||||
|
||||
*size = __builtin_bswap16(free0);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_get_rx_received_size(emac_w5500_t *emac, uint16_t *size)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint16_t received0, received1 = 0;
|
||||
|
||||
do
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received0, sizeof(received0)), err, TAG,
|
||||
"Read RX RSR failed");
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received1, sizeof(received1)), err, TAG,
|
||||
"Read RX RSR failed");
|
||||
} while (received0 != received1);
|
||||
|
||||
*size = __builtin_bswap16(received0);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_write_buffer(emac_w5500_t *emac, const void *buffer, uint32_t len, uint16_t offset)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint32_t remain = len;
|
||||
const uint8_t *buf = buffer;
|
||||
offset %= W5500_TX_MEM_SIZE;
|
||||
|
||||
if (offset + len > W5500_TX_MEM_SIZE)
|
||||
{
|
||||
remain = (offset + len) % W5500_TX_MEM_SIZE;
|
||||
len = W5500_TX_MEM_SIZE - offset;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_MEM_SOCK_TX(0, offset), buf, len), err, TAG, "Write TX buffer failed");
|
||||
offset += len;
|
||||
buf += len;
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_MEM_SOCK_TX(0, offset), buf, remain), err, TAG, "Write TX buffer failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_read_buffer(emac_w5500_t *emac, void *buffer, uint32_t len, uint16_t offset)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint32_t remain = len;
|
||||
uint8_t *buf = buffer;
|
||||
offset %= W5500_RX_MEM_SIZE;
|
||||
|
||||
if (offset + len > W5500_RX_MEM_SIZE)
|
||||
{
|
||||
remain = (offset + len) % W5500_RX_MEM_SIZE;
|
||||
len = W5500_RX_MEM_SIZE - offset;
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_MEM_SOCK_RX(0, offset), buf, len), err, TAG, "Read RX buffer failed");
|
||||
offset += len;
|
||||
buf += len;
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_MEM_SOCK_RX(0, offset), buf, remain), err, TAG, "Read RX buffer failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_set_mac_addr(emac_w5500_t *emac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MAC, emac->addr, 6), err, TAG, "Write MAC address register failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_reset(emac_w5500_t *emac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
/* software reset */
|
||||
uint8_t mr = W5500_MR_RST; // Set RST bit (auto clear)
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MR, &mr, sizeof(mr)), err, TAG, "Write MR failed");
|
||||
|
||||
uint32_t to = 0;
|
||||
|
||||
for (to = 0; to < emac->sw_reset_timeout_ms / 10; to++)
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_MR, &mr, sizeof(mr)), err, TAG, "Read MR failed");
|
||||
|
||||
if (!(mr & W5500_MR_RST))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_FALSE(to < emac->sw_reset_timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "Reset timeout");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_verify_id(emac_w5500_t *emac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t version = 0;
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_VERSIONR, &version, sizeof(version)), err, TAG, "Read VERSIONR failed");
|
||||
|
||||
// W5500 doesn't have chip ID, we just print the version number instead
|
||||
ESP_LOGI(TAG, "version=%x", version);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_setup_default(emac_w5500_t *emac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t reg_value = 16;
|
||||
|
||||
// Only SOCK0 can be used as MAC RAW mode, so we give the whole buffer (16KB TX and 16KB RX) to SOCK0
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RXBUF_SIZE(0), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Set rx buffer size failed");
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(0), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Set tx buffer size failed");
|
||||
|
||||
reg_value = 0;
|
||||
|
||||
for (int i = 1; i < 8; i++)
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RXBUF_SIZE(i), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Set SOCK_RXBUF_SIZE failed");
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(i), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Set SOCK_TXBUF_SIZE failed");
|
||||
}
|
||||
|
||||
/* Enable ping block, disable PPPoE, WOL */
|
||||
reg_value = W5500_MR_PB;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MR, ®_value, sizeof(reg_value)), err, TAG, "Write MR failed");
|
||||
|
||||
/* Disable interrupt for all sockets by default */
|
||||
reg_value = 0;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed");
|
||||
|
||||
/* Enable MAC RAW mode for SOCK0, enable MAC filter, no blocking broadcast and multicast */
|
||||
reg_value = W5500_SMR_MAC_RAW | W5500_SMR_MAC_FILTER;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_MR(0), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Write SOCK0 MR failed");
|
||||
|
||||
/* Enable receive event for SOCK0 */
|
||||
reg_value = W5500_SIR_RECV;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_IMR(0), ®_value, sizeof(reg_value)), err, TAG,
|
||||
"Write SOCK0 IMR failed");
|
||||
|
||||
/* Set the interrupt re-assert level to maximum (~1.5ms) to lower the chances of missing it */
|
||||
uint16_t int_level = __builtin_bswap16(0xFFFF);
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_INTLEVEL, &int_level, sizeof(int_level)), err, TAG,
|
||||
"Write INTLEVEL failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_start(esp_eth_mac_t *mac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
uint8_t reg_value = 0;
|
||||
/* open SOCK0 */
|
||||
ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_OPEN, 100), err, TAG, "Issue OPEN command failed");
|
||||
|
||||
/* enable interrupt for SOCK0 */
|
||||
reg_value = W5500_SIMR_SOCK0;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t emac_w5500_stop(esp_eth_mac_t *mac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
uint8_t reg_value = 0;
|
||||
/* disable interrupt */
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed");
|
||||
/* close SOCK0 */
|
||||
ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_CLOSE, 100), err, TAG, "Issue SCR_CLOSE command failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
IRAM_ATTR static void w5500_isr_handler(void *arg)
|
||||
{
|
||||
emac_w5500_t *emac = (emac_w5500_t *)arg;
|
||||
BaseType_t high_task_wakeup = pdFALSE;
|
||||
|
||||
/* notify w5500 task */
|
||||
vTaskNotifyGiveFromISR(emac->rx_task_hdl, &high_task_wakeup);
|
||||
|
||||
if (high_task_wakeup != pdFALSE)
|
||||
{
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static void emac_w5500_task(void *arg)
|
||||
{
|
||||
emac_w5500_t *emac = (emac_w5500_t *)arg;
|
||||
uint8_t status = 0;
|
||||
uint8_t *buffer = NULL;
|
||||
uint32_t length = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// check if the task receives any notification
|
||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)) == 0 && // if no notification ...
|
||||
gpio_get_level(emac->int_gpio_num) != 0)
|
||||
{
|
||||
// ...and no interrupt asserted
|
||||
continue; // -> just continue to check again
|
||||
}
|
||||
|
||||
/* read interrupt status */
|
||||
w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status));
|
||||
|
||||
/* packet received */
|
||||
if (status & W5500_SIR_RECV)
|
||||
{
|
||||
status = W5500_SIR_RECV;
|
||||
// clear interrupt status
|
||||
w5500_write(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status));
|
||||
|
||||
do
|
||||
{
|
||||
length = ETH_MAX_PACKET_SIZE;
|
||||
buffer = heap_caps_malloc(length, MALLOC_CAP_DMA);
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
ESP_LOGE(TAG, "No mem for receive buffer");
|
||||
break;
|
||||
}
|
||||
else if (emac->parent.receive(&emac->parent, buffer, &length) == ESP_OK)
|
||||
{
|
||||
/* pass the buffer to stack (e.g. TCP/IP layer) */
|
||||
if (length)
|
||||
{
|
||||
emac->eth->stack_input(emac->eth, buffer, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
} while (emac->packets_remain);
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_mediator(esp_eth_mac_t *mac, esp_eth_mediator_t *eth)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_GOTO_ON_FALSE(eth, ESP_ERR_INVALID_ARG, err, TAG, "Can't set mac's mediator to null");
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
emac->eth = eth;
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_write_phy_reg(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
// PHY register and MAC registers are mixed together in W5500
|
||||
// The only PHY register is PHYCFGR
|
||||
ESP_GOTO_ON_FALSE(phy_reg == W5500_REG_PHYCFGR, ESP_FAIL, err, TAG, "Wrong PHY register");
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_PHYCFGR, ®_value, sizeof(uint8_t)), err, TAG,
|
||||
"write PHY register failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_read_phy_reg(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_GOTO_ON_FALSE(reg_value, ESP_ERR_INVALID_ARG, err, TAG, "Can't set reg_value to null");
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
// PHY register and MAC registers are mixed together in W5500
|
||||
// The only PHY register is PHYCFGR
|
||||
ESP_GOTO_ON_FALSE(phy_reg == W5500_REG_PHYCFGR, ESP_FAIL, err, TAG, "Wrong PHY register");
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_PHYCFGR, reg_value, sizeof(uint8_t)), err, TAG,
|
||||
"read PHY register failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_addr(esp_eth_mac_t *mac, uint8_t *addr)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Invalid argument");
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
memcpy(emac->addr, addr, 6);
|
||||
ESP_GOTO_ON_ERROR(w5500_set_mac_addr(emac), err, TAG, "Set mac address failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_get_addr(esp_eth_mac_t *mac, uint8_t *addr)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Invalid argument");
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
memcpy(addr, emac->addr, 6);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_link(esp_eth_mac_t *mac, eth_link_t link)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
switch (link)
|
||||
{
|
||||
case ETH_LINK_UP:
|
||||
ESP_LOGD(TAG, "Link is up");
|
||||
ESP_GOTO_ON_ERROR(mac->start(mac), err, TAG, "W5500 start failed");
|
||||
break;
|
||||
|
||||
case ETH_LINK_DOWN:
|
||||
ESP_LOGD(TAG, "link is down");
|
||||
ESP_GOTO_ON_ERROR(mac->stop(mac), err, TAG, "W5500 stop failed");
|
||||
break;
|
||||
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown link status");
|
||||
break;
|
||||
}
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_speed(esp_eth_mac_t *mac, eth_speed_t speed)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
switch (speed)
|
||||
{
|
||||
case ETH_SPEED_10M:
|
||||
ESP_LOGD(TAG, "Setting to 10Mbps");
|
||||
break;
|
||||
|
||||
case ETH_SPEED_100M:
|
||||
ESP_LOGD(TAG, "Setting to 100Mbps");
|
||||
break;
|
||||
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown speed");
|
||||
break;
|
||||
}
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_duplex(esp_eth_mac_t *mac, eth_duplex_t duplex)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
switch (duplex)
|
||||
{
|
||||
case ETH_DUPLEX_HALF:
|
||||
ESP_LOGD(TAG, "Setting to HALF_DUPLEX");
|
||||
break;
|
||||
|
||||
case ETH_DUPLEX_FULL:
|
||||
ESP_LOGD(TAG, "Setting to FULL_DUPLEX");
|
||||
break;
|
||||
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown duplex");
|
||||
break;
|
||||
}
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_promiscuous(esp_eth_mac_t *mac, bool enable)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
uint8_t smr = 0;
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_MR(0), &smr, sizeof(smr)), err, TAG, "Read SOCK0 MR failed");
|
||||
|
||||
if (enable)
|
||||
{
|
||||
smr &= ~W5500_SMR_MAC_FILTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
smr |= W5500_SMR_MAC_FILTER;
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_MR(0), &smr, sizeof(smr)), err, TAG, "Write SOCK0 MR failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_enable_flow_ctrl(esp_eth_mac_t *mac, bool enable)
|
||||
{
|
||||
/* w5500 doesn't support flow control function, so accept any value */
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_set_peer_pause_ability(esp_eth_mac_t *mac, uint32_t ability)
|
||||
{
|
||||
/* w5500 doesn't support PAUSE function, so accept any value */
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static inline bool is_w5500_sane_for_rxtx(emac_w5500_t *emac)
|
||||
{
|
||||
uint8_t phycfg;
|
||||
|
||||
/* phy is ok for rx and tx operations if bits RST and LNK are set (no link down, no reset) */
|
||||
if (w5500_read(emac, W5500_REG_PHYCFGR, &phycfg, 1) == ESP_OK && (phycfg & 0x8001))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_transmit(esp_eth_mac_t *mac, uint8_t *buf, uint32_t length)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
uint16_t offset = 0;
|
||||
|
||||
// check if there're free memory to store this packet
|
||||
uint16_t free_size = 0;
|
||||
ESP_GOTO_ON_ERROR(w5500_get_tx_free_size(emac, &free_size), err, TAG, "Get free size failed");
|
||||
ESP_GOTO_ON_FALSE(length <= free_size, ESP_ERR_NO_MEM, err, TAG, "Free size (%d) < send length (%d)", length,
|
||||
free_size);
|
||||
|
||||
// get current write pointer
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_WR(0), &offset, sizeof(offset)), err, TAG, "Read TX WR failed");
|
||||
offset = __builtin_bswap16(offset);
|
||||
|
||||
// copy data to tx memory
|
||||
ESP_GOTO_ON_ERROR(w5500_write_buffer(emac, buf, length, offset), err, TAG, "Write frame failed");
|
||||
|
||||
// update write pointer
|
||||
offset += length;
|
||||
offset = __builtin_bswap16(offset);
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TX_WR(0), &offset, sizeof(offset)), err, TAG, "Write TX WR failed");
|
||||
|
||||
// issue SEND command
|
||||
ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_SEND, 100), err, TAG, "Issue SEND command failed");
|
||||
|
||||
// pooling the TX done event
|
||||
int retry = 0;
|
||||
uint8_t status = 0;
|
||||
|
||||
while (!(status & W5500_SIR_SEND))
|
||||
{
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)), err, TAG, "Read SOCK0 IR failed");
|
||||
|
||||
if ((retry++ > 3 && !is_w5500_sane_for_rxtx(emac)) || retry > 10)
|
||||
{
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// clear the event bit
|
||||
status = W5500_SIR_SEND;
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)), err, TAG, "Write SOCK0 IR failed");
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_receive(esp_eth_mac_t *mac, uint8_t *buf, uint32_t *length)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
uint16_t offset = 0;
|
||||
uint16_t rx_len = 0;
|
||||
uint16_t remain_bytes = 0;
|
||||
emac->packets_remain = false;
|
||||
|
||||
w5500_get_rx_received_size(emac, &remain_bytes);
|
||||
|
||||
if (remain_bytes)
|
||||
{
|
||||
// get current read pointer
|
||||
ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RD(0), &offset, sizeof(offset)), err, TAG, "Read RX RD failed");
|
||||
|
||||
offset = __builtin_bswap16(offset);
|
||||
|
||||
// read head first
|
||||
ESP_GOTO_ON_ERROR(w5500_read_buffer(emac, &rx_len, sizeof(rx_len), offset), err, TAG, "Read frame header failed");
|
||||
|
||||
rx_len = __builtin_bswap16(rx_len) - 2; // data size includes 2 bytes of header
|
||||
offset += 2;
|
||||
|
||||
// read the payload
|
||||
ESP_GOTO_ON_ERROR(w5500_read_buffer(emac, buf, rx_len, offset), err, TAG, "Read payload failed, len=%d, offset=%d",
|
||||
rx_len, offset);
|
||||
|
||||
offset += rx_len;
|
||||
|
||||
// update read pointer
|
||||
offset = __builtin_bswap16(offset);
|
||||
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RX_RD(0), &offset, sizeof(offset)), err, TAG, "Write RX RD failed");
|
||||
|
||||
/* issue RECV command */
|
||||
ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_RECV, 100), err, TAG, "Issue RECV command failed");
|
||||
|
||||
// check if there're more data need to process
|
||||
remain_bytes -= rx_len + 2;
|
||||
emac->packets_remain = remain_bytes > 0;
|
||||
}
|
||||
|
||||
*length = rx_len;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_init(esp_eth_mac_t *mac)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
esp_eth_mediator_t *eth = emac->eth;
|
||||
esp_rom_gpio_pad_select_gpio(emac->int_gpio_num);
|
||||
gpio_set_direction(emac->int_gpio_num, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(emac->int_gpio_num, GPIO_PULLUP_ONLY);
|
||||
gpio_set_intr_type(emac->int_gpio_num, GPIO_INTR_NEGEDGE); // active low
|
||||
gpio_intr_enable(emac->int_gpio_num);
|
||||
gpio_isr_handler_add(emac->int_gpio_num, w5500_isr_handler, emac);
|
||||
|
||||
ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LLINIT, NULL), err, TAG, "Lowlevel init failed");
|
||||
|
||||
/* reset w5500 */
|
||||
ESP_GOTO_ON_ERROR(w5500_reset(emac), err, TAG, "Reset w5500 failed");
|
||||
|
||||
/* verify chip id */
|
||||
ESP_GOTO_ON_ERROR(w5500_verify_id(emac), err, TAG, "Verify chip ID failed");
|
||||
|
||||
/* default setup of internal registers */
|
||||
ESP_GOTO_ON_ERROR(w5500_setup_default(emac), err, TAG, "W5500 default setup failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
gpio_isr_handler_remove(emac->int_gpio_num);
|
||||
gpio_reset_pin(emac->int_gpio_num);
|
||||
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_deinit(esp_eth_mac_t *mac)
|
||||
{
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
esp_eth_mediator_t *eth = emac->eth;
|
||||
mac->stop(mac);
|
||||
gpio_isr_handler_remove(emac->int_gpio_num);
|
||||
gpio_reset_pin(emac->int_gpio_num);
|
||||
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t emac_w5500_del(esp_eth_mac_t *mac)
|
||||
{
|
||||
emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent);
|
||||
|
||||
vTaskDelete(emac->rx_task_hdl);
|
||||
vSemaphoreDelete(emac->spi_lock);
|
||||
free(emac);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
esp_eth_mac_t *esp_eth_mac_new_w5500(const eth_w5500_config_t *w5500_config, const eth_mac_config_t *mac_config)
|
||||
{
|
||||
esp_eth_mac_t *ret = NULL;
|
||||
emac_w5500_t *emac = NULL;
|
||||
|
||||
ESP_GOTO_ON_FALSE(w5500_config && mac_config, NULL, err, TAG, "Invalid argument");
|
||||
|
||||
emac = calloc(1, sizeof(emac_w5500_t));
|
||||
ESP_GOTO_ON_FALSE(emac, NULL, err, TAG, "No mem for MAC instance");
|
||||
|
||||
/* w5500 driver is interrupt driven */
|
||||
ESP_GOTO_ON_FALSE(w5500_config->int_gpio_num >= 0, NULL, err, TAG, "Invalid interrupt gpio number");
|
||||
|
||||
/* bind methods and attributes */
|
||||
emac->sw_reset_timeout_ms = mac_config->sw_reset_timeout_ms;
|
||||
emac->int_gpio_num = w5500_config->int_gpio_num;
|
||||
emac->spi_hdl = w5500_config->spi_hdl;
|
||||
emac->parent.set_mediator = emac_w5500_set_mediator;
|
||||
emac->parent.init = emac_w5500_init;
|
||||
emac->parent.deinit = emac_w5500_deinit;
|
||||
emac->parent.start = emac_w5500_start;
|
||||
emac->parent.stop = emac_w5500_stop;
|
||||
emac->parent.del = emac_w5500_del;
|
||||
emac->parent.write_phy_reg = emac_w5500_write_phy_reg;
|
||||
emac->parent.read_phy_reg = emac_w5500_read_phy_reg;
|
||||
emac->parent.set_addr = emac_w5500_set_addr;
|
||||
emac->parent.get_addr = emac_w5500_get_addr;
|
||||
emac->parent.set_speed = emac_w5500_set_speed;
|
||||
emac->parent.set_duplex = emac_w5500_set_duplex;
|
||||
emac->parent.set_link = emac_w5500_set_link;
|
||||
emac->parent.set_promiscuous = emac_w5500_set_promiscuous;
|
||||
emac->parent.set_peer_pause_ability = emac_w5500_set_peer_pause_ability;
|
||||
emac->parent.enable_flow_ctrl = emac_w5500_enable_flow_ctrl;
|
||||
emac->parent.transmit = emac_w5500_transmit;
|
||||
emac->parent.receive = emac_w5500_receive;
|
||||
|
||||
/* create mutex */
|
||||
emac->spi_lock = xSemaphoreCreateMutex();
|
||||
ESP_GOTO_ON_FALSE(emac->spi_lock, NULL, err, TAG, "Create lock failed");
|
||||
|
||||
/* create w5500 task */
|
||||
BaseType_t core_num = tskNO_AFFINITY;
|
||||
|
||||
if (mac_config->flags & ETH_MAC_FLAG_PIN_TO_CORE)
|
||||
{
|
||||
core_num = cpu_hal_get_core_id();
|
||||
}
|
||||
|
||||
BaseType_t xReturned = xTaskCreatePinnedToCore(emac_w5500_task, "w5500_tsk", mac_config->rx_task_stack_size, emac,
|
||||
mac_config->rx_task_prio, &emac->rx_task_hdl, core_num);
|
||||
ESP_GOTO_ON_FALSE(xReturned == pdPASS, NULL, err, TAG, "Create w5500 task failed");
|
||||
|
||||
return &(emac->parent);
|
||||
|
||||
err:
|
||||
|
||||
if (emac)
|
||||
{
|
||||
if (emac->rx_task_hdl)
|
||||
{
|
||||
vTaskDelete(emac->rx_task_hdl);
|
||||
}
|
||||
|
||||
if (emac->spi_lock)
|
||||
{
|
||||
vSemaphoreDelete(emac->spi_lock);
|
||||
}
|
||||
|
||||
free(emac);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
|
@ -0,0 +1,372 @@
|
|||
/****************************************************************************************************************************
|
||||
esp_eth_phy_w5500.c
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_eth.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "esp_rom_sys.h"
|
||||
#include "w5500.h"
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static const char *TAG = "w5500.phy";
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/***************Vendor Specific Register***************/
|
||||
/**
|
||||
@brief PHYCFGR(PHY Configuration Register)
|
||||
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t link: 1; /*!< Link status */
|
||||
uint8_t speed: 1; /*!< Speed status */
|
||||
uint8_t duplex: 1; /*!< Duplex status */
|
||||
uint8_t opmode: 3; /*!< Operation mode */
|
||||
uint8_t opsel: 1; /*!< Operation select */
|
||||
uint8_t reset: 1; /*!< Reset, when this bit is '0', PHY will get reset */
|
||||
};
|
||||
|
||||
uint8_t val;
|
||||
} phycfg_reg_t;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
esp_eth_phy_t parent;
|
||||
esp_eth_mediator_t *eth;
|
||||
int addr;
|
||||
uint32_t reset_timeout_ms;
|
||||
uint32_t autonego_timeout_ms;
|
||||
eth_link_t link_status;
|
||||
int reset_gpio_num;
|
||||
} phy_w5500_t;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_update_link_duplex_speed(phy_w5500_t *w5500)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
esp_eth_mediator_t *eth = w5500->eth;
|
||||
eth_speed_t speed = ETH_SPEED_10M;
|
||||
eth_duplex_t duplex = ETH_DUPLEX_HALF;
|
||||
phycfg_reg_t phycfg;
|
||||
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG,
|
||||
"Read PHYCFG failed");
|
||||
eth_link_t link = phycfg.link ? ETH_LINK_UP : ETH_LINK_DOWN;
|
||||
|
||||
/* check if link status changed */
|
||||
if (w5500->link_status != link)
|
||||
{
|
||||
/* when link up, read negotiation result */
|
||||
if (link == ETH_LINK_UP)
|
||||
{
|
||||
if (phycfg.speed)
|
||||
{
|
||||
speed = ETH_SPEED_100M;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed = ETH_SPEED_10M;
|
||||
}
|
||||
|
||||
if (phycfg.duplex)
|
||||
{
|
||||
duplex = ETH_DUPLEX_FULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
duplex = ETH_DUPLEX_HALF;
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_SPEED, (void *)speed), err, TAG, "Change speed failed");
|
||||
ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_DUPLEX, (void *)duplex), err, TAG, "Change duplex failed");
|
||||
}
|
||||
|
||||
ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LINK, (void *)link), err, TAG, "Change link failed");
|
||||
w5500->link_status = link;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_set_mediator(esp_eth_phy_t *phy, esp_eth_mediator_t *eth)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_FALSE(eth, ESP_ERR_INVALID_ARG, err, TAG, "Can't set mediator to null");
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
w5500->eth = eth;
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_get_link(esp_eth_phy_t *phy)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
|
||||
/* Updata information about link, speed, duplex */
|
||||
ESP_GOTO_ON_ERROR(w5500_update_link_duplex_speed(w5500), err, TAG, "Update link duplex speed failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_reset(esp_eth_phy_t *phy)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
|
||||
w5500->link_status = ETH_LINK_DOWN;
|
||||
esp_eth_mediator_t *eth = w5500->eth;
|
||||
|
||||
phycfg_reg_t phycfg;
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG,
|
||||
"Read PHYCFG failed");
|
||||
|
||||
phycfg.reset = 0; // set to '0' will reset internal PHY
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed");
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
phycfg.reset = 1; // set to '1' after reset
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_reset_hw(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
|
||||
// set reset_gpio_num to a negative value can skip hardware reset phy chip
|
||||
if (w5500->reset_gpio_num >= 0)
|
||||
{
|
||||
esp_rom_gpio_pad_select_gpio(w5500->reset_gpio_num);
|
||||
gpio_set_direction(w5500->reset_gpio_num, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(w5500->reset_gpio_num, 0);
|
||||
esp_rom_delay_us(100); // insert min input assert time
|
||||
gpio_set_level(w5500->reset_gpio_num, 1);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
|
||||
esp_eth_mediator_t *eth = w5500->eth;
|
||||
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
w5500->link_status = ETH_LINK_DOWN;
|
||||
phycfg_reg_t phycfg;
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG,
|
||||
"Read PHYCFG failed");
|
||||
|
||||
phycfg.opsel = 1; // PHY working mode configured by register
|
||||
phycfg.opmode = 7; // all capable, auto-negotiation enabled
|
||||
ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_pwrctl(esp_eth_phy_t *phy, bool enable)
|
||||
{
|
||||
// power control is not supported for W5500 internal PHY
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_set_addr(esp_eth_phy_t *phy, uint32_t addr)
|
||||
{
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
w5500->addr = addr;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_get_addr(esp_eth_phy_t *phy, uint32_t *addr)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Addr can't be null");
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
*addr = w5500->addr;
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_del(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
free(w5500);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_advertise_pause_ability(esp_eth_phy_t *phy, uint32_t ability)
|
||||
{
|
||||
// pause ability advertisement is not supported for W5500 internal PHY
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_loopback(esp_eth_phy_t *phy, bool enable)
|
||||
{
|
||||
// Loopback is not supported for W5500 internal PHY
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_init(esp_eth_phy_t *phy)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
/* Power on Ethernet PHY */
|
||||
ESP_GOTO_ON_ERROR(w5500_pwrctl(phy, true), err, TAG, "Power control failed");
|
||||
|
||||
/* Reset Ethernet PHY */
|
||||
ESP_GOTO_ON_ERROR(w5500_reset(phy), err, TAG, "Reset failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
static esp_err_t w5500_deinit(esp_eth_phy_t *phy)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
/* Power off Ethernet PHY */
|
||||
ESP_GOTO_ON_ERROR(w5500_pwrctl(phy, false), err, TAG, "Power control failed");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
esp_eth_phy_t *esp_eth_phy_new_w5500(const eth_phy_config_t *config)
|
||||
{
|
||||
esp_eth_phy_t *ret = NULL;
|
||||
|
||||
ESP_GOTO_ON_FALSE(config, NULL, err, TAG, "Invalid arguments");
|
||||
|
||||
phy_w5500_t *w5500 = calloc(1, sizeof(phy_w5500_t));
|
||||
ESP_GOTO_ON_FALSE(w5500, NULL, err, TAG, "No mem for PHY instance");
|
||||
|
||||
/* bind methods and attributes */
|
||||
w5500->addr = config->phy_addr;
|
||||
w5500->reset_timeout_ms = config->reset_timeout_ms;
|
||||
w5500->reset_gpio_num = config->reset_gpio_num;
|
||||
w5500->link_status = ETH_LINK_DOWN;
|
||||
w5500->autonego_timeout_ms = config->autonego_timeout_ms;
|
||||
w5500->parent.reset = w5500_reset;
|
||||
w5500->parent.reset_hw = w5500_reset_hw;
|
||||
w5500->parent.init = w5500_init;
|
||||
w5500->parent.deinit = w5500_deinit;
|
||||
w5500->parent.set_mediator = w5500_set_mediator;
|
||||
w5500->parent.negotiate = w5500_negotiate;
|
||||
w5500->parent.get_link = w5500_get_link;
|
||||
w5500->parent.pwrctl = w5500_pwrctl;
|
||||
w5500->parent.get_addr = w5500_get_addr;
|
||||
w5500->parent.set_addr = w5500_set_addr;
|
||||
w5500->parent.advertise_pause_ability = w5500_advertise_pause_ability;
|
||||
w5500->parent.loopback = w5500_loopback;
|
||||
w5500->parent.del = w5500_del;
|
||||
|
||||
return &(w5500->parent);
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/****************************************************************************************************************************
|
||||
esp_eth_spi_w5500.c
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_event.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_eth_w5500.h"
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
static const char *TAG = "w5500.spi";
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
esp_eth_mac_t* w5500_new_mac( spi_device_handle_t *spi_handle, int INT_GPIO )
|
||||
{
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG( *spi_handle );
|
||||
w5500_config.int_gpio_num = INT_GPIO;
|
||||
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
|
||||
//eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
//phy_config.reset_gpio_num = -1;
|
||||
|
||||
mac_config.smi_mdc_gpio_num = -1; // w5500 doesn't have SMI interface
|
||||
mac_config.smi_mdio_gpio_num = -1;
|
||||
mac_config.rx_task_prio = 1;
|
||||
|
||||
return esp_eth_mac_new_w5500( &w5500_config, &mac_config );
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
esp_eth_mac_t* w5500_begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPICLOCK_MHZ,
|
||||
int SPIHOST)
|
||||
{
|
||||
if (ESP_OK != gpio_install_isr_service(0))
|
||||
{
|
||||
ESP_LOGE(TAG, "%s(%d): Error gpio_install_isr_service", __FUNCTION__, __LINE__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* w5500 ethernet driver is based on spi driver */
|
||||
spi_bus_config_t buscfg =
|
||||
{
|
||||
.miso_io_num = MISO_GPIO,
|
||||
.mosi_io_num = MOSI_GPIO,
|
||||
.sclk_io_num = SCLK_GPIO,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
};
|
||||
|
||||
if ( ESP_OK != spi_bus_initialize( SPIHOST, &buscfg, 1 ))
|
||||
{
|
||||
ESP_LOGE(TAG, "%s(%d): Error spi_bus_initialize", __FUNCTION__, __LINE__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
spi_device_interface_config_t devcfg =
|
||||
{
|
||||
.command_bits = 16,
|
||||
.address_bits = 8,
|
||||
.mode = 0,
|
||||
.clock_speed_hz = SPICLOCK_MHZ * 1000 * 1000,
|
||||
.spics_io_num = CS_GPIO,
|
||||
.queue_size = 20,
|
||||
.cs_ena_posttrans = w5500_cal_spi_cs_hold_time(SPICLOCK_MHZ),
|
||||
};
|
||||
|
||||
spi_device_handle_t spi_handle = NULL;
|
||||
|
||||
if (ESP_OK != spi_bus_add_device( SPIHOST, &devcfg, &spi_handle ))
|
||||
{
|
||||
ESP_LOGE(TAG, "%s(%d): Error spi_bus_add_device", __FUNCTION__, __LINE__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return w5500_new_mac( &spi_handle, INT_GPIO );
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
138
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h
Normal file
138
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
/****************************************************************************************************************************
|
||||
esp_eth_w5500.h
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#include "esp_eth_phy.h"
|
||||
#include "esp_eth_mac.h"
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define CS_HOLD_TIME_MIN_NS 210
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/*
|
||||
// From tools/sdk/esp32/include/esp_eth/include/esp_eth_mac.h
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *spi_hdl; //!< Handle of SPI device driver
|
||||
int int_gpio_num; //!< Interrupt GPIO number
|
||||
} eth_w5500_config_t;
|
||||
|
||||
|
||||
#define ETH_W5500_DEFAULT_CONFIG(spi_device) \
|
||||
{ \
|
||||
.spi_hdl = spi_device, \
|
||||
.int_gpio_num = 4, \
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@brief Compute amount of SPI bit-cycles the CS should stay active after the transmission
|
||||
to meet w5500 CS Hold Time specification.
|
||||
|
||||
@param clock_speed_mhz SPI Clock frequency in MHz (valid range is <1, 20>)
|
||||
@return uint8_t
|
||||
*/
|
||||
static inline uint8_t w5500_cal_spi_cs_hold_time(int clock_speed_mhz)
|
||||
{
|
||||
if (clock_speed_mhz <= 0 || clock_speed_mhz > 20)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int temp = clock_speed_mhz * CS_HOLD_TIME_MIN_NS;
|
||||
uint8_t cs_posttrans = temp / 1000;
|
||||
|
||||
if (temp % 1000)
|
||||
{
|
||||
cs_posttrans += 1;
|
||||
}
|
||||
|
||||
return cs_posttrans;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@brief Create w5500 Ethernet MAC instance
|
||||
|
||||
@param[in] w5500_config: w5500 specific configuration
|
||||
@param[in] mac_config: Ethernet MAC configuration
|
||||
|
||||
@return
|
||||
- instance: create MAC instance successfully
|
||||
- NULL: create MAC instance failed because some error occurred
|
||||
*/
|
||||
esp_eth_mac_t *esp_eth_mac_new_w5500(const eth_w5500_config_t *w5500_config,
|
||||
const eth_mac_config_t *mac_config);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@brief Create a PHY instance of w5500
|
||||
|
||||
@param[in] config: configuration of PHY
|
||||
|
||||
@return
|
||||
- instance: create PHY instance successfully
|
||||
- NULL: create PHY instance failed because some error occurred
|
||||
*/
|
||||
esp_eth_phy_t *esp_eth_phy_new_w5500(const eth_phy_config_t *config);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
// todo: the below functions should be accessed through ioctl in the future
|
||||
/**
|
||||
@brief Set w5500 Duplex mode. It sets Duplex mode first to the PHY and then
|
||||
MAC is set based on what PHY indicates.
|
||||
|
||||
@param phy w5500 PHY Handle
|
||||
@param duplex Duplex mode
|
||||
|
||||
@return esp_err_t
|
||||
- ESP_OK when PHY registers were correctly written.
|
||||
*/
|
||||
esp_err_t w5500_set_phy_duplex(esp_eth_phy_t *phy, eth_duplex_t duplex);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
118
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h
Normal file
118
lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h
Normal file
|
@ -0,0 +1,118 @@
|
|||
/****************************************************************************************************************************
|
||||
w5500.h
|
||||
|
||||
For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500)
|
||||
|
||||
AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer
|
||||
|
||||
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500
|
||||
Licensed under GPLv3 license
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_ADDR_OFFSET (16) // Address length
|
||||
#define W5500_BSB_OFFSET (3) // Block Select Bits offset
|
||||
#define W5500_RWB_OFFSET (2) // Read Write Bits offset
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_BSB_COM_REG (0x00) // Common Register
|
||||
#define W5500_BSB_SOCK_REG(s) ((s)*4+1) // Socket Register
|
||||
#define W5500_BSB_SOCK_TX_BUF(s) ((s)*4+2) // Socket TX Buffer
|
||||
#define W5500_BSB_SOCK_RX_BUF(s) ((s)*4+3) // Socket RX Buffer
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_ACCESS_MODE_READ (0) // Read Mode
|
||||
#define W5500_ACCESS_MODE_WRITE (1) // Write Mode
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_SPI_OP_MODE_VDM (0x00) // Variable Data Length Mode (SPI frame is controlled by CS line)
|
||||
#define W5500_SPI_OP_MODE_FDM_1 (0x01) // Fixed Data Length Mode, 1 Byte Length
|
||||
#define W5500_SPI_OP_MODE_FDM_2 (0x02) // Fixed Data Length Mode, 2 Bytes Length
|
||||
#define W5500_SPI_OP_MODE_FDM_4 (0x03) // Fixed Data Length Mode, 4 Bytes Length
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_MAKE_MAP(offset, bsb) ((offset) << W5500_ADDR_OFFSET | (bsb) << W5500_BSB_OFFSET)
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_REG_MR W5500_MAKE_MAP(0x0000, W5500_BSB_COM_REG) // Mode
|
||||
#define W5500_REG_MAC W5500_MAKE_MAP(0x0009, W5500_BSB_COM_REG) // MAC Address
|
||||
#define W5500_REG_INTLEVEL W5500_MAKE_MAP(0x0013, W5500_BSB_COM_REG) // Interrupt Level Timeout
|
||||
#define W5500_REG_IR W5500_MAKE_MAP(0x0015, W5500_BSB_COM_REG) // Interrupt
|
||||
#define W5500_REG_IMR W5500_MAKE_MAP(0x0016, W5500_BSB_COM_REG) // Interrupt Mask
|
||||
#define W5500_REG_SIR W5500_MAKE_MAP(0x0017, W5500_BSB_COM_REG) // Socket Interrupt
|
||||
#define W5500_REG_SIMR W5500_MAKE_MAP(0x0018, W5500_BSB_COM_REG) // Socket Interrupt Mask
|
||||
#define W5500_REG_RTR W5500_MAKE_MAP(0x0019, W5500_BSB_COM_REG) // Retry Time
|
||||
#define W5500_REG_RCR W5500_MAKE_MAP(0x001B, W5500_BSB_COM_REG) // Retry Count
|
||||
#define W5500_REG_PHYCFGR W5500_MAKE_MAP(0x002E, W5500_BSB_COM_REG) // PHY Configuration
|
||||
#define W5500_REG_VERSIONR W5500_MAKE_MAP(0x0039, W5500_BSB_COM_REG) // Chip version
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_REG_SOCK_MR(s) W5500_MAKE_MAP(0x0000, W5500_BSB_SOCK_REG(s)) // Socket Mode
|
||||
#define W5500_REG_SOCK_CR(s) W5500_MAKE_MAP(0x0001, W5500_BSB_SOCK_REG(s)) // Socket Command
|
||||
#define W5500_REG_SOCK_IR(s) W5500_MAKE_MAP(0x0002, W5500_BSB_SOCK_REG(s)) // Socket Interrupt
|
||||
#define W5500_REG_SOCK_SR(s) W5500_MAKE_MAP(0x0004, W5500_BSB_SOCK_REG(s)) // Socket Status
|
||||
#define W5500_REG_SOCK_RXBUF_SIZE(s) W5500_MAKE_MAP(0x001E, W5500_BSB_SOCK_REG(s)) // Socket Receive Buffer Size
|
||||
#define W5500_REG_SOCK_TXBUF_SIZE(s) W5500_MAKE_MAP(0x001F, W5500_BSB_SOCK_REG(s)) // Socket Transmit Buffer Size
|
||||
#define W5500_REG_SOCK_TX_FSR(s) W5500_MAKE_MAP(0x0020, W5500_BSB_SOCK_REG(s)) // Socket TX Free Size
|
||||
#define W5500_REG_SOCK_TX_RD(s) W5500_MAKE_MAP(0x0022, W5500_BSB_SOCK_REG(s)) // Socket TX Read Pointer
|
||||
#define W5500_REG_SOCK_TX_WR(s) W5500_MAKE_MAP(0x0024, W5500_BSB_SOCK_REG(s)) // Socket TX Write Pointer
|
||||
#define W5500_REG_SOCK_RX_RSR(s) W5500_MAKE_MAP(0x0026, W5500_BSB_SOCK_REG(s)) // Socket RX Received Size
|
||||
#define W5500_REG_SOCK_RX_RD(s) W5500_MAKE_MAP(0x0028, W5500_BSB_SOCK_REG(s)) // Socket RX Read Pointer
|
||||
#define W5500_REG_SOCK_RX_WR(s) W5500_MAKE_MAP(0x002A, W5500_BSB_SOCK_REG(s)) // Socket RX Write Pointer
|
||||
#define W5500_REG_SOCK_IMR(s) W5500_MAKE_MAP(0x002C, W5500_BSB_SOCK_REG(s)) // Socket Interrupt Mask
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_MEM_SOCK_TX(s,addr) W5500_MAKE_MAP(addr, W5500_BSB_SOCK_TX_BUF(s)) // Socket TX buffer address
|
||||
#define W5500_MEM_SOCK_RX(s,addr) W5500_MAKE_MAP(addr, W5500_BSB_SOCK_RX_BUF(s)) // Socket RX buffer address
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_MR_RST (1<<7) // Software reset
|
||||
#define W5500_MR_PB (1<<4) // Ping block (block the response to a ping request)
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_SIMR_SOCK0 (1<<0) // Socket 0 interrupt
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_SMR_MAC_RAW (1<<2) // MAC RAW mode
|
||||
#define W5500_SMR_MAC_FILTER (1<<7) // MAC filter
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_SCR_OPEN (0x01) // Open command
|
||||
#define W5500_SCR_CLOSE (0x10) // Close command
|
||||
#define W5500_SCR_SEND (0x20) // Send command
|
||||
#define W5500_SCR_RECV (0x40) // Recv command
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#define W5500_SIR_RECV (1<<2) // Receive done
|
||||
#define W5500_SIR_SEND (1<<4) // Send done
|
||||
|
||||
////////////////////////////////////////
|
||||
|
70
lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf
Normal file
70
lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Code formatting rules for Arduino libraries, modified from for KH libraries:
|
||||
#
|
||||
# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
|
||||
#
|
||||
|
||||
# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
|
||||
|
||||
--mode=c
|
||||
--lineend=linux
|
||||
--style=allman
|
||||
|
||||
# -r or -R
|
||||
#--recursive
|
||||
|
||||
# -c => Converts tabs into spaces
|
||||
convert-tabs
|
||||
|
||||
# -s2 => 2 spaces indentation
|
||||
--indent=spaces=2
|
||||
|
||||
# -t2 => tab =2 spaces
|
||||
#--indent=tab=2
|
||||
|
||||
# -C
|
||||
--indent-classes
|
||||
|
||||
# -S
|
||||
--indent-switches
|
||||
|
||||
# -xW
|
||||
--indent-preproc-block
|
||||
|
||||
# -Y => indent classes, switches (and cases), comments starting at column 1
|
||||
--indent-col1-comments
|
||||
|
||||
# -M120 => maximum of 120 spaces to indent a continuation line
|
||||
--max-continuation-indent=120
|
||||
|
||||
# -xC120 => max‑code‑length will break a line if the code exceeds # characters
|
||||
--max-code-length=120
|
||||
|
||||
# -f =>
|
||||
--break-blocks
|
||||
|
||||
# -p => put a space around operators
|
||||
--pad-oper
|
||||
|
||||
# -xg => Insert space padding after commas
|
||||
--pad-comma
|
||||
|
||||
# -H => put a space after if/for/while
|
||||
pad-header
|
||||
|
||||
# -xb => Break one line headers (e.g. if/for/while)
|
||||
--break-one-line-headers
|
||||
|
||||
# -c => Converts tabs into spaces
|
||||
#--convert-tabs
|
||||
|
||||
# if you like one-liners, keep them
|
||||
#keep-one-line-statements
|
||||
|
||||
# -xV
|
||||
--attach-closing-while
|
||||
|
||||
#unpad-paren
|
||||
|
||||
# -xp
|
||||
remove-comment-prefix
|
||||
|
6
lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh
Normal file
6
lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
for dir in . ; do
|
||||
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
|
||||
done
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue