IP Configuration

This commit is contained in:
Gašper Dobrovoljc
2023-03-11 15:11:03 +01:00
commit ec125f27db
662 changed files with 103738 additions and 0 deletions

70
lib/WiFiEsp/CHANGES.txt Normal file
View File

@@ -0,0 +1,70 @@
2.2.2 (2017-11-03)
* Make SSID a const char * in begin() #116
* Replace NULL with 0 to avoid compilation warnings
* Changing _ESPLOGLEVEL_ requires editing debug.h #88
2.2.1 (2017-01-02)
* Fixing Issue #69 (Can't declare member function to have static linkage)
* Supporting ESP8266 firmware 2.X
2.1.2 (2016-05-08)
* Added retry in EspDrv::wifiDriverInit method
* Clean buffer in ScanNetwork (bug #43)
2.1.1 (2016-05-09)
* Implemented gatwayIP() and subnetMask() methods
2.1 (2016-03-13)
* SSL connection support
* Implementation of config and configAP methods
* Fixed read methods WiFiEspClient.read(buf, size) and WiFiEspUDP::read(buf, size)
* Fixed possible buffer overflow in EspDrv.sendCmdGet
* Added beginAP methods similar to WiFi101 library - parameters order for beginAP is now different!
1.6 (2016-02-21)
* Improved UDP support
* Added WiFiEspClient.remoteIP() method
* Consistent use use of uint16_t to manage port numbers
* Added AT+CIPDINFO=1 during init to return remote IP and port with IPD
* Added AT+CWAUTOCONN=0 during init to disable autoconnect
1.5.1 (2016-02-11)
* Fix in EspDrv.getScanNetworks method
* Fix buffer overflow in getFwVersion
1.5 (2016-01-25)
* Implemented scanNetworks method
* Increased ring buffer size to 32 to read long SSID names
1.4.2 (2016-01-05)
* Fixed compilation problem when using WiFiEspClient.print
1.4.1 (2016-01-05)
* Speed optimizations
1.4 (2016-01-04)
* Reduced dynamic memory footprint
1.3 (2016-01-03)
* UDP support (experimental)
* Fixed WiFiEspClient.connected and WiFi.status and methods
* Connection close detection
* Ring buffer optimization
* Client peek method fixed
1.2 (2015-12-29)
* Redesigned WiFi.init method to accept a Stream object
* Use CUR when starting the AP
* Small improvements to samples
1.1 (2015-12-20)
* Fix for receiving large data packets
* Access point mode support
* Ring buffer class is now used in EspDrv.cpp
* Removed not implemented methods
* Prints firmware version if not recognized
* Multiple exclamation marks fixed for Arduino Mega
* Cleaned up comments
1.0 (2015-12-11)
* First stable release

675
lib/WiFiEsp/LICENSE Normal file
View File

@@ -0,0 +1,675 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
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>.

102
lib/WiFiEsp/README.md Normal file
View File

@@ -0,0 +1,102 @@
# WiFiEsp
With an ESP8266 board, WiFiEsp library allows an Arduino board to connect to the internet.
It can serve as either a server accepting incoming connections or a client making outgoing ones.
The WiFiEsp library is very similar to the Arduino [WiFi](http://www.arduino.cc/en/Reference/WiFi) and [Ethernet](http://www.arduino.cc/en/Reference/Ethernet) libraries, and many of the function calls are the same.
Supports ESP SDK version 1.1.1 and above (AT version 0.25 and above).
## Features
- APIs compatible with standard Arduino WiFi library.
- Use AT commands of standard ESP firmware (no need to flash a custom firmware).
- Support hardware and software serial ports.
- Configurable tracing level.
## Wiring
The WiFiEsp library has been designed to work with the [ESP WiFi shield](http://www.instructables.com/id/Cheap-Arduino-WiFi-Shield-With-ESP8266/).
It is a cheap version of the Arduino WiFi shield that uses an ESP-01 module to provide networking capabilities to Arduino boards.
## Examples
- [ConnectWPA](https://github.com/bportaluri/WiFiEsp/blob/master/examples/ConnectWPA/ConnectWPA.ino) - Demonstrates how to connect to a network that is encrypted with WPA2 Personal
- [WebClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClient/WebClient.ino) - Connect to a remote webserver
- [WebClientRepeating](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientRepeating/WebClientRepeating.ino) - Make repeated HTTP calls to a webserver
- [WebServer](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServer/WebServer.ino) - Serve a webpage from the WiFi shield
- [WebServerAP](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerAP/WebServerAP.ino) - Serve a webpage from the WiFi shield starting a local Access Point
- [WebServerLed](https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebServerLed/WebServerLed.ino) - Turn on and off a led from a webpage
- [UdpNTPClient](https://github.com/bportaluri/WiFiEsp/blob/master/examples/UdpNTPClient/UdpNTPClient.ino) - Query a Network Time Protocol (NTP) server using UDP
## Supported APIs
Most of the standard Arduino WiFi library methods are available. Refer to the [WiFi library page](http://www.arduino.cc/en/Reference/WiFi) for more details.
### WiFiEsp class
- begin() - Not all authentication types
- disconnect() - YES
- config()
- setDNS() - NO (no AT command available)
- SSID() - YES
- BSSID() - YES
- RSSI() - YES
- encryptionType() - NO (no AT command available)
- scanNetworks() - YES
- getSocket()
- macAddress() - YES
### WiFiEspServer class
The WiFiEspServer class creates servers which can send data to and receive data from connected clients (programs running on other computers or devices).
- WiFiEspServer() - YES
- begin() - YES
- available() - YES
- write() - YES
- print() - YES
- println() - YES
### Client class
The WiFiEspClient class creates clients that can connect to servers and send and receive data.
- WiFiEspClient() - YES
- connected() - YES
- connect() - YES
- write() - YES
- print() - YES
- println() - YES
- available() - YES
- read() - YES
- flush() - YES
- stop() - YES
### WiFiEspUDP class
The UDP class enables UDP message to be sent and received.
- WiFiUDP - YES
- begin() - YES
- available() - YES
- beginPacket() - YES
- endPacket() - YES
- write() - YES
- parsePacket() - YES
- peek()
- read() - YES
- flush()
- stop()
- remoteIP() - YES
- remotePort() - YES
## Contributing
If you discover a bug or would like to propose a new feature, please open a new [issue](https://github.com/bportaluri/WiFiEsp/issues).

View File

@@ -0,0 +1,94 @@
/*
WiFiEsp example: ConnectWPA
This example connects to an encrypted WiFi network using an ESP8266 module.
Then it prints the MAC address of the WiFi shield, the IP address obtained
and other network details.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-connect.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
}
void loop()
{
// print the network connection information every 10 seconds
Serial.println();
printCurrentNet();
printWifiData();
delay(10000);
}
void printWifiData()
{
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print your MAC address
byte mac[6];
WiFi.macAddress(mac);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void printCurrentNet()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to
byte bssid[6];
WiFi.BSSID(bssid);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
Serial.print("BSSID: ");
Serial.println(buf);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.println(rssi);
}

View File

@@ -0,0 +1,109 @@
/*
WiFiEsp example: ScanNetworks
This example prints the Wifi shield's MAC address, and
scans for available Wifi networks using the Wifi shield.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// Print WiFi MAC address
printMacAddress();
}
void loop()
{
// scan for existing networks
Serial.println();
Serial.println("Scanning available networks...");
listNetworks();
delay(10000);
}
void printMacAddress()
{
// get your MAC address
byte mac[6];
WiFi.macAddress(mac);
// print MAC address
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void listNetworks()
{
// scan for nearby networks
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("Couldn't get a wifi connection");
while (true);
}
// print the list of networks seen
Serial.print("Number of available networks:");
Serial.println(numSsid);
// print the network number and name for each network found
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
}
}
void printEncryptionType(int thisType) {
// read the encryption type and print out the name
switch (thisType) {
case ENC_TYPE_WEP:
Serial.print("WEP");
break;
case ENC_TYPE_WPA_PSK:
Serial.print("WPA_PSK");
break;
case ENC_TYPE_WPA2_PSK:
Serial.print("WPA2_PSK");
break;
case ENC_TYPE_WPA_WPA2_PSK:
Serial.print("WPA_WPA2_PSK");
break;
case ENC_TYPE_NONE:
Serial.print("None");
break;
}
Serial.println();
}

View File

@@ -0,0 +1,154 @@
/*
WiFiEsp example: UdpNTPClient
Get the time from a Network Time Protocol (NTP) time server.
Demonstrates use of UDP to send and receive data packets
For more on NTP time servers and the messages needed to communicate with them,
see http://en.wikipedia.org/wiki/Network_Time_Protocol
NOTE: The serial buffer size must be larger than 36 + packet size
In this example we use an UDP packet of 48 bytes so the buffer must be
at least 36+48=84 bytes that exceeds the default buffer size (64).
You must modify the serial buffer size to 128
For HardwareSerial modify _SS_MAX_RX_BUFF in
Arduino\hardware\arduino\avr\cores\arduino\SoftwareSerial.h
For SoftwareSerial modify _SS_MAX_RX_BUFF in
Arduino\hardware\arduino\avr\libraries\SoftwareSerial\SoftwareSerial.h
*/
#include "WiFiEsp.h"
#include "WiFiEspUdp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char timeServer[] = "time.nist.gov"; // NTP server
unsigned int localPort = 2390; // local port to listen for UDP packets
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
const int UDP_TIMEOUT = 2000; // timeout in miliseconds to wait for an UDP packet to arrive
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
// A UDP instance to let us send and receive packets over UDP
WiFiEspUDP Udp;
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
Udp.begin(localPort);
}
void loop()
{
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait for a reply for UDP_TIMEOUT miliseconds
unsigned long startMs = millis();
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
Serial.println(Udp.parsePacket());
if (Udp.parsePacket()) {
Serial.println("packet received");
// We've received a packet, read the data from it into the buffer
Udp.read(packetBuffer, NTP_PACKET_SIZE);
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);
// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);
// print the hour, minute and second:
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(':');
if (((epoch % 3600) / 60) < 10) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(':');
if ((epoch % 60) < 10) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
Serial.println(epoch % 60); // print the second
}
// wait ten seconds before asking for the time again
delay(10000);
}
// send an NTP request to the time server at the given address
void sendNTPpacket(char *ntpSrv)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(ntpSrv, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}

View File

@@ -0,0 +1,109 @@
/*
WiFiEsp example: WiFi UDP Send and Receive String
This sketch wait an UDP packet on localPort using a WiFi shield.
When a packet is received an 'ACK' packet is sent to the client on port remotePort.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
unsigned int localPort = 10002; // local port to listen on
char packetBuffer[255]; // buffer to hold incoming packet
char ReplyBuffer[] = "ACK"; // a string to send back
WiFiEspUDP Udp;
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
Udp.begin(localPort);
Serial.print("Listening on port ");
Serial.println(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

View File

@@ -0,0 +1,106 @@
/*
WiFiEsp example: WebClient
This sketch connects to google website using an ESP8266 module to
perform a simple web search.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "arduino.cc";
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /asciilogo.txt HTTP/1.1");
client.println("Host: arduino.cc");
client.println("Connection: close");
client.println();
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

View File

@@ -0,0 +1,121 @@
/*
WiFiEsp example: WebClientRepeating
This sketch connects to a web server and makes an HTTP request
using an Arduino ESP8266 module.
It repeats the HTTP call each 10 seconds.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "arduino.cc";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
printWifiStatus();
}
void loop()
{
// if there's incoming data from the net connection send it out the serial port
// this is for debugging purposes only
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if 10 seconds have passed since your last connection,
// then connect again and send data
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server
void httpRequest()
{
Serial.println();
// close any connection before send a new request
// this will free the socket on the WiFi shield
client.stop();
// if there's a successful connection
if (client.connect(server, 80)) {
Serial.println("Connecting...");
// send the HTTP PUT request
client.println(F("GET /asciilogo.txt HTTP/1.1"));
client.println(F("Host: arduino.cc"));
client.println("Connection: close");
client.println();
// note the time that the connection was made
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection
Serial.println("Connection failed");
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

View File

@@ -0,0 +1,106 @@
/*
WiFiEsp example: WebClient
This sketch connects to google website using an ESP8266 module to
perform a simple web search.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "www.google.com";
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connectSSL(server, 443)) {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET / HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

View File

@@ -0,0 +1,136 @@
/*
WiFiEsp example: WebServer
A simple web server that shows the value of the analog input
pins via a web page using an ESP8266 module.
This sketch will print the IP address of your ESP8266 module (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to display the web page.
The web page will be automatically refreshed each 20 seconds.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
int reqCount = 0; // number of requests received
WiFiEspServer server(80);
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
printWifiStatus();
// start the web server on port 80
server.begin();
}
void loop()
{
// listen for incoming clients
WiFiEspClient client = server.available();
if (client) {
Serial.println("New client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
Serial.println("Sending response");
// send a standard http response header
// use \r\n instead of many println statements to speedup data send
client.print(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n" // the connection will be closed after completion of the response
"Refresh: 20\r\n" // refresh the page automatically every 20 sec
"\r\n");
client.print("<!DOCTYPE HTML>\r\n");
client.print("<html>\r\n");
client.print("<h1>Hello World!</h1>\r\n");
client.print("Requests received: ");
client.print(++reqCount);
client.print("<br>\r\n");
client.print("Analog input A0: ");
client.print(analogRead(0));
client.print("<br>\r\n");
client.print("</html>\r\n");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println("Client disconnected");
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
Serial.println();
}

View File

@@ -0,0 +1,128 @@
/*
WiFiEsp example: WebServerAP
A simple web server that shows the value of the analog input
pins via a web page using an ESP8266 module.
This sketch will start an access point and print the IP address of your
ESP8266 module to the Serial monitor. From there, you can open
that address in a web browser to display the web page.
The web page will be automatically refreshed each 20 seconds.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "TwimEsp"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
int reqCount = 0; // number of requests received
WiFiEspServer server(80);
// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);
void setup()
{
Serial.begin(115200); // initialize serial for debugging
Serial1.begin(9600); // initialize serial for ESP module
WiFi.init(&Serial1); // initialize ESP module
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true); // don't continue
}
Serial.print("Attempting to start AP ");
Serial.println(ssid);
// uncomment these two lines if you want to set the IP address of the AP
//IPAddress localIp(192, 168, 111, 111);
//WiFi.configAP(localIp);
// start access point
status = WiFi.beginAP(ssid, 10, pass, ENC_TYPE_WPA2_PSK);
Serial.println("Access point started");
printWifiStatus();
// start the web server on port 80
server.begin();
Serial.println("Server started");
}
void loop()
{
WiFiEspClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New client"); // print a message out the serial port
buf.init(); // initialize the circular buffer
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
buf.push(c); // push it to the ring buffer
// you got two newline characters in a row
// that's the end of the HTTP request, so send a response
if (buf.endsWith("\r\n\r\n")) {
sendHttpResponse(client);
break;
}
}
}
// give the web browser time to receive the data
delay(10);
// close the connection
client.stop();
Serial.println("Client disconnected");
}
}
void sendHttpResponse(WiFiEspClient client)
{
client.print(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n" // the connection will be closed after completion of the response
"Refresh: 20\r\n" // refresh the page automatically every 20 sec
"\r\n");
client.print("<!DOCTYPE HTML>\r\n");
client.print("<html>\r\n");
client.print("<h1>Hello World!</h1>\r\n");
client.print("Requests received: ");
client.print(++reqCount);
client.print("<br>\r\n");
client.print("Analog input A0: ");
client.print(analogRead(0));
client.print("<br>\r\n");
client.print("</html>\r\n");
}
void printWifiStatus()
{
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, connect to ");
Serial.print(ssid);
Serial.print(" and open a browser to http://");
Serial.println(ip);
Serial.println();
}

View File

@@ -0,0 +1,142 @@
/*
WiFiEsp example: WebServerLed
A simple web server that lets you turn on and of an LED via a web page.
This sketch will print the IP address of your ESP8266 module (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to turn on and off the LED on pin 13.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS;
int ledStatus = LOW;
WiFiEspServer server(80);
// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
Serial.begin(115200); // initialize serial for debugging
Serial1.begin(9600); // initialize serial for ESP module
WiFi.init(&Serial1); // initialize ESP module
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
printWifiStatus();
// start the web server on port 80
server.begin();
}
void loop()
{
WiFiEspClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New client"); // print a message out the serial port
buf.init(); // initialize the circular buffer
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
buf.push(c); // push it to the ring buffer
// printing the stream to the serial monitor will slow down
// the receiving of data from the ESP filling the serial buffer
//Serial.write(c);
// you got two newline characters in a row
// that's the end of the HTTP request, so send a response
if (buf.endsWith("\r\n\r\n")) {
sendHttpResponse(client);
break;
}
// Check to see if the client request was "GET /H" or "GET /L":
if (buf.endsWith("GET /H")) {
Serial.println("Turn led ON");
ledStatus = HIGH;
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}
else if (buf.endsWith("GET /L")) {
Serial.println("Turn led OFF");
ledStatus = LOW;
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
}
}
// close the connection
client.stop();
Serial.println("Client disconnected");
}
}
void sendHttpResponse(WiFiEspClient client)
{
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("The LED is ");
client.print(ledStatus);
client.println("<br>");
client.println("<br>");
client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");
// The HTTP response ends with another blank line:
client.println();
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
Serial.println();
}

59
lib/WiFiEsp/keywords.txt Normal file
View File

@@ -0,0 +1,59 @@
#######################################
# Syntax Coloring Map For WiFiEsp
#######################################
#######################################
# Library (KEYWORD3)
#######################################
WiFiEsp KEYWORD3
#######################################
# Datatypes (KEYWORD1)
#######################################
WiFiEspClient KEYWORD1
WiFiEspServer KEYWORD1
WiFiEspUDP KEYWORD1
RingBuffer KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
firmwareVersion KEYWORD2
status KEYWORD2
connect KEYWORD2
write KEYWORD2
available KEYWORD2
config KEYWORD2
setDNS KEYWORD2
read KEYWORD2
flush KEYWORD2
stop KEYWORD2
connected KEYWORD2
begin KEYWORD2
disconnect KEYWORD2
macAddress KEYWORD2
localIP KEYWORD2
subnetMask KEYWORD2
gatewayIP KEYWORD2
scanNetworks KEYWORD2
SSID KEYWORD2
BSSID KEYWORD2
RSSI KEYWORD2
encryptionType KEYWORD2
getResult KEYWORD2
getSocket KEYWORD2
beginPacket KEYWORD2
endPacket KEYWORD2
parsePacket KEYWORD2
remoteIP KEYWORD2
remotePort KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@@ -0,0 +1,9 @@
name=WiFiEsp
version=2.2.2
author=bportaluri
maintainer=Bruno Portaluri <bportaluri@gmail.com>
sentence=Arduino WiFi library for ESP8266
paragraph=Arduino WiFi library for ESP8266. Works only with SDK version 1.1.1 and above (AT version 0.25 and above).
category=Other
url=https://github.com/bportaluri/WiFiEsp
architectures=*

233
lib/WiFiEsp/src/WiFiEsp.cpp Normal file
View File

@@ -0,0 +1,233 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#include "WiFiEsp.h"
int16_t WiFiEspClass::_state[MAX_SOCK_NUM] = { NA_STATE, NA_STATE, NA_STATE, NA_STATE };
uint16_t WiFiEspClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
uint8_t WiFiEspClass::espMode = 0;
WiFiEspClass::WiFiEspClass()
{
}
void WiFiEspClass::init(Stream* espSerial)
{
LOGINFO(F("Initializing ESP module"));
EspDrv::wifiDriverInit(espSerial);
}
char* WiFiEspClass::firmwareVersion()
{
return EspDrv::getFwVersion();
}
int WiFiEspClass::begin(const char* ssid, const char* passphrase)
{
espMode = 1;
if (EspDrv::wifiConnect(ssid, passphrase))
return WL_CONNECTED;
return WL_CONNECT_FAILED;
}
int WiFiEspClass::beginAP(const char* ssid, uint8_t channel, const char* pwd, uint8_t enc, bool apOnly)
{
if(apOnly)
espMode = 2;
else
espMode = 3;
if (EspDrv::wifiStartAP(ssid, pwd, channel, enc, espMode))
return WL_CONNECTED;
return WL_CONNECT_FAILED;
}
int WiFiEspClass::beginAP(const char* ssid)
{
return beginAP(ssid, 10, "", 0);
}
int WiFiEspClass::beginAP(const char* ssid, uint8_t channel)
{
return beginAP(ssid, channel, "", 0);
}
void WiFiEspClass::config(IPAddress ip)
{
EspDrv::config(ip);
}
void WiFiEspClass::configAP(IPAddress ip)
{
EspDrv::configAP(ip);
}
int WiFiEspClass::disconnect()
{
return EspDrv::disconnect();
}
uint8_t* WiFiEspClass::macAddress(uint8_t* mac)
{
// TODO we don't need _mac variable
uint8_t* _mac = EspDrv::getMacAddress();
memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
return mac;
}
IPAddress WiFiEspClass::localIP()
{
IPAddress ret;
if(espMode==1)
EspDrv::getIpAddress(ret);
else
EspDrv::getIpAddressAP(ret);
return ret;
}
IPAddress WiFiEspClass::subnetMask()
{
IPAddress mask;
if(espMode==1)
EspDrv::getNetmask(mask);
return mask;
}
IPAddress WiFiEspClass::gatewayIP()
{
IPAddress gw;
if(espMode==1)
EspDrv::getGateway(gw);
return gw;
}
char* WiFiEspClass::SSID()
{
return EspDrv::getCurrentSSID();
}
uint8_t* WiFiEspClass::BSSID(uint8_t* bssid)
{
// TODO we don't need _bssid
uint8_t* _bssid = EspDrv::getCurrentBSSID();
memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
return bssid;
}
int32_t WiFiEspClass::RSSI()
{
return EspDrv::getCurrentRSSI();
}
int8_t WiFiEspClass::scanNetworks()
{
return EspDrv::getScanNetworks();
}
char* WiFiEspClass::SSID(uint8_t networkItem)
{
return EspDrv::getSSIDNetoworks(networkItem);
}
int32_t WiFiEspClass::RSSI(uint8_t networkItem)
{
return EspDrv::getRSSINetoworks(networkItem);
}
uint8_t WiFiEspClass::encryptionType(uint8_t networkItem)
{
return EspDrv::getEncTypeNetowrks(networkItem);
}
uint8_t WiFiEspClass::status()
{
return EspDrv::getConnectionStatus();
}
////////////////////////////////////////////////////////////////////////////
// Non standard methods
////////////////////////////////////////////////////////////////////////////
void WiFiEspClass::reset(void)
{
EspDrv::reset();
}
/*
void ESP8266::hardReset(void)
{
connected = false;
strcpy(ip, "");
digitalWrite(ESP8266_RST, LOW);
delay(ESP8266_HARD_RESET_DURATION);
digitalWrite(ESP8266_RST, HIGH);
delay(ESP8266_HARD_RESET_DURATION);
}
*/
bool WiFiEspClass::ping(const char *host)
{
return EspDrv::ping(host);
}
uint8_t WiFiEspClass::getFreeSocket()
{
// ESP Module assigns socket numbers in ascending order, so we will assign them in descending order
for (int i = MAX_SOCK_NUM - 1; i >= 0; i--)
{
if (_state[i] == NA_STATE)
{
return i;
}
}
return SOCK_NOT_AVAIL;
}
void WiFiEspClass::allocateSocket(uint8_t sock)
{
_state[sock] = sock;
}
void WiFiEspClass::releaseSocket(uint8_t sock)
{
_state[sock] = NA_STATE;
}
WiFiEspClass WiFi;

274
lib/WiFiEsp/src/WiFiEsp.h Normal file
View File

@@ -0,0 +1,274 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef WiFiEsp_h
#define WiFiEsp_h
#include <Arduino.h>
#include <Stream.h>
#include <IPAddress.h>
#include <inttypes.h>
#include "WiFiEspClient.h"
#include "WiFiEspServer.h"
#include "utility/EspDrv.h"
#include "utility/RingBuffer.h"
#include "utility/debug.h"
class WiFiEspClass
{
public:
static int16_t _state[MAX_SOCK_NUM];
static uint16_t _server_port[MAX_SOCK_NUM];
WiFiEspClass();
/**
* Initialize the ESP module.
*
* param espSerial: the serial interface (HW or SW) used to communicate with the ESP module
*/
static void init(Stream* espSerial);
/**
* Get firmware version
*/
static char* firmwareVersion();
// NOT IMPLEMENTED
//int begin(char* ssid);
// NOT IMPLEMENTED
//int begin(char* ssid, uint8_t key_idx, const char* key);
/**
* Start Wifi connection with passphrase
* the most secure supported mode will be automatically selected
*
* param ssid: Pointer to the SSID string.
* param passphrase: Passphrase. Valid characters in a passphrase
* must be between ASCII 32-126 (decimal).
*/
int begin(const char* ssid, const char* passphrase);
/**
* Change Ip configuration settings disabling the DHCP client
*
* param local_ip: Static ip configuration
*/
void config(IPAddress local_ip);
// NOT IMPLEMENTED
//void config(IPAddress local_ip, IPAddress dns_server);
// NOT IMPLEMENTED
//void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
// NOT IMPLEMENTED
//void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
// NOT IMPLEMENTED
//void setDNS(IPAddress dns_server1);
// NOT IMPLEMENTED
//void setDNS(IPAddress dns_server1, IPAddress dns_server2);
/**
* Disconnect from the network
*
* return: one value of wl_status_t enum
*/
int disconnect(void);
/**
* Get the interface MAC address.
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
uint8_t* macAddress(uint8_t* mac);
/**
* Get the interface IP address.
*
* return: Ip address value
*/
IPAddress localIP();
/**
* Get the interface subnet mask address.
*
* return: subnet mask address value
*/
IPAddress subnetMask();
/**
* Get the gateway ip address.
*
* return: gateway ip address value
*/
IPAddress gatewayIP();
/**
* Return the current SSID associated with the network
*
* return: ssid string
*/
char* SSID();
/**
* Return the current BSSID associated with the network.
* It is the MAC address of the Access Point
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
uint8_t* BSSID(uint8_t* bssid);
/**
* Return the current RSSI /Received Signal Strength in dBm)
* associated with the network
*
* return: signed value
*/
int32_t RSSI();
/**
* Return Connection status.
*
* return: one of the value defined in wl_status_t
* see https://www.arduino.cc/en/Reference/WiFiStatus
*/
uint8_t status();
/*
* Return the Encryption Type associated with the network
*
* return: one value of wl_enc_type enum
*/
//uint8_t encryptionType();
/*
* Start scan WiFi networks available
*
* return: Number of discovered networks
*/
int8_t scanNetworks();
/*
* Return the SSID discovered during the network scan.
*
* param networkItem: specify from which network item want to get the information
*
* return: ssid string of the specified item on the networks scanned list
*/
char* SSID(uint8_t networkItem);
/*
* Return the encryption type of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
*/
uint8_t encryptionType(uint8_t networkItem);
/*
* Return the RSSI of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: signed value of RSSI of the specified item on the networks scanned list
*/
int32_t RSSI(uint8_t networkItem);
// NOT IMPLEMENTED
//int hostByName(const char* aHostname, IPAddress& aResult);
////////////////////////////////////////////////////////////////////////////
// Non standard methods
////////////////////////////////////////////////////////////////////////////
/**
* Start the ESP access point.
*
* param ssid: Pointer to the SSID string.
* param channel: WiFi channel (1-14)
* param pwd: Passphrase. Valid characters in a passphrase
* must be between ASCII 32-126 (decimal).
* param enc: encryption type (enum wl_enc_type)
* param apOnly: Set to false if you want to run AP and Station modes simultaneously
*/
int beginAP(const char* ssid, uint8_t channel, const char* pwd, uint8_t enc, bool apOnly=true);
/*
* Start the ESP access point with open security.
*/
int beginAP(const char* ssid);
int beginAP(const char* ssid, uint8_t channel);
/**
* Change IP address of the AP
*
* param ip: Static ip configuration
*/
void configAP(IPAddress ip);
/**
* Restart the ESP module.
*/
void reset();
/**
* Ping a host.
*/
bool ping(const char *host);
friend class WiFiEspClient;
friend class WiFiEspServer;
friend class WiFiEspUDP;
private:
static uint8_t getFreeSocket();
static void allocateSocket(uint8_t sock);
static void releaseSocket(uint8_t sock);
static uint8_t espMode;
};
extern WiFiEspClass WiFi;
#endif

View File

@@ -0,0 +1,290 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#include <inttypes.h>
#include "WiFiEsp.h"
#include "WiFiEspClient.h"
#include "WiFiEspServer.h"
#include "utility/EspDrv.h"
#include "utility/debug.h"
WiFiEspClient::WiFiEspClient() : _sock(255)
{
}
WiFiEspClient::WiFiEspClient(uint8_t sock) : _sock(sock)
{
}
////////////////////////////////////////////////////////////////////////////////
// Overrided Print methods
////////////////////////////////////////////////////////////////////////////////
// the standard print method will call write for each character in the buffer
// this is very slow on ESP
size_t WiFiEspClient::print(const __FlashStringHelper *ifsh)
{
printFSH(ifsh, false);
}
// if we do override this, the standard println will call the print
// method twice
size_t WiFiEspClient::println(const __FlashStringHelper *ifsh)
{
printFSH(ifsh, true);
}
////////////////////////////////////////////////////////////////////////////////
// Implementation of Client virtual methods
////////////////////////////////////////////////////////////////////////////////
int WiFiEspClient::connectSSL(const char* host, uint16_t port)
{
return connect(host, port, SSL_MODE);
}
int WiFiEspClient::connectSSL(IPAddress ip, uint16_t port)
{
char s[16];
sprintf_P(s, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
return connect(s, port, SSL_MODE);
}
int WiFiEspClient::connect(const char* host, uint16_t port)
{
return connect(host, port, TCP_MODE);
}
int WiFiEspClient::connect(IPAddress ip, uint16_t port)
{
char s[16];
sprintf_P(s, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
return connect(s, port, TCP_MODE);
}
/* Private method */
int WiFiEspClient::connect(const char* host, uint16_t port, uint8_t protMode)
{
LOGINFO1(F("Connecting to"), host);
_sock = WiFiEspClass::getFreeSocket();
if (_sock != NO_SOCKET_AVAIL)
{
if (!EspDrv::startClient(host, port, _sock, protMode))
return 0;
WiFiEspClass::allocateSocket(_sock);
}
else
{
LOGERROR(F("No socket available"));
return 0;
}
return 1;
}
size_t WiFiEspClient::write(uint8_t b)
{
return write(&b, 1);
}
size_t WiFiEspClient::write(const uint8_t *buf, size_t size)
{
if (_sock >= MAX_SOCK_NUM or size==0)
{
setWriteError();
return 0;
}
bool r = EspDrv::sendData(_sock, buf, size);
if (!r)
{
setWriteError();
LOGERROR1(F("Failed to write to socket"), _sock);
delay(4000);
stop();
return 0;
}
return size;
}
int WiFiEspClient::available()
{
if (_sock != 255)
{
int bytes = EspDrv::availData(_sock);
if (bytes>0)
{
return bytes;
}
}
return 0;
}
int WiFiEspClient::read()
{
uint8_t b;
if (!available())
return -1;
bool connClose = false;
EspDrv::getData(_sock, &b, false, &connClose);
if (connClose)
{
WiFiEspClass::releaseSocket(_sock);
_sock = 255;
}
return b;
}
int WiFiEspClient::read(uint8_t* buf, size_t size)
{
if (!available())
return -1;
return EspDrv::getDataBuf(_sock, buf, size);
}
int WiFiEspClient::peek()
{
uint8_t b;
if (!available())
return -1;
bool connClose = false;
EspDrv::getData(_sock, &b, true, &connClose);
if (connClose)
{
WiFiEspClass::releaseSocket(_sock);
_sock = 255;
}
return b;
}
void WiFiEspClient::flush()
{
while (available())
read();
}
void WiFiEspClient::stop()
{
if (_sock == 255)
return;
LOGINFO1(F("Disconnecting "), _sock);
EspDrv::stopClient(_sock);
WiFiEspClass::releaseSocket(_sock);
_sock = 255;
}
uint8_t WiFiEspClient::connected()
{
return (status() == ESTABLISHED);
}
WiFiEspClient::operator bool()
{
return _sock != 255;
}
////////////////////////////////////////////////////////////////////////////////
// Additional WiFi standard methods
////////////////////////////////////////////////////////////////////////////////
uint8_t WiFiEspClient::status()
{
if (_sock == 255)
{
return CLOSED;
}
if (EspDrv::availData(_sock))
{
return ESTABLISHED;
}
if (EspDrv::getClientState(_sock))
{
return ESTABLISHED;
}
WiFiEspClass::releaseSocket(_sock);
_sock = 255;
return CLOSED;
}
IPAddress WiFiEspClient::remoteIP()
{
IPAddress ret;
EspDrv::getRemoteIpAddress(ret);
return ret;
}
////////////////////////////////////////////////////////////////////////////////
// Private Methods
////////////////////////////////////////////////////////////////////////////////
size_t WiFiEspClient::printFSH(const __FlashStringHelper *ifsh, bool appendCrLf)
{
size_t size = strlen_P((char*)ifsh);
if (_sock >= MAX_SOCK_NUM or size==0)
{
setWriteError();
return 0;
}
bool r = EspDrv::sendData(_sock, ifsh, size, appendCrLf);
if (!r)
{
setWriteError();
LOGERROR1(F("Failed to write to socket"), _sock);
delay(4000);
stop();
return 0;
}
return size;
}

View File

@@ -0,0 +1,144 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef WiFiEspClient_h
#define WiFiEspClient_h
#include "Arduino.h"
#include "Print.h"
#include "Client.h"
#include "IPAddress.h"
class WiFiEspClient : public Client
{
public:
WiFiEspClient();
WiFiEspClient(uint8_t sock);
// override Print.print method
size_t print(const __FlashStringHelper *ifsh);
size_t println(const __FlashStringHelper *ifsh);
/*
* Connect to the specified IP address and port. The return value indicates success or failure.
* Returns true if the connection succeeds, false if not.
*/
virtual int connect(IPAddress ip, uint16_t port);
/*
* Connect to the specified host and port. The return value indicates success or failure.
* Returns true if the connection succeeds, false if not.
*/
virtual int connect(const char *host, uint16_t port);
/*
* Connect to the specified IP address and port using SSL. The return value indicates success or failure.
* Returns true if the connection succeeds, false if not.
*/
int connectSSL(IPAddress ip, uint16_t port);
/*
* Connect to the specified host and port using SSL. The return value indicates success or failure.
* Returns true if the connection succeeds, false if not.
*/
int connectSSL(const char* host, uint16_t port);
/*
* Write a character to the server the client is connected to.
* Returns the number of characters written.
*/
virtual size_t write(uint8_t);
/*
* Write data to the server the client is connected to.
* Returns the number of characters written.
*/
virtual size_t write(const uint8_t *buf, size_t size);
virtual int available();
/*
* Read the next byte received from the server the client is connected to (after the last call to read()).
* Returns the next byte (or character), or -1 if none is available.
*/
virtual int read();
virtual int read(uint8_t *buf, size_t size);
/*
* Returns the next byte (character) of incoming serial data without removing it from the internal serial buffer.
*/
virtual int peek();
/*
* Discard any bytes that have been written to the client but not yet read.
*/
virtual void flush();
/*
* Disconnect from the server.
*/
virtual void stop();
/*
* Whether or not the client is connected.
* Note that a client is considered connected if the connection has been closed but there is still unread data.
* Returns true if the client is connected, false if not.
*/
virtual uint8_t connected();
uint8_t status();
virtual operator bool();
// needed to correctly handle overriding
// see http://stackoverflow.com/questions/888235/overriding-a-bases-overloaded-function-in-c
using Print::write;
using Print::print;
using Print::println;
/*
* Returns the remote IP address.
*/
IPAddress remoteIP();
friend class WiFiEspServer;
private:
uint8_t _sock; // connection id
int connect(const char* host, uint16_t port, uint8_t protMode);
size_t printFSH(const __FlashStringHelper *ifsh, bool appendCrLf);
};
#endif

View File

@@ -0,0 +1,99 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#include "WiFiEspServer.h"
#include "utility/EspDrv.h"
#include "utility/debug.h"
WiFiEspServer::WiFiEspServer(uint16_t port)
{
_port = port;
}
void WiFiEspServer::begin()
{
LOGDEBUG(F("Starting server"));
/* The ESP Module only allows socket 1 to be used for the server */
#if 0
_sock = WiFiEspClass::getFreeSocket();
if (_sock == SOCK_NOT_AVAIL)
{
LOGERROR(F("No socket available for server"));
return;
}
#else
_sock = 1; // If this is already in use, the startServer attempt will fail
#endif
WiFiEspClass::allocateSocket(_sock);
_started = EspDrv::startServer(_port, _sock);
if (_started)
{
LOGINFO1(F("Server started on port"), _port);
}
else
{
LOGERROR(F("Server failed to start"));
}
}
WiFiEspClient WiFiEspServer::available(byte* status)
{
// TODO the original method seems to handle automatic server restart
int bytes = EspDrv::availData(0);
if (bytes>0)
{
LOGINFO1(F("New client"), EspDrv::_connId);
WiFiEspClass::allocateSocket(EspDrv::_connId);
WiFiEspClient client(EspDrv::_connId);
return client;
}
return WiFiEspClient(255);
}
uint8_t WiFiEspServer::status()
{
return EspDrv::getServerState(0);
}
size_t WiFiEspServer::write(uint8_t b)
{
return write(&b, 1);
}
size_t WiFiEspServer::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
{
if (WiFiEspClass::_state[sock] != 0)
{
WiFiEspClient client(sock);
n += client.write(buffer, size);
}
}
return n;
}

View File

@@ -0,0 +1,63 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef WiFiEspServer_h
#define WiFiEspServer_h
#include <Server.h>
#include "WiFiEsp.h"
class WiFiEspClient;
class WiFiEspServer : public Server
{
public:
WiFiEspServer(uint16_t port);
/*
* Gets a client that is connected to the server and has data available for reading.
* The connection persists when the returned client object goes out of scope; you can close it by calling client.stop().
* Returns a Client object; if no Client has data available for reading, this object will evaluate to false in an if-statement.
*/
WiFiEspClient available(uint8_t* status = NULL);
/*
* Start the TCP server
*/
void begin();
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
uint8_t status();
using Print::write;
private:
uint16_t _port;
uint8_t _sock;
bool _started;
};
#endif

View File

@@ -0,0 +1,193 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#include "WiFiEsp.h"
#include "WiFiEspUdp.h"
#include "utility/EspDrv.h"
#include "utility/debug.h"
/* Constructor */
WiFiEspUDP::WiFiEspUDP() : _sock(NO_SOCKET_AVAIL) {}
/* Start WiFiUDP socket, listening at local port PORT */
uint8_t WiFiEspUDP::begin(uint16_t port)
{
uint8_t sock = WiFiEspClass::getFreeSocket();
if (sock != NO_SOCKET_AVAIL)
{
EspDrv::startClient("0", port, sock, UDP_MODE);
WiFiEspClass::allocateSocket(sock); // allocating the socket for the listener
WiFiEspClass::_server_port[sock] = port;
_sock = sock;
_port = port;
return 1;
}
return 0;
}
/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int WiFiEspUDP::available()
{
if (_sock != NO_SOCKET_AVAIL)
{
int bytes = EspDrv::availData(_sock);
if (bytes>0)
{
return bytes;
}
}
return 0;
}
/* Release any resources being used by this WiFiUDP instance */
void WiFiEspUDP::stop()
{
if (_sock == NO_SOCKET_AVAIL)
return;
// Discard data that might be in the incoming buffer
flush();
// Stop the listener and return the socket to the pool
EspDrv::stopClient(_sock);
WiFiEspClass::_state[_sock] = NA_STATE;
WiFiEspClass::_server_port[_sock] = 0;
_sock = NO_SOCKET_AVAIL;
}
int WiFiEspUDP::beginPacket(const char *host, uint16_t port)
{
if (_sock == NO_SOCKET_AVAIL)
_sock = WiFiEspClass::getFreeSocket();
if (_sock != NO_SOCKET_AVAIL)
{
//EspDrv::startClient(host, port, _sock, UDP_MODE);
_remotePort = port;
strcpy(_remoteHost, host);
WiFiEspClass::allocateSocket(_sock);
return 1;
}
return 0;
}
int WiFiEspUDP::beginPacket(IPAddress ip, uint16_t port)
{
char s[18];
sprintf_P(s, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
return beginPacket(s, port);
}
int WiFiEspUDP::endPacket()
{
return 1; //ServerDrv::sendUdpData(_sock);
}
size_t WiFiEspUDP::write(uint8_t byte)
{
return write(&byte, 1);
}
size_t WiFiEspUDP::write(const uint8_t *buffer, size_t size)
{
bool r = EspDrv::sendDataUdp(_sock, _remoteHost, _remotePort, buffer, size);
if (!r)
{
return 0;
}
return size;
}
int WiFiEspUDP::parsePacket()
{
return available();
}
int WiFiEspUDP::read()
{
uint8_t b;
if (!available())
return -1;
bool connClose = false;
// Read the data and handle the timeout condition
if (! EspDrv::getData(_sock, &b, false, &connClose))
return -1; // Timeout occured
return b;
}
int WiFiEspUDP::read(uint8_t* buf, size_t size)
{
if (!available())
return -1;
return EspDrv::getDataBuf(_sock, buf, size);
}
int WiFiEspUDP::peek()
{
uint8_t b;
if (!available())
return -1;
return b;
}
void WiFiEspUDP::flush()
{
// Discard all input data
int count = available();
while (count-- > 0)
read();
}
IPAddress WiFiEspUDP::remoteIP()
{
IPAddress ret;
EspDrv::getRemoteIpAddress(ret);
return ret;
}
uint16_t WiFiEspUDP::remotePort()
{
return EspDrv::getRemotePort();
}
////////////////////////////////////////////////////////////////////////////////
// Private Methods
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,97 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef WiFiEspUdp_h
#define WiFiEspUdp_h
#include <Udp.h>
#define UDP_TX_PACKET_MAX_SIZE 24
class WiFiEspUDP : public UDP {
private:
uint8_t _sock; // socket ID for Wiz5100
uint16_t _port; // local port to listen on
uint16_t _remotePort;
char _remoteHost[30];
public:
WiFiEspUDP(); // Constructor
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual void stop(); // Finish with the UDP socket
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port);
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port);
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket();
// Write a single byte into the packet
virtual size_t write(uint8_t);
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size);
using Print::write;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket();
// Number of bytes remaining in the current packet
virtual int available();
// Read a single byte from the current packet
virtual int read();
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len);
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
// Return the next byte from the current packet without moving on to the next byte
virtual int peek();
virtual void flush(); // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP();
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort();
friend class WiFiEspServer;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,340 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef EspDrv_h
#define EspDrv_h
#include "Stream.h"
#include "IPAddress.h"
#include "RingBuffer.h"
// Maximum size of a SSID
#define WL_SSID_MAX_LENGTH 32
// Size of a MAC-address or BSSID
#define WL_MAC_ADDR_LENGTH 6
// Size of a MAC-address or BSSID
#define WL_IPV4_LENGTH 4
// Maximum size of a SSID list
#define WL_NETWORKS_LIST_MAXNUM 10
// Maxmium number of socket
#define MAX_SOCK_NUM 4
// Socket not available constant
#define SOCK_NOT_AVAIL 255
// Default state value for Wifi state field
#define NA_STATE -1
#define WL_FW_VER_LENGTH 6
#define NO_SOCKET_AVAIL 255
// maximum size of AT command
#define CMD_BUFFER_SIZE 200
typedef enum eProtMode {TCP_MODE, UDP_MODE, SSL_MODE} tProtMode;
typedef enum {
WL_FAILURE = -1,
WL_SUCCESS = 1,
} wl_error_code_t;
/* Authentication modes */
enum wl_auth_mode {
AUTH_MODE_INVALID,
AUTH_MODE_AUTO,
AUTH_MODE_OPEN_SYSTEM,
AUTH_MODE_SHARED_KEY,
AUTH_MODE_WPA,
AUTH_MODE_WPA2,
AUTH_MODE_WPA_PSK,
AUTH_MODE_WPA2_PSK
};
typedef enum {
WL_NO_SHIELD = 255,
WL_IDLE_STATUS = 0,
//WL_NO_SSID_AVAIL,
//WL_SCAN_COMPLETED,
WL_CONNECTED,
WL_CONNECT_FAILED,
//WL_CONNECTION_LOST,
WL_DISCONNECTED
} wl_status_t;
/* Encryption modes */
enum wl_enc_type {
ENC_TYPE_NONE = 0,
ENC_TYPE_WEP = 1,
ENC_TYPE_WPA_PSK = 2,
ENC_TYPE_WPA2_PSK = 3,
ENC_TYPE_WPA_WPA2_PSK = 4
};
enum wl_tcp_state {
CLOSED = 0,
LISTEN = 1,
SYN_SENT = 2,
SYN_RCVD = 3,
ESTABLISHED = 4,
FIN_WAIT_1 = 5,
FIN_WAIT_2 = 6,
CLOSE_WAIT = 7,
CLOSING = 8,
LAST_ACK = 9,
TIME_WAIT = 10
};
class EspDrv
{
public:
static void wifiDriverInit(Stream *espSerial);
/* Start Wifi connection with passphrase
*
* param ssid: Pointer to the SSID string.
* param passphrase: Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
*/
static bool wifiConnect(const char* ssid, const char* passphrase);
/*
* Start the Access Point
*/
static bool wifiStartAP(const char* ssid, const char* pwd, uint8_t channel, uint8_t enc, uint8_t espMode);
/*
* Set ip configuration disabling dhcp client
*/
static void config(IPAddress local_ip);
/*
* Set ip configuration disabling dhcp client
*/
static void configAP(IPAddress local_ip);
/*
* Disconnect from the network
*
* return: WL_SUCCESS or WL_FAILURE
*/
static int8_t disconnect();
/*
*
*
* return: one value of wl_status_t enum
*/
static uint8_t getConnectionStatus();
/*
* Get the interface MAC address.
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
static uint8_t* getMacAddress();
/*
* Get the interface IP address.
*
* return: copy the ip address value in IPAddress object
*/
static void getIpAddress(IPAddress& ip);
static void getIpAddressAP(IPAddress& ip);
/*
* Get the interface IP netmask.
* This can be used to retrieve settings configured through DHCP.
*
* return: true if successful
*/
static bool getNetmask(IPAddress& mask);
/*
* Get the interface IP gateway.
* This can be used to retrieve settings configured through DHCP.
*
* return: true if successful
*/
static bool getGateway(IPAddress& mask);
/*
* Return the current SSID associated with the network
*
* return: ssid string
*/
static char* getCurrentSSID();
/*
* Return the current BSSID associated with the network.
* It is the MAC address of the Access Point
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
static uint8_t* getCurrentBSSID();
/*
* Return the current RSSI /Received Signal Strength in dBm)
* associated with the network
*
* return: signed value
*/
static int32_t getCurrentRSSI();
/*
* Get the networks available
*
* return: Number of discovered networks
*/
static uint8_t getScanNetworks();
/*
* Return the SSID discovered during the network scan.
*
* param networkItem: specify from which network item want to get the information
*
* return: ssid string of the specified item on the networks scanned list
*/
static char* getSSIDNetoworks(uint8_t networkItem);
/*
* Return the RSSI of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: signed value of RSSI of the specified item on the networks scanned list
*/
static int32_t getRSSINetoworks(uint8_t networkItem);
/*
* Return the encryption type of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
*/
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
/*
* Get the firmware version
*/
static char* getFwVersion();
////////////////////////////////////////////////////////////////////////////
// Client/Server methods
////////////////////////////////////////////////////////////////////////////
static bool startServer(uint16_t port, uint8_t sock);
static bool startClient(const char* host, uint16_t port, uint8_t sock, uint8_t protMode);
static void stopClient(uint8_t sock);
static uint8_t getServerState(uint8_t sock);
static uint8_t getClientState(uint8_t sock);
static bool getData(uint8_t connId, uint8_t *data, bool peek, bool* connClose);
static int getDataBuf(uint8_t connId, uint8_t *buf, uint16_t bufSize);
static bool sendData(uint8_t sock, const uint8_t *data, uint16_t len);
static bool sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t len, bool appendCrLf=false);
static bool sendDataUdp(uint8_t sock, const char* host, uint16_t port, const uint8_t *data, uint16_t len);
static uint16_t availData(uint8_t connId);
static bool ping(const char *host);
static void reset();
static void getRemoteIpAddress(IPAddress& ip);
static uint16_t getRemotePort();
////////////////////////////////////////////////////////////////////////////////
private:
static Stream *espSerial;
static long _bufPos;
static uint8_t _connId;
static uint16_t _remotePort;
static uint8_t _remoteIp[WL_IPV4_LENGTH];
// firmware version string
static char fwVersion[WL_FW_VER_LENGTH];
// settings of requested network
static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH];
static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM];
static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM];
// settings of current selected network
static char _ssid[WL_SSID_MAX_LENGTH];
static uint8_t _bssid[WL_MAC_ADDR_LENGTH];
static uint8_t _mac[WL_MAC_ADDR_LENGTH];
static uint8_t _localIp[WL_IPV4_LENGTH];
// the ring buffer is used to search the tags in the stream
static RingBuffer ringBuf;
//static int sendCmd(const char* cmd, int timeout=1000);
static int sendCmd(const __FlashStringHelper* cmd, int timeout=1000);
static int sendCmd(const __FlashStringHelper* cmd, int timeout, ...);
static bool sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, const char* endTag, char* outStr, int outStrLen);
static bool sendCmdGet(const __FlashStringHelper* cmd, const __FlashStringHelper* startTag, const __FlashStringHelper* endTag, char* outStr, int outStrLen);
static int readUntil(int timeout, const char* tag=NULL, bool findTags=true);
static void espEmptyBuf(bool warn=true);
static int timedRead();
friend class WiFiEsp;
friend class WiFiEspServer;
friend class WiFiEspClient;
friend class WiFiEspUdp;
};
extern EspDrv espDrv;
#endif

