This commit is contained in:
xin
2025-07-08 08:54:35 +08:00
parent bc81bd41ac
commit 6de3458dfc
376 changed files with 68605 additions and 246 deletions

View 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

View File

@ -0,0 +1,101 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
### Describe the bug
A clear and concise description of what the bug is.
### Steps to Reproduce
Steps to reproduce the behavior. Including the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) sketches
### Expected behavior
A clear and concise description of what you expected to happen.
### Actual behavior
A clear and concise description of what you expected to happen.
### Debug and AT-command log (if applicable)
A clear and concise description of what you expected to happen.
### Screenshots
If applicable, add screenshots to help explain your problem.
---
### Information
Please ensure to specify the following:
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* Board type (e.g. ESP32_DEV)
* 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 as you've always been. 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-57-generic #63~20.04.1-Ubuntu SMP Wed Nov 30 13:40:16 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. ...
```
---
### 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/WebServer_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/WebServer_ESP32_W5500_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_ESP32_W5500_GitHub$
```
2. Issue astyle command
```
xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_ESP32_W5500_GitHub$ bash utils/restyle.sh
```

View File

@ -0,0 +1,24 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
### Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
### Describe the solution you'd like
A clear and concise description of what you want to happen.
### Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
### Additional context
Add any other context or screenshots about the feature request here.

View File

@ -0,0 +1,10 @@
# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file
version: 2
updates:
# Configure check for outdated GitHub Actions actions in workflows.
# See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot
- package-ecosystem: github-actions
directory: / # Check the repository's workflows under /.github/workflows/
schedule:
interval: daily

View File

@ -0,0 +1,31 @@
# Configuration for probot-stale - https://github.com/probot/stale
daysUntilStale: 60
daysUntilClose: 14
limitPerRun: 30
staleLabel: stale
exemptLabels:
- pinned
- security
- "to be implemented"
- "for reference"
- "move to PR"
- "enhancement"
only: issues
onlyLabels: []
exemptProjects: false
exemptMilestones: false
exemptAssignees: false
markComment: >
[STALE_SET] This issue has been automatically marked as stale because it has not had
recent activity. It will be closed in 14 days if no further activity occurs. Thank you
for your contributions.
unmarkComment: >
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it opening the future.
closeComment: >
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

View File

@ -0,0 +1,12 @@
name: auto-github-actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v

View File

@ -0,0 +1,16 @@
name: Report Size Deltas
on:
schedule:
- cron: '*/5 * * * *'
jobs:
report:
runs-on: ubuntu-latest
steps:
- name: Comment size deltas reports to PRs
uses: arduino/report-size-deltas@v1
with:
# The name of the workflow artifact created by the "Compile Examples" workflow
sketches-reports-source: sketches-reports

View File

@ -0,0 +1,22 @@
name: Spell Check
on:
pull_request:
push:
schedule:
# run every Tuesday at 3 AM UTC
- cron: "0 3 * * 2"
workflow_dispatch:
repository_dispatch:
jobs:
spellcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# See: https://github.com/codespell-project/actions-codespell/blob/master/README.md
- name: Spell check
uses: codespell-project/actions-codespell@master

32
lib/WebServer_ESP32_W5500/.gitignore vendored Normal file
View 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

View File

@ -0,0 +1 @@
{"type": "library", "name": "WebServer_ESP32_W5500", "version": "1.5.3", "spec": {"owner": "khoih-prog", "id": 14754, "name": "WebServer_ESP32_W5500", "requirements": null, "uri": null}}

View File

