Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cb843c636 | ||
|
|
35d43080b4 | ||
|
|
2379954e53 | ||
|
|
1153d520aa | ||
|
|
86a0c6495e | ||
|
|
b691c1b98b | ||
|
|
87984ddf22 | ||
|
|
f2d87e5fe1 | ||
|
|
17e1b04421 | ||
|
|
5a5350b48a | ||
|
|
16d24257f8 | ||
|
|
233dbbbbcd | ||
|
|
c11a245270 | ||
|
|
e7dabe52bc | ||
|
|
ccad41d7a5 | ||
|
|
34588d6b35 | ||
|
|
b1d131492b | ||
|
|
2fab6bb4cf | ||
|
|
a2e850fb72 |
+35
@@ -0,0 +1,35 @@
|
||||
# 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
|
||||
|
||||
# Visual Studio folder and files
|
||||
.vs
|
||||
+1
-1
@@ -29,7 +29,7 @@ Please ensure to specify the following:
|
||||
Arduino IDE version: 1.8.13
|
||||
ESP32 Core Version 1.0.4
|
||||
OS: Ubuntu 20.04 LTS
|
||||
Linux xy-Inspiron-3593 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
|
||||
Linux xy-Inspiron-3593 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
Context:
|
||||
I encountered an endless loop while trying to connect to Local WiFi.
|
||||
|
||||
@@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2019 Khoi Hoang
|
||||
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.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
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>.
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Arduino.h - Main include file for the Arduino SDK
|
||||
Copyright (c) 2014 Arduino LLC. 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 Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CORE_HAS_LIBB64
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t word;
|
||||
|
||||
// some libraries and sketches depend on this AVR stuff,
|
||||
// assuming Arduino.h or WProgram.h automatically includes it...
|
||||
//
|
||||
#include "avr/pgmspace.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "avr/dtostrf.h"
|
||||
#include "avr/io.h"
|
||||
|
||||
#include "binary.h"
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
#include "sam.h"
|
||||
|
||||
#include "wiring_constants.h"
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
|
||||
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
|
||||
|
||||
void yield( void ) ;
|
||||
|
||||
/* system functions */
|
||||
int main( void );
|
||||
void init( void );
|
||||
|
||||
/* sketch */
|
||||
void setup( void ) ;
|
||||
void loop( void ) ;
|
||||
|
||||
int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
#include "variant.h"
|
||||
|
||||
#include "wiring.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_shift.h"
|
||||
#include "wiring_pwm.h"
|
||||
#include "WInterrupts.h"
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
#ifndef interruptsStatus
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
|
||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Arduino.h - Main include file for the Arduino SDK
|
||||
Copyright (c) 2014 Arduino LLC. 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 Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CORE_HAS_LIBB64
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t word;
|
||||
|
||||
// some libraries and sketches depend on this AVR stuff,
|
||||
// assuming Arduino.h or WProgram.h automatically includes it...
|
||||
//
|
||||
#include "avr/pgmspace.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "avr/dtostrf.h"
|
||||
#include "avr/io.h"
|
||||
|
||||
#include "binary.h"
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
#include "sam.h"
|
||||
|
||||
#include "wiring_constants.h"
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
|
||||
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
|
||||
|
||||
void yield( void ) ;
|
||||
|
||||
/* system functions */
|
||||
int main( void );
|
||||
void init( void );
|
||||
|
||||
/* sketch */
|
||||
void setup( void ) ;
|
||||
void loop( void ) ;
|
||||
|
||||
int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
#include "variant.h"
|
||||
|
||||
#include "wiring.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_shift.h"
|
||||
#include "wiring_pwm.h"
|
||||
#include "WInterrupts.h"
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
#ifndef interruptsStatus
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
|
||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Arduino.h - Main include file for the Arduino SDK
|
||||
Copyright (c) 2014 Arduino LLC. 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 Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CORE_HAS_LIBB64
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t word;
|
||||
|
||||
// some libraries and sketches depend on this AVR stuff,
|
||||
// assuming Arduino.h or WProgram.h automatically includes it...
|
||||
//
|
||||
#include "avr/pgmspace.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "avr/dtostrf.h"
|
||||
#include "avr/io.h"
|
||||
|
||||
#include "binary.h"
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
#include "sam.h"
|
||||
|
||||
#include "wiring_constants.h"
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
|
||||
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
|
||||
|
||||
void yield( void ) ;
|
||||
|
||||
/* system functions */
|
||||
int main( void );
|
||||
void init( void );
|
||||
|
||||
/* sketch */
|
||||
void setup( void ) ;
|
||||
void loop( void ) ;
|
||||
|
||||
int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
#include "variant.h"
|
||||
|
||||
#include "wiring.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_shift.h"
|
||||
#include "wiring_pwm.h"
|
||||
#include "WInterrupts.h"
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
#ifndef interruptsStatus
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
|
||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Arduino.h - Main include file for the Arduino SDK
|
||||
Copyright (c) 2014 Arduino LLC. 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 Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CORE_HAS_LIBB64
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t word;
|
||||
|
||||
// some libraries and sketches depend on this AVR stuff,
|
||||
// assuming Arduino.h or WProgram.h automatically includes it...
|
||||
//
|
||||
#include "avr/pgmspace.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "avr/dtostrf.h"
|
||||
#include "avr/io.h"
|
||||
|
||||
#include "binary.h"
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
#include "sam.h"
|
||||
|
||||
#include "wiring_constants.h"
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
|
||||
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
|
||||
|
||||
void yield( void ) ;
|
||||
|
||||
/* system functions */
|
||||
int main( void );
|
||||
void init( void );
|
||||
|
||||
/* sketch */
|
||||
void setup( void ) ;
|
||||
void loop( void ) ;
|
||||
|
||||
int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
#include "variant.h"
|
||||
|
||||
#include "wiring.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_shift.h"
|
||||
#include "wiring_pwm.h"
|
||||
#include "WInterrupts.h"
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
#ifndef interruptsStatus
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
|
||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,227 @@
|
||||
# Copyright (c) 2014-2015 Arduino LLC. 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
|
||||
|
||||
# Arduino SAMD Core and platform.
|
||||
#
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Adafruit SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) Boards
|
||||
version=1.6.5
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall -Wno-expansion-to-defined
|
||||
compiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined
|
||||
|
||||
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
build.cache_flags=
|
||||
build.flags.optimize=
|
||||
build.flags.maxspi=
|
||||
build.flags.maxqspi=
|
||||
build.flags.usbstack=
|
||||
build.flags.debug=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
#compiler.c.elf.extra_flags=-v
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Core/Include/" "-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/DSP/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
|
||||
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
|
||||
|
||||
compiler.libraries.ldflags=
|
||||
|
||||
# USB Flags
|
||||
# ---------
|
||||
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON -DUSB_CONFIG_POWER={build.usb_power} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {build.flags.usbstack} {build.flags.debug} "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src"
|
||||
|
||||
# Default advertised device power setting in mA
|
||||
build.usb_power=100
|
||||
|
||||
# Default usb manufacturer will be replaced at compile time using
|
||||
# numeric vendor ID if available or by board's specific value.
|
||||
build.usb_manufacturer="Unknown"
|
||||
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} "-L{build.variant.path}" -lm "{build.path}/{archive_file}" -Wl,--end-group
|
||||
|
||||
## Create output (bin file)
|
||||
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||
|
||||
## Create output (hex file)
|
||||
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
build.preferred_out_format=bin
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=\.text\s+([0-9]+).*
|
||||
|
||||
#
|
||||
# BOSSA
|
||||
#
|
||||
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossac.cmd=bossac
|
||||
tools.bossac.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossac.upload.params.verbose=-i -d
|
||||
tools.bossac.upload.params.quiet=
|
||||
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
tools.bossac.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
# v1.8.0
|
||||
|
||||
tools.bossac18.path={runtime.tools.bossac-1.8.0-48-gb176eee.path}
|
||||
tools.bossac18.cmd=bossac
|
||||
|
||||
tools.bossac18.upload.params.verbose=-i -d
|
||||
tools.bossac18.upload.params.quiet=
|
||||
tools.bossac18.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U -i --offset={upload.offset} -w -v "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossac18.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossac18.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
#
|
||||
# BOSSA (ignore binary size)
|
||||
#
|
||||
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossacI.cmd=bossac
|
||||
tools.bossacI.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossacI.upload.params.verbose=-i -d
|
||||
tools.bossacI.upload.params.quiet=
|
||||
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload
|
||||
#
|
||||
|
||||
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd.cmd=bin/openocd
|
||||
tools.openocd.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd.upload.params.verbose=-d2
|
||||
tools.openocd.upload.params.quiet=-d0
|
||||
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
|
||||
|
||||
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
|
||||
tools.openocd.program.params.verbose=-d2
|
||||
tools.openocd.program.params.quiet=-d0
|
||||
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
|
||||
|
||||
tools.openocd.erase.params.verbose=-d3
|
||||
tools.openocd.erase.params.quiet=-d0
|
||||
tools.openocd.erase.pattern=
|
||||
|
||||
tools.openocd.bootloader.params.verbose=-d2
|
||||
tools.openocd.bootloader.params.quiet=-d0
|
||||
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload - version with configurable bootloader size
|
||||
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
|
||||
#
|
||||
|
||||
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd-withbootsize.cmd=bin/openocd
|
||||
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd-withbootsize.upload.params.verbose=-d2
|
||||
tools.openocd-withbootsize.upload.params.quiet=-d0
|
||||
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
|
||||
|
||||
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
|
||||
tools.openocd-withbootsize.program.params.verbose=-d2
|
||||
tools.openocd-withbootsize.program.params.quiet=-d0
|
||||
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
|
||||
|
||||
tools.openocd-withbootsize.erase.params.verbose=-d3
|
||||
tools.openocd-withbootsize.erase.params.quiet=-d0
|
||||
tools.openocd-withbootsize.erase.pattern=
|
||||
|
||||
tools.openocd-withbootsize.bootloader.params.verbose=-d2
|
||||
tools.openocd-withbootsize.bootloader.params.quiet=-d0
|
||||
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
# Copyright (c) 2014-2015 Arduino LLC. 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
|
||||
|
||||
# Arduino SAMD Core and platform.
|
||||
#
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Arduino SAMD (32-bits ARM Cortex-M0+) Boards
|
||||
version=1.8.10
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
# EXPERIMENTAL feature: optimization flags
|
||||
# - this is alpha and may be subject to change without notice
|
||||
compiler.optimization_flags=-Os
|
||||
compiler.optimization_flags.release=-Os
|
||||
compiler.optimization_flags.debug=-Og -g3
|
||||
|
||||
compiler.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.optimization_flags} -Wl,--gc-sections -save-temps
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
#compiler.c.elf.extra_flags=-v
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
|
||||
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
|
||||
|
||||
compiler.libraries.ldflags=
|
||||
|
||||
# USB Flags
|
||||
# ---------
|
||||
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
|
||||
|
||||
# Default usb manufacturer will be replaced at compile time using
|
||||
# numeric vendor ID if available or by board's specific value.
|
||||
build.usb_manufacturer="Unknown"
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} -lm "{build.path}/{archive_file}" -Wl,--end-group
|
||||
|
||||
## Create output (bin file)
|
||||
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||
|
||||
## Create output (hex file)
|
||||
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
build.preferred_out_format=bin
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.text|\.data|)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
|
||||
|
||||
|
||||
# Debugger configuration (general options)
|
||||
# ----------------------------------------
|
||||
# EXPERIMENTAL feature:
|
||||
# - this is alpha and may be subject to change without notice
|
||||
debug.executable={build.path}/{build.project_name}.elf
|
||||
debug.toolchain=gcc
|
||||
debug.toolchain.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
|
||||
debug.toolchain.prefix=arm-none-eabi-
|
||||
debug.server=openocd
|
||||
debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd
|
||||
debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/
|
||||
debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript}
|
||||
|
||||
# Upload/Debug tools
|
||||
# ------------------
|
||||
|
||||
#
|
||||
# AVRDUDE
|
||||
#
|
||||
tools.avrdude.path={runtime.tools.avrdude.path}
|
||||
tools.avrdude.cmd={path}/bin/avrdude
|
||||
tools.avrdude.config.path={path}/etc/avrdude.conf
|
||||
|
||||
tools.avrdude.upload.params.verbose=-v -v
|
||||
tools.avrdude.upload.params.quiet=-q -q
|
||||
tools.avrdude.upload.params.noverify=-V
|
||||
tools.avrdude.upload.pattern="{cmd}" "-C{config.path}" {upload.verbose} -p{build.emu.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} "-Uflash:w:{build.path}/{build.project_name}.hex:i"
|
||||
|
||||
tools.avrdude_remote.upload.pattern="openocd --version 2>&1 | grep 2016 && if opkg update; then opkg upgrade openocd; exit 1; else echo 'Please connect your board to the Internet in order to upgrade tools' >&2; exit 1; fi || /usr/bin/run-avrdude /tmp/sketch.hex"
|
||||
|
||||
tools.avrdude.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.avrdude.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
#
|
||||
# BOSSA
|
||||
#
|
||||
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossac.cmd=bossac
|
||||
tools.bossac.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossac.upload.params.verbose=-i -d
|
||||
tools.bossac.upload.params.quiet=
|
||||
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
arduinoota.extraflags=
|
||||
tools.bossac.network_cmd={runtime.tools.arduinoOTA-1.3.0.path}/bin/arduinoOTA
|
||||
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b {arduinoota.extraflags}
|
||||
|
||||
#
|
||||
# BOSSA (ignore binary size)
|
||||
#
|
||||
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossacI.cmd=bossac
|
||||
tools.bossacI.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossacI.upload.params.verbose=-i -d
|
||||
tools.bossacI.upload.params.quiet=
|
||||
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload
|
||||
#
|
||||
|
||||
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd.cmd=bin/openocd
|
||||
tools.openocd.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd.upload.params.verbose=-d2
|
||||
tools.openocd.upload.params.quiet=-d0
|
||||
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
|
||||
|
||||
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
tools.openocd.program.params.verbose=-d2
|
||||
tools.openocd.program.params.quiet=-d0
|
||||
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.hex} verify reset; shutdown"
|
||||
|
||||
tools.openocd.erase.params.verbose=-d3
|
||||
tools.openocd.erase.params.quiet=-d0
|
||||
tools.openocd.erase.pattern=
|
||||
|
||||
tools.openocd.bootloader.params.verbose=-d2
|
||||
tools.openocd.bootloader.params.quiet=-d0
|
||||
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload - version with configurable bootloader size
|
||||
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
|
||||
#
|
||||
|
||||
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd-withbootsize.cmd=bin/openocd
|
||||
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd-withbootsize.upload.params.verbose=-d2
|
||||
tools.openocd-withbootsize.upload.params.quiet=-d0
|
||||
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
|
||||
|
||||
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
|
||||
tools.openocd-withbootsize.program.params.verbose=-d2
|
||||
tools.openocd-withbootsize.program.params.quiet=-d0
|
||||
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
|
||||
|
||||
tools.openocd-withbootsize.erase.params.verbose=-d3
|
||||
tools.openocd-withbootsize.erase.params.quiet=-d0
|
||||
tools.openocd-withbootsize.erase.pattern=
|
||||
|
||||
tools.openocd-withbootsize.bootloader.params.verbose=-d2
|
||||
tools.openocd-withbootsize.bootloader.params.quiet=-d0
|
||||
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
# Copyright (c) 2014-2015 Arduino LLC. 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
|
||||
|
||||
# Arduino SAMD Core and platform.
|
||||
#
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Arduino SAMD (32-bits ARM Cortex-M0+) Boards
|
||||
version=1.8.11
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
# EXPERIMENTAL feature: optimization flags
|
||||
# - this is alpha and may be subject to change without notice
|
||||
compiler.optimization_flags=-Os
|
||||
compiler.optimization_flags.release=-Os
|
||||
compiler.optimization_flags.debug=-Og -g3
|
||||
|
||||
compiler.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.optimization_flags} -Wl,--gc-sections -save-temps
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
#compiler.c.elf.extra_flags=-v
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
|
||||
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
|
||||
|
||||
compiler.libraries.ldflags=
|
||||
|
||||
# USB Flags
|
||||
# ---------
|
||||
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
|
||||
|
||||
# Default usb manufacturer will be replaced at compile time using
|
||||
# numeric vendor ID if available or by board's specific value.
|
||||
build.usb_manufacturer="Unknown"
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DBOARD_NAME="{build.board}" -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} -lm "{build.path}/{archive_file}" -Wl,--end-group
|
||||
|
||||
## Create output (bin file)
|
||||
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||
|
||||
## Create output (hex file)
|
||||
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
build.preferred_out_format=bin
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.text|\.data|)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
|
||||
|
||||
|
||||
# Debugger configuration (general options)
|
||||
# ----------------------------------------
|
||||
# EXPERIMENTAL feature:
|
||||
# - this is alpha and may be subject to change without notice
|
||||
debug.executable={build.path}/{build.project_name}.elf
|
||||
debug.toolchain=gcc
|
||||
debug.toolchain.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
|
||||
debug.toolchain.prefix=arm-none-eabi-
|
||||
debug.server=openocd
|
||||
debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd
|
||||
debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/
|
||||
debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript}
|
||||
|
||||
# Upload/Debug tools
|
||||
# ------------------
|
||||
|
||||
#
|
||||
# AVRDUDE
|
||||
#
|
||||
tools.avrdude.path={runtime.tools.avrdude.path}
|
||||
tools.avrdude.cmd={path}/bin/avrdude
|
||||
tools.avrdude.config.path={path}/etc/avrdude.conf
|
||||
|
||||
tools.avrdude.upload.params.verbose=-v -v
|
||||
tools.avrdude.upload.params.quiet=-q -q
|
||||
tools.avrdude.upload.params.noverify=-V
|
||||
tools.avrdude.upload.pattern="{cmd}" "-C{config.path}" {upload.verbose} -p{build.emu.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} "-Uflash:w:{build.path}/{build.project_name}.hex:i"
|
||||
|
||||
tools.avrdude_remote.upload.pattern="openocd --version 2>&1 | grep 2016 && if opkg update; then opkg upgrade openocd; exit 1; else echo 'Please connect your board to the Internet in order to upgrade tools' >&2; exit 1; fi || /usr/bin/run-avrdude /tmp/sketch.hex"
|
||||
|
||||
tools.avrdude.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.avrdude.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
#
|
||||
# BOSSA
|
||||
#
|
||||
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossac.cmd=bossac
|
||||
tools.bossac.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossac.upload.params.verbose=-i -d
|
||||
tools.bossac.upload.params.quiet=
|
||||
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
arduinoota.extraflags=
|
||||
tools.bossac.network_cmd={runtime.tools.arduinoOTA-1.3.0.path}/bin/arduinoOTA
|
||||
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b {arduinoota.extraflags}
|
||||
|
||||
#
|
||||
# BOSSA (ignore binary size)
|
||||
#
|
||||
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
|
||||
tools.bossacI.cmd=bossac
|
||||
tools.bossacI.cmd.windows=bossac.exe
|
||||
|
||||
tools.bossacI.upload.params.verbose=-i -d
|
||||
tools.bossacI.upload.params.quiet=
|
||||
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
|
||||
|
||||
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload
|
||||
#
|
||||
|
||||
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd.cmd=bin/openocd
|
||||
tools.openocd.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd.upload.params.verbose=-d2
|
||||
tools.openocd.upload.params.quiet=-d0
|
||||
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
|
||||
|
||||
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
tools.openocd.program.params.verbose=-d2
|
||||
tools.openocd.program.params.quiet=-d0
|
||||
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.hex} verify reset; shutdown"
|
||||
|
||||
tools.openocd.erase.params.verbose=-d3
|
||||
tools.openocd.erase.params.quiet=-d0
|
||||
tools.openocd.erase.pattern=
|
||||
|
||||
tools.openocd.bootloader.params.verbose=-d2
|
||||
tools.openocd.bootloader.params.quiet=-d0
|
||||
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload - version with configurable bootloader size
|
||||
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
|
||||
#
|
||||
|
||||
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
|
||||
tools.openocd-withbootsize.cmd=bin/openocd
|
||||
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
|
||||
|
||||
tools.openocd-withbootsize.upload.params.verbose=-d2
|
||||
tools.openocd-withbootsize.upload.params.quiet=-d0
|
||||
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
|
||||
|
||||
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
|
||||
tools.openocd-withbootsize.program.params.verbose=-d2
|
||||
tools.openocd-withbootsize.program.params.quiet=-d0
|
||||
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
|
||||
|
||||
tools.openocd-withbootsize.erase.params.verbose=-d3
|
||||
tools.openocd-withbootsize.erase.params.quiet=-d0
|
||||
tools.openocd-withbootsize.erase.pattern=
|
||||
|
||||
tools.openocd-withbootsize.bootloader.params.verbose=-d2
|
||||
tools.openocd-withbootsize.bootloader.params.quiet=-d0
|
||||
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Stream.h - base class for character-based streams.
|
||||
Copyright (c) 2010 David A. Mellis. 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 Stream_h
|
||||
#define Stream_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
bool find(const uint8_t *target) { return find ((const char *)target); }
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); }
|
||||
bool findUntil(const char *target, char *terminator);
|
||||
bool findUntil(const uint8_t *target, char *terminator) { return findUntil((const char *)target, terminator); }
|
||||
bool findUntil(const char *target, size_t targetLen, char *terminate, size_t termLen);
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); }
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
String readString(size_t max = 120);
|
||||
String readStringUntil(char terminator, size_t max = 120);
|
||||
int getReadError() { return read_error; }
|
||||
void clearReadError() { setReadError(0); }
|
||||
protected:
|
||||
void setReadError(int err = 1) { read_error = err; }
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
|
||||
//int timedRead();
|
||||
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Stream.h - base class for character-based streams.
|
||||
Copyright (c) 2010 David A. Mellis. 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 Stream_h
|
||||
#define Stream_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
bool find(const uint8_t *target) { return find ((const char *)target); }
|
||||
bool find(const String &target) { return find(target.c_str()); }
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); }
|
||||
bool find(const String &target, size_t length) { return find(target.c_str(), length); }
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((const char *)target, terminator); }
|
||||
bool findUntil(const String &target, const char *terminator) { return findUntil(target.c_str(), terminator); }
|
||||
bool findUntil(const char *target, const String &terminator) { return findUntil(target, terminator.c_str()); }
|
||||
bool findUntil(const String &target, const String &terminator) { return findUntil(target.c_str(), terminator.c_str()); }
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); }
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
String readString(size_t max = 120);
|
||||
String readStringUntil(char terminator, size_t max = 120);
|
||||
int getReadError() { return read_error; }
|
||||
void clearReadError() { setReadError(0); }
|
||||
protected:
|
||||
void setReadError(int err = 1) { read_error = err; }
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
|
||||
//int timedRead();
|
||||
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Stream.h - base class for character-based streams.
|
||||
Copyright (c) 2010 David A. Mellis. 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 Stream_h
|
||||
#define Stream_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
bool find(const uint8_t *target) { return find ((const char *)target); }
|
||||
bool find(const String &target) { return find(target.c_str()); }
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); }
|
||||
bool find(const String &target, size_t length) { return find(target.c_str(), length); }
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((const char *)target, terminator); }
|
||||
bool findUntil(const String &target, const char *terminator) { return findUntil(target.c_str(), terminator); }
|
||||
bool findUntil(const char *target, const String &terminator) { return findUntil(target, terminator.c_str()); }
|
||||
bool findUntil(const String &target, const String &terminator) { return findUntil(target.c_str(), terminator.c_str()); }
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); }
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
String readString(size_t max = 120);
|
||||
String readStringUntil(char terminator, size_t max = 120);
|
||||
int getReadError() { return read_error; }
|
||||
void clearReadError() { setReadError(0); }
|
||||
protected:
|
||||
void setReadError(int err = 1) { read_error = err; }
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
|
||||
//int timedRead();
|
||||
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,74 @@
|
||||
---
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
|
||||
* [Why do we need the new Async AsyncHTTPRequest_Generic library](#why-do-we-need-this-async-asynchttprequest_generic-library)
|
||||
* [Features](#features)
|
||||
* [Supports](#supports)
|
||||
* [Principles of operation](#principles-of-operation)
|
||||
* [Changelog](#changelog)
|
||||
* [Releases v1.1.2](#releases-v112)
|
||||
* [Releases v1.1.1](#releases-v111)
|
||||
* [Releases v1.1.0](#releases-v110)
|
||||
* [Releases v1.0.2](#releases-v102)
|
||||
* [Releases v1.0.1](#releases-v101)
|
||||
* [Releases v1.0.0](#releases-v100)
|
||||
* [AsyncHTTPRequest_Generic for ESP32, ESP8266 using built-in WiFi and STM32 boards using built-in LAN8742A Ethernet](#asynchttprequest_generic-for-esp32-esp8266-using-built-in-wifi-and-stm32-boards-using-built-in-lan8742a-ethernet)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Installation](#installation)
|
||||
* [Use Arduino Library Manager](#use-arduino-library-manager)
|
||||
* [Manual Install](#manual-install)
|
||||
* [VS Code & PlatformIO](#vs-code--platformio)
|
||||
* [Packages' Patches](#packages-patches)
|
||||
* [1. For Adafruit nRF52840 and nRF52832 boards](#1-for-adafruit-nRF52840-and-nRF52832-boards)
|
||||
* [2. For Teensy boards](#2-for-teensy-boards)
|
||||
* [3. For Arduino SAM DUE boards](#3-for-arduino-sam-due-boards)
|
||||
* [4. For Arduino SAMD boards](#4-for-arduino-samd-boards)
|
||||
* [For core version v1.8.10+](#for-core-version-v1810)
|
||||
* [For core version v1.8.9-](#for-core-version-v189-)
|
||||
* [5. For Adafruit SAMD boards](#5-for-adafruit-samd-boards)
|
||||
* [6. For Seeeduino SAMD boards](#6-for-seeeduino-samd-boards)
|
||||
* [7. For STM32 boards](#7-for-stm32-boards)
|
||||
* [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
|
||||
* [Note for Platform IO using ESP32 LittleFS](#note-for-platform-io-using-esp32-littlefs)
|
||||
* [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)
|
||||
* [Examples](#examples)
|
||||
* [AsyncHTTPRequest_ESP](examples/AsyncHTTPRequest_ESP)
|
||||
* [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager)
|
||||
* [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32)
|
||||
* [AsyncCustomHeader_STM32](examples/AsyncCustomHeader_STM32)
|
||||
* [AsyncDweetGet_STM32](examples/AsyncDweetGet_STM32)
|
||||
* [AsyncDweetPost_STM32](examples/AsyncDweetPost_STM32)
|
||||
* [AsyncSimpleGET_STM32](examples/AsyncSimpleGET_STM32)
|
||||
* [AsyncWebClientRepeating_STM32](examples/AsyncWebClientRepeating_STM32)
|
||||
* [Example AsyncHTTPRequest_STM32](#example-asynchttprequest_stm32)
|
||||
* [1. File AsyncHTTPRequest_STM32.ino](#1-file-asynchttprequest_stm32ino)
|
||||
* [2. File defines.h](#2-file-definesh)
|
||||
* [Debug Terminal Output Samples](#debug-termimal-output-samples)
|
||||
* [1. AsyncHTTPRequest_STM32 running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A ](#1-asynchttprequest_stm32-running-on-stm32f7-nucleo-144-nucleo_f767zi-using-built-in-lan8742a)
|
||||
* [2. AsyncHTTPRequest_ESP_WiFiManager running on ESP8266_NODEMCU](#2-asynchttprequest_esp_wifimanager-running-on-esp8266_nodemcu)
|
||||
* [3. AsyncHTTPRequest_ESP_WiFiManager running on ESP32_DEV](#3-asynchttprequest_esp_wifimanager-running-on-esp32_dev)
|
||||
* [4. AsyncHTTPRequest_ESP running on ESP8266_NODEMCU](#4-asynchttprequest_esp-running-on-esp8266_nodemcu)
|
||||
* [5. AsyncWebClientRepeating_STM32 running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A](#5-asyncwebclientrepeating_stm32-running-on-stm32f7-nucleo-144-nucleo_f767zi-using-built-in-lan8742a)
|
||||
* [Debug](#debug)
|
||||
* [Troubleshooting](#troubleshooting)
|
||||
* [Issues](#issues)
|
||||
* [Releases](#releases)
|
||||
* [TO DO](#to-do)
|
||||
* [DONE](#done)
|
||||
* [Contributions and Thanks](#contributions-and-thanks)
|
||||
* [Contributing](#contributing)
|
||||
* [License and credits](#license-and-credits)
|
||||
* [Copyright](#copyright)
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Why do we need this Async [AsyncHTTPRequest_Generic library](https://github.com/khoih-prog/AsyncHTTPRequest_Generic)
|
||||
|
||||
#### Features
|
||||
@@ -19,9 +87,9 @@
|
||||
4. Relying on **[`STM32duino LwIP`](https://github.com/stm32duino/LwIP)/[`STM32duino STM32Ethernet`](https://github.com/stm32duino/STM32Ethernet)/[`STM32AsyncTCP`](https://github.com/philbowles/STM32AsyncTCP) for STM32 using built-in LAN8742A Ethernet.**
|
||||
5. Methods similar in format and usage to XmlHTTPrequest in Javascript.
|
||||
|
||||
#### Supports:
|
||||
#### Supports
|
||||
|
||||
1. **GET and POST**
|
||||
1. **GET, POST, PUT, PATCH, DELETE and HEAD**
|
||||
2. Request and response headers
|
||||
3. Chunked response
|
||||
4. Single String response for short (<~5K) responses (heap permitting).
|
||||
@@ -45,6 +113,26 @@ Chunked responses are recognized and handled transparently.
|
||||
---
|
||||
---
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
### Releases v1.1.2
|
||||
|
||||
1. Rename _lock and _unlock to avoid conflict with [**ESP32/ESP8266 AsyncWebServer**](https://github.com/me-no-dev/ESPAsyncWebServer) library. Check [**compatibility with ESPAsyncWebServer #11**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/11)
|
||||
2. Fix compiler warnings.
|
||||
|
||||
### Releases v1.1.1
|
||||
|
||||
1. Prevent crash if request and/or method not correct.
|
||||
|
||||
|
||||
### Releases v1.1.0
|
||||
|
||||
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
|
||||
2. Add Table of Contents
|
||||
3. Add Version String
|
||||
|
||||
|
||||
### Releases v1.0.2
|
||||
|
||||
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
||||
@@ -80,17 +168,18 @@ This library is based on, modified from:
|
||||
---
|
||||
---
|
||||
|
||||
## Prerequisite
|
||||
## Prerequisites
|
||||
|
||||
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
|
||||
2. [`ESP8266 Core 2.7.4+`](https://github.com/esp8266/Arduino) for ESP8266-based boards.
|
||||
3. [`ESP32 Core 1.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards
|
||||
4. [`Arduino Core for STM32 1.9.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for for STM32 using built-in Ethernet LAN8742A.
|
||||
2. [`ESP8266 Core 2.7.4+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [](https://github.com/esp8266/Arduino/releases/latest/)
|
||||
3. [`ESP32 Core 1.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [Latest stable release 
|
||||
4. [`Arduino Core for STM32 1.9.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for for STM32 using built-in Ethernet LAN8742A. [](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest)
|
||||
5. [`ESPAsyncTCP v1.2.2+`](https://github.com/me-no-dev/ESPAsyncTCP) for ESP8266.
|
||||
6. [`AsyncTCP v1.1.1+`](https://github.com/me-no-dev/AsyncTCP) for ESP32.
|
||||
7. [`STM32Ethernet library v1.2.0+`](https://github.com/stm32duino/STM32Ethernet) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery).
|
||||
8. [`LwIP library v2.1.2+`](https://github.com/stm32duino/LwIP) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery).
|
||||
9. [`STM32AsyncTCP library`](https://github.com/philbowles/STM32AsyncTCP) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery).
|
||||
7. [`STM32Ethernet library v1.2.0+`](https://github.com/stm32duino/STM32Ethernet) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). [](https://github.com/stm32duino/STM32Ethernet/releases/latest)
|
||||
8. [`LwIP library v2.1.2+`](https://github.com/stm32duino/LwIP) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). [](https://github.com/stm32duino/LwIP/releases/latest)
|
||||
9. [`STM32AsyncTCP library v1.0.0+`](https://github.com/philbowles/STM32AsyncTCP) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery).
|
||||
10. [`ESPAsync_WiFiManager library v1.4.3+`](https://github.com/khoih-prog/ESPAsync_WiFiManager) for ESP32/ESP8266 using some examples. [](https://github.com/khoih-prog/ESPAsync_WiFiManager/releases)
|
||||
|
||||
---
|
||||
|
||||
@@ -110,7 +199,7 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncH
|
||||
|
||||
1. Install [VS Code](https://code.visualstudio.com/)
|
||||
2. Install [PlatformIO](https://platformio.org/platformio-ide)
|
||||
3. Install **AsyncHTTPRequest_Generic** library by using [Library Manager](https://docs.platformio.org/en/latest/librarymanager/). Search for ***AsyncHTTPRequest_Generic*** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
|
||||
3. Install [**AsyncHTTPRequest_Generic** library](https://platformio.org/lib/show/11235/AsyncHTTPRequest_Generic) by using [Library Manager](https://platformio.org/lib/show/11235/AsyncHTTPRequest_Generic/installation). Search for AsyncHTTPRequest_Generic 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)
|
||||
|
||||
---
|
||||
@@ -118,7 +207,9 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncH
|
||||
|
||||
### Packages' Patches
|
||||
|
||||
1. ***To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards***, you have to copy the whole [nRF52 0.21.0](Packages_Patches/adafruit/hardware/nrf52/0.21.0) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0).
|
||||
#### 1. For Adafruit nRF52840 and nRF52832 boards
|
||||
|
||||
**To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards**, you have to copy the whole [nRF52 0.21.0](Packages_Patches/adafruit/hardware/nrf52/0.21.0) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0).
|
||||
|
||||
Supposing the Adafruit nRF52 version is 0.21.0. These files must be copied into the directory:
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/platform.txt`
|
||||
@@ -127,7 +218,7 @@ Supposing the Adafruit nRF52 version is 0.21.0. These files must be copied into
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B302_ublox/variant.cpp`
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B112_ublox/variant.h`
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B112_ublox/variant.cpp`
|
||||
- ***`~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/cores/nRF5/Udp.h`***
|
||||
- **`~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/cores/nRF5/Udp.h`**
|
||||
|
||||
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z
|
||||
These files must be copied into the directory:
|
||||
@@ -138,20 +229,30 @@ These files must be copied into the directory:
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.cpp`
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.h`
|
||||
- `~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.cpp`
|
||||
- ***`~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h`***
|
||||
- **`~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h`**
|
||||
|
||||
2. ***To be able to compile and run on Teensy boards***, you have to copy the file [Teensy boards.txt](Packages_Patches/hardware/teensy/avr/boards.txt) into Teensy hardware directory (./arduino-1.8.12/hardware/teensy/avr/boards.txt).
|
||||
#### 2. For Teensy boards
|
||||
|
||||
**To be able to compile and run on Teensy boards**, you have to copy the files in [**Packages_Patches for Teensy directory**](Packages_Patches/hardware/teensy/avr) into Teensy hardware directory (./arduino-1.8.13/hardware/teensy/avr/boards.txt).
|
||||
|
||||
Supposing the Arduino version is 1.8.12. This file must be copied into the directory:
|
||||
Supposing the Arduino version is 1.8.13. These files must be copied into the directory:
|
||||
|
||||
- `./arduino-1.8.12/hardware/teensy/avr/boards.txt`
|
||||
- `./arduino-1.8.13/hardware/teensy/avr/boards.txt`
|
||||
- `./arduino-1.8.13/hardware/teensy/avr/cores/teensy/Stream.h`
|
||||
- `./arduino-1.8.13/hardware/teensy/avr/cores/teensy3/Stream.h`
|
||||
- `./arduino-1.8.13/hardware/teensy/avr/cores/teensy4/Stream.h`
|
||||
|
||||
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
|
||||
This file must be copied into the directory:
|
||||
These files must be copied into the directory:
|
||||
|
||||
- `./arduino-x.yy.zz/hardware/teensy/avr/boards.txt`
|
||||
- `./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h`
|
||||
- `./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h`
|
||||
- `./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h`
|
||||
|
||||
3. ***To be able to compile and run on SAM DUE boards***, you have to copy the whole [SAM DUE](Packages_Patches/arduino/hardware/sam/1.6.12) directory into Arduino sam directory (~/.arduino15/packages/arduino/hardware/sam/1.6.12).
|
||||
#### 3. For Arduino SAM DUE boards
|
||||
|
||||
**To be able to compile and run on SAM DUE boards**, you have to copy the whole [SAM DUE](Packages_Patches/arduino/hardware/sam/1.6.12) directory into Arduino sam directory (~/.arduino15/packages/arduino/hardware/sam/1.6.12).
|
||||
|
||||
Supposing the Arduino SAM core version is 1.6.12. This file must be copied into the directory:
|
||||
|
||||
@@ -162,9 +263,26 @@ This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/arduino/hardware/sam/x.yy.zz/platform.txt`
|
||||
|
||||
4. ***To be able to compile without error and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards***, you have to copy the whole [Arduino SAMD cores 1.8.9](Packages_Patches/arduino/hardware/samd/1.8.9) directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.9).
|
||||
#### 4. For Arduino SAMD boards
|
||||
|
||||
***To be able to compile without error and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards***, you have to copy the whole [Arduino SAMD cores 1.8.10](Packages_Patches/arduino/hardware/samd/1.8.10) directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.10).
|
||||
|
||||
#### For core version v1.8.10+
|
||||
|
||||
Supposing the Arduino SAMD version is 1.8.11. Now only one file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/arduino/hardware/samd/1.8.11/platform.txt`
|
||||
|
||||
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
|
||||
|
||||
This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/arduino/hardware/samd/x.yy.zz/platform.txt`
|
||||
|
||||
#### For core version v1.8.9-
|
||||
|
||||
Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/arduino/hardware/samd/1.8.9/platform.txt`
|
||||
- ***`~/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino/Arduino.h`***
|
||||
|
||||
@@ -184,7 +302,9 @@ These files must be copied into the directory:
|
||||
|
||||
Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy the `Arduino.h` file anymore.
|
||||
|
||||
5. ***To be able to automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the file [Adafruit SAMD platform.txt](Packages_Patches/adafruit/hardware/samd/1.6.4) into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.6.4).
|
||||
#### 5. For Adafruit SAMD boards
|
||||
|
||||
***To be able to automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the file [Adafruit SAMD platform.txt](Packages_Patches/adafruit/hardware/samd/1.6.4) into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.6.4).
|
||||
|
||||
Supposing the Adafruit SAMD core version is 1.6.4. This file must be copied into the directory:
|
||||
|
||||
@@ -195,7 +315,9 @@ This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt`
|
||||
|
||||
6. ***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the file [Seeeduino SAMD platform.txt](Packages_Patches/Seeeduino/hardware/samd/1.8.1) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1).
|
||||
#### 6. For Seeeduino SAMD boards
|
||||
|
||||
***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the file [Seeeduino SAMD platform.txt](Packages_Patches/Seeeduino/hardware/samd/1.8.1) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1).
|
||||
|
||||
Supposing the Seeeduino SAMD core version is 1.8.1. This file must be copied into the directory:
|
||||
|
||||
@@ -206,7 +328,9 @@ This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt`
|
||||
|
||||
7. ***To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards***, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/1.9.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/1.9.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
|
||||
#### 7. For STM32 boards
|
||||
|
||||
**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/1.9.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/1.9.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
|
||||
|
||||
Supposing the STM32 stm32 core version is 1.9.0. These files must be copied into the directory:
|
||||
|
||||
@@ -235,6 +359,29 @@ To use the old standard cpp way, just
|
||||
---
|
||||
---
|
||||
|
||||
### Note for Platform IO using ESP32 LittleFS
|
||||
|
||||
In Platform IO, to fix the error when using [`LittleFS_esp32 v1.0`](https://github.com/lorol/LITTLEFS) for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line
|
||||
|
||||
from
|
||||
|
||||
```
|
||||
//#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
|
||||
```
|
||||
|
||||
to
|
||||
|
||||
```
|
||||
#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
|
||||
```
|
||||
|
||||
It's advisable to use the latest [`LittleFS_esp32 v1.0.5+`](https://github.com/lorol/LITTLEFS) to avoid the issue.
|
||||
|
||||
Thanks to [Roshan](https://github.com/solroshan) to report the issue in [Error esp_littlefs.c 'utime_p'](https://github.com/khoih-prog/ESPAsync_WiFiManager/issues/28)
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
### 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.
|
||||
@@ -298,11 +445,11 @@ Please take a look at other examples, as well.
|
||||
#include "defines.h"
|
||||
|
||||
// 600s = 10 minutes to not flooding, 10s in testing
|
||||
#define HTTP_REQUEST_INTERVAL_MS 10000 // 600000
|
||||
#define HTTP_REQUEST_INTERVAL_MS 10000 //600000
|
||||
|
||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||
|
||||
#include <Ticker.h> // https://github.com/sstaub/Ticker
|
||||
#include <Ticker.h> // https://github.com/sstaub/Ticker
|
||||
|
||||
AsyncHTTPRequest request;
|
||||
|
||||
@@ -313,16 +460,33 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
request.send();
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -339,6 +503,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
@@ -367,7 +532,6 @@ void loop(void)
|
||||
{
|
||||
sendHTTPRequest.update();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
@@ -376,17 +540,6 @@ void loop(void)
|
||||
|
||||
|
||||
```cpp
|
||||
/*
|
||||
Currently support
|
||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||
- Nucleo-144 (F429ZI, F767ZI)
|
||||
- Discovery (STM32F746G-DISCOVERY)
|
||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||
*/
|
||||
|
||||
#ifndef defines_h
|
||||
#define defines_h
|
||||
|
||||
@@ -494,12 +647,13 @@ IPAddress ip(192, 168, 2, 232);
|
||||
---
|
||||
---
|
||||
|
||||
### Debug Terminal Oouput Samples
|
||||
### Debug Terminal Ouput Samples
|
||||
|
||||
#### 1. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A
|
||||
|
||||
```
|
||||
Start AsyncHTTPRequest_STM32 on NUCLEO_F767ZI
|
||||
AsyncHTTPRequest_Generic v1.1.2
|
||||
AsyncHTTPRequest @ IP : 192.168.2.72
|
||||
|
||||
**************************************
|
||||
@@ -544,6 +698,7 @@ week_number: 37
|
||||
|
||||
```
|
||||
Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP8266_NODEMCU
|
||||
AsyncHTTPRequest_Generic v1.1.2
|
||||
Stored: SSID = HueNet1, Pass = 12345678
|
||||
Got stored Credentials. Timeout 120s
|
||||
ConnectMultiWiFi in setup
|
||||
@@ -576,6 +731,7 @@ HHHHHH
|
||||
|
||||
```
|
||||
Starting AsyncHTTPRequest_ESP_WiFiManager using SPIFFS on ESP32_DEV
|
||||
AsyncHTTPRequest_Generic v1.1.2
|
||||
Stored: SSID = HueNet1, Pass = 12345678
|
||||
Got stored Credentials. Timeout 120s
|
||||
ConnectMultiWiFi in setup
|
||||
@@ -626,6 +782,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH
|
||||
|
||||
```
|
||||
Starting AsyncHTTPRequest_ESP using ESP8266_NODEMCU
|
||||
AsyncHTTPRequest_Generic v1.1.2
|
||||
Connecting to WiFi SSID: HueNet1
|
||||
...........
|
||||
HTTP WebServer is @ IP : 192.168.2.81
|
||||
@@ -657,6 +814,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H
|
||||
|
||||
```
|
||||
Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI
|
||||
AsyncHTTPRequest_Generic v1.1.2
|
||||
AsyncHTTPRequest @ IP : 192.168.2.72
|
||||
|
||||
**************************************
|
||||
@@ -748,10 +906,26 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro
|
||||
1. Initially add support to STM32 using built-in LAN8742A Etnernet. Tested on **STM32F7 Nucleo-144 F767ZI**.
|
||||
2. Add more examples.
|
||||
3. Add debugging features.
|
||||
4. Add PUT, PATCH, DELETE and HEAD besides GET and POST.
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Releases
|
||||
|
||||
### Releases v1.1.2
|
||||
|
||||
1. Rename _lock and _unlock to avoid conflict with [**ESP32/ESP8266 AsyncWebServer**](https://github.com/me-no-dev/ESPAsyncWebServer) library. Check [**compatibility with ESPAsyncWebServer #11**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/11)
|
||||
2. Fix compiler warnings.
|
||||
|
||||
### Releases v1.1.1
|
||||
|
||||
1. Prevent crash if request and/or method not correct.
|
||||
|
||||
### Releases v1.1.0
|
||||
|
||||
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
|
||||
|
||||
### Releases v1.0.2
|
||||
|
||||
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
||||
@@ -776,10 +950,16 @@ This library is based on, modified, bug-fixed and improved from:
|
||||
|
||||
2. Thanks to [Daniel Brunner](https://github.com/0xFEEDC0DE64) to report and make PR in [Fixed linker errors when included in multiple .cpp files](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/pull/1) leading to v1.0.1. See [**HOWTO Fix `Multiple Definitions` Linker Error**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic#HOWTO-Fix-Multiple-Definitions-Linker-Error)
|
||||
|
||||
3. Thanks to [gleniat](https://github.com/gleniat) to make enhancement request in[Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5) leading to v1.1.0.
|
||||
|
||||
4. Thanks to [BadDwarf](https://github.com/baddwarf) to report [**compatibility with ESPAsyncWebServer #11**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/11) leading to the enhancement in v1.1.2.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/boblemaire"><img src="https://github.com/boblemaire.png" width="100px;" alt="boblemaire"/><br /><sub><b>⭐️ Bob Lemaire</b></sub></a><br /></td>
|
||||
<td align="center"><a href="https://github.com/0xFEEDC0DE64"><img src="https://github.com/0xFEEDC0DE64.png" width="100px;" alt="0xFEEDC0DE64"/><br /><sub><b>Daniel Brunner</b></sub></a><br /></td>
|
||||
<td align="center"><a href="https://github.com/gleniat"><img src="https://github.com/gleniat.png" width="100px;" alt="gleniat"/><br /><sub><b>gleniat</b></sub></a><br /></td>
|
||||
<td align="center"><a href="https://github.com/baddwarf"><img src="https://github.com/baddwarf.png" width="100px;" alt="baddwarf"/><br /><sub><b>BadDwarf</b></sub></a><br /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -797,7 +977,7 @@ If you want to contribute to this project:
|
||||
|
||||
### License and credits ###
|
||||
|
||||
- The library is licensed under [MIT](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/blob/master/LICENSE)
|
||||
- The library is licensed under [GPLv3](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/blob/master/LICENSE)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "defines.h"
|
||||
@@ -48,18 +51,34 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
|
||||
|
||||
request.open("GET", GET_ServerAddress);
|
||||
requestOpenResult = request.open("GET", GET_ServerAddress);
|
||||
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
|
||||
request.send();
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -76,6 +95,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/**
|
||||
@@ -59,10 +62,25 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
|
||||
request.send();
|
||||
requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +120,8 @@ void parseResponse(String responseText)
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
String responseText = request->responseText();
|
||||
@@ -123,6 +143,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
|
||||
@@ -53,6 +56,8 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
String postData = "sensorValue=";
|
||||
@@ -60,8 +65,21 @@ void sendRequest(void)
|
||||
|
||||
Serial.println("\nMaking new POST request");
|
||||
|
||||
request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
|
||||
request.send();
|
||||
requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +119,8 @@ void parseResponse(String responseText)
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
String responseText = request->responseText();
|
||||
@@ -122,6 +142,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/****************************************************************************************************************************
|
||||
AsyncHTTPMultiRequests.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||
|
||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||
|
||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||
|
||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||
Licensed under MIT license
|
||||
|
||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
as published bythe 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
//************************************************************************************************************
|
||||
//
|
||||
// There are scores of ways to use AsyncHTTPRequest. The important thing to keep in mind is that
|
||||
// it is asynchronous and just like in JavaScript, everything is event driven. You will have some
|
||||
// reason to initiate an asynchronous HTTP request in your program, but then sending the request
|
||||
// headers and payload, gathering the response headers and any payload, and processing
|
||||
// of that response, can (and probably should) all be done asynchronously.
|
||||
//
|
||||
// In this example, a Ticker function is setup to fire every 300 seconds to initiate a request.
|
||||
// Everything is handled in AsyncHTTPRequest without blocking.
|
||||
// The callback onReadyStateChange is made progressively and like most JS scripts, we look for
|
||||
// readyState == 4 (complete) here. At that time the response is retrieved and printed.
|
||||
//
|
||||
// Note that there is no code in loop(). A code entered into loop would run oblivious to
|
||||
// the ongoing HTTP requests. The Ticker could be removed and periodic calls to sendRequest()
|
||||
// could be made in loop(), resulting in the same asynchronous handling.
|
||||
//
|
||||
// For demo purposes, debug is turned on for handling of the first request. These are the
|
||||
// events that are being handled in AsyncHTTPRequest. They all begin with Debug(nnn) where
|
||||
// nnn is the elapsed time in milliseconds since the transaction was started.
|
||||
//
|
||||
//*************************************************************************************************************
|
||||
|
||||
#if !( defined(ESP8266) || defined(ESP32) )
|
||||
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// Level from 0-4
|
||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||
#define _ASYNC_HTTP_LOGLEVEL_ 1
|
||||
|
||||
// 300s = 5 minutes to not flooding
|
||||
#define HTTP_REQUEST_INTERVAL 30 //300
|
||||
|
||||
// 10s
|
||||
#define HEARTBEAT_INTERVAL 10
|
||||
|
||||
int status; // the Wifi radio's status
|
||||
|
||||
const char* ssid = "your_ssid";
|
||||
const char* password = "your_pass";
|
||||
|
||||
#if (ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#elif (ESP32)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||
#include <Ticker.h>
|
||||
|
||||
AsyncHTTPRequest request;
|
||||
Ticker ticker;
|
||||
Ticker ticker1;
|
||||
|
||||
void heartBeatPrint(void)
|
||||
{
|
||||
static int num = 1;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
Serial.print(F("H")); // H means connected to WiFi
|
||||
else
|
||||
Serial.print(F("F")); // F means not connected to WiFi
|
||||
|
||||
if (num == 80)
|
||||
{
|
||||
Serial.println();
|
||||
num = 1;
|
||||
}
|
||||
else if (num++ % 10 == 0)
|
||||
{
|
||||
Serial.print(F(" "));
|
||||
}
|
||||
}
|
||||
|
||||
// To replace with your real APP_API
|
||||
#define APP_API "SECRECT_APP_API"
|
||||
|
||||
String requestPart1 = "http://api.openweathermap.org/data/2.5/onecall?lat=-24.32&lon=-46.9983";
|
||||
String requestAPPID = "&appid=" + String(APP_API);
|
||||
|
||||
// exclude fields: current,minutely,hourly,daily,alerts
|
||||
String requestCurrent = requestPart1 + "&exclude=minutely,hourly,daily,alerts" + requestAPPID;
|
||||
String requestMinutely = requestPart1 + "&exclude=current,hourly,daily,alerts" + requestAPPID;
|
||||
String requestHourly = requestPart1 + "&exclude=current,minutely,daily,alerts" + requestAPPID;
|
||||
String requestDaily = requestPart1 + "&exclude=current,minutely,hourly,alerts" + requestAPPID;
|
||||
String requestAlert = requestPart1 + "&exclude=current,minutely,hourly,daily" + requestAPPID;
|
||||
|
||||
#define NUM_REQUESTS 5
|
||||
|
||||
const char* requestName[ NUM_REQUESTS ] = { "Current", "Minutely", "Hourly", "Daily", "Alert" };
|
||||
|
||||
const char* requestAll[ NUM_REQUESTS ] = { requestCurrent.c_str(), requestMinutely.c_str(), requestHourly.c_str(), requestDaily.c_str(), requestAlert.c_str() };
|
||||
|
||||
uint8_t requestIndex = 0;
|
||||
|
||||
void sendRequest()
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
requestOpenResult = request.open("GET", requestAll[requestIndex] );
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.print("\n***************"); Serial.print(requestName[ requestIndex ]); Serial.println("***************");
|
||||
Serial.println(request->responseText());
|
||||
Serial.println("**************************************");
|
||||
|
||||
#if 1
|
||||
// Bypass hourly
|
||||
if (requestIndex == 1)
|
||||
requestIndex = 3;
|
||||
else
|
||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||
#else
|
||||
// hourly too long, not display anyway. Not enough heap.
|
||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||
#endif
|
||||
|
||||
request->setDebug(false);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
delay(200);
|
||||
|
||||
Serial.println("\nStarting AsyncHTTPMultiRequests using " + String(ARDUINO_BOARD));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
Serial.println("Connecting to WiFi SSID: " + String(ssid));
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.print(F("\nHTTP WebServer is @ IP : "));
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
request.setDebug(false);
|
||||
|
||||
request.onReadyStateChange(requestCB);
|
||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||
|
||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||
|
||||
// Send first request now
|
||||
sendRequest();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
//************************************************************************************************************
|
||||
//
|
||||
@@ -102,11 +105,22 @@ void heartBeatPrint(void)
|
||||
|
||||
void sendRequest()
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
request.send();
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -116,6 +130,8 @@ void sendRequest()
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -133,6 +149,7 @@ void setup()
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStarting AsyncHTTPRequest_ESP using " + String(ARDUINO_BOARD));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
//************************************************************************************************************
|
||||
//
|
||||
@@ -48,6 +51,8 @@
|
||||
//
|
||||
//*************************************************************************************************************
|
||||
|
||||
// Important note: This code is intended to run with the ESPAsync_WiFiManager library version 1.4.1+.
|
||||
|
||||
#if !( defined(ESP8266) || defined(ESP32) )
|
||||
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
@@ -223,6 +228,10 @@ bool initialConfig = false;
|
||||
IPAddress dns1IP = gatewayIP;
|
||||
IPAddress dns2IP = IPAddress(8, 8, 8, 8);
|
||||
|
||||
IPAddress APStaticIP = IPAddress(192, 168, 100, 1);
|
||||
IPAddress APStaticGW = IPAddress(192, 168, 100, 1);
|
||||
IPAddress APStaticSN = IPAddress(255, 255, 255, 0);
|
||||
|
||||
#include <ESPAsync_WiFiManager.h> //https://github.com/khoih-prog/ESPAsync_WiFiManager
|
||||
|
||||
#define HTTP_PORT 80
|
||||
@@ -236,6 +245,139 @@ DNSServer dnsServer;
|
||||
AsyncHTTPRequest request;
|
||||
Ticker ticker;
|
||||
|
||||
///////////////////////////////////////////
|
||||
// New in v1.4.0
|
||||
/******************************************
|
||||
* // Defined in ESPAsync_WiFiManager.h
|
||||
typedef struct
|
||||
{
|
||||
IPAddress _ap_static_ip;
|
||||
IPAddress _ap_static_gw;
|
||||
IPAddress _ap_static_sn;
|
||||
|
||||
} WiFi_AP_IPConfig;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
IPAddress _sta_static_ip;
|
||||
IPAddress _sta_static_gw;
|
||||
IPAddress _sta_static_sn;
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
IPAddress _sta_static_dns1;
|
||||
IPAddress _sta_static_dns2;
|
||||
#endif
|
||||
} WiFi_STA_IPConfig;
|
||||
******************************************/
|
||||
|
||||
WiFi_AP_IPConfig WM_AP_IPconfig;
|
||||
WiFi_STA_IPConfig WM_STA_IPconfig;
|
||||
|
||||
void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig)
|
||||
{
|
||||
in_WM_AP_IPconfig._ap_static_ip = APStaticIP;
|
||||
in_WM_AP_IPconfig._ap_static_gw = APStaticGW;
|
||||
in_WM_AP_IPconfig._ap_static_sn = APStaticSN;
|
||||
}
|
||||
|
||||
void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig)
|
||||
{
|
||||
in_WM_STA_IPconfig._sta_static_ip = stationIP;
|
||||
in_WM_STA_IPconfig._sta_static_gw = gatewayIP;
|
||||
in_WM_STA_IPconfig._sta_static_sn = netMask;
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
in_WM_STA_IPconfig._sta_static_dns1 = dns1IP;
|
||||
in_WM_STA_IPconfig._sta_static_dns2 = dns2IP;
|
||||
#endif
|
||||
}
|
||||
|
||||
void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig)
|
||||
{
|
||||
LOGERROR3(F("stationIP ="), in_WM_STA_IPconfig._sta_static_ip, ", gatewayIP =", in_WM_STA_IPconfig._sta_static_gw);
|
||||
LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn);
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
LOGERROR3(F("dns1IP ="), in_WM_STA_IPconfig._sta_static_dns1, ", dns2IP =", in_WM_STA_IPconfig._sta_static_dns2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig)
|
||||
{
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
||||
WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2);
|
||||
#else
|
||||
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
||||
WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
|
||||
uint8_t connectMultiWiFi()
|
||||
{
|
||||
#if ESP32
|
||||
// For ESP32, this better be 0 to shorten the connect time
|
||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 0
|
||||
#else
|
||||
// For ESP8266, this better be 2200 to enable connect the 1st time
|
||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
|
||||
#endif
|
||||
|
||||
#define WIFI_MULTI_CONNECT_WAITING_MS 100L
|
||||
|
||||
uint8_t status;
|
||||
|
||||
LOGERROR(F("ConnectMultiWiFi with :"));
|
||||
|
||||
if ( (Router_SSID != "") && (Router_Pass != "") )
|
||||
{
|
||||
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass );
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
|
||||
{
|
||||
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
|
||||
if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
|
||||
{
|
||||
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
|
||||
}
|
||||
}
|
||||
|
||||
LOGERROR(F("Connecting MultiWifi..."));
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
#if !USE_DHCP_IP
|
||||
// New in v1.4.0
|
||||
configWiFi(WM_STA_IPconfig);
|
||||
//////
|
||||
#endif
|
||||
|
||||
int i = 0;
|
||||
status = wifiMulti.run();
|
||||
delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);
|
||||
|
||||
while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
|
||||
{
|
||||
status = wifiMulti.run();
|
||||
|
||||
if ( status == WL_CONNECTED )
|
||||
break;
|
||||
else
|
||||
delay(WIFI_MULTI_CONNECT_WAITING_MS);
|
||||
}
|
||||
|
||||
if ( status == WL_CONNECTED )
|
||||
{
|
||||
LOGERROR1(F("WiFi connected after time: "), i);
|
||||
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI());
|
||||
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() );
|
||||
}
|
||||
else
|
||||
LOGERROR(F("WiFi not connected"));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void heartBeatPrint(void)
|
||||
{
|
||||
static int num = 1;
|
||||
@@ -292,16 +434,31 @@ void check_status(void)
|
||||
}
|
||||
}
|
||||
|
||||
void loadConfigData(void)
|
||||
void loadConfigData()
|
||||
{
|
||||
File file = FileFS.open(CONFIG_FILENAME, "r");
|
||||
LOGERROR(F("LoadWiFiCfgFile "));
|
||||
|
||||
memset(&WM_config, 0, sizeof(WM_config));
|
||||
|
||||
// New in v1.4.0
|
||||
memset(&WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig));
|
||||
//////
|
||||
|
||||
if (file)
|
||||
{
|
||||
file.readBytes((char *) &WM_config, sizeof(WM_config));
|
||||
file.readBytes((char *) &WM_config, sizeof(WM_config));
|
||||
|
||||
// New in v1.4.0
|
||||
file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig));
|
||||
//////
|
||||
|
||||
file.close();
|
||||
LOGERROR(F("OK"));
|
||||
|
||||
// New in v1.4.0
|
||||
displayIPConfigStruct(WM_STA_IPconfig);
|
||||
//////
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -309,14 +466,19 @@ void loadConfigData(void)
|
||||
}
|
||||
}
|
||||
|
||||
void saveConfigData(void)
|
||||
void saveConfigData()
|
||||
{
|
||||
File file = FileFS.open(CONFIG_FILENAME, "w");
|
||||
LOGERROR(F("SaveWiFiCfgFile "));
|
||||
|
||||
if (file)
|
||||
{
|
||||
file.write((uint8_t*) &WM_config, sizeof(WM_config));
|
||||
file.write((uint8_t*) &WM_config, sizeof(WM_config));
|
||||
|
||||
// New in v1.4.0
|
||||
file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig));
|
||||
//////
|
||||
|
||||
file.close();
|
||||
LOGERROR(F("OK"));
|
||||
}
|
||||
@@ -326,88 +488,35 @@ void saveConfigData(void)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t connectMultiWiFi(void)
|
||||
{
|
||||
#if ESP32
|
||||
// For ESP32, this better be 0 to shorten the connect time
|
||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 0
|
||||
#else
|
||||
// For ESP8266, this better be 2200 to enable connect the 1st time
|
||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
|
||||
#endif
|
||||
|
||||
#define WIFI_MULTI_CONNECT_WAITING_MS 100L
|
||||
|
||||
uint8_t status;
|
||||
|
||||
LOGERROR(F("ConnectMultiWiFi with :"));
|
||||
|
||||
if ( (Router_SSID != "") && (Router_Pass != "") )
|
||||
{
|
||||
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass );
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
|
||||
{
|
||||
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
|
||||
if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
|
||||
{
|
||||
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
|
||||
}
|
||||
}
|
||||
|
||||
LOGERROR(F("Connecting MultiWifi..."));
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
#if !USE_DHCP_IP
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
||||
WiFi.config(stationIP, gatewayIP, netMask, dns1IP, dns2IP);
|
||||
#else
|
||||
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
||||
WiFi.config(stationIP, gatewayIP, netMask);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int i = 0;
|
||||
status = wifiMulti.run();
|
||||
delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);
|
||||
|
||||
while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
|
||||
{
|
||||
status = wifiMulti.run();
|
||||
|
||||
if ( status == WL_CONNECTED )
|
||||
break;
|
||||
else
|
||||
delay(WIFI_MULTI_CONNECT_WAITING_MS);
|
||||
}
|
||||
|
||||
if ( status == WL_CONNECTED )
|
||||
{
|
||||
LOGERROR1(F("WiFi connected after time: "), i);
|
||||
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI());
|
||||
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() );
|
||||
}
|
||||
else
|
||||
LOGERROR(F("WiFi not connected"));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void sendRequest()
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
request.send();
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -426,6 +535,8 @@ void setup()
|
||||
|
||||
Serial.print("\nStarting AsyncHTTPRequest_ESP_WiFiManager using " + String(FS_Name));
|
||||
Serial.println(" on " + String(ARDUINO_BOARD));
|
||||
Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION);
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
if (FORMAT_FILESYSTEM)
|
||||
FileFS.format();
|
||||
@@ -447,6 +558,11 @@ void setup()
|
||||
|
||||
unsigned long startedAt = millis();
|
||||
|
||||
// New in v1.4.0
|
||||
initAPIPConfigStruct(WM_AP_IPconfig);
|
||||
initSTAIPConfigStruct(WM_STA_IPconfig);
|
||||
//////
|
||||
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
|
||||
//ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer);
|
||||
@@ -459,7 +575,9 @@ void setup()
|
||||
//ESPAsync_wifiManager.resetSettings();
|
||||
|
||||
//set custom ip for portal
|
||||
ESPAsync_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0));
|
||||
// New in v1.4.0
|
||||
ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig);
|
||||
//////
|
||||
|
||||
ESPAsync_wifiManager.setMinimumSignalQuality(-1);
|
||||
|
||||
@@ -469,13 +587,10 @@ void setup()
|
||||
//////
|
||||
|
||||
#if !USE_DHCP_IP
|
||||
#if USE_CONFIGURABLE_DNS
|
||||
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
||||
ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP);
|
||||
#else
|
||||
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
||||
ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask);
|
||||
#endif
|
||||
// Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5
|
||||
// New in v1.4.0
|
||||
ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig);
|
||||
//////
|
||||
#endif
|
||||
|
||||
// New from v1.1.1
|
||||
@@ -549,6 +664,11 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
// New in v1.4.0
|
||||
ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig);
|
||||
displayIPConfigStruct(WM_STA_IPconfig);
|
||||
//////
|
||||
|
||||
saveConfigData();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
//************************************************************************************************************
|
||||
//
|
||||
@@ -66,16 +69,33 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
request.send();
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -92,6 +112,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "defines.h"
|
||||
@@ -48,15 +51,32 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
request.open("GET", GET_ServerAddress);
|
||||
request.send();
|
||||
requestOpenResult = request.open("GET", GET_ServerAddress);
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -73,6 +93,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncSimpleGET_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "defines.h"
|
||||
@@ -50,16 +53,32 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||
|
||||
void sendRequest(void)
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
request.open("GET", (GET_ServerAddress + GET_Location).c_str());
|
||||
requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str());
|
||||
|
||||
request.send();
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send bad request");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Can't send request");
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
Serial.println("\n**************************************");
|
||||
@@ -76,6 +95,7 @@ void setup(void)
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME));
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
// start the ethernet connection and the server
|
||||
// Use random mac
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Currently support
|
||||
|
||||
+21
-10
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name":"AsyncHTTPRequest_Generic",
|
||||
"version": "1.0.2",
|
||||
"description":"Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
|
||||
"version": "1.1.2",
|
||||
"description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
|
||||
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP,stm32,ethernet,wifi,lan8742a",
|
||||
"authors": [
|
||||
{
|
||||
@@ -22,31 +22,42 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["*"],
|
||||
"dependencies": [
|
||||
"dependencies":
|
||||
[
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "AsyncTCP",
|
||||
"platforms": "espressif32"
|
||||
"version": ">=1.1.1",
|
||||
"platforms": ["espressif32"]
|
||||
},
|
||||
{
|
||||
"name": "ESP AsyncTCP",
|
||||
"owner": "me-no-dev",
|
||||
"name": "ESPAsyncTCP",
|
||||
"version": ">=1.2.2",
|
||||
"platforms": "espressif8266"
|
||||
},
|
||||
{
|
||||
"owner": "khoih.prog",
|
||||
"name": "ESPAsync_WiFiManager",
|
||||
"version": ">=1.4.3",
|
||||
"platforms": ["espressif8266", "espressif32"]
|
||||
},
|
||||
{
|
||||
"owner": "stm32duino",
|
||||
"name": "STM32duino LwIP",
|
||||
"version": ">=2.1.2",
|
||||
"platforms": "ststm32"
|
||||
},
|
||||
{
|
||||
"name": "STM32duino STM32Ethernet",
|
||||
"owner": "stm32duino",
|
||||
"name": "STM32Ethernet",
|
||||
"version": ">=1.2.0",
|
||||
"platforms": "ststm32"
|
||||
},
|
||||
{
|
||||
"name": "STM32 AsyncTCP",
|
||||
"platforms": "ststm32"
|
||||
"name": "external-repo",
|
||||
"version": "https://github.com/philbowles/STM32AsyncTCP"
|
||||
}
|
||||
]
|
||||
],
|
||||
"platforms": ["espressif8266", "espressif32", "ststm32"]
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
name=AsyncHTTPRequest_Generic
|
||||
version=1.0.2
|
||||
version=1.1.2
|
||||
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
|
||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||
license=MIT
|
||||
sentence=Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.
|
||||
sentence=Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.
|
||||
paragraph=This AsyncHTTPRequest_Generic Library, supporting GET and POST, for ESP32, ESP8266 and STM32 with built-in LAN8742A Ethernet, such as Nucleo-144 F767ZI, etc.
|
||||
category=Communication,AsyncTCP,AsyncHTTP
|
||||
url=https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||
|
||||
+12
-12
@@ -35,19 +35,19 @@ upload_speed = 921600
|
||||
|
||||
lib_deps =
|
||||
; PlatformIO 4.x
|
||||
AsyncTCP@~1.1.1
|
||||
ESPAsyncTCP@~1.2.2
|
||||
STM32AsyncTCP@~1.0.0
|
||||
STM32duino LwIP@~2.1.2
|
||||
STM32duino STM32Ethernet@~1.2.0
|
||||
ESPAsync_WiFiManager@~1.1.2
|
||||
AsyncTCP@>=1.1.1
|
||||
ESPAsyncTCP@>=1.2.2
|
||||
STM32AsyncTCP@>=1.0.0
|
||||
STM32duino LwIP@>=2.1.2
|
||||
STM32duino STM32Ethernet@>=1.2.0
|
||||
ESPAsync_WiFiManager@>=1.4.1
|
||||
; PlatformIO 5.x
|
||||
; me-no-dev/AsyncTCP@~1.1.1
|
||||
; me-no-dev/ESPAsyncTCP@~1.2.2
|
||||
; philbowles/STM32AsyncTCP@~1.0.0
|
||||
; stm32duino/STM32duino LwIP@~2.1.2
|
||||
; stm32duino/STM32duino STM32Ethernet@~1.2.0
|
||||
; khoih-prog/ESPAsync_WiFiManager@~1.1.2
|
||||
; me-no-dev/AsyncTCP@>=1.1.1
|
||||
; me-no-dev/ESPAsyncTCP@>=1.2.2
|
||||
; philbowles/STM32AsyncTCP@>=1.0.0
|
||||
; stm32duino/STM32duino LwIP@>=2.1.2
|
||||
; stm32duino/STM32duino STM32Ethernet@>=1.2.0
|
||||
; khoih-prog/ESPAsync_WiFiManager@>=1.4.1
|
||||
|
||||
build_flags =
|
||||
; set your debug output (default=Serial)
|
||||
|
||||
@@ -17,17 +17,23 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
#ifdef ASYNC_HTTP_DEBUG_PORT
|
||||
#define A_DBG_PORT ASYNC_HTTP_DEBUG_PORT
|
||||
#else
|
||||
@@ -69,3 +75,5 @@
|
||||
#define AHTTP_LOGDEBUG2(x,y,z) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.println(z); }
|
||||
#define AHTTP_LOGDEBUG3(x,y,z,w) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.print(z); A_DBG_PORT.print(" "); A_DBG_PORT.println(w); }
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
|
||||
@@ -17,18 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.2"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -57,8 +63,8 @@
|
||||
#define MUTEX_LOCK_NR if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return;}
|
||||
#define MUTEX_LOCK(returnVal) if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return returnVal;}
|
||||
|
||||
#define _lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _unlock xSemaphoreGiveRecursive(threadLock)
|
||||
#define _AHTTP_lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _AHTTP_unlock xSemaphoreGiveRecursive(threadLock)
|
||||
|
||||
#elif ESP8266
|
||||
|
||||
@@ -67,8 +73,8 @@
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||
@@ -78,8 +84,8 @@
|
||||
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#endif
|
||||
|
||||
@@ -218,16 +224,29 @@ class AsyncHTTPRequest
|
||||
size_t responseLength(); // indicated response length or sum of chunks to date
|
||||
int responseHTTPcode(); // HTTP response code or (negative) error code
|
||||
String responseText(); // response (whole* or partial* as string)
|
||||
|
||||
char* responseLongText(); // response long (whole* or partial* as string)
|
||||
|
||||
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
|
||||
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
|
||||
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
|
||||
String version(); // Version of AsyncHTTPRequest
|
||||
//___________________________________________________________________________________________________________________________________
|
||||
|
||||
private:
|
||||
|
||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
||||
|
||||
reqStates _readyState;
|
||||
// New in v1.1.1
|
||||
bool _requestReadyToSend;
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||
|
||||
HTTPmethod _HTTPmethod;
|
||||
|
||||
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||
//////
|
||||
|
||||
reqStates _readyState;
|
||||
|
||||
int16_t _HTTPcode; // HTTP response code or (negative) exception code
|
||||
bool _chunked; // Processing chunked response
|
||||
@@ -286,3 +305,5 @@ class AsyncHTTPRequest
|
||||
};
|
||||
|
||||
#include "AsyncHTTPRequest_Impl_Generic.h"
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
@@ -17,17 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
|
||||
#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
|
||||
|
||||
//**************************************************************************************************************
|
||||
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
|
||||
@@ -90,6 +97,8 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
|
||||
if (_readyState != readyStateUnsent && _readyState != readyStateDone)
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: not ready");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,6 +118,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
_chunked = false;
|
||||
_contentRead = 0;
|
||||
_readyState = readyStateUnsent;
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = false;
|
||||
//////
|
||||
|
||||
if (strcmp(method, "GET") == 0)
|
||||
{
|
||||
@@ -118,15 +131,43 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPOST;
|
||||
}
|
||||
// New in v1.1.0
|
||||
else if (strcmp(method, "PUT") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPUT;
|
||||
}
|
||||
else if (strcmp(method, "PATCH") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPATCH;
|
||||
}
|
||||
else if (strcmp(method, "DELETE") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodDELETE;
|
||||
}
|
||||
else if (strcmp(method, "HEAD") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodHEAD;
|
||||
}
|
||||
//////
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: Bad method");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!_parseURL(URL))
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: error parsing URL");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: not connected");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -140,11 +181,21 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
SAFE_DELETE_ARRAY(hostName)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = true;
|
||||
//////
|
||||
|
||||
AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName);
|
||||
|
||||
return _connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: error alloc");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, void* arg)
|
||||
@@ -163,8 +214,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
|
||||
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send()
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
{
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -173,7 +234,7 @@ bool AsyncHTTPRequest::send()
|
||||
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -181,7 +242,17 @@ bool AsyncHTTPRequest::send()
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(String body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -189,7 +260,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -197,7 +268,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -205,7 +276,17 @@ bool AsyncHTTPRequest::send(String body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const char* body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -213,7 +294,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +302,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -229,7 +310,17 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -237,7 +328,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -245,7 +336,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -253,7 +344,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -261,7 +362,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -269,7 +370,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -288,7 +389,7 @@ void AsyncHTTPRequest::abort()
|
||||
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
reqStates AsyncHTTPRequest::readyState()
|
||||
@@ -313,7 +414,7 @@ String AsyncHTTPRequest::responseText()
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseText() no data");
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -328,7 +429,7 @@ String AsyncHTTPRequest::responseText()
|
||||
_HTTPcode = HTTPCODE_TOO_LESS_RAM;
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -336,13 +437,61 @@ String AsyncHTTPRequest::responseText()
|
||||
localString = _response->readString(avail);
|
||||
_contentRead += localString.length();
|
||||
|
||||
AHTTP_LOGDEBUG3("responseText(char)", localString.substring(0, 16).c_str(), ", avail =", avail);
|
||||
//AHTTP_LOGDEBUG3("responseText(char)", localString.substring(0, 16).c_str(), ", avail =", avail);
|
||||
AHTTP_LOGDEBUG3("responseText(char)", localString, ", avail =", avail);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return localString;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
|
||||
#if 1
|
||||
|
||||
#if (ESP32)
|
||||
#define GLOBAL_STR_LEN (32 * 1024)
|
||||
#elif (ESP8266)
|
||||
#define GLOBAL_STR_LEN (16 * 1024)
|
||||
#else
|
||||
#define GLOBAL_STR_LEN (4 * 1024)
|
||||
#endif
|
||||
|
||||
char globalLongString[GLOBAL_STR_LEN + 1];
|
||||
|
||||
char* AsyncHTTPRequest::responseLongText()
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseLongText()");
|
||||
|
||||
MUTEX_LOCK(NULL)
|
||||
|
||||
if ( ! _response || _readyState < readyStateLoading || ! available())
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseText() no data");
|
||||
|
||||
_AHTTP_unlock;
|
||||
|
||||
//return String();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// String localString;
|
||||
size_t avail = available();
|
||||
size_t lenToCopy = (avail <= GLOBAL_STR_LEN) ? avail : GLOBAL_STR_LEN;
|
||||
|
||||
strncpy(globalLongString, _response->readString(avail).c_str(), lenToCopy );
|
||||
globalLongString[ lenToCopy + 1 ] = 0;
|
||||
|
||||
_contentRead += _response->readString(avail).length();
|
||||
|
||||
AHTTP_LOGDEBUG3("responseLongText(char)", globalLongString, ", avail =", avail);
|
||||
|
||||
_AHTTP_unlock;
|
||||
|
||||
return globalLongString;
|
||||
}
|
||||
#endif
|
||||
|
||||
//**************************************************************************************************************
|
||||
size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
|
||||
{
|
||||
@@ -362,7 +511,7 @@ size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
|
||||
|
||||
_contentRead += avail;
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return avail;
|
||||
}
|
||||
@@ -589,13 +738,19 @@ bool AsyncHTTPRequest::_buildRequest()
|
||||
return false;
|
||||
}
|
||||
|
||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
||||
// New in v1.1.1
|
||||
AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
|
||||
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||
//////
|
||||
|
||||
_request->write(_URL->path);
|
||||
_request->write(_URL->query);
|
||||
_request->write(" HTTP/1.1\r\n");
|
||||
|
||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
|
||||
|
||||
SAFE_DELETE(_URL)
|
||||
|
||||
_URL = nullptr;
|
||||
@@ -758,11 +913,18 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
_client = client;
|
||||
_setReadyState(readyStateOpened);
|
||||
|
||||
// KH test
|
||||
_response = new xbuf;
|
||||
//_response = new xbuf(256);
|
||||
//////
|
||||
|
||||
if (!_response)
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onConnect: Can't new _responser");
|
||||
///////
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -773,11 +935,17 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
_client->onAck([](void* obj, AsyncClient * client, size_t len, uint32_t time)
|
||||
{
|
||||
(void) client;
|
||||
(void) len;
|
||||
(void) time;
|
||||
|
||||
((AsyncHTTPRequest*)(obj))->_send();
|
||||
}, this);
|
||||
|
||||
_client->onData([](void* obj, AsyncClient * client, void* data, size_t len)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
((AsyncHTTPRequest*)(obj))->_onData(data, len);
|
||||
}, this);
|
||||
|
||||
@@ -788,12 +956,14 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onPoll(AsyncClient* client)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
MUTEX_LOCK_NR
|
||||
|
||||
if (_timeout && (millis() - _lastActivity) > (_timeout * 1000))
|
||||
@@ -809,12 +979,14 @@ void AsyncHTTPRequest::_onPoll(AsyncClient* client)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onError(AsyncClient* client, int8_t error)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
AHTTP_LOGDEBUG1("_onError handler error =", error);
|
||||
|
||||
_HTTPcode = error;
|
||||
@@ -823,6 +995,8 @@ void AsyncHTTPRequest::_onError(AsyncClient* client, int8_t error)
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
AHTTP_LOGDEBUG("\n_onDisconnect handler");
|
||||
|
||||
MUTEX_LOCK_NR
|
||||
@@ -850,7 +1024,7 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
_lastActivity = 0;
|
||||
_setReadyState(readyStateDone);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@@ -866,6 +1040,11 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
if (_chunks)
|
||||
{
|
||||
_chunks->write((uint8_t*)Vbuf, len);
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onData: _processChunks");
|
||||
///////
|
||||
|
||||
_processChunks();
|
||||
}
|
||||
else
|
||||
@@ -878,7 +1057,11 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
{
|
||||
if ( ! _collectHeaders())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onData: headers not complete");
|
||||
///////
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -918,7 +1101,7 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
}
|
||||
|
||||
@@ -1203,7 +1386,7 @@ String AsyncHTTPRequest::headers()
|
||||
|
||||
_response += "\r\n";
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return _response;
|
||||
}
|
||||
@@ -1263,7 +1446,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const char* name, const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr->next;
|
||||
}
|
||||
@@ -1283,7 +1466,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(const char* name)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -1303,7 +1486,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(int ndx)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -1328,3 +1511,5 @@ char* AsyncHTTPRequest::_charstar(const __FlashStringHelper * str)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
|
||||
+9
-1
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/********************************************************************************************
|
||||
@@ -46,6 +49,9 @@
|
||||
********************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifndef XBUF_H
|
||||
#define XBUF_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct xseg
|
||||
@@ -149,3 +155,5 @@ class xbuf: public Print
|
||||
|
||||
#include "utility/xbuf_Impl.h"
|
||||
|
||||
#endif // XBUF_H
|
||||
|
||||
|
||||
+23
-1
@@ -17,17 +17,23 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef XBUF_IMPL_H
|
||||
#define XBUF_IMPL_H
|
||||
|
||||
xbuf::xbuf(const uint16_t segSize) : _head(nullptr), _tail(nullptr), _used(0), _free(0), _offset(0)
|
||||
{
|
||||
_segSize = (segSize + 3) & -4;//((segSize + 3) >> 2) << 2;
|
||||
@@ -289,9 +295,17 @@ String xbuf::readString(int endPos)
|
||||
|
||||
if ( ! result.reserve(endPos + 1))
|
||||
{
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG1("xbuf::readString: can't reserve size = ", endPos + 1);
|
||||
///////
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG1("xbuf::readString: Reserved size = ", endPos + 1);
|
||||
///////
|
||||
|
||||
if (endPos > _used)
|
||||
{
|
||||
endPos = _used;
|
||||
@@ -363,6 +377,9 @@ void xbuf::addSeg()
|
||||
{
|
||||
_tail->next = (xseg*) new uint32_t[_segSize / 4 + 1];
|
||||
|
||||
if (_tail->next == NULL)
|
||||
AHTTP_LOGERROR("xbuf::addSeg: error new 1");
|
||||
|
||||
// KH, Must check NULL here
|
||||
_tail = _tail->next;
|
||||
}
|
||||
@@ -370,6 +387,9 @@ void xbuf::addSeg()
|
||||
{
|
||||
// KH, Must check NULL here
|
||||
_tail = _head = (xseg*) new uint32_t[_segSize / 4 + 1];
|
||||
|
||||
if (_tail == NULL)
|
||||
AHTTP_LOGERROR("xbuf::addSeg: error new 2");
|
||||
}
|
||||
|
||||
// KH, Must check NULL here
|
||||
@@ -397,3 +417,5 @@ void xbuf::remSeg()
|
||||
_offset = 0;
|
||||
}
|
||||
|
||||
#endif // XBUF_IMPL_H
|
||||
|
||||
|
||||
@@ -17,17 +17,23 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
#ifdef ASYNC_HTTP_DEBUG_PORT
|
||||
#define A_DBG_PORT ASYNC_HTTP_DEBUG_PORT
|
||||
#else
|
||||
@@ -69,3 +75,5 @@
|
||||
#define AHTTP_LOGDEBUG2(x,y,z) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.println(z); }
|
||||
#define AHTTP_LOGDEBUG3(x,y,z,w) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.print(z); A_DBG_PORT.print(" "); A_DBG_PORT.println(w); }
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
|
||||
@@ -17,19 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "AsyncHTTPRequest_Debug_Generic.h"
|
||||
#include "AsyncHTTPRequest_Generic.h"
|
||||
|
||||
|
||||
#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
|
||||
|
||||
//**************************************************************************************************************
|
||||
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
|
||||
, _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr)
|
||||
@@ -110,6 +115,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
_chunked = false;
|
||||
_contentRead = 0;
|
||||
_readyState = readyStateUnsent;
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = false;
|
||||
//////
|
||||
|
||||
if (strcmp(method, "GET") == 0)
|
||||
{
|
||||
@@ -119,13 +128,35 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPOST;
|
||||
}
|
||||
// New in v1.1.0
|
||||
else if (strcmp(method, "PUT") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPUT;
|
||||
}
|
||||
else if (strcmp(method, "PATCH") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPATCH;
|
||||
}
|
||||
else if (strcmp(method, "DELETE") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodDELETE;
|
||||
}
|
||||
else if (strcmp(method, "HEAD") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodHEAD;
|
||||
}
|
||||
//////
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!_parseURL(URL))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
|
||||
{
|
||||
return false;
|
||||
@@ -141,6 +172,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
SAFE_DELETE_ARRAY(hostName)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = true;
|
||||
//////
|
||||
|
||||
return _connect();
|
||||
}
|
||||
@@ -164,8 +199,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
|
||||
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send()
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
{
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -174,7 +219,7 @@ bool AsyncHTTPRequest::send()
|
||||
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -182,7 +227,17 @@ bool AsyncHTTPRequest::send()
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(String body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -190,7 +245,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -198,7 +253,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -206,7 +261,17 @@ bool AsyncHTTPRequest::send(String body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const char* body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -214,7 +279,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -222,7 +287,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -230,7 +295,17 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -238,7 +313,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -246,7 +321,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -254,7 +329,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -262,7 +347,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -270,7 +355,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -289,7 +374,7 @@ void AsyncHTTPRequest::abort()
|
||||
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
reqStates AsyncHTTPRequest::readyState()
|
||||
@@ -314,7 +399,7 @@ String AsyncHTTPRequest::responseText()
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseText() no data");
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -329,7 +414,7 @@ String AsyncHTTPRequest::responseText()
|
||||
_HTTPcode = HTTPCODE_TOO_LESS_RAM;
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -339,7 +424,7 @@ String AsyncHTTPRequest::responseText()
|
||||
|
||||
AHTTP_LOGDEBUG3("responseText(char)", localString.substring(0, 16).c_str(), ", avail =", avail);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return localString;
|
||||
}
|
||||
@@ -363,7 +448,7 @@ size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
|
||||
|
||||
_contentRead += avail;
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return avail;
|
||||
}
|
||||
@@ -590,13 +675,19 @@ bool AsyncHTTPRequest::_buildRequest()
|
||||
return false;
|
||||
}
|
||||
|
||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
||||
// New in v1.1.1
|
||||
AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
|
||||
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||
//////
|
||||
|
||||
_request->write(_URL->path);
|
||||
_request->write(_URL->query);
|
||||
_request->write(" HTTP/1.1\r\n");
|
||||
|
||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
|
||||
|
||||
SAFE_DELETE(_URL)
|
||||
|
||||
_URL = nullptr;
|
||||
@@ -763,7 +854,7 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
if (!_response)
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -789,7 +880,7 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@@ -810,7 +901,7 @@ void AsyncHTTPRequest::_onPoll(AsyncClient* client)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@@ -851,7 +942,7 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
_lastActivity = 0;
|
||||
_setReadyState(readyStateDone);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@@ -879,7 +970,7 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
{
|
||||
if ( ! _collectHeaders())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -919,7 +1010,7 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
}
|
||||
|
||||
@@ -1204,7 +1295,7 @@ String AsyncHTTPRequest::headers()
|
||||
|
||||
_response += "\r\n";
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return _response;
|
||||
}
|
||||
@@ -1264,7 +1355,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const char* name, const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr->next;
|
||||
}
|
||||
@@ -1284,7 +1375,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(const char* name)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -1304,7 +1395,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(int ndx)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
|
||||
@@ -17,18 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.2"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -57,8 +63,8 @@
|
||||
#define MUTEX_LOCK_NR if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return;}
|
||||
#define MUTEX_LOCK(returnVal) if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return returnVal;}
|
||||
|
||||
#define _lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _unlock xSemaphoreGiveRecursive(threadLock)
|
||||
#define _AHTTP_lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _AHTTP_unlock xSemaphoreGiveRecursive(threadLock)
|
||||
|
||||
#elif ESP8266
|
||||
|
||||
@@ -67,8 +73,8 @@
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||
@@ -78,8 +84,8 @@
|
||||
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#endif
|
||||
|
||||
@@ -225,9 +231,19 @@ class AsyncHTTPRequest
|
||||
|
||||
private:
|
||||
|
||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
||||
|
||||
reqStates _readyState;
|
||||
// New in v1.1.1
|
||||
bool _requestReadyToSend;
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||
|
||||
HTTPmethod _HTTPmethod;
|
||||
|
||||
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||
//////
|
||||
|
||||
reqStates _readyState;
|
||||
|
||||
int16_t _HTTPcode; // HTTP response code or (negative) exception code
|
||||
bool _chunked; // Processing chunked response
|
||||
@@ -285,3 +301,6 @@ class AsyncHTTPRequest
|
||||
bool _collectHeaders();
|
||||
};
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include "utility/xbuf.h"
|
||||
|
||||
+10
-1
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/********************************************************************************************
|
||||
@@ -46,6 +49,9 @@
|
||||
********************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifndef XBUF_H
|
||||
#define XBUF_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct xseg
|
||||
@@ -147,3 +153,6 @@ class xbuf: public Print
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // XBUF_H
|
||||
|
||||
|
||||
@@ -17,17 +17,23 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
#ifdef ASYNC_HTTP_DEBUG_PORT
|
||||
#define A_DBG_PORT ASYNC_HTTP_DEBUG_PORT
|
||||
#else
|
||||
@@ -69,3 +75,5 @@
|
||||
#define AHTTP_LOGDEBUG2(x,y,z) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.println(z); }
|
||||
#define AHTTP_LOGDEBUG3(x,y,z,w) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.print(z); A_DBG_PORT.print(" "); A_DBG_PORT.println(w); }
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_DEBUG_GENERIC_H
|
||||
|
||||
|
||||
@@ -17,18 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.2"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -57,8 +63,8 @@
|
||||
#define MUTEX_LOCK_NR if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return;}
|
||||
#define MUTEX_LOCK(returnVal) if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return returnVal;}
|
||||
|
||||
#define _lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _unlock xSemaphoreGiveRecursive(threadLock)
|
||||
#define _AHTTP_lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
|
||||
#define _AHTTP_unlock xSemaphoreGiveRecursive(threadLock)
|
||||
|
||||
#elif ESP8266
|
||||
|
||||
@@ -67,8 +73,8 @@
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||
@@ -78,8 +84,8 @@
|
||||
|
||||
#define MUTEX_LOCK_NR
|
||||
#define MUTEX_LOCK(returnVal)
|
||||
#define _lock
|
||||
#define _unlock
|
||||
#define _AHTTP_lock
|
||||
#define _AHTTP_unlock
|
||||
|
||||
#endif
|
||||
|
||||
@@ -218,16 +224,29 @@ class AsyncHTTPRequest
|
||||
size_t responseLength(); // indicated response length or sum of chunks to date
|
||||
int responseHTTPcode(); // HTTP response code or (negative) error code
|
||||
String responseText(); // response (whole* or partial* as string)
|
||||
|
||||
char* responseLongText(); // response long (whole* or partial* as string)
|
||||
|
||||
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
|
||||
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
|
||||
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
|
||||
String version(); // Version of AsyncHTTPRequest
|
||||
//___________________________________________________________________________________________________________________________________
|
||||
|
||||
private:
|
||||
|
||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
||||
|
||||
reqStates _readyState;
|
||||
// New in v1.1.1
|
||||
bool _requestReadyToSend;
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||
|
||||
HTTPmethod _HTTPmethod;
|
||||
|
||||
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||
//////
|
||||
|
||||
reqStates _readyState;
|
||||
|
||||
int16_t _HTTPcode; // HTTP response code or (negative) exception code
|
||||
bool _chunked; // Processing chunked response
|
||||
@@ -286,3 +305,5 @@ class AsyncHTTPRequest
|
||||
};
|
||||
|
||||
#include "AsyncHTTPRequest_Impl_Generic.h"
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_GENERIC_H
|
||||
|
||||
@@ -17,17 +17,24 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
|
||||
#define CANT_SEND_BAD_REQUEST F("Can't send() bad request")
|
||||
|
||||
//**************************************************************************************************************
|
||||
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
|
||||
@@ -90,6 +97,8 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
|
||||
if (_readyState != readyStateUnsent && _readyState != readyStateDone)
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: not ready");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,6 +118,10 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
_chunked = false;
|
||||
_contentRead = 0;
|
||||
_readyState = readyStateUnsent;
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = false;
|
||||
//////
|
||||
|
||||
if (strcmp(method, "GET") == 0)
|
||||
{
|
||||
@@ -118,15 +131,43 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPOST;
|
||||
}
|
||||
// New in v1.1.0
|
||||
else if (strcmp(method, "PUT") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPUT;
|
||||
}
|
||||
else if (strcmp(method, "PATCH") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodPATCH;
|
||||
}
|
||||
else if (strcmp(method, "DELETE") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodDELETE;
|
||||
}
|
||||
else if (strcmp(method, "HEAD") == 0)
|
||||
{
|
||||
_HTTPmethod = HTTPmethodHEAD;
|
||||
}
|
||||
//////
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: Bad method");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!_parseURL(URL))
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: error parsing URL");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: not connected");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -140,11 +181,21 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
||||
SAFE_DELETE_ARRAY(hostName)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
// New in v1.1.1
|
||||
_requestReadyToSend = true;
|
||||
//////
|
||||
|
||||
AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName);
|
||||
|
||||
return _connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG("open: error alloc");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, void* arg)
|
||||
@@ -163,8 +214,18 @@ void AsyncHTTPRequest::setTimeout(int seconds)
|
||||
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send()
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
{
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG("send()");
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -173,7 +234,7 @@ bool AsyncHTTPRequest::send()
|
||||
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -181,7 +242,17 @@ bool AsyncHTTPRequest::send()
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(String body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(String)", body.substring(0, 16).c_str(), ", length =", body.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -189,7 +260,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -197,7 +268,7 @@ bool AsyncHTTPRequest::send(String body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -205,7 +276,17 @@ bool AsyncHTTPRequest::send(String body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const char* body)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body, ", length =", strlen(body));
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -213,7 +294,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +302,7 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
_request->write(body);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -229,7 +310,17 @@ bool AsyncHTTPRequest::send(const char* body)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", (char*) body, ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -237,7 +328,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -245,7 +336,7 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -253,7 +344,17 @@ bool AsyncHTTPRequest::send(const uint8_t* body, size_t len)
|
||||
//**************************************************************************************************************
|
||||
bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
// New in v1.1.1
|
||||
if (_requestReadyToSend)
|
||||
{
|
||||
AHTTP_LOGDEBUG3("send(char)", body->peekString(16).c_str(), ", length =", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
AHTTP_LOGDEBUG(CANT_SEND_BAD_REQUEST);
|
||||
return false;
|
||||
}
|
||||
//////
|
||||
|
||||
MUTEX_LOCK(false)
|
||||
|
||||
@@ -261,7 +362,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
|
||||
if ( ! _buildRequest())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -269,7 +370,7 @@ bool AsyncHTTPRequest::send(xbuf* body, size_t len)
|
||||
_request->write(body, len);
|
||||
_send();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -288,7 +389,7 @@ void AsyncHTTPRequest::abort()
|
||||
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
//**************************************************************************************************************
|
||||
reqStates AsyncHTTPRequest::readyState()
|
||||
@@ -313,7 +414,7 @@ String AsyncHTTPRequest::responseText()
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseText() no data");
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -328,7 +429,7 @@ String AsyncHTTPRequest::responseText()
|
||||
_HTTPcode = HTTPCODE_TOO_LESS_RAM;
|
||||
_client->abort();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -336,13 +437,61 @@ String AsyncHTTPRequest::responseText()
|
||||
localString = _response->readString(avail);
|
||||
_contentRead += localString.length();
|
||||
|
||||
AHTTP_LOGDEBUG3("responseText(char)", localString.substring(0, 16).c_str(), ", avail =", avail);
|
||||
//AHTTP_LOGDEBUG3("responseText(char)", localString.substring(0, 16).c_str(), ", avail =", avail);
|
||||
AHTTP_LOGDEBUG3("responseText(char)", localString, ", avail =", avail);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return localString;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
|
||||
#if 1
|
||||
|
||||
#if (ESP32)
|
||||
#define GLOBAL_STR_LEN (32 * 1024)
|
||||
#elif (ESP8266)
|
||||
#define GLOBAL_STR_LEN (16 * 1024)
|
||||
#else
|
||||
#define GLOBAL_STR_LEN (4 * 1024)
|
||||
#endif
|
||||
|
||||
char globalLongString[GLOBAL_STR_LEN + 1];
|
||||
|
||||
char* AsyncHTTPRequest::responseLongText()
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseLongText()");
|
||||
|
||||
MUTEX_LOCK(NULL)
|
||||
|
||||
if ( ! _response || _readyState < readyStateLoading || ! available())
|
||||
{
|
||||
AHTTP_LOGDEBUG("responseText() no data");
|
||||
|
||||
_AHTTP_unlock;
|
||||
|
||||
//return String();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// String localString;
|
||||
size_t avail = available();
|
||||
size_t lenToCopy = (avail <= GLOBAL_STR_LEN) ? avail : GLOBAL_STR_LEN;
|
||||
|
||||
strncpy(globalLongString, _response->readString(avail).c_str(), lenToCopy );
|
||||
globalLongString[ lenToCopy + 1 ] = 0;
|
||||
|
||||
_contentRead += _response->readString(avail).length();
|
||||
|
||||
AHTTP_LOGDEBUG3("responseLongText(char)", globalLongString, ", avail =", avail);
|
||||
|
||||
_AHTTP_unlock;
|
||||
|
||||
return globalLongString;
|
||||
}
|
||||
#endif
|
||||
|
||||
//**************************************************************************************************************
|
||||
size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
|
||||
{
|
||||
@@ -362,7 +511,7 @@ size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
|
||||
|
||||
_contentRead += avail;
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return avail;
|
||||
}
|
||||
@@ -589,13 +738,19 @@ bool AsyncHTTPRequest::_buildRequest()
|
||||
return false;
|
||||
}
|
||||
|
||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
||||
// New in v1.1.1
|
||||
AHTTP_LOGDEBUG1("_HTTPmethod =", _HTTPmethod);
|
||||
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
//////
|
||||
|
||||
// New in v1.1.0
|
||||
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||
//////
|
||||
|
||||
_request->write(_URL->path);
|
||||
_request->write(_URL->query);
|
||||
_request->write(" HTTP/1.1\r\n");
|
||||
|
||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||
|
||||
|
||||
SAFE_DELETE(_URL)
|
||||
|
||||
_URL = nullptr;
|
||||
@@ -758,11 +913,18 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
_client = client;
|
||||
_setReadyState(readyStateOpened);
|
||||
|
||||
// KH test
|
||||
_response = new xbuf;
|
||||
//_response = new xbuf(256);
|
||||
//////
|
||||
|
||||
if (!_response)
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onConnect: Can't new _responser");
|
||||
///////
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -773,11 +935,17 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
_client->onAck([](void* obj, AsyncClient * client, size_t len, uint32_t time)
|
||||
{
|
||||
(void) client;
|
||||
(void) len;
|
||||
(void) time;
|
||||
|
||||
((AsyncHTTPRequest*)(obj))->_send();
|
||||
}, this);
|
||||
|
||||
_client->onData([](void* obj, AsyncClient * client, void* data, size_t len)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
((AsyncHTTPRequest*)(obj))->_onData(data, len);
|
||||
}, this);
|
||||
|
||||
@@ -788,12 +956,14 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
|
||||
|
||||
_lastActivity = millis();
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onPoll(AsyncClient* client)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
MUTEX_LOCK_NR
|
||||
|
||||
if (_timeout && (millis() - _lastActivity) > (_timeout * 1000))
|
||||
@@ -809,12 +979,14 @@ void AsyncHTTPRequest::_onPoll(AsyncClient* client)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onError(AsyncClient* client, int8_t error)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
AHTTP_LOGDEBUG1("_onError handler error =", error);
|
||||
|
||||
_HTTPcode = error;
|
||||
@@ -823,6 +995,8 @@ void AsyncHTTPRequest::_onError(AsyncClient* client, int8_t error)
|
||||
//**************************************************************************************************************
|
||||
void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
AHTTP_LOGDEBUG("\n_onDisconnect handler");
|
||||
|
||||
MUTEX_LOCK_NR
|
||||
@@ -850,7 +1024,7 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
|
||||
_lastActivity = 0;
|
||||
_setReadyState(readyStateDone);
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
}
|
||||
|
||||
//**************************************************************************************************************
|
||||
@@ -866,6 +1040,11 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
if (_chunks)
|
||||
{
|
||||
_chunks->write((uint8_t*)Vbuf, len);
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onData: _processChunks");
|
||||
///////
|
||||
|
||||
_processChunks();
|
||||
}
|
||||
else
|
||||
@@ -878,7 +1057,11 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
{
|
||||
if ( ! _collectHeaders())
|
||||
{
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG("_onData: headers not complete");
|
||||
///////
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -918,7 +1101,7 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
|
||||
_onDataCB(_onDataCBarg, this, available());
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
}
|
||||
|
||||
@@ -1203,7 +1386,7 @@ String AsyncHTTPRequest::headers()
|
||||
|
||||
_response += "\r\n";
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return _response;
|
||||
}
|
||||
@@ -1263,7 +1446,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const char* name, const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr->next;
|
||||
}
|
||||
@@ -1283,7 +1466,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(const char* name)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -1303,7 +1486,7 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(int ndx)
|
||||
hdr = hdr->next;
|
||||
}
|
||||
|
||||
_unlock;
|
||||
_AHTTP_unlock;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -1328,3 +1511,5 @@ char* AsyncHTTPRequest::_charstar(const __FlashStringHelper * str)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ASYNC_HTTP_REQUEST_GENERIC_IMPL_H
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/********************************************************************************************
|
||||
@@ -46,6 +49,9 @@
|
||||
********************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifndef XBUF_H
|
||||
#define XBUF_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct xseg
|
||||
@@ -149,3 +155,5 @@ class xbuf: public Print
|
||||
|
||||
#include "utility/xbuf_Impl.h"
|
||||
|
||||
#endif // XBUF_H
|
||||
|
||||
|
||||
@@ -17,17 +17,23 @@
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.2
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||
1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct.
|
||||
1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef XBUF_IMPL_H
|
||||
#define XBUF_IMPL_H
|
||||
|
||||
xbuf::xbuf(const uint16_t segSize) : _head(nullptr), _tail(nullptr), _used(0), _free(0), _offset(0)
|
||||
{
|
||||
_segSize = (segSize + 3) & -4;//((segSize + 3) >> 2) << 2;
|
||||
@@ -289,9 +295,17 @@ String xbuf::readString(int endPos)
|
||||
|
||||
if ( ! result.reserve(endPos + 1))
|
||||
{
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG1("xbuf::readString: can't reserve size = ", endPos + 1);
|
||||
///////
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// KH, to remove
|
||||
AHTTP_LOGDEBUG1("xbuf::readString: Reserved size = ", endPos + 1);
|
||||
///////
|
||||
|
||||
if (endPos > _used)
|
||||
{
|
||||
endPos = _used;
|
||||
@@ -363,6 +377,9 @@ void xbuf::addSeg()
|
||||
{
|
||||
_tail->next = (xseg*) new uint32_t[_segSize / 4 + 1];
|
||||
|
||||
if (_tail->next == NULL)
|
||||
AHTTP_LOGERROR("xbuf::addSeg: error new 1");
|
||||
|
||||
// KH, Must check NULL here
|
||||
_tail = _tail->next;
|
||||
}
|
||||
@@ -370,6 +387,9 @@ void xbuf::addSeg()
|
||||
{
|
||||
// KH, Must check NULL here
|
||||
_tail = _head = (xseg*) new uint32_t[_segSize / 4 + 1];
|
||||
|
||||
if (_tail == NULL)
|
||||
AHTTP_LOGERROR("xbuf::addSeg: error new 2");
|
||||
}
|
||||
|
||||
// KH, Must check NULL here
|
||||
@@ -397,3 +417,5 @@ void xbuf::remSeg()
|
||||
_offset = 0;
|
||||
}
|
||||
|
||||
#endif // XBUF_IMPL_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user