View File

@@ -0,0 +1,105 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#include "RingBuffer.h"
#include <Arduino.h>
RingBuffer::RingBuffer(unsigned int size)
{
_size = size;
// add one char to terminate the string
ringBuf = new char[size+1];
ringBufEnd = &ringBuf[size];
init();
}
RingBuffer::~RingBuffer() {}
void RingBuffer::reset()
{
ringBufP = ringBuf;
}
void RingBuffer::init()
{
ringBufP = ringBuf;
memset(ringBuf, 0, _size+1);
}
void RingBuffer::push(char c)
{
*ringBufP = c;
ringBufP++;
if (ringBufP>=ringBufEnd)
ringBufP = ringBuf;
}
bool RingBuffer::endsWith(const char* str)
{
int findStrLen = strlen(str);
// b is the start position into the ring buffer
char* b = ringBufP-findStrLen;
if(b < ringBuf)
b = b + _size;
char *p1 = (char*)&str[0];
char *p2 = p1 + findStrLen;
for(char *p=p1; p<p2; p++)
{
if(*p != *b)
return false;
b++;
if (b == ringBufEnd)
b=ringBuf;
}
return true;
}
void RingBuffer::getStr(char * destination, unsigned int skipChars)
{
int len = ringBufP-ringBuf-skipChars;
// copy buffer to destination string
strncpy(destination, ringBuf, len);
// terminate output string
//destination[len]=0;
}
void RingBuffer::getStrN(char * destination, unsigned int skipChars, unsigned int num)
{
int len = ringBufP-ringBuf-skipChars;
if (len>num)
len=num;
// copy buffer to destination string
strncpy(destination, ringBuf, len);
// terminate output string
//destination[len]=0;
}