@ -0,0 +1,81 @@
## Contributing to WebServer_ESP32_W5500
### Reporting Bugs
Please report bugs in WebServer_ESP32_W5500 if you find them.
However, before reporting a bug please check through the following:
* [Existing Open Issues](https://github.com/khoih-prog/WebServer_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/WebServer_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 type (e.g. ESP32_DEV)
* 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 as you've always been. 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-57-generic #63~20.04.1-Ubuntu SMP Wed Nov 30 13:40:16 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. ...
```
---
### 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/WebServer_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/WebServer_ESP32_W5500_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_ESP32_W5500_GitHub$
```
2. Issue astyle command
```
xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_ESP32_W5500_GitHub$ bash utils/restyle.sh
```

View 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>.

View File

@ -0,0 +1,35 @@
/*
Server.h - Base class that provides Server
Copyright (c) 2011 Adrian McEwen. All right 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
*/
#ifndef server_h
#define server_h
#include "Print.h"
class Server: public Print
{
public:
// KH, change to fix compiler error for EthernetWebServer
// error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
// virtual void begin(uint16_t port=0) =0;
//virtual void begin() = 0;
void begin() {};
};
#endif

View File

@ -0,0 +1,800 @@
## WebServer_ESP32_W5500 Library
[![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/WebServer_ESP32_W5500)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/WebServer_ESP32_W5500.svg)](https://github.com/khoih-prog/WebServer_ESP32_W5500/releases)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/WebServer_ESP32_W5500.svg)](http://github.com/khoih-prog/WebServer_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
* [Why do we need this WebServer_ESP32_W5500 library](#why-do-we-need-this-WebServer_ESP32_W5500-library)
* [Features](#features)
* [Currently supported Boards](#currently-supported-boards)
* [Changelog](changelog.md)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Use Arduino Library Manager](#use-arduino-library-manager)
* [Manual Install](#manual-install)
* [VS Code & PlatformIO](#vs-code--platformio)
* [Libraries' Patches](#libraries-patches)
* [1. For fixing ESP32 compile error](#1-for-fixing-esp32-compile-error)
* [HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)](#howto-use-analogread-with-esp32-running-wifi-andor-bluetooth-btble)
* [1. ESP32 has 2 ADCs, named ADC1 and ADC2](#1--esp32-has-2-adcs-named-adc1-and-adc2)
* [2. ESP32 ADCs functions](#2-esp32-adcs-functions)
* [3. ESP32 WiFi uses ADC2 for WiFi functions](#3-esp32-wifi-uses-adc2-for-wifi-functions)
* [Usage](#usage)
* [Class Constructor](#class-constructor)
* [Basic Operation](#basic-operations)
* [Advanced Options](#advanced-options)
* [Other Function Calls](#other-function-calls)
* [How to connect W5500 to ESP32](#How-to-connect-W5500-to-ESP32)
* [Examples](#examples)
* [Original Examples](#original-examples)
* [ 1. AdvancedWebServer](examples/AdvancedWebServer)
* [ 2. HelloServer](examples/HelloServer)
* [ 3. HelloServer2](examples/HelloServer2)
* [ 4. HttpBasicAuth](examples/HttpBasicAuth)
* [ 5. **MQTTClient_Auth**](examples/MQTTClient_Auth)
* [ 6. **MQTTClient_Basic**](examples/MQTTClient_Basic)
* [ 7. **MQTT_ThingStream**](examples/MQTT_ThingStream)
* [ 8. PostServer](examples/PostServer)
* [ 9. SimpleAuthentication](examples/SimpleAuthentication)
* [10. UdpNTPClient](examples/UdpNTPClient)
* [11. UdpSendReceive](examples/UdpSendReceive)
* [12. WebClient](examples/WebClient)
* [13. WebClientRepeating](examples/WebClientRepeating)
* [14. WebServer](examples/WebServer)
* [15. **multiFileProject**](examples/multiFileProject)
* [Example AdvancedWebServer](#example-advancedwebserver)
* [File AdvancedWebServer.ino](#file-advancedwebserverino)
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
* [ 1. AdvancedWebServer on ESP32_DEV with ESP32_W5500](#1-AdvancedWebServer-on-ESP32_DEV-with-ESP32_W5500)
* [ 2. MQTT_ThingStream on ESP32_DEV with ESP32_W5500](#3-MQTT_ThingStream-on-ESP32_DEV-with-ESP32_W5500)
* [ 3. MQTTClient_Auth on ESP32_DEV with ESP32_W5500](#4-MQTTClient_Auth-on-ESP32_DEV-with-ESP32_W5500)
* [ 4. MQTTClient_Basic on ESP32_DEV with ESP32_W5500](#5-MQTTClient_Basic-on-ESP32_DEV-with-ESP32_W5500)
* [ 6. WebClient on ESP32_DEV with ESP32_W5500](#6-WebClient-on-ESP32_DEV-with-ESP32_W5500)
* [ 7. UDPSendReceive on ESP32_DEV with ESP32_W5500](#7-UDPSendReceive-on-ESP32_DEV-with-ESP32_W5500)
* [Debug](#debug)
* [Troubleshooting](#troubleshooting)
* [Releases](#releases)
* [Issues](#issues)
* [TO DO](#to-do)
* [DONE](#done)
* [Contributions and Thanks](#contributions-and-thanks)
* [Contributing](#contributing)
* [License](#license)
* [Copyright](#copyright)
---
---
### Why do we need this [WebServer_ESP32_W5500 library](https://github.com/khoih-prog/WebServer_ESP32_W5500)
#### Features
This [**WebServer_ESP32_W5500 library**](https://github.com/khoih-prog/WebServer_ESP32_W5500) is a simple yet complete WebServer wrapper library for **ESP32-based** boards using `LwIP W5500 Ethernet`. The functions are similar and compatible to those of [`ESP32 WebServer`](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer) and [`ESP8266WebServer`](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer) libraries to make life much easier to port sketches from ESP8266/ESP32.
This [**WebServer_ESP32_W5500 library**](https://github.com/khoih-prog/WebServer_ESP32_W5500) also provides high-level **HTTP(S), MQTT(S) and WebSockets Client** by using the functions from ESP32's [**HTTPClient Library**](https://github.com/espressif/arduino-esp32/tree/master/libraries/HTTPClient)
The library provides these features:
1. TCP Server and Client
2. UDP Server and Client
3. HTTP(S) Server and Client
4. HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time.
5. **High-level HTTP(S) (GET, POST, PUT, PATCH, DELETE), MQTT(S) and WebSocket Client**.
Library is providing similar functions to:
1. [Ivan Grokhotkov's ESP32 WebServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer)
2. [HTTPClient Library](https://github.com/espressif/arduino-esp32/tree/master/libraries/HTTPClient)
---
#### Currently supported Boards
This [**WebServer_ESP32_W5500** library](https://github.com/khoih-prog/WebServer_ESP32_W5500) currently supports these following boards:
1. **ESP32_DEV with W5500 boards** using `LwIP W5500 Ethernet`
---
#### W5500
<p align="center">
<img src="https://github.com/khoih-prog/WebServer_ESP32_W5500/raw/main/pics/W5500.png">
</p>
<p align="center">
<img src="https://github.com/khoih-prog/WebServer_ESP32_W5500/raw/main/pics/W5500_small.png">
</p>
---
---
## Prerequisites
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
2. [`ESP32 Core 2.0.6+`](https://github.com/espressif/arduino-esp32) for ESP32-based ESP32_DEV with W5500 boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
---
---
## Installation
### Use Arduino Library Manager
The best and easiest way is to use `Arduino Library Manager`. Search for `WebServer_ESP32_W5500`, then select / install the latest version.
You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/WebServer_ESP32_W5500) for more detailed instructions.
### Manual Install
1. Navigate to [WebServer_ESP32_W5500](https://github.com/khoih-prog/WebServer_ESP32_W5500) page.
2. Download the latest release `WebServer_ESP32_W5500-main.zip`.
3. Extract the zip file to `WebServer_ESP32_W5500-main` directory
4. Copy the whole `WebServer_ESP32_W5500-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
### VS Code & PlatformIO:
1. Install [VS Code](https://code.visualstudio.com/)
2. Install [PlatformIO](https://platformio.org/platformio-ide)
3. Install [**WebServer_ESP32_W5500** library](https://registry.platformio.org/libraries/khoih-prog/WebServer_ESP32_W5500) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/WebServer_ESP32_W5500/installation). Search for WebServer_ESP32_W5500 in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
---
---
### Libraries' Patches
#### 1. For fixing ESP32 compile error
To fix [`ESP32 compile error`](https://github.com/espressif/arduino-esp32), just copy the following file into the [`ESP32`](https://github.com/espressif/arduino-esp32) cores/esp32 directory (e.g. ./arduino-1.8.19/hardware/espressif/cores/esp32) to overwrite the old file:
- [Server.h](LibraryPatches/esp32/cores/esp32/Server.h)
---
---
### HOWTO Fix `Multiple Definitions` Linker Error
The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases.
You can include this `.hpp` file
```cpp
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "WebServer_ESP32_W5500.hpp" //https://github.com/khoih-prog/WebServer_ESP32_W5500
```
in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
```cpp
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "WebServer_ESP32_W5500.h" //https://github.com/khoih-prog/WebServer_ESP32_W5500
```
Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo.
---
---
### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
Please have a look at [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to have more detailed description and solution of the issue.
#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2
#### 2. ESP32 ADCs functions
- `ADC1` controls ADC function for pins **GPIO32-GPIO39**
- `ADC2` controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27**
#### 3.. ESP32 WiFi uses ADC2 for WiFi functions
Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61)
> In ADC2, there're two locks used for different cases:
> 1. lock shared with app and Wi-Fi:
> ESP32:
> When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.
> ESP32S2:
> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
>
> 2. lock shared between tasks:
> when several tasks sharing the ADC2, we want to guarantee
> all the requests will be handled.
> Since conversions are short (about 31us), app returns the lock very soon,
> we use a spinlock to stand there waiting to do conversions one by one.
>
> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
- In order to use `ADC2` for other functions, we have to **acquire complicated firmware locks and very difficult to do**
- So, it's not advisable to use `ADC2` with WiFi/BlueTooth (BT/BLE).
- Use `ADC1`, and pins GPIO32-GPIO39
- If somehow it's a must to use those pins serviced by `ADC2` (**GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27**), use the **fix mentioned at the end** of [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to work with ESP32 WiFi/BlueTooth (BT/BLE).
---
---
#### Usage
#### Class Constructor
```cpp
WebServer server(80);
```
Creates the WebServer_ESP32_W5500 class object.
*Parameters:*
host port number: ``int port`` (default is the standard HTTP port 80)
#### Basic Operations
**Starting the server**
```cpp
void begin();
```
**Handling incoming client requests**
```cpp
void handleClient();
```
**Disabling the server**
```cpp
void close();
void stop();
```
Both methods function the same
**Client request handlers**
```cpp
void on();
void addHandler();
void onNotFound();
void onFileUpload();
```
Example:
```cpp
server.on("/", handlerFunction);
server.onNotFound(handlerFunction); // called when handler is not assigned
server.onFileUpload(handlerFunction); // handle file uploads
```
**Sending responses to the client**
```cpp
void send();
void send_P();
```
`Parameters:`
`code` - HTTP response code, can be `200` or `404`, etc.
`content_type` - HTTP content type, like `"text/plain"` or `"image/png"`, etc.
`content` - actual content body
#### Advanced Options
**Getting information about request arguments**
```cpp
const String & arg();
const String & argName();
int args();
bool hasArg();
```
`Function usage:`
`arg` - get request argument value, use `arg("plain")` to get POST body
`argName` - get request argument name
`args` - get arguments count
`hasArg` - check if argument exist
**Getting information about request headers**
```cpp
const String & header();
const String & headerName();
const String & hostHeader();
int headers();
bool hasHeader();
```
`Function usage:`
`header` - get request header value
`headerName` - get request header name
`hostHeader` - get request host header if available, else empty string
`headers` - get header count
`hasHeader` - check if header exist
**Authentication**
```cpp
bool authenticate();
void requestAuthentication();
```
`Function usage:`
`authenticate` - server authentication, returns true if client is authenticated else false
`requestAuthentication` - sends authentication failure response to the client
`Example Usage:`
```cpp
if(!server.authenticate(username, password))
{
server.requestAuthentication();
}
```
#### Other Function Calls
```cpp
const String & uri(); // get the current uri
HTTPMethod method(); // get the current method
WiFiClient client(); // get the current client
HTTPUpload & upload(); // get the current upload
void setContentLength(); // set content length
void sendHeader(); // send HTTP header
void sendContent(); // send content
void sendContent_P();
void collectHeaders(); // set the request headers to collect
void serveStatic();
size_t streamFile();
```
---
---
### How to connect W5500 to ESP32
You can change the `INT` pin to another one. Default is `GPIO4`
```cpp
// Must connect INT to GPIOxx or not working
#define INT_GPIO 4
```
---
#### W5500
<p align="center">
<img src="https://github.com/khoih-prog/WebServer_ESP32_W5500/raw/main/pics/W5500.png">
</p>
<p align="center">
<img src="https://github.com/khoih-prog/WebServer_ESP32_W5500/raw/main/pics/W5500_small.png">
</p>
---
#### ESP32_DEV
|W5500|<--->|ESP32|
|:-:|:-:|:-:|
|MOSI|<--->|GPIO23|
|MISO|<--->|GPIO19|
|SCK|<--->|GPIO18|
|SS/CS|<--->|GPIO5|
|INT|<--->|GPIO4|
|RST|<--->|RST|
|GND|<--->|GND|
|3.3V|<--->|3.3V|
---
---
### Examples:
#### Original Examples
1. [AdvancedWebServer](examples/AdvancedWebServer)
2. [HelloServer](examples/HelloServer)
3. [HelloServer2](examples/HelloServer2)
4. [HttpBasicAuth](examples/HttpBasicAuth)
5. [**MQTTClient_Auth**](examples/MQTTClient_Auth)
6. [**MQTTClient_Basic**](examples/MQTTClient_Basic)
7. [**MQTT_ThingStream**](examples/MQTT_ThingStream)
8. [PostServer](examples/PostServer)
9. [SimpleAuthentication](examples/SimpleAuthentication)
10. [UdpNTPClient](examples/UdpNTPClient)
11. [UdpSendReceive](examples/UdpSendReceive)
12. [WebClient](examples/WebClient)
13. [WebClientRepeating](examples/WebClientRepeating)
14. [WebServer](examples/WebServer)
15. [**multiFileProject**](examples/multiFileProject) **New**
---
---
### Example [AdvancedWebServer](examples/AdvancedWebServer)
#### File [AdvancedWebServer.ino](examples/AdvancedWebServer/AdvancedWebServer.ino)
https://github.com/khoih-prog/WebServer_ESP32_W5500/blob/c8bccad4dfff3a3e15611537fa023d6ea3c28937/examples/AdvancedWebServer/AdvancedWebServer.ino#L41-L275
---
---
### Debug Terminal Output Samples
#### 1. AdvancedWebServer on ESP32_DEV with ESP32_W5500
The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on ESP32_DEV with ESP32_W5500
<p align="center">
<img src="https://github.com/khoih-prog/WebServer_ESP32_W5500/raw/main/pics/AdvancedWebServer.png">
</p>
```cpp
Start AdvancedWebServer on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
HTTP EthernetWebServer is @ IP : 192.168.2.78
.......... .......... .......... .....
```
---
#### 2. MQTT_ThingStream on ESP32_DEV with ESP32_W5500
The terminal output of **ESP32_DEV with W5500** running [MQTT_ThingStream example](examples/MQTT_ThingStream)
```cpp
Start MQTT_ThingStream on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
***************************************
ESP32_Pub
***************************************
MQTT Message Send : ESP32_Pub => Hello from MQTT_ThingStream on ESP32_DEV with ESP32_W5500
MQTT Message receive [ESP32_Pub] Hello from MQTT_ThingStream on ESP32_DEV with ESP32_W5500
MQTT Message Send : ESP32_Pub => Hello from MQTT_ThingStream on ESP32_DEV with ESP32_W5500
MQTT Message receive [ESP32_Pub] Hello from MQTT_ThingStream on ESP32_DEV with ESP32_W5500
```
---
#### 4. MQTTClient_Auth on ESP32_DEV with ESP32_W5500
The terminal output of **ESP32_DEV with W5500** running [MQTTClient_Auth example](examples/MQTTClient_Auth)
```cpp
Start MQTTClient_Auth on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
Attempting MQTT connection to broker.emqx.io...connected
Message Send : MQTT_Pub => Hello from MQTTClient_Auth on ESP32_DEV with ESP32_W5500
Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on ESP32_DEV with ESP32_W5500
Message Send : MQTT_Pub => Hello from MQTTClient_Auth on ESP32_DEV with ESP32_W5500
Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on ESP32_DEV with ESP32_W5500
```
---
#### 5. MQTTClient_Basic on ESP32_DEV with ESP32_W5500
The terminal output of **ESP32_DEV with W5500** running [MQTTClient_Basic example](examples/MQTTClient_Basic)
```cpp
Start MQTTClient_Basic on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
Message Send : MQTT_Pub => Hello from MQTTClient_Basic on ESP32_DEV with ESP32_W5500
Message arrived [MQTT_Pub] Hello from MQTTClient_Basic on ESP32_DEV with ESP32_W5500
Message Send : MQTT_Pub => Hello from MQTTClient_Basic on ESP32_DEV with ESP32_W5500
Message Send : MQTT_Pub => Hello from MQTTClient_Basic on ESP32_DEV with ESP32_W5500
Message arrived [MQTT_Pub] Hello from MQTTClient_Basic on ESP32_DEV with ESP32_W5500
```
---
#### 6. WebClient on ESP32_DEV with ESP32_W5500
The terminal output of **ESP32_DEV with W5500** running [WebClient example](examples/WebClient)
```cpp
Start WebClient on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
Starting connection to server...
Connected to server
HTTP/1.1 200 OK
Date: Wed, 11 Jan 2023 19:19:39 GMT
Content-Type: text/plain
Content-Length: 2263
Connection: close
x-amz-id-2: Tibw9r4/epZQzFM/rmO3cvTdq1DH4jSKocwQ9aMHx4RlkSotUFEGantuPNlKQKGqoHtdqwpFKw0=
x-amz-request-id: SD2XWDHW10J2H90M
Last-Modified: Wed, 23 Feb 2022 14:56:42 GMT
ETag: "667cf48afcc12c38c8c1637947a04224"
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=HDCMzIyDC7oeBtywXTEb50R8fKz1H%2B7cB18KeeJVTdmf6NrFvvbxfSPcInISlUQCNqHTVbYQp4rVNVXnwo8qvTMn8bP92ozfI53aScTnOJvPaBYaK4vOt%2FZxKfHsj3o%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 78800158694b1839-EWR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;;
;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;;
.;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;;
;;;;;; ;;;;;;; ;;;;;;, ;;;;;;.
,;;;;; ;;;;;;.;;;;;;` ;;;;;;
;;;;;. ;;;;;;;;;;;` ``` ;;;;;`
;;;;; ;;;;;;;;;, ;;; .;;;;;
`;;;;: `;;;;;;;; ;;; ;;;;;
,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;
:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;
:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;
.;;;;. ;;;;;;;. ;;; ;;;;;
;;;;; ;;;;;;;;; ;;; ;;;;;
;;;;; .;;;;;;;;;; ;;; ;;;;;,
;;;;;; `;;;;;;;;;;;; ;;;;;
`;;;;;, .;;;;;; ;;;;;;; ;;;;;;
;;;;;;: :;;;;;;. ;;;;;;; ;;;;;;
;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;:
;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;;
`;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;:
,;;;;;;;;;;;;;, ;;;;;;;;;;;;;;
.;;;;;;;;;` ,;;;;;;;;:
;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;;
;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;;
,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;;
;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;.
;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;`
,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
Disconnecting from server...
```
---
#### 7. UDPSendReceive on ESP32_DEV with ESP32_W5500
The terminal output of **ESP32_DEV with W5500** running [UDPSendReceive example](examples/UDPSendReceive)
```cpp
Start UDPSendReceive on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
[EWS] Default SPI pinout:
[EWS] SPI_HOST: 2
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] CS: 5
[EWS] INT: 4
[EWS] SPI Clock (MHz): 25
[EWS] =========================
ETH Started
ETH Connected
ETH MAC: B4:E6:2D:E9:68:AC, IPv4: 192.168.2.78
FULL_DUPLEX, 100Mbps
Starting connection to server...
Listening on port 2390
UDP Packet received, size 48
From 132.163.97.3, port 123
Seconds since Jan 1 1900 = 3882452857
Unix time = 1673464057
The UTC time is 19:07:37
```
---
---
### Debug
Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change the _ETHERNET_WEBSERVER_LOGLEVEL_ to 0
```cpp
// Use this to output debug msgs to Serial
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Use this to disable all output debug msgs
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0
```
---
## Troubleshooting
If you get compilation errors, more often than not, you may need to install a newer version of the board's core, applying Libraries' Patches, Packages' Patches or this library latest version.
---
---
### Issues ###
Submit issues to: [WebServer_ESP32_W5500 issues](https://github.com/khoih-prog/WebServer_ESP32_W5500/issues)
---
### TO DO
1. Bug Searching and Killing
### DONE
1. Add support to ESP32-based **ESP32_DEV with W5500** using `LwIP W5500 Ethernet`
2. Using `SPI_DMA_CH_AUTO`
3. Using `ESP32` built-in ESP32 Ethernet `MAC Address`
---
---
### Contributions and Thanks
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
1. Based on the [Ivan Grokhotkov's ESP32 WebServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer) and [HTTPClient Library](https://github.com/espressif/arduino-esp32/tree/master/libraries/HTTPClient) libraries.
<table>
<tr>
<td align="center"><a href="https://github.com/igrr"><img src="https://github.com/igrr.png" width="100px;" alt="igrr"/><br /><sub><b>⭐️ Ivan Grokhotkov</b></sub></a><br /></td>
</tr>
</table>
---
### Contributing
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
---
### License
- The library is licensed under [GPLv3](https://github.com/khoih-prog/WebServer_ESP32_W5500/blob/main/LICENSE)
---
## Copyright
- Copyright (c) 2016- Hristo Gochkov
- Copyright (c) 2022- Khoi Hoang

View File

@ -0,0 +1,42 @@
## WebServer_ESP32_W5500 Library
[![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/WebServer_ESP32_W5500)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/WebServer_ESP32_W5500.svg)](https://github.com/khoih-prog/WebServer_ESP32_W5500/releases)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/WebServer_ESP32_W5500.svg)](http://github.com/khoih-prog/WebServer_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.5.3](#releases-v153)
* [Releases v1.5.2](#releases-v152)
* [Releases v1.5.1](#releases-v151)
---
---
## Changelog
#### Releases v1.5.3
1. Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
2. Improve library and examples code
#### Releases v1.5.2
1. Suppress compile error when using aggressive compile settings
#### Releases v1.5.1
1. Initial coding to support ESP32 boards using `W5500 LwIP Ethernet`. Sync with [WebServer_WT32_ETH01 v1.5.1](https://github.com/khoih-prog/WebServer_WT32_ETH01)

View File

@ -0,0 +1,275 @@
/****************************************************************************************************************************
AdvancedWebServer.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Copyright (c) 2015, Majenko Technologies
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 name of Majenko Technologies 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 HOLDER 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.
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
int reqCount = 0; // number of requests received
void handleRoot()
{
#define BUFFER_SIZE 400
char temp[BUFFER_SIZE];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
int day = hr / 24;
hr = hr % 24;
snprintf(temp, BUFFER_SIZE - 1,
"<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>AdvancedWebServer %s</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h2>Hi from WebServer_ESP32_W5500!</h2>\
<h3>on %s</h3>\
<p>Uptime: %d d %02d:%02d:%02d</p>\
<img src=\"/test.svg\" />\
</body>\
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60);
server.send(200, F("text/html"), temp);
}
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void drawGraph()
{
String out;
out.reserve(3000);
char temp[70];
out += F("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n");
out += F("<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"2\" stroke=\"rgb(0, 0, 0)\" />\n");
out += F("<g stroke=\"blue\">\n");
int y = rand() % 130;
for (int x = 10; x < 300; x += 10)
{
int y2 = rand() % 130;
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
out += temp;
y = y2;
}
out += F("</g>\n</svg>\n");
server.send(200, F("image/svg+xml"), out);
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart AdvancedWebServer on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), handleRoot);
server.on(F("/test.svg"), drawGraph);
server.on(F("/inline"), []()
{
server.send(200, F("text/plain"), F("This works as well"));
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(ETH.localIP());
}
void heartBeatPrint()
{
static int num = 1;
Serial.print(F("."));
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 10000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
void loop()
{
server.handleClient();
check_status();
}

View File

@ -0,0 +1,167 @@
/****************************************************************************************************************************
HelloServer.ino - Dead simple web-server for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
void handleRoot()
{
String html = F("Hello from HelloServer running on ");
html += String(BOARD_NAME);
server.send(200, F("text/plain"), html);
}
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart HelloServer on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), handleRoot);
server.on(F("/inline"), []()
{
server.send(200, F("text/plain"), F("This works as well"));
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(ETH.localIP());
}
void loop()
{
server.handleClient();
}

View File

@ -0,0 +1,190 @@
/****************************************************************************************************************************
HelloServer2.h - Dead simple web-server for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
void handleRoot()
{
String html = F("Hello from HelloServer2 running on ");
html += String(BOARD_NAME);
server.send(200, F("text/plain"), html);
}
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart HelloServer2 on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), handleRoot);
server.on(F("/inline"), []()
{
server.send(200, F("text/plain"), F("This works as well"));
});
server.on(F("/gif"), []()
{
static const uint8_t gif[] PROGMEM =
{
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d,
0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c,
0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b
};
char gif_colored[sizeof(gif)];
memcpy_P(gif_colored, gif, sizeof(gif));
// Set the background to a random set of colors
gif_colored[16] = millis() % 256;
gif_colored[17] = millis() % 256;
gif_colored[18] = millis() % 256;
server.send_P(200, "image/gif", gif_colored, sizeof(gif_colored));
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP HelloServer2 started @ IP : "));
Serial.println(ETH.localIP());
}
void loop()
{
server.handleClient();
}

View File

@ -0,0 +1,150 @@
/****************************************************************************************************************************
HTTPBasicAuth.h - Dead simple web-server for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
const char* www_username = "admin";
const char* www_password = "esp32_w5500";
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart HTTPBasicAuth on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), []()
{
if (!server.authenticate(www_username, www_password))
{
return server.requestAuthentication();
}
server.send(200, F("text/plain"), F("Login OK"));
});
server.begin();
Serial.print(F("HTTP HTTPBasicAuth started @ IP : "));
Serial.println(ETH.localIP());
Serial.print(F("Open http://"));
Serial.print(ETH.localIP());
Serial.println(F("/ in your browser to see it working"));
Serial.print(F("Using username : "));
Serial.print(www_username);
Serial.print(F(" and password : "));
Serial.println(www_password);
}
void loop()
{
server.handleClient();
}

View File

@ -0,0 +1,245 @@
/****************************************************************************************************************************
MQTTClient_Auth.ino - Dead simple MQTT Client for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
/*
Basic MQTT example (without SSL!) with Authentication
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- providing username and password
- publishes "hello world" to the topic "outTopic"
- subscribes to the topic "inTopic", printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
*/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
#include <PubSubClient.h>
// Update these with values suitable for your network.
//const char* mqttServer = "broker.example"; // Broker address
const char* mqttServer = "broker.emqx.io"; // Broker address
//const char* mqttServer = "broker.shiftr.io"; // Broker address
const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique
const char *TOPIC = "MQTT_Pub"; // Topic to subscribe to
const char *subTopic = "MQTT_Sub"; // Topic to subscribe to
//IPAddress mqttServer(172, 16, 0, 2);
void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (unsigned int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
WiFiClient ethClient;
PubSubClient client(mqttServer, 1883, callback, ethClient);
void reconnect()
{
// Loop until we're reconnected
while (!client.connected())
{
Serial.print("Attempting MQTT connection to ");
Serial.print(mqttServer);
// Attempt to connect
if (client.connect("arduino", "try", "try"))
{
Serial.println("...connected");
// Once connected, publish an announcement...
String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME);
client.publish(TOPIC, data.c_str());
//Serial.println("Published connection message successfully!");
//Serial.print("Subscribed to: ");
//Serial.println(subTopic);
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
// ... and resubscribe
client.subscribe(subTopic);
// for loopback testing
client.subscribe(TOPIC);
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
}
else
{
Serial.print("...failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart MQTTClient_Auth on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
// Note - the default maximum packet size is 128 bytes. If the
// combined length of clientId, username and password exceed this use the
// following to increase the buffer size:
// client.setBufferSize(255);
}
#define MQTT_PUBLISH_INTERVAL_MS 5000L
String data = "Hello from MQTTClient_Auth on " + String(ARDUINO_BOARD) + " with " + String(SHIELD_TYPE);
const char *pubData = data.c_str();
unsigned long lastMsg = 0;
void loop()
{
static unsigned long now;
if (!client.connected())
{
reconnect();
}
// Sending Data
now = millis();
if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS)
{
lastMsg = now;
if (!client.publish(TOPIC, pubData))
{
Serial.println("Message failed to send.");
}
Serial.print("Message Send : " + String(TOPIC) + " => ");
Serial.println(data);
}
client.loop();
}

View File

@ -0,0 +1,247 @@
/****************************************************************************************************************************
MQTTClient_Basic.ino - Dead simple MQTT Client for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
/*
Basic MQTT example (without SSL!) with Authentication
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- providing username and password
- publishes "hello world" to the topic "outTopic"
- subscribes to the topic "inTopic", printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
*/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
#include <PubSubClient.h>
// Update these with values suitable for your network.
//const char* mqttServer = "broker.example"; // Broker address
const char* mqttServer = "broker.emqx.io"; // Broker address
//const char* mqttServer = "broker.shiftr.io"; // Broker address
const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique
const char *TOPIC = "MQTT_Pub"; // Topic to subscribe to
const char *subTopic = "MQTT_Sub"; // Topic to subscribe to
//IPAddress mqttServer(172, 16, 0, 2);
void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (unsigned int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
WiFiClient ethClient;
PubSubClient client(mqttServer, 1883, callback, ethClient);
void reconnect()
{
// Loop until we're reconnected
while (!client.connected())
{
//Serial.print("Attempting MQTT connection to ");
//Serial.print(mqttServer);
// Attempt to connect
if (client.connect(ID, "try", "try"))
{
//Serial.println("...connected");
// Once connected, publish an announcement...
String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME);
client.publish(TOPIC, data.c_str());
//Serial.println("Published connection message successfully!");
//Serial.print("Subscribed to: ");
//Serial.println(subTopic);
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
// ... and resubscribe
client.subscribe(subTopic);
// for loopback testing
client.subscribe(TOPIC);
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
}
else
{
Serial.print("...failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart MQTTClient_Basic on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
client.setServer(mqttServer, 1883);
client.setCallback(callback);
// Allow the hardware to sort itself out
delay(1500);
}
#define MQTT_PUBLISH_INTERVAL_MS 5000L
String data = "Hello from MQTTClient_Basic on " + String(ARDUINO_BOARD) + " with " + String(SHIELD_TYPE);
const char *pubData = data.c_str();
unsigned long lastMsg = 0;
void loop()
{
static unsigned long now;
if (!client.connected())
{
reconnect();
}
// Sending Data
now = millis();
if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS)
{
lastMsg = now;
if (!client.publish(TOPIC, pubData))
{
Serial.println("Message failed to send.");
}
Serial.print("Message Send : " + String(TOPIC) + " => ");
Serial.println(data);
}
client.loop();
}

View File

@ -0,0 +1,293 @@
/****************************************************************************************************************************
MQTT_ThingStream.ino - Dead simple MQTT Client for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
/*
Basic MQTT example (without SSL!)
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- publishes {Hello from MQTTClient_SSL on NUCLEO_F767ZI} to the topic [STM32_Pub]
- subscribes to the topic [STM32_Sub], printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
You will need to populate "certificates.h" with your trust anchors
(see https://github.com/OPEnSLab-OSU/SSLClient/blob/master/TrustAnchors.md)
and my_cert/my_key with your certificate/private key pair
(see https://github.com/OPEnSLab-OSU/SSLClient#mtls).
*/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
#include <PubSubClient.h>
const char my_cert[] = "FIXME";
const char my_key[] = "FIXME";
#define USING_THINGSTREAM_IO false //true
#if USING_THINGSTREAM_IO
const char *MQTT_PREFIX_TOPIC = "esp32-sniffer/";
const char *MQTT_ANNOUNCE_TOPIC = "/status";
const char *MQTT_CONTROL_TOPIC = "/control";
const char *MQTT_BLE_TOPIC = "/ble";
// GOT FROM ThingsStream!
const char *MQTT_SERVER = "mqtt.thingstream.io";
const char *MQTT_USER = "MQTT_USER";
const char *MQTT_PASS = "MQTT_PASS";
const char *MQTT_CLIENT_ID = "MQTT_CLIENT_ID";
String topic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC;
String subTopic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC;
#else
const char* MQTT_SERVER = "broker.emqx.io"; // Broker address
const char* ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique
String topic = "ESP32_Pub"; // Topic to subscribe to
String subTopic = "ESP32_Sub"; // Topic to subscribe to
#endif
void mqtt_receive_callback(char* topic, byte* payload, unsigned int length);
const int MQTT_PORT = 1883; //if you use SSL //1883 no SSL
unsigned long lastMsg = 0;
// Initialize the SSL client library
// Arguments: EthernetClient, our trust anchors
WiFiClient ethClient;
PubSubClient client(MQTT_SERVER, MQTT_PORT, mqtt_receive_callback, ethClient);
/*
Called whenever a payload is received from a subscribed MQTT topic
*/
void mqtt_receive_callback(char* topic, byte* payload, unsigned int length)
{
Serial.print("MQTT Message receive [");
Serial.print(topic);
Serial.print("] ");
for (unsigned int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
void reconnect()
{
// Loop until we're reconnected
while (!client.connected())
{
//Serial.print("Attempting MQTT connection to ");
//Serial.println(MQTT_SERVER);
// Attempt to connect
#if USING_THINGSTREAM_IO
int connect_status = client.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, topic.c_str(), 2, false, "");
#else
int connect_status = client.connect(ID);
#endif
if (connect_status)
{
//Serial.println("...connected");
// Once connected, publish an announcement...
String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME);
client.publish(topic.c_str(), data.c_str());
//Serial.println("Published connection message successfully!");
//Serial.print("Subscribed to: ");
//Serial.println(subTopic);
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
// ... and resubscribe
client.subscribe(subTopic.c_str());
// for loopback testing
client.subscribe(topic.c_str());
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
//ethClientSSL.flush();
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart MQTT_ThingStream on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
// Note - the default maximum packet size is 256 bytes. If the
// combined length of clientId, username and password exceed this use the
// following to increase the buffer size:
//client.setBufferSize(256);
Serial.println("***************************************");
Serial.println(topic);
Serial.println("***************************************");
}
#define MQTT_PUBLISH_INTERVAL_MS 5000L
String data = "Hello from MQTT_ThingStream on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE);
const char *pubData = data.c_str();
void loop()
{
static unsigned long now;
if (!client.connected())
{
reconnect();
}
// Sending Data
now = millis();
if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS)
{
lastMsg = now;
if (!client.publish(topic.c_str(), pubData))
{
Serial.println("Message failed to send.");
}
Serial.print("MQTT Message Send : " + topic + " => ");
Serial.println(data);
}
client.loop();
}

View File

@ -0,0 +1,215 @@
/****************************************************************************************************************************
PostServer.h - Dead simple web-server for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
const String postForms =
F("<html>\
<head>\
<title>WebServer_ESP32_ENC POST handling</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>POST plain text to /postplain/</h1><br>\
<form method=\"post\" enctype=\"text/plain\" action=\"/postplain/\">\
<input type=\"text\" name=\'{\"hello\": \"world\", \"trash\": \"\' value=\'\"}\'><br>\
<input type=\"submit\" value=\"Submit\">\
</form>\
<h1>POST form data to /postform/</h1><br>\
<form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
<input type=\"text\" name=\"hello\" value=\"world\"><br>\
<input type=\"submit\" value=\"Submit\">\
</form>\
</body>\
</html>");
void handleRoot()
{
server.send(200, F("text/html"), postForms);
}
void handlePlain()
{
if (server.method() != HTTP_POST)
{
server.send(405, F("text/plain"), F("Method Not Allowed"));
}
else
{
server.send(200, F("text/plain"), "POST body was:\n" + server.arg("plain"));
}
}
void handleForm()
{
if (server.method() != HTTP_POST)
{
server.send(405, F("text/plain"), F("Method Not Allowed"));
}
else
{
String message = F("POST form was:\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(200, F("text/plain"), message);
}
}
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart POSTServer on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), handleRoot);
server.on(F("/postplain/"), handlePlain);
server.on(F("/postform/"), handleForm);
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP POSTServer started @ IP : "));
Serial.println(ETH.localIP());
}
void loop()
{
server.handleClient();
}

View File

@ -0,0 +1,268 @@
/****************************************************************************************************************************
SimpleAuthentication.ino - Dead simple web-server for Ethernet shields
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WebServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
//Check if header is present and correct
bool is_authenticated()
{
Serial.println(F("Enter is_authenticated"));
if (server.hasHeader(F("Cookie")))
{
Serial.print(F("Found cookie: "));
String cookie = server.header(F("Cookie"));
Serial.println(cookie);
if (cookie.indexOf(F("ESPSESSIONID=1")) != -1)
{
Serial.println(F("Authentication Successful"));
return true;
}
}
Serial.println(F("Authentication Failed"));
return false;
}
//login page, also called for disconnect
void handleLogin()
{
String msg;
if (server.hasHeader(F("Cookie")))
{
Serial.print(F("Found cookie: "));
String cookie = server.header(F("Cookie"));
Serial.println(cookie);
}
if (server.hasArg(F("DISCONNECT")))
{
Serial.println(F("Disconnection"));
server.sendHeader(F("Location"), F("/login"));
server.sendHeader(F("Cache-Control"), F("no-cache"));
server.sendHeader(F("Set-Cookie"), F("ESPSESSIONID=0"));
server.send(301);
return;
}
if (server.hasArg(F("USERNAME")) && server.hasArg(F("PASSWORD")))
{
if (server.arg(F("USERNAME")) == F("admin") && server.arg(F("PASSWORD")) == F("password"))
{
server.sendHeader(F("Location"), F("/"));
server.sendHeader(F("Cache-Control"), F("no-cache"));
server.sendHeader(F("Set-Cookie"), F("ESPSESSIONID=1"));
server.send(301);
Serial.println(F("Log in Successful"));
return;
}
msg = F("Wrong username/password! try again.");
Serial.println(F("Log in Failed"));
}
String content = F("<html><body><form action='/login' method='POST'>To log in, please use : admin/password<br>");
content += F("User:<input type='text' name='USERNAME' placeholder='user name'><br>");
content += F("Password:<input type='password' name='PASSWORD' placeholder='password'><br>");
content += F("<input type='submit' name='SUBMIT' value='Submit'></form>");
content += msg;
content += F("<br>");
content += F("You also can go <a href='/inline'>here</a></body></html>");
server.send(200, F("text/html"), content);
}
//root page can be accessed only if authentication is ok
void handleRoot()
{
String header;
Serial.println(F("Enter handleRoot"));
if (!is_authenticated())
{
server.sendHeader(F("Location"), F("/login"));
server.sendHeader(F("Cache-Control"), F("no-cache"));
server.send(301);
return;
}
String content = F("<html><body><H2>Hello, you're connected to WebServer_ESP32_W5500 running on ");
content += String(ARDUINO_BOARD);
content += F("!</H2><br>");
if (server.hasHeader(F("User-Agent")))
{
content += F("the user agent used is : ");
content += server.header(F("User-Agent"));
content += F("<br><br>");
}
content += F("You can access this page until you <a href=\"/login?DISCONNECT=YES\">disconnect</a></body></html>");
server.send(200, F("text/html"), content);
}
//no need authentication
void handleNotFound()
{
String message = F("File Not Found\n\n");
message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, F("text/plain"), message);
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart SimpleAuthentication on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
server.on(F("/"), handleRoot);
server.on(F("/login"), handleLogin);
server.on(F("/inline"), []()
{
server.send(200, F("text/plain"), F("This works without need of authentication"));
});
server.onNotFound(handleNotFound);
//here the list of headers to be recorded
const char * headerkeys[] = {"User-Agent", "Cookie"} ;
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
//ask server to track these headers
server.collectHeaders(headerkeys, headerkeyssize);
server.begin();
Serial.print(F("HTTP SimpleAuthentication is @ IP : "));
Serial.println(ETH.localIP());
}
void loop()
{
server.handleClient();
}

View File

@ -0,0 +1,236 @@
/****************************************************************************************************************************
UdpNTPClient.ino - Simple Arduino web server sample for ESP8266 AT-command shield
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
/*
The Arduino board communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno
and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53,
is not used to select the Ethernet controller chip, but it must be kept as an output or the SPI interface won't work.
*/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
char timeServer[] = "time.nist.gov"; // NTP server
unsigned int localPort = 2390; // local port to listen for UDP packets
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
const int UDP_TIMEOUT = 2000; // timeout in milliseconds to wait for an UDP packet to arrive
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
// send an NTP request to the time server at the given address
void sendNTPpacket(char *ntpSrv)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(ntpSrv, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart UdpNTPClient on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
Udp.begin(localPort);
}
void loop()
{
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait for a reply for UDP_TIMEOUT milliseconds
unsigned long startMs = millis();
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print(F("UDP Packet received, size "));
Serial.println(packetSize);
Serial.print(F("From "));
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(F(", port "));
Serial.println(Udp.remotePort());
// We've received a packet, read the data from it into the buffer
Udp.read(packetBuffer, NTP_PACKET_SIZE);
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print(F("Seconds since Jan 1 1900 = "));
Serial.println(secsSince1900);
// now convert NTP time into )everyday time:
Serial.print(F("Unix time = "));
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);
// print the hour, minute and second:
Serial.print(F("The UTC time is ")); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(F(":"));
if (((epoch % 3600) / 60) < 10)
{
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print(F("0"));
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(F(":"));
if ((epoch % 60) < 10)
{
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print(F("0"));
}
Serial.println(epoch % 60); // print the second
}
// wait ten seconds before asking for the time again
delay(10000);
}

View File

@ -0,0 +1,237 @@
/****************************************************************************************************************************
UDPSendReceive.ino - Simple Arduino web server sample for ESP8266/ESP32 AT-command shield
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
char timeServer[] = "time.nist.gov"; // NTP server
unsigned int localPort = 2390; // local port to listen for UDP packets
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
const int UDP_TIMEOUT = 2000; // timeout in milliseconds to wait for an UDP packet to arrive
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming packet
byte ReplyBuffer[] = "ACK"; // a string to send back
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
// send an NTP request to the time server at the given address
void sendNTPpacket(char *ntpSrv)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(ntpSrv, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart UDPSendReceive on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
Serial.println(F("\nStarting connection to server..."));
// if you get a connection, report back via serial:
Udp.begin(localPort);
Serial.print(F("Listening on port "));
Serial.println(localPort);
}
void loop()
{
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait for a reply for UDP_TIMEOUT milliseconds
unsigned long startMs = millis();
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print(F("UDP Packet received, size "));
Serial.println(packetSize);
Serial.print(F("From "));
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(F(", port "));
Serial.println(Udp.remotePort());
// We've received a packet, read the data from it into the buffer
Udp.read(packetBuffer, NTP_PACKET_SIZE);
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print(F("Seconds since Jan 1 1900 = "));
Serial.println(secsSince1900);
// now convert NTP time into )everyday time:
Serial.print(F("Unix time = "));
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);
// print the hour, minute and second:
Serial.print(F("The UTC time is ")); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(F(":"));
if (((epoch % 3600) / 60) < 10)
{
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print(F("0"));
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(F(":"));
if ((epoch % 60) < 10)
{
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print(F("0"));
}
Serial.println(epoch % 60); // print the second
}
// wait ten seconds before asking for the time again
delay(10000);
}

View File

@ -0,0 +1,166 @@
/****************************************************************************************************************************
WebClient.ino - Simple Arduino web server sample for Ethernet shield
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
char server[] = "arduino.tips";
// Initialize the Ethernet client object
WiFiClient client;
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart WebClient on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
// KH, Dynamic not OK yet
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
Serial.println();
Serial.println(F("Starting connection to server..."));
// if you get a connection, report back via serial
if (client.connect(server, 80))
{
Serial.println(F("Connected to server"));
// Make a HTTP request
client.println(F("GET /asciilogo.txt HTTP/1.1"));
client.println(F("Host: arduino.tips"));
client.println(F("Connection: close"));
client.println();
}
}
void printoutData()
{
// if there are incoming bytes available
// from the server, read them and print them
while (client.available())
{
char c = client.read();
Serial.write(c);
Serial.flush();
}
}
void loop()
{
printoutData();
// if the server's disconnected, stop the client
if (!client.connected())
{
Serial.println();
Serial.println(F("Disconnecting from server..."));
client.stop();
// do nothing forever
while (true)
yield();
}
}

View File

@ -0,0 +1,179 @@
/****************************************************************************************************************************
WebClientRepeating.ino - Simple Arduino web server sample for Ethernet shield
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
/*
The Arduino board communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno
and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53,
is not used to select the Ethernet controller chip, but it must be kept as an output or the SPI interface won't work.
*/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
char server[] = "arduino.tips";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
// Initialize the Web client object
WiFiClient client;
// this method makes a HTTP connection to the server
void httpRequest()
{
Serial.println();
// close any connection before send a new request
// this will free the socket on the WiFi shield
client.stop();
// if there's a successful connection
if (client.connect(server, 80))
{
Serial.println(F("Connecting..."));
// send the HTTP PUT request
client.println(F("GET /asciilogo.txt HTTP/1.1"));
client.println(F("Host: arduino.tips"));
client.println(F("Connection: close"));
client.println();
// note the time that the connection was made
lastConnectionTime = millis();
}
else
{
// if you couldn't make a connection
Serial.println(F("Connection failed"));
}
}
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart WebClientRepeating on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
}
void loop()
{
// if there's incoming data from the net connection send it out the serial port
// this is for debugging purposes only
while (client.available())
{
char c = client.read();
Serial.write(c);
Serial.flush();
}
// if 10 seconds have passed since your last connection,
// then connect again and send data
if (millis() - lastConnectionTime > postingInterval)
{
httpRequest();
}
}

View File

@ -0,0 +1,190 @@
/****************************************************************************************************************************
WebServer.ino - Simple Arduino web server sample for Ethernet shield
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
WiFiServer server(80);
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};
// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
int reqCount = 0; // number of requests received
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart WebServer on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);
ESP32_W5500_waitForConnect();
///////////////////////////////////
// start the web server on port 80
server.begin();
}
void loop()
{
// listen for incoming clients
WiFiClient client = server.available();
if (client)
{
Serial.println(F("New client"));
// an http request ends with a blank line
bool currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
Serial.println(F("Sending response"));
// send a standard http response header
// use \r\n instead of many println statements to speedup data send
client.print(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n" // the connection will be closed after completion of the response
"Refresh: 20\r\n" // refresh the page automatically every 20 sec
"\r\n");
client.print("<!DOCTYPE HTML>\r\n");
client.print("<html>\r\n");
client.print(String("<h2>Hello World from ") + BOARD_NAME + "!</h2>\r\n");
client.print("Requests received: ");
client.print(++reqCount);
client.print("<br>\r\n");
client.print("<br>\r\n");
client.print("</html>\r\n");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println(F("Client disconnected"));
}
}

View File

@ -0,0 +1,14 @@
/****************************************************************************************************************************
multiFileProject.cpp
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
// To demo how to include files in multi-file Projects
#include "multiFileProject.h"

View File

@ -0,0 +1,36 @@
/****************************************************************************************************************************
multiFileProject.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
// To demo how to include files in multi-file Projects
#pragma once
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 1
//////////////////////////////////////////////////////////
// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST SPI3_HOST
//#define SPI_CLOCK_MHZ 25
// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
//////////////////////////////////////////////////////////
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "WebServer_ESP32_W5500.hpp"

View File

@ -0,0 +1,37 @@
/****************************************************************************************************************************
multiFileProject.ino
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
*****************************************************************************************************************************/
// To demo how to include files in multi-file Projects
#include "multiFileProject.h"
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "WebServer_ESP32_W5500.h"
void setup()
{
Serial.begin(115200);
while (!Serial);
delay(500);
Serial.println("\nStart multiFileProject");
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
Serial.print("You're OK now");
}
void loop()
{
// put your main code here, to run repeatedly:
}

View File

@ -0,0 +1,30 @@
{
"name": "WebServer_ESP32_W5500",
"version": "1.5.3",
"keywords": "WebServer, Ethernet, MQTT, MQTTS, HTTP, HTTPS, SSL, Arduino, ESP32, W5500, HTTP-Client, WebSocket-Client, MQTT-Client, server, client, websocket, LittleFS, SPIFFS, ThingStream",
"description": "Simple Ethernet WebServer, HTTP/HTTPS Client wrapper library for ESP32 boards using W5500 with LwIP Ethernet library. The WebServer supports HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time. It provides HTTP(S), MQTT(S) Client and supports WebServer serving from LittleFS/SPIFFS",
"authors":
{
"name": "Khoi Hoang",
"url": "https://github.com/khoih-prog",
"maintainer": true
},
"repository":
{
"type": "git",
"url": "https://github.com/khoih-prog/WebServer_ESP32_W5500"
},
"homepage": "https://github.com/khoih-prog/WebServer_ESP32_W5500",
"export": {
"exclude": [
"linux",
"extras",
"tests"
]
},
"license": "GPL-3.0",
"frameworks": "*",
"platforms": "espressif32",
"examples": "examples/*/*/*.ino",
"headers": ["WebServer_ESP32_W5500.h", "WebServer_ESP32_W5500.hpp"]
}

View File

@ -0,0 +1,11 @@
name=WebServer_ESP32_W5500
version=1.5.3
author=Khoi Hoang
license=GPLv3
maintainer=Khoi Hoang <khoih.prog@gmail.com>
sentence=Simple Ethernet WebServer, HTTP/HTTPS Client wrapper library for ESP32 boards using W5500 with LwIP Ethernet library.
paragraph=The WebServer supports HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time. It provides HTTP(S), MQTT(S) Client and supports WebServer serving from LittleFS/SPIFFS
category=Communication
url=https://github.com/khoih-prog/WebServer_ESP32_W5500
architectures=esp32
includes=WebServer_ESP32_W5500.h, WebServer_ESP32_W5500.hpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

View File

@ -0,0 +1,163 @@
;PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
; ============================================================
; chose environment:
; ESP32
; esp32s2
; esp32s3
; esp32c3
; ============================================================
default_envs = ESP32
[env]
; ============================================================
; Serial configuration
; choose upload speed, serial-monitor speed
; ============================================================
upload_speed = 921600
;upload_port = COM11
;monitor_speed = 9600
;monitor_port = COM11
; ============================================================
; Checks for the compatibility with frameworks and dev/platforms
lib_compat_mode = strict
lib_ldf_mode = chain+
;lib_ldf_mode = deep+
; ============================================================
lib_deps =
; ============================================================
build_flags =
; set your debug output (default=Serial)
-D DEBUG_ESP_PORT=Serial
; comment the following line to enable WiFi debugging
-D NDEBUG
; ============================================================
; ============================================================
[env:ESP32]
platform = espressif32
framework = arduino
; ============================================================
; Board configuration
; choose your board by uncommenting one of the following lines
; ============================================================
;board = esp32cam
;board = alksesp32
;board = featheresp32
;board = espea32
;board = bpi-bit
;board = d-duino-32
board = esp32doit-devkit-v1
;board = pocket_32
;board = fm-devkit
;board = pico32
;board = esp32-evb
;board = esp32-gateway
;board = esp32-pro
;board = esp32-poe
;board = oroca_edubot
;board = onehorse32dev
;board = lopy
;board = lopy4
;board = wesp32
;board = esp32thing
;board = sparkfun_lora_gateway_1-channel
;board = ttgo-lora32-v1
;board = ttgo-t-beam
;board = turta_iot_node
;board = lolin_d32
;board = lolin_d32_pro
;board = lolin32
;board = wemosbat
;board = widora-air
;board = xinabox_cw02
;board = iotbusio
;board = iotbusproteus
;board = nina_w10
; ============================================================
; ============================================================
[env:esp32s2]
platform = espressif32
framework = arduino
; toolchain download links see
; refer "name": "xtensa-esp32s2-elf-gcc","version": "gcc8_4_0-esp-2021r1" section of
; https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
; e.g. Windows: https://github.com/espressif/crosstool-NG/releases/download/esp-2021r1/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r1-win32.zip
platform_packages =
toolchain-xtensa32s2@file://C:\Users\Max\Downloads\xtensa-esp32s2-elf
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#a4118ea88987c28aac3a49bcb9cc5d6c0acc6f3f
platformio/tool-esptoolpy @ ~1.30100
framework = arduino
board = esp32dev
board_build.mcu = esp32s2
board_build.partitions = huge_app.csv
board_build.variant = esp32s2
board_build.f_cpu = 240000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_build.arduino.ldscript = esp32s2_out.ld
build_unflags =
-DARDUINO_ESP32_DEV
-DARDUINO_VARIANT="esp32"
build_flags =
-DARDUINO_ESP32S2_DEV
-DARDUINO_VARIANT="esp32s2"
; ============================================================
; ============================================================
[env:esp32s3]
platform = espressif32
framework = arduino
board_build.mcu = esp32s3
board_build.partitions = huge_app.csv
board_build.variant = esp32s3
board_build.f_cpu = 240000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_build.arduino.ldscript = esp32s3_out.ld
build_unflags =
-DARDUINO_ESP32_DEV
-DARDUINO_VARIANT="esp32"
build_flags =
-DARDUINO_ESP32S3_DEV
-DARDUINO_VARIANT="esp32s3"
; ============================================================
; ============================================================
[env:esp32sc3]
platform = espressif32
framework = arduino
board_build.mcu = esp32c3
board_build.partitions = huge_app.csv
board_build.variant = esp32c3
board_build.f_cpu = 160000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_build.arduino.ldscript = esp32c3_out.ld
build_unflags =
-DARDUINO_ESP32_DEV
-DARDUINO_VARIANT="esp32"
build_flags =
-DARDUINO_ESP32S3_DEV
-DARDUINO_VARIANT="esp32c3"
; ============================================================
; ============================================================

View File

@ -0,0 +1,93 @@
/****************************************************************************************************************************
WebServer_ESP32_W5500.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#pragma once
#ifndef WEBSERVER_ESP32_W5500_H
#define WEBSERVER_ESP32_W5500_H
//////////////////////////////////////////////////////////////
//#if !defined(USING_CORE_ESP32_CORE_V200_PLUS)
#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 (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#warning Using code for ESP32 core v2.0.0+ in WebServer_ESP32_W5500.h
#endif
#define WEBSERVER_ESP32_W5500_VERSION "WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+"
#else
#if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#warning Using code for ESP32 core v1.0.6- in WebServer_ESP32_W5500.h
#endif
#define WEBSERVER_ESP32_W5500_VERSION "WebServer_ESP32_W5500 v1.5.3 for core v1.0.6-"
#endif
#define WEBSERVER_ESP32_W5500_VERSION_MAJOR 1
#define WEBSERVER_ESP32_W5500_VERSION_MINOR 5
#define WEBSERVER_ESP32_W5500_VERSION_PATCH 3
#define WEBSERVER_ESP32_W5500_VERSION_INT 1005003
//////////////////////////////////////////////////////////////
#if ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \
ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \
ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM )
#error ESP32_S2 not supported. Use WebServer_ESP32_SC_W5500 library
#elif ( ARDUINO_ESP32C3_DEV )
#error ESP32_C3 not supported. Use WebServer_ESP32_SC_W5500 library
#elif ( defined(ARDUINO_ESP32S3_DEV) || defined(ARDUINO_ESP32_S3_BOX) || defined(ARDUINO_TINYS3) || \
defined(ARDUINO_PROS3) || defined(ARDUINO_FEATHERS3) )
#error ESP32_S3 not supported. Use WebServer_ESP32_SC_W5500 library
#elif ESP32
#if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#warning Using ESP32 architecture for WebServer_ESP32_W5500
#endif
#define BOARD_NAME ARDUINO_BOARD
#else
#error This code is designed to run on ESP32 platform! Please check your Tools->Board setting.
#endif
//////////////////////////////////////////////////////////////
#include <Arduino.h>
#include "WebServer_ESP32_W5500_Debug.h"
//////////////////////////////////////////////////////////////
#include "w5500/esp32_w5500.h"
#include "WebServer_ESP32_W5500.hpp"
#include "WebServer_ESP32_W5500_Impl.h"
#endif // WEBSERVER_ESP32_W5500_H

View File

@ -0,0 +1,88 @@
/****************************************************************************************************************************
WebServer_ESP32_W5500.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#pragma once
#ifndef WEBSERVER_ESP32_W5500_HPP
#define WEBSERVER_ESP32_W5500_HPP
//////////////////////////////////////////////////////////////
//#define CONFIG_ETH_SPI_ETHERNET_W5500 true
//////////////////////////////////////////////////////////////
#include <WiFi.h>
#include <WebServer.h> // Introduce corresponding libraries
#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
//////////////////////////////////////////////////////////////
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);
//////////////////////////////////////////////////////////////
#endif // WEBSERVER_ESP32_W5500_HPP

View File

@ -0,0 +1,111 @@
/****************************************************************************************************************************
WebServer_ESP32_W5500_Debug.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#pragma once
#ifndef WEBSERVER_ESP32_W5500_DEBUG_H
#define WEBSERVER_ESP32_W5500_DEBUG_H
#include <Arduino.h>
#include <stdio.h>
///////////////////////////////////////
#ifdef DEBUG_ETHERNET_WEBSERVER_PORT
#define ET_DEBUG_OUTPUT DEBUG_ETHERNET_WEBSERVER_PORT
#else
#define ET_DEBUG_OUTPUT Serial
#endif
///////////////////////////////////////
// Change _ETHERNET_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 _ETHERNET_WEBSERVER_LOGLEVEL_
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0
#endif
///////////////////////////////////////
const char EWS_MARK[] = "[EWS] ";
const char EWS_SPACE[] = " ";
const char EWS_LINE[] = "========================================\n";
#define EWS_PRINT_MARK EWS_PRINT(EWS_MARK)
#define EWS_PRINT_SP EWS_PRINT(EWS_SPACE)
#define EWS_PRINT_LINE EWS_PRINT(EWS_LINE)
#define EWS_PRINT ET_DEBUG_OUTPUT.print
#define EWS_PRINTLN ET_DEBUG_OUTPUT.println
///////////////////////////////////////
#define ET_LOG(x) { EWS_PRINTLN(x); }
#define ET_LOG0(x) { EWS_PRINT(x); }
#define ET_LOG1(x,y) { EWS_PRINT(x); EWS_PRINTLN(y); }
#define ET_LOG2(x,y,z) { EWS_PRINT(x); EWS_PRINT(y); EWS_PRINTLN(z); }
#define ET_LOG3(x,y,z,w) { EWS_PRINT(x); EWS_PRINT(y); EWS_PRINT(z); EWS_PRINTLN(w); }
///////////////////////////////////////
#define ET_LOGERROR(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINTLN(x); }
#define ET_LOGERROR_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; }
#define ET_LOGERROR0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT(x); }
#define ET_LOGERROR1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); }
#define ET_LOGERROR2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); }
#define ET_LOGERROR3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); }
///////////////////////////////////////
#define ET_LOGWARN(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINTLN(x); }
#define ET_LOGWARN_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; }
#define ET_LOGWARN0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT(x); }
#define ET_LOGWARN1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); }
#define ET_LOGWARN2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); }
#define ET_LOGWARN3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); }
///////////////////////////////////////
#define ET_LOGINFO(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINTLN(x); }
#define ET_LOGINFO_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; }
#define ET_LOGINFO0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT(x); }
#define ET_LOGINFO1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); }
#define ET_LOGINFO2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); }
#define ET_LOGINFO3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); }
///////////////////////////////////////
#define ET_LOGDEBUG(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINTLN(x); }
#define ET_LOGDEBUG_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; }
#define ET_LOGDEBUG0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT(x); }
#define ET_LOGDEBUG1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); }
#define ET_LOGDEBUG2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); }
#define ET_LOGDEBUG3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); }
///////////////////////////////////////
#endif // WEBSERVER_ESP32_W5500_DEBUG_H

View File

@ -0,0 +1,161 @@
/****************************************************************************************************************************
WebServer_ESP32_W5500_Impl.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#pragma once
#ifndef WEBSERVER_ESP32_W5500_IMPL_H
#define WEBSERVER_ESP32_W5500_IMPL_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:
ET_LOG(F("\nETH Started"));
//set eth hostname here
ETH.setHostname("ESP32_W5500");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
ET_LOG(F("ETH Connected"));
break;
case ARDUINO_EVENT_ETH_GOT_IP:
if (!ESP32_W5500_eth_connected)
{
ET_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP());
if (ETH.fullDuplex())
{
ET_LOG0(F("FULL_DUPLEX, "));
}
else
{
ET_LOG0(F("HALF_DUPLEX, "));
}
ET_LOG1(ETH.linkSpeed(), F("Mbps"));
ESP32_W5500_eth_connected = true;
}
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
ET_LOG("ETH Disconnected");
ESP32_W5500_eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
ET_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:
ET_LOG(F("\nETH Started"));
//set eth hostname here
ETH.setHostname("ESP32_W5500");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
ET_LOG(F("ETH Connected"));
break;
case SYSTEM_EVENT_ETH_GOT_IP:
if (!ESP32_W5500_eth_connected)
{
ET_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP());
if (ETH.fullDuplex())
{
ET_LOG0(F("FULL_DUPLEX, "));
}
else
{
ET_LOG0(F("HALF_DUPLEX, "));
}
ET_LOG1(ETH.linkSpeed(), F("Mbps"));
ESP32_W5500_eth_connected = true;
}
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
ET_LOG("ETH Disconnected");
ESP32_W5500_eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
ET_LOG("\nETH Stopped");
ESP32_W5500_eth_connected = false;
break;
#endif
default:
break;
}
}
//////////////////////////////////////////////////////////////
#endif // WEBSERVER_ESP32_W5500_IMPL_H

View File

@ -0,0 +1,439 @@
/****************************************************************************************************************************
esp32_w5500.cpp
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#include "WebServer_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 );
if ( esp_read_mac(mac_eth, ESP_MAC_ETH) == ESP_OK )
{
char macStr[18] = { 0 };
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac_eth[0], mac_eth[1], mac_eth[2],
mac_eth[3], mac_eth[4], mac_eth[5]);
ET_LOGINFO1("Using built-in mac_eth =", macStr);
esp_base_mac_addr_set( mac_eth );
}
else
{
ET_LOGINFO("Using user mac_eth");
memcpy(mac_eth, W5500_Mac, sizeof(mac_eth));
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)
{
ET_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)
{
ET_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(&eth_config, &eth_handle) != ESP_OK || eth_handle == NULL)
{
ET_LOG("esp_eth_driver_install failed");
return false;
}
eth_mac->set_addr(eth_mac, mac_eth);
#if 1
if ( (SPICLOCK_MHZ < 14) || (SPICLOCK_MHZ > 25) )
{
ET_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)
{
ET_LOGERROR("esp_netif_attach failed");
return false;
}
if (esp_eth_start(eth_handle) != ESP_OK)
{
ET_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)
{
ET_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)
{
ET_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)
{
ET_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))
{
ET_LOGDEBUG("localIP NULL");
return IPAddress();
}
ET_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;

View File

@ -0,0 +1,104 @@
/****************************************************************************************************************************
esp32_w5500.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#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;
uint8_t mac_eth[6] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF };
#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_ */

View File

@ -0,0 +1,958 @@
/****************************************************************************************************************************
esp_eth_mac_w5500.c
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
// 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), &reg_value, sizeof(reg_value)), err, TAG,
"Set rx buffer size failed");
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(0), &reg_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), &reg_value, sizeof(reg_value)), err, TAG,
"Set SOCK_RXBUF_SIZE failed");
ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(i), &reg_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, &reg_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, &reg_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), &reg_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), &reg_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, &reg_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, &reg_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, &reg_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;
}
////////////////////////////////////////

View File

@ -0,0 +1,379 @@
/****************************************************************************************************************************
esp_eth_phy_w5500.c
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
// 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;
}
////////////////////////////////////////

View File

@ -0,0 +1,110 @@
/****************************************************************************************************************************
esp_eth_spi_w5500.c
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
#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, SPI_DMA_CH_AUTO ))
{
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 );
}
////////////////////////////////////////

View File

@ -0,0 +1,146 @@
/****************************************************************************************************************************
esp_eth_w5500.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
// 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

View File

@ -0,0 +1,126 @@
/****************************************************************************************************************************
w5500.h
For Ethernet shields using ESP32_W5500 (ESP32 + W5500)
WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer
Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500
Licensed under GPLv3 license
Version: 1.5.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.5.1 K Hoang 29/11/2022 Initial coding for ESP32_W5500 (ESP32 + W5500). Sync with WebServer_WT32_ETH01 v1.5.1
1.5.2 K Hoang 06/01/2023 Suppress compile error when using aggressive compile settings
1.5.3 K Hoang 11/01/2023 Using `SPI_DMA_CH_AUTO` and built-in ESP32 MAC
*****************************************************************************************************************************/
// 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
////////////////////////////////////////

View 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 => maxcodelength 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

View 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