View File

@@ -0,0 +1,47 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef RingBuffer_h
#define RingBuffer_h
class RingBuffer
{
public:
RingBuffer(unsigned int size);
~RingBuffer();
void reset();
void init();
void push(char c);
int getPos();
bool endsWith(const char* str);
void getStr(char * destination, unsigned int skipChars);
void getStrN(char * destination, unsigned int skipChars, unsigned int num);
private:
unsigned int _size;
char* ringBuf;
char* ringBufEnd;
char* ringBufP;
};
#endif

View File

@@ -0,0 +1,49 @@
/*--------------------------------------------------------------------
This file is part of the Arduino WiFiEsp library.
The Arduino WiFiEsp library 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.
The Arduino WiFiEsp 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef EspDebug_H
#define EspDebug_H
#include <stdio.h>
// Change _ESPLOGLEVEL_ to set tracing and logging verbosity
// 0: DISABLED: no logging
// 1: ERROR: errors
// 2: WARN: errors and warnings
// 3: INFO: errors, warnings and informational (default)
// 4: DEBUG: errors, warnings, informational and debug
#ifndef _ESPLOGLEVEL_
#define _ESPLOGLEVEL_ 2
#endif
#define LOGERROR(x) if(_ESPLOGLEVEL_>0) { Serial.print("[WiFiEsp] "); Serial.println(x); }
#define LOGERROR1(x,y) if(_ESPLOGLEVEL_>2) { Serial.print("[WiFiEsp] "); Serial.print(x); Serial.print(" "); Serial.println(y); }
#define LOGWARN(x) if(_ESPLOGLEVEL_>1) { Serial.print("[WiFiEsp] "); Serial.println(x); }
#define LOGWARN1(x,y) if(_ESPLOGLEVEL_>2) { Serial.print("[WiFiEsp] "); Serial.print(x); Serial.print(" "); Serial.println(y); }
#define LOGINFO(x) if(_ESPLOGLEVEL_>2) { Serial.print("[WiFiEsp] "); Serial.println(x); }
#define LOGINFO1(x,y) if(_ESPLOGLEVEL_>2) { Serial.print("[WiFiEsp] "); Serial.print(x); Serial.print(" "); Serial.println(y); }
#define LOGDEBUG(x) if(_ESPLOGLEVEL_>3) { Serial.println(x); }
#define LOGDEBUG0(x) if(_ESPLOGLEVEL_>3) { Serial.print(x); }
#define LOGDEBUG1(x,y) if(_ESPLOGLEVEL_>3) { Serial.print(x); Serial.print(" "); Serial.println(y); }
#define LOGDEBUG2(x,y,z) if(_ESPLOGLEVEL_>3) { Serial.print(x); Serial.print(" "); Serial.print(y); Serial.print(" "); Serial.println(z); }
#endif

View File

@@ -0,0 +1,142 @@
/*
WiFiEsp test: BasicTest
Performs basic connectivity test and checks.
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pwd[] = "12345678"; // your network password
char pwdErr[] = "xxxx"; // wrong password
void setup()
{
Serial.begin(115200);
Serial1.begin(9600);
WiFi.init(&Serial1);
}
void loop()
{
assertEquals("Firmware version", WiFi.firmwareVersion(), "1.5.2");
assertEquals("Status is (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
assertEquals("Check SSID", WiFi.SSID(), ssid);
IPAddress ip = WiFi.localIP();
assertNotEquals("Check IP Address", ip[0], 0);
Serial.print("IP Address: ");
Serial.println(ip);
byte mac[6]={0,0,0,0,0,0};
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
Serial.println();
assertEquals("Disconnect", WiFi.disconnect(), WL_DISCONNECTED);
assertEquals("Check status (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
assertEquals("IP Address", WiFi.localIP(), 0);
assertEquals("Check SSID", WiFi.SSID(), "");
assertEquals("Wrong pwd", WiFi.begin(ssid, pwdErr), WL_CONNECT_FAILED);
IPAddress localIp(192, 168, 168, 111);
WiFi.config(localIp);
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
ip = WiFi.localIP();
assertNotEquals("Check IP Address", ip[0], 0);
Serial.println("END OF TESTS");
delay(60000);
}
////////////////////////////////////////////////////////////////////////////////////
void assertNotEquals(const char* test, int actual, int expected)
{
if(actual!=expected)
pass(test);
else
fail(test, actual, expected);
}
void assertEquals(const char* test, int actual, int expected)
{
if(actual==expected)
pass(test);
else
fail(test, actual, expected);
}
void assertEquals(const char* test, char* actual, char* expected)
{
if(strcmp(actual, expected) == 0)
pass(test);
else
fail(test, actual, expected);
}
void pass(const char* test)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.println(" > PASSED");
Serial.println();
}
void fail(const char* test, char* actual, char* expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=\"");
Serial.print(actual);
Serial.print("\", expected=\"");
Serial.print(expected);
Serial.println("\")");
Serial.println();
delay(10000);
}
void fail(const char* test, int actual, int expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=");
Serial.print(actual);
Serial.print(", expected=");
Serial.print(expected);
Serial.println(")");
Serial.println();
delay(10000);
}

View File

@@ -0,0 +1,184 @@
/*
WiFiEsp test: ClientTest
Test client functions.
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pwd[] = "12345678"; // your network password
// Initialize the Wifi client library
WiFiEspClient client;
void setup()
{
Serial.begin(115200);
Serial1.begin(9600);
WiFi.init(&Serial1);
}
void loop()
{
bool f;
int c;
assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
assertEquals("Ping", WiFi.ping("www.google.com"), true);
assertEquals("Not connected", client.connected(), false);
assertEquals("Connect to server", client.connect("www.brainjar.com", 80), 1);
assertEquals("Connected", client.connected(), true);
//--------------------------------------------------------------
// HTTP request without 'Connection: close' command
client.println("GET /java/host/test.html HTTP/1.1");
client.println("Host: www.brainjar.com");
client.println();
// wait for the response
long _startMillis = millis();
while (!client.available() and (millis()-_startMillis < 2000))
{
}
assertEquals("Response received", (millis()-_startMillis < 2000), true);
f = client.find("<html>");
assertEquals("Response check", f, true);
if (f)
{
while( (c = client.read()) > 0)
Serial.print((char)c);
}
assertEquals("Connected", client.connected(), true);
//--------------------------------------------------------------
delay(5000);
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
assertEquals("Connected", client.connected(), true);
//--------------------------------------------------------------
// HTTP request without 'Connection: close' command
client.println("GET /java/host/test.html HTTP/1.1");
client.println("Host: www.brainjar.com");
client.println("Connection: close");
client.println();
// wait for the response
_startMillis = millis();
while (!client.available() and (millis()-_startMillis < 2000))
{
}
assertEquals("Response received", (millis()-_startMillis < 2000), true);
f = client.find("<html>");
assertEquals("Response check", f, true);
if (f)
{
while( (c = client.read()) > 0)
Serial.print((char)c);
}
//--------------------------------------------------------------
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
assertEquals("Not connected", client.connected(), false);
assertEquals("Ping", WiFi.ping("www.google.com"), true);
assertEquals("Connect", WiFi.disconnect(), WL_DISCONNECTED);
assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
Serial.println("END OF TESTS");
delay(30000);
}
////////////////////////////////////////////////////////////////////////////////////
void assertEquals(const char* test, int actual, int expected)
{
if(actual==expected)
pass(test);
else
fail(test, actual, expected);
}
void assertEquals(const char* test, char* actual, char* expected)
{
if(strcmp(actual, expected) == 0)
pass(test);
else
fail(test, actual, expected);
}
void pass(const char* test)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.println(" > PASSED");
Serial.println();
}
void fail(const char* test, char* actual, char* expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=\"");
Serial.print(actual);
Serial.print("\", expected=\"");
Serial.print(expected);
Serial.println("\")");
Serial.println();
delay(10000);
}
void fail(const char* test, int actual, int expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=");
Serial.print(actual);
Serial.print(", expected=");
Serial.print(expected);
Serial.println(")");
Serial.println();
delay(10000);
}

View File

@@ -0,0 +1,48 @@
// EspDebug - Test sketch for ESP8266 module
#include "Arduino.h"
// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
void setup()
{
Serial.begin(115200); // serial port used for debugging
Serial1.begin(9600); // your ESP's baud rate might be different
}
void loop()
{
if(Serial1.available()) // check if the ESP is sending a message
{
while(Serial1.available())
{
int c = Serial1.read(); // read the next character
Serial.write((char)c); // writes data to the serial monitor
}
}
if(Serial.available())
{
// wait to let all the input command in the serial buffer
delay(10);
// read the input command in a string
String cmd = "";
while(Serial.available())
{
cmd += (char)Serial.read();
}
// print the command and send it to the ESP
Serial.println();
Serial.print(">>>> ");
Serial.println(cmd);
// send the read character to the ESP
Serial1.print(cmd);
}
}

View File

@@ -0,0 +1,58 @@
/*
WiFiEsp test: RingBufferTest
Test of the RingBuffer class.
*/
#include "WiFiEsp.h"
RingBuffer buf(5);
void setup()
{
Serial.begin(115200);
Serial.println("Starting tests");
buf.init();
buf.push('a');
assert(10, buf.endsWith("a"), true);
assert(11, buf.endsWith("A"), false);
assert(12, buf.endsWith("ab"), false);
buf.push('b');
assert(21, buf.endsWith("a"), false);
assert(22, buf.endsWith("A"), false);
assert(23, buf.endsWith("ab"), true);
buf.push('c');
buf.push('d');
buf.push('e');
assert(31, buf.endsWith("abcde"), true);
assert(32, buf.endsWith("de"), true);
buf.push('f');
assert(43, buf.endsWith("bcdef"), true);
assert(44, buf.endsWith("ef"), true);
Serial.println("Done");
}
void loop()
{
// nothing to do
}
void assert(int i, bool x, bool y)
{
if (x!=y)
{
Serial.print ("FAIL ");
Serial.println(i);
}
}