Repository: ItKindaWorks/ESPHelper
Branch: master
Commit: 2c73749013fb
Files: 29
Total size: 176.3 KB
Directory structure:
gitextract_xucz34ps/
├── LICENSE
├── README.md
├── examples/
│ ├── AdvancedFeatures/
│ │ ├── MQTT_Will/
│ │ │ └── MQTT_Will.ino
│ │ ├── arbitraryConfigKeys/
│ │ │ └── arbitraryConfigKeys.ino
│ │ ├── configAndStatusApDemo/
│ │ │ └── configAndStatusApDemo.ino
│ │ ├── configServerApDemo/
│ │ │ └── configServerApDemo.ino
│ │ ├── configServerDemo/
│ │ │ └── configServerDemo.ino
│ │ ├── multiNetwork/
│ │ │ └── multiNetwork.ino
│ │ └── secureMQTT/
│ │ └── secureMQTT.ino
│ ├── GettingStarted/
│ │ ├── Adafruit_IO/
│ │ │ └── Adafruit_IO.ino
│ │ ├── OTA/
│ │ │ └── OTA.ino
│ │ ├── RelayControlV2/
│ │ │ └── RelayControlV2.ino
│ │ ├── basicUse/
│ │ │ └── basicUse.ino
│ │ ├── basicUserPass/
│ │ │ └── basicUserPass.ino
│ │ ├── buttonDemo/
│ │ │ └── buttonDemo.ino
│ │ ├── relayControl/
│ │ │ └── relayControl.ino
│ │ └── wifiCallback/
│ │ └── wifiCallback.ino
│ └── InputOutput/
│ ├── RGBLight/
│ │ └── RGBLight.ino
│ └── temperatureSensor_ds18b20/
│ └── temperatureSensor_ds18b20.ino
├── keywords.txt
├── library.json
├── src/
│ ├── ESPHelper.cpp
│ ├── ESPHelper.h
│ ├── ESPHelperWebConfig.cpp
│ ├── ESPHelperWebConfig.h
│ ├── config_html.h
│ └── sharedData.h
├── static/
│ └── config.html
└── web_to_header.py
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
================================================
FILE: README.md
================================================
# ESPHelper
ESPHelper is a C++ library designed to simplify WiFi and MQTT connectivity for ESP8266 and ESP32 platforms. It manages WiFi and MQTT connections, automatic reconnection, topic subscriptions, and supports OTA (Over-The-Air) updates, making it ideal for IoT and home automation projects.
## Features
- **Automatic WiFi and MQTT Connection Management:** Handles connecting, reconnecting, and resubscribing to MQTT topics.
- **MQTT Topic Subscription Management:** Add, remove, and auto-resubscribe to topics.
- **OTA Updates:** Easily enable/disable OTA, set OTA password and hostname.
- **Broadcast Mode:** Create an access point for configuration or OTA when no WiFi is available.
- **Web Configuration:** Optional web interface for device configuration ([`ESPHelperWebConfig`](src/ESPHelperWebConfig.h)).
- **Callback Support:** Set custom callbacks for WiFi connection, WiFi loss, and MQTT messages.
- **Secure MQTT:** Supports SSL/TLS connections to MQTT brokers.
## Requirements
Make sure you have these libraries installed:
* [Metro](https://github.com/ItKindaWorks/ESPHelper_Metro)
* [PubSubClient](https://github.com/knolleary/pubsubclient) (Current Supported Version - 2.8)
* [ArduinoJson](https://github.com/bblanchon/ArduinoJson) (Current Supported Version - 7.0.4)
* [SafeString](https://github.com/PowerBroker2/SafeString) (Current Supported Version - 4.1.30)
In addition to those libraries, make sure that you have the ESP core files installed for your platform.
* [ESP8266 Arduino Core](https://github.com/esp8266/Arduino)
* [ESP32 Arduino Core](https://github.com/espressif/arduino-esp32)
## Getting Started
See the [examples/GettingStarted](examples/GettingStarted/) folder for usage examples.
### Basic Usage
```cpp
#include "ESPHelper.h"
ESPHelper helper;
void setup() {
helper.setSSID("yourSSID");
helper.setPASS("yourPassword");
helper.setMQTTIP("mqtt.example.com");
helper.begin();
}
void loop() {
helper.loop();
}
```
Useful Methods:
---------------
* *bool begin();*
Initialize the system (must be called once).
* *int loop();*
must be called as often as possible to maintain connections and run the various subsystems
* *bool subscribe(char\* topic);*
subscribe to a given MQTT topic (will NOT auto re-subscribe on connection lost)
* *bool addSubscription(char\* topic);*
add a topic to the subscription list (will auto re-subscribe on connection lost)
* *bool removeSubscription(char\* topic);*
remove a topic from the subscription list and unsubscribe
* *void publish(char\* topic, char\* payload);*
publish a given MQTT message to a given topic
### ToDo
* Implement callback for lost WiFi connection
================================================
FILE: examples/AdvancedFeatures/MQTT_Will/MQTT_Will.ino
================================================
/*
MQTT_Will.ino
Copyright (c) 2018 Sk4zz All right reserved.
github.com/Sk4zz
This file is part of ESPHelper
github.com/ItKindaWorks
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "ESPHelper.h"
#define INTERNAL_LED 2 //Set Pin Number for the internal LED this is for ESP-12E
#define STATUS_TOPIC "test/status" //Set the default topic to publish status messages
// Update these with values suitable for your network.
netInfo homeNet = { .mqttHost = "192.168.2.3", //can be blank if not using MQTT
.mqttUser = "", //can be blank
.mqttPass = "", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "",
.pass = "",
.otaPassword = "", //password for OTA flashing. can be left blank
.hostname ="ESP8266", //Hostname of the board
.willTopic = STATUS_TOPIC, //Topic for Last Will
.willMessage = "offline", //Last Will message
.willQoS = 1, //QoS of last will message
.willRetain = 1}; //Retain flag for last will message
ESPHelper myESP(&homeNet);
bool MQTT_Connection;
bool checkMqttConnection() {
// Check if the Connection status has changed.
// If Status changed to FULL_CONNECTION publish "online" status message on STATUS_TOPIC
// Toggle the INTERNAL_LED
if( MQTT_Connection != (myESP.getStatus() == FULL_CONNECTION) ){
MQTT_Connection = (myESP.getStatus() == FULL_CONNECTION);
if (MQTT_Connection) {
Serial.print("Full Connection established. publishing status on Topic ");
Serial.println(STATUS_TOPIC);
myESP.publish(STATUS_TOPIC, "online", true);
}
digitalWrite(INTERNAL_LED, !MQTT_Connection);
}
}
void setup() {
Serial.begin(115200);
pinMode(INTERNAL_LED, OUTPUT); // Initialize the INTERNAL_LED pin as an output
digitalWrite(INTERNAL_LED, HIGH); // Switch INTERNAL_LED OFF
MQTT_Connection = false;
myESP.OTA_enable();
myESP.addSubscription("test/incoming");
myESP.setMQTTCallback(callback);
myESP.begin();
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
void loop() {
myESP.loop(); //run the loop() method as often as possible - this keeps the network services running
checkMqttConnection();
yield();
}
================================================
FILE: examples/AdvancedFeatures/arbitraryConfigKeys/arbitraryConfigKeys.ino
================================================
/*
arbitraryConfigKeys.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelperFS.h"
//filename and json key to use in the demo
const char* file = "/test.json";
const char* keyName = "count";
void setup(void){
Serial.begin(115200);
//load the filesystem and initialize the key to 0 (then close the FS)
//Note: Although it is not strictly necessary to close the FS it is still a good idea
//to only have the FS open as long as it is needed and then close it again to prevent
//possible data corruption. It does make things a bit slower but it's also safer.
ESPHelperFS::begin();
ESPHelperFS::addKey(keyName, "0", file);
ESPHelperFS::end();
}
void loop(void){
//load the FS and load the config file key
ESPHelperFS::begin();
String value = ESPHelperFS::loadKey(keyName, file);
//convert the string to int and increment the counter
int counter = value.toInt();
counter++;
//print out the new value of the counter
Serial.print("Counter = ");
Serial.println(counter);
//convert the key back to a char string for saving
char dataOut[5];
sprintf(dataOut, "%d", counter);
//save the updated key and close the filesystem
ESPHelperFS::addKey(keyName, dataOut, file);
ESPHelperFS::end();
//wait for a second
delay(1000);
}
================================================
FILE: examples/AdvancedFeatures/configAndStatusApDemo/configAndStatusApDemo.ino
================================================
/*
configAndStatusAPDemo.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "ESPHelperFS.h"
#include "ESPHelperWebConfig.h"
#include "Metro.h"
//enable this to allow the device to reset if it goes into broadcast mode
//for more than a set amount of time (3 min by default). This is useful
//in environments where the device has a weak network signal and experiences
//occasional dropouts.
bool BROADCAST_TIMEOUT_EN = false;
netInfo config;
ESPHelper myESP;
//setup a server on port 80 (http). We use an external server here because we want more than just a config page
//but also a status page or anything else that we want to display
ESP8266WebServer server(80);
ESPHelperWebConfig configPage(&server, "/config");
//defualt net info for unconfigured devices
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS",
.otaPassword = "YOUR OTA PASS",
.hostname = "NEW-ESP8266"};
//timeout before starting AP mode for configuration
Metro connectTimeout = Metro(20000);
Metro broadcastModeTimeout = Metro(180000);
bool timeout = false;
//AP moade setup info
const char* broadcastSSID = "ESP-Hotspot";
const char* broadcastPASS = "";
IPAddress broadcastIP = {192, 168, 1, 1};
void setup(void){
Serial.begin(115200);
//print some debug
Serial.println("Starting Up - Please Wait...");
delay(100);
//startup the wifi and web server (more in the lines below)
startWifi();
//setup the http server and config page (fillConfig will take the netInfo file and use that for
//default values)
configPage.fillConfig(&config);
configPage.begin(config.hostname);
// Actually start the server (again this would be done automatically
//if we were just using the config page and didnt use an external server...)
server.begin();
server.on("/", HTTP_GET, handleStatus);
}
void loop(void){
//get the current status of ESPHelper
int espHelperStatus = myESP.loop();
manageESPHelper(espHelperStatus);
if(espHelperStatus >= FULL_CONNECTION){
//regular loop code goes here
}
delay(5);
}
//ESPHelper & config setup and runtime handler functions
void manageESPHelper(int wifiStatus){
if (BROADCAST_TIMEOUT_EN && wifiStatus == BROADCAST && broadcastModeTimeout.check())
{
Serial.println("BROADCAST mode timeout and reset ESP");
ESP.reset();
delay(5000);
}
//if the unit is broadcasting or connected to wifi then reset the timeout vars
if(wifiStatus == BROADCAST || wifiStatus >= WIFI_ONLY){
connectTimeout.reset();
timeout = false;
}
//otherwise check for a timeout condition and handle setting up broadcast
else if(wifiStatus < WIFI_ONLY){
checkForWifiTimeout();
}
//handle saving a new network config
if(configPage.handle()){
Serial.println("Saving new network config and restarting...");
myESP.saveConfigFile(configPage.getConfig(), "/netConfig.json");
delay(500);
ESP.restart();
}
}
void startWifi(){
loadConfig();
//setup other ESPHelper info and enable OTA updates
myESP.setHopping(false);
myESP.OTA_setPassword(config.otaPassword);
myESP.OTA_setHostnameWithVersion(config.hostname);
myESP.OTA_enable();
Serial.println("Connecting to network");
delay(10);
//connect to wifi before proceeding. If cannot connect then switch to ap mode and create a network to config from
while(myESP.loop() < WIFI_ONLY){
checkForWifiTimeout();
if(timeout){return;}
delay(10);
}
Serial.println("Sucess!");
Serial.println(String("To connect to this device go to " + String(myESP.getIP())));
}
//attempt to load a network configuration from the filesystem
void loadConfig(){
//check for a good config file and start ESPHelper with the file stored on the ESP
if(ESPHelperFS::begin()){
Serial.println("Filesystem loaded - Loading Config");
if(ESPHelperFS::validateConfig("/netConfig.json") == GOOD_CONFIG){
Serial.println("Config loaded");
delay(10);
myESP.begin("/netConfig.json");
}
//if no good config can be loaded (no file/corruption/etc.) then
//attempt to generate a new config and restart the module
else{
Serial.println("Could not load config - saving new config from default values and restarting");
delay(10);
ESPHelperFS::createConfig(&homeNet, "/netConfig.json");
ESPHelperFS::end();
ESP.restart();
}
}
//if the filesystem cannot be started, just fail over to the
//built in network config hardcoded in here
else{
Serial.println("Could not load filesystem, proceeding with default config values");
delay(10);
myESP.begin(&homeNet);
}
//load the netInfo from espHelper for use in the config page
config = myESP.getNetInfo();
}
//function that checks for no network connection for a period of time
//and starting up AP mode when that time has elapsed
void checkForWifiTimeout(){
if(connectTimeout.check() && !timeout){
Serial.println("Network Connection timeout - starting broadcast (AP) mode...");
timeout = true;
myESP.broadcastMode(broadcastSSID, broadcastPASS, broadcastIP);
myESP.OTA_setPassword(config.otaPassword);
myESP.OTA_setHostnameWithVersion(config.hostname);
myESP.OTA_enable();
broadcastModeTimeout.reset();
}
}
//main config page that allows user to enter in configuration info
void handleStatus() {
server.send(200, "text/html", \
String("<html>\
<header>\
<title>Device Info</title>\
</header>\
<body>\
<p><strong>System Status</strong></br>\
Device Name: " + String(myESP.getHostname()) + "</br>\
Connected SSID: " + String(myESP.getSSID()) + "</br>\
Device IP: " + String(myESP.getIP()) + "</br>\
Uptime (ms): " + String(millis()) + "</p>\
</body>\
</html>"));
}
================================================
FILE: examples/AdvancedFeatures/configServerApDemo/configServerApDemo.ino
================================================
/*
configServerApDemo.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "ESPHelperFS.h"
#include "ESPHelperWebConfig.h"
#include "Metro.h"
netInfo config;
ESPHelper myESP;
ESPHelperWebConfig configPage(80, "/");
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS",
.otaPassword = "YOUR OTA PASS",
.hostname = "NEW-ESP8266"};
Metro connectTimeout = Metro(20000);
bool timeout = false;
const char* broadcastSSID = "ESP-Hotspot";
const char* broadcastPASS = "";
IPAddress broadcastIP = {192, 168, 1, 1};
void setup(void){
Serial.begin(115200);
//print some debug
Serial.println("Starting Up - Please Wait...");
delay(100);
//startup the wifi and web server
startWifi();
configPage.begin(config.hostname);
}
void loop(void){
//get the current status of ESPHelper
int espHelperStatus = myESP.loop();
manageESPHelper(espHelperStatus);
if(espHelperStatus >= FULL_CONNECTION){
//regular loop code goes here
}
delay(5);
}
//ESPHelper & config setup and runtime handler functions
void manageESPHelper(int wifiStatus){
//if the unit is broadcasting or connected to wifi then reset the timeout vars
if(wifiStatus == BROADCAST || wifiStatus >= WIFI_ONLY){
connectTimeout.reset();
timeout = false;
}
//otherwise check for a timeout condition and handle setting up broadcast
else if(wifiStatus < WIFI_ONLY){
checkForWifiTimeout();
}
//handle saving a new network config
if(configPage.handle()){
Serial.println("Saving new network config and restarting...");
myESP.saveConfigFile(configPage.getConfig(), "/netConfig.json");
delay(500);
ESP.restart();
}
}
void startWifi(){
loadConfig();
//setup other ESPHelper info and enable OTA updates
myESP.setHopping(false);
myESP.OTA_setPassword(config.otaPassword);
myESP.OTA_setHostnameWithVersion(config.hostname);
myESP.OTA_enable();
Serial.println("Connecting to network");
delay(10);
//connect to wifi before proceeding. If cannot connect then switch to ap mode and create a network to config from
while(myESP.loop() < WIFI_ONLY){
checkForWifiTimeout();
if(timeout){return;}
delay(10);
}
Serial.println("Sucess!");
Serial.println(String("To connect to this device go to " + String(myESP.getIP())));
}
//attempt to load a network configuration from the filesystem
void loadConfig(){
//check for a good config file and start ESPHelper with the file stored on the ESP
if(ESPHelperFS::begin()){
Serial.println("Filesystem loaded - Loading Config");
if(ESPHelperFS::validateConfig("/netConfig.json") == GOOD_CONFIG){
Serial.println("Config loaded");
delay(10);
myESP.begin("/netConfig.json");
}
//if no good config can be loaded (no file/corruption/etc.) then
//attempt to generate a new config and restart the module
else{
Serial.println("Could not load config - saving new config from default values and restarting");
delay(10);
ESPHelperFS::createConfig(&homeNet, "/netConfig.json");
ESPHelperFS::end();
ESP.restart();
}
}
//if the filesystem cannot be started, just fail over to the
//built in network config hardcoded in here
else{
Serial.println("Could not load filesystem, proceeding with default config values");
delay(10);
myESP.begin(&homeNet);
}
//load the netInfo from espHelper
config = myESP.getNetInfo();
}
//function that checks for no network connection for a period of time
//and starting up AP mode when that time has elapsed
void checkForWifiTimeout(){
if(connectTimeout.check() && !timeout){
Serial.println("Network Connection timeout - starting broadcast (AP) mode...");
timeout = true;
myESP.broadcastMode(broadcastSSID, broadcastPASS, broadcastIP);
myESP.OTA_setPassword(config.otaPassword);
myESP.OTA_setHostnameWithVersion(config.hostname);
myESP.OTA_enable();
}
}
================================================
FILE: examples/AdvancedFeatures/configServerDemo/configServerDemo.ino
================================================
/*
configServerDemo.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "ESPHelperFS.h"
#include "ESPHelperWebConfig.h"
netInfo config;
ESPHelper myESP;
ESPHelperWebConfig configPage(80, "/");
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS",
.otaPassword = "YOUR OTA PASS",
.hostname = "NEW-ESP8266"};
void setup(void){
loadConfig();
//setup other ESPHelper info and enable OTA updates
myESP.setHopping(false);
myESP.OTA_setPassword(config.otaPassword);
myESP.OTA_setHostnameWithVersion(config.hostname);
myESP.OTA_enable();
//startup the config page
configPage.begin(config.hostname);
}
void loop(void){
if(myESP.loop() >= FULL_CONNECTION){
//regular loop code goes here
}
//handle saving a new network config
if(configPage.handle()){
Serial.println("Saving new network config and restarting...");
myESP.saveConfigFile(configPage.getConfig(), "/netConfig.json");
delay(500);
ESP.restart();
}
delay(5);
}
//attempt to load a network configuration from the filesystem
void loadConfig(){
//check for a good config file and start ESPHelper with the file stored on the ESP
if(ESPHelperFS::begin()){
Serial.println("Filesystem loaded - Loading Config");
if(ESPHelperFS::validateConfig("/netConfig.json") == GOOD_CONFIG){
Serial.println("Config loaded");
delay(10);
myESP.begin("/netConfig.json");
}
//if no good config can be loaded (no file/corruption/etc.) then
//attempt to generate a new config and restart the module
else{
Serial.println("Could not load config - saving new config from default values and restarting");
delay(10);
ESPHelperFS::createConfig(&homeNet, "/netConfig.json");
ESPHelperFS::end();
ESP.restart();
}
}
//if the filesystem cannot be started, just fail over to the
//built in network config hardcoded in here
else{
Serial.println("Could not load filesystem, proceeding with default config values");
delay(10);
myESP.begin(&homeNet);
}
//load the netInfo from espHelper
config = myESP.getNetInfo();
}
================================================
FILE: examples/AdvancedFeatures/multiNetwork/multiNetwork.ino
================================================
/*
MultiNetwork.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
//set this info for your own network
netInfo homeNet1 = {.mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
netInfo homeNet2 = {.mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
netInfo homeNet3 = {.mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
netInfo *knownNetworks[3] = {
&homeNet1,
&homeNet2,
&homeNet3
};
ESPHelper myESP(knownNetworks, 3);
void setup() {
Serial.begin(115200); //start the serial line
delay(500);
Serial.println("Starting Up, Please Wait...");
// myESP.setHopping(false); //uncomment to prevent hopping between networks in network array
myESP.addSubscription("/test");
myESP.setMQTTCallback(callback);
myESP.begin();
Serial.println("Initialization Finished.");
}
void loop(){
myESP.loop(); //run the loop() method as often as possible - this keeps the network services running
//Put application code here
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//put mqtt callback code here
}
================================================
FILE: examples/AdvancedFeatures/secureMQTT/secureMQTT.ino
================================================
/*
secureMQTT.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "Metro.h"
#define SSID "YOUR SSID"
#define NETWORK_PASS "YOUR NETWORK PASS"
#define MQTT_HOST "MQTT_HOST"
#define MQTT_USERNAME "YOUR_MQTT_USERNAME"
#define MQTT_PASS "YOUR_MQTT_PASSWORD"
#define MQTT_PORT 1883
#define MQTT_TOPIC "/test"
//SHA1 fingerprint for the host that you want to connect to.
const char* fingerprint = "11:22:33:44:55:66:77:88:99:AA:BB:CC:EE:FF:11:22:33:44:55:66";
//Metro timer for 5 second intervals (used to time publishing to MQTT)
Metro postMetro = Metro(5000);
netInfo homeNet = { .mqttHost = MQTT_HOST,
.mqttUser = MQTT_USERNAME,
.mqttPass = MQTT_PASS,
.mqttPort = MQTT_PORT, //default port for MQTT is 1883 - only change if needed.
.ssid = SSID,
.pass = NETWORK_PASS};
ESPHelper myESP(&homeNet);
int counter = 0;
void setup() {
Serial.begin(115200);
//setup ESPHelper
myESP.useSecureClient(fingerprint);
myESP.setMQTTCallback(callback);
myESP.addSubscription(MQTT_TOPIC);
myESP.begin();
}
void loop(){
//check and make sure that we have a full connection to both WIFI and MQTT
//and only post if the timer has gone off
if(myESP.loop() == FULL_CONNECTION && postMetro.check()){
//print to the serial line
Serial.print(counter);
Serial.println(" Sent");
//generate a string from our counter variable
char pubString[10];
itoa(counter, pubString, 10);
//publish the data to MQTT
myESP.publish(MQTT_TOPIC, pubString);
//increment the counter
counter++;
}
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//generate a new payload string that is null terminated
char newPayload[40];
memcpy(newPayload, payload, length);
newPayload[length] = '\0';
//print that info back out the the serial line
Serial.print(newPayload);
Serial.println(" Received");
}
================================================
FILE: examples/GettingStarted/Adafruit_IO/Adafruit_IO.ino
================================================
/*
Adafruit_IO.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "Metro.h"
#define SSID "YOUR SSID"
#define NETWORK_PASS "YOUR NETWORK PASS"
#define AIO_USERNAME "YOUR_AIO_USERNAME"
#define AIO_KEY "YOUR_AIO_KEY"
#define AIO_FEED "AIO_FEED_NAME"
//Metro timer for 5 second intervals (used to time publishing to MQTT)
Metro postMetro = Metro(5000);
netInfo homeNet = { .mqttHost = "io.adafruit.com", //can be blank if not using MQTT
.mqttUser = AIO_USERNAME, //can be blank
.mqttPass = AIO_KEY, //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = SSID,
.pass = NETWORK_PASS};
ESPHelper myESP(&homeNet);
int counter = 0;
void setup() {
Serial.begin(115200);
//setup ESPHelper
myESP.setMQTTCallback(callback);
myESP.addSubscription(AIO_USERNAME"/feeds/"AIO_FEED);
myESP.begin();
}
void loop(){
//check and make sure that we have a full connection to both WIFI and MQTT
//and only post if the timer has gone off
if(myESP.loop() == FULL_CONNECTION && postMetro.check()){
//print to the serial line
Serial.print(counter);
Serial.println(" Sent");
//generate a string from our counter variable
char pubString[10];
itoa(counter, pubString, 10);
//publish the data to MQTT
myESP.publish(AIO_USERNAME"/feeds/"AIO_FEED, pubString);
//increment the counter
counter++;
}
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//generate a new payload string that is null terminated
char newPayload[40];
memcpy(newPayload, payload, length);
newPayload[length] = '\0';
//print that info back out the the serial line
Serial.print(newPayload);
Serial.println(" Received");
}
================================================
FILE: examples/GettingStarted/OTA/OTA.ino
================================================
/*
OTA.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
Serial.begin(115200); //start the serial line
delay(500);
Serial.println("Starting Up, Please Wait...");
myESP.OTA_enable();
myESP.OTA_setPassword("SET OTA PASSWORD");
myESP.OTA_setHostnameWithVersion("SET OTA HOSTNAME");
myESP.addSubscription("/test");
myESP.setMQTTCallback(callback);
myESP.begin();
Serial.println("Initialization Finished.");
}
void loop(){
myESP.loop(); //run the loop() method as often as possible - this keeps the network services running
//Put application code here
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//put mqtt callback code here
}
================================================
FILE: examples/GettingStarted/RelayControlV2/RelayControlV2.ino
================================================
/*
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#define TOPIC "/your/mqtt/topic"
#define STATUS TOPIC "/status" //dont change this - this is for the status topic which is whatever your mqtt topic is plus /status (ex /home/light/status)
#define NETWORK_HOSTNAME "YOUR OTA HOST NAME"
#define OTA_PASSWORD "YOUR OTA PASSWORD"
#define RELAY_PIN 3 //rx pin on esp
#define BLINK_PIN 1 //tx/led on esp-01
#define BUTTON_PIN 0
char* relayTopic = TOPIC;
char* statusTopic = STATUS;
char* hostnameStr = NETWORK_HOSTNAME;
char* otaPassword = OTA_PASSWORD;
//initialized the pins
const int buttonPin = BUTTON_PIN;
const int relayPin = RELAY_PIN;
const int blinkPin = BLINK_PIN;
//this is the current state of the relay
bool currentState = false;
//flag to mark when a rising edge has been detected
bool risingEdge = false;
//keeps track of the previous button state for edge detection
bool lastButtonState = false;
//set this info for your own network
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
//setup Arduino OTA
myESP.OTA_enable();
myESP.OTA_setPassword(otaPassword);
myESP.OTA_setHostnameWithVersion(hostnameStr);
//enable the connection heartbeat
myESP.enableHeartbeat(blinkPin);
//add a subscription to the relatTopic
myESP.addSubscription(relayTopic);
//add in the MQTT callback
myESP.setMQTTCallback(callback);
//start ESPHelper
myESP.begin();
//set the button as an input
pinMode(buttonPin, INPUT);
//set the relay pin as an output and set to off
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
}
void loop(){
if(myESP.loop() == FULL_CONNECTION){
//read the state of the button (LOW is pressed)
bool buttonState = digitalRead(buttonPin);
//if the button is pressed (LOW) and previously was not pressed(HIGH)
if(buttonState == LOW && lastButtonState == HIGH){
//debounce the signal and if the button is still pressed, mark as a rising edge
delay(50);
if(digitalRead(buttonPin) == LOW){
lastButtonState = LOW;
risingEdge = true;
}
}
//else if the button is not pressed and set lastButtonState to HIGH and reset the rising edge flag
else if(buttonState == HIGH){
lastButtonState = HIGH;
risingEdge = false;
}
//rising edge detected
if(risingEdge){
//set the state to the opposite of the current state
setState(!currentState);
//reset the rising edge flag
risingEdge = false;
}
}
yield();
}
void callback(char* topic, byte* payload, unsigned int length) {
if(payload[0] == '1'){
setState(true);
}
else{
setState(false);
}
}
//sets a new state for the relay and publishes to MQTT
void setState(bool newState){
//dont do anything unless the newState and currentState are different
if(newState != currentState){
//set the current state
currentState = newState;
//publish to the MQTT status topic
if(currentState){myESP.publish(statusTopic, "1", true);}
else{myESP.publish(statusTopic, "0", true);}
//set the relay on or off
digitalWrite(relayPin, currentState);
}
}
================================================
FILE: examples/GettingStarted/basicUse/basicUse.ino
================================================
/*
basicUse.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
Serial.begin(115200); //start the serial line
delay(500);
Serial.println("Starting Up, Please Wait...");
myESP.addSubscription("/test");
myESP.setMQTTCallback(callback);
myESP.begin();
Serial.println("Initialization Finished.");
}
void loop(){
myESP.loop(); //run the loop() method as often as possible - this keeps the network services running
//Put application code here
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//put mqtt callback code here
}
================================================
FILE: examples/GettingStarted/basicUserPass/basicUserPass.ino
================================================
/*
basicUserPass.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include "Metro.h"
#define SSID "YOUR SSID"
#define NETWORK_PASS "YOUR NETWORK PASS"
#define MQTT_HOST "MQTT_HOST"
#define MQTT_USERNAME "YOUR_MQTT_USERNAME"
#define MQTT_PASS "YOUR_MQTT_PASSWORD"
#define MQTT_PORT 1883
#define MQTT_TOPIC "/test"
//Metro timer for 5 second intervals (used to time publishing to MQTT)
Metro postMetro = Metro(5000);
netInfo homeNet = { .mqttHost = MQTT_HOST,
.mqttUser = MQTT_USERNAME,
.mqttPass = MQTT_PASS,
.mqttPort = MQTT_PORT, //default port for MQTT is 1883 - only change if needed.
.ssid = SSID,
.pass = NETWORK_PASS};
ESPHelper myESP(&homeNet);
int counter = 0;
void setup() {
Serial.begin(115200);
//setup ESPHelper
myESP.setMQTTCallback(callback);
myESP.addSubscription(MQTT_TOPIC);
myESP.begin();
}
void loop(){
//check and make sure that we have a full connection to both WIFI and MQTT
//and only post if the timer has gone off
if(myESP.loop() == FULL_CONNECTION && postMetro.check()){
//print to the serial line
Serial.print(counter);
Serial.println(" Sent");
//generate a string from our counter variable
char pubString[10];
itoa(counter, pubString, 10);
//publish the data to MQTT
myESP.publish(MQTT_TOPIC, pubString);
//increment the counter
counter++;
}
yield();
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
//generate a new payload string that is null terminated
char newPayload[40];
memcpy(newPayload, payload, length);
newPayload[length] = '\0';
//print that info back out the the serial line
Serial.print(newPayload);
Serial.println(" Received");
}
================================================
FILE: examples/GettingStarted/buttonDemo/buttonDemo.ino
================================================
/*
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This is a simple demo of an MQTT enabled button. A button is attahed
to pin 0 with a pull-up resistor and each time the button is pressed,
it toggles the state and publishes the new state to the MQTT broker.
It is also subscribed to the same topic that it publishes to so that
the state of the toggle can be updated from the MQTT side.
*/
#include "ESPHelper.h"
#define TOPIC "/your/mqtt/topic"
#define NETWORK_HOSTNAME "YOUR OTA HOSTNAME"
#define OTA_PASSWORD "YOUR OTA PASSWORD"
#define BUTTON_PIN 0 //button on pin 0 with pull up resistor (pulled low on press)
#define BLINK_PIN 1
char* buttonTopic = TOPIC;
char* hostnameStr = NETWORK_HOSTNAME;
const int buttonPin = BUTTON_PIN;
const int blinkPin = BLINK_PIN;
bool currentState = false;
bool lastButtonState = false;
//set this info for your own network
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
//setup ota on esphelper
myESP.OTA_enable();
myESP.OTA_setPassword(OTA_PASSWORD);
myESP.OTA_setHostnameWithVersion(hostnameStr);
//enable the connection heartbeat
myESP.enableHeartbeat(blinkPin);
//subscribe to the button topic (this allows outside control of the state of the switch)
myESP.addSubscription(buttonTopic);
//setup the mqtt callback function
myESP.setMQTTCallback(callback);
//start ESPHelper
myESP.begin();
//set the button pin as an input
pinMode(buttonPin, INPUT);
}
void loop(){
if(myESP.loop() == FULL_CONNECTION){
//read the button (low on press, high on release)
bool buttonState = digitalRead(buttonPin);
//if the button is pressed (LOW) and previously was not pressed(HIGH)
if(buttonState == LOW && lastButtonState == HIGH){
//invert the current state
currentState = !currentState;
//publish to mqtt based on current state
if(currentState){
myESP.publish(buttonTopic, "1", true);
}
else{
myESP.publish(buttonTopic, "0", true);
}
//set the lastButtonState to LOW to prevent multiple triggers
lastButtonState = LOW;
//wait half a second (poor mans debounce)
delay(500);
}
//else if the button is not pressed and set lastButtonState to HIGH
else if(buttonState == HIGH){lastButtonState = HIGH;}
}
yield();
}
void callback(char* topic, byte* payload, unsigned int length) {
//if the payload is '1' then set the state to true
if(payload[0] == '1'){
currentState = true;
}
//otherwise set the current state to false
else{
currentState = false;
}
}
================================================
FILE: examples/GettingStarted/relayControl/relayControl.ino
================================================
/*
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of RelayControl
RelayControl 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.
RelayControl 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 RelayControl. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This is a simple MQTT relay/light controller program for the ESP8266.
By sending a '1' or '0' to the relayTopic the relayPin can be toggled
on or off. This program also posts a status update to the status topic
which is the relayTopic plus "/status" (ex. if the relayTopic
is "/home/light" then the statusTopic would be "home/light/status")
*/
#include "ESPHelper.h"
#define TOPIC "/your/mqtt/topic"
#define STATUS TOPIC "/status" //dont change this - this is for the status topic which is whatever your mqtt topic is plus /status (ex /home/light/status)
#define NETWORK_HOSTNAME "YOUR OTA HOST NAME"
#define OTA_PASSWORD "YOUR OTA PASSWORD"
#define RELAY_PIN 3 //rx pin on esp
#define BLINK_PIN 1 //tx/led on esp-01
char* relayTopic = TOPIC;
char* statusTopic = STATUS;
char* hostnameStr = NETWORK_HOSTNAME;
const int relayPin = RELAY_PIN;
const int blinkPin = BLINK_PIN; //tx pin on esp
//set this info for your own network
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
//setup ota
myESP.OTA_enable();
myESP.OTA_setPassword(OTA_PASSWORD);
myESP.OTA_setHostnameWithVersion(hostnameStr);
//setup the rest of ESPHelper
myESP.enableHeartbeat(blinkPin); //comment out to disable the heartbeat
myESP.addSubscription(relayTopic); //add the relay topic to the subscription list
myESP.setMQTTCallback(callback);
myESP.begin();
pinMode(relayPin, OUTPUT);
delay(100);
}
void loop(){
//loop ESPHelper and wait for commands from mqtt
myESP.loop();
yield();
}
//mqtt callback
void callback(char* topic, byte* payload, unsigned int length) {
String topicStr = topic;
//if the payload from mqtt was 1, turn the relay on and update the status topic with 1
if(payload[0] == '1'){
digitalWrite(relayPin, HIGH);
myESP.publish(statusTopic, "1",true);
}
//else turn the relay off and update the status topic with 0
else if (payload[0] == '0'){
digitalWrite(relayPin, LOW);
myESP.publish(statusTopic, "0", true);
}
}
================================================
FILE: examples/GettingStarted/wifiCallback/wifiCallback.ino
================================================
/*
wifiCallback.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
Serial.begin(115200); //start the serial line
delay(500);
Serial.println("Starting Up, Please Wait...");
myESP.addSubscription("/test");
myESP.setWifiCallback(wifiCallback);
myESP.setMQTTCallback(MQTTcallback);
myESP.begin();
Serial.println("Initialization Finished.");
}
void loop(){
myESP.loop(); //run the loop() method as often as possible - this keeps the network services running
//Put application code here
yield();
}
void MQTTcallback(char* topic, uint8_t* payload, unsigned int length) {
//put mqtt callback code here
}
void wifiCallback(){
Serial.println("WiFi Connected!");
}
================================================
FILE: examples/InputOutput/RGBLight/RGBLight.ino
================================================
/*
wifiRGB.ino
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of wifiRGB
wifiRGB 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.
wifiRGB 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 wifiRGB. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This is an MQTT RGB light controller program for the ESP8266.
The light can be controlled in one of three ways. You can send
an HSB update, RGB update, or moodlight mode on/off.
All updates must be formatted correctly, see below:
ex RGB string: "r255,050,000" (r = 255, g = 050, b = 000)
ex HSB string: "h1.00,0.50,0.01" (h = 1.00, s = 0.50, b = 0.01)
ex moodlight string: "m1" (moodlight activate)
This program also posts a status update to the status topic
which is the lightTopic plus "/status" (ex. if the lightTopic
is "/home/RGBlight" then the statusTopic would be "home/RGBlight/status")
*/
#include "ESPHelper.h"
#include <HSBColor.h>
#include "Metro.h"
#define TOPIC "/your/mqtt/topic"
#define STATUS TOPIC "/status"
#define NETWORK_HOSTNAME "YOUR OTA HOSTNAME"
#define OTA_PASSWORD "YOUR OTA PASSWORD"
#define RED_PIN 12
#define GREEN_PIN 13
#define BLUE_PIN 14
typedef struct lightState{
double hue;
double saturation;
double brightness;
int red;
int redRate;
int green;
int greenRate;
int blue;
int blueRate;
int fadePeriod;
int updateType;
};
typedef struct timer {
unsigned long previousTime;
int interval;
};
enum superModes {SET, MOOD};
enum moodColors{RED, GREEN, BLUE};
enum modes {NORMAL, FADING};
enum updateTypes{HSB, RGB, POWER};
lightState nextState;
int superMode = SET; //overall mode of the light (moodlight, network controlled, etc)
boolean newCommand = false;
char* lightTopic = TOPIC;
char* statusTopic = STATUS;
char* hostnameStr = NETWORK_HOSTNAME;
const int redPin = RED_PIN;
const int greenPin = GREEN_PIN;
const int bluePin = BLUE_PIN;
char statusString[50]; //string containing the current setting for the light
//set this info for your own network
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
//initialize the light as an output and set to LOW (off)
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
//all off
digitalWrite(redPin, LOW); //all off
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1000);
colorTest();
//setup ota on esphelper
myESP.OTA_enable();
myESP.OTA_setPassword(OTA_PASSWORD);
myESP.OTA_setHostnameWithVersion(hostnameStr);
//subscribe to the lighttopic
myESP.setMQTTCallback(callback);
myESP.addSubscription(lightTopic);
myESP.begin();
}
void loop(){
static bool connected = false; //keeps track of connection state to reset from MOOD to SET when network connection is made
if(myESP.loop() == FULL_CONNECTION){
//if the light was previously not connected to wifi and mqtt, update the status topic with the light being off
if(!connected){
connected = true; //we have reconnected so now we dont need to flag the setting anymore
myESP.publish(statusTopic, "h0.00,0.00,0.00 ", true);
}
lightHandler();
}
yield();
}
void lightHandler(){
//new and current lightStates
static lightState newState;
static lightState currentState;
static int currentMoodColor = 0; //the current moodlight chosen color
static int isFading = 0;
//if the super mode is mood light and the light isnt currently fading,
//then change to a new color and start a new fade
if(superMode == MOOD && isFading == 0){
if(currentMoodColor == RED){
nextState.red = 0;
nextState.green = 1023;
nextState.blue = 0;
nextState.updateType = RGB;
newCommand = true;
currentMoodColor = GREEN;
}
else if(currentMoodColor == GREEN){
nextState.red = 0;
nextState.green = 0;
nextState.blue = 1023;
nextState.updateType = RGB;
newCommand = true;
currentMoodColor = BLUE;
}
else if(currentMoodColor == BLUE){
nextState.red = 1023;
nextState.green = 0;
nextState.blue = 0;
nextState.updateType = RGB;
newCommand = true;
currentMoodColor = RED;
}
}
lightUpdater(&newState, currentState);
isFading = lightChanger(newState, ¤tState);
}
//this function actually changes the light values and does the fading
//returns 1 if fading
//returns 0 if not fading
//returns -1 if the timer doesnt get triggered
int lightChanger(lightState newState, lightState *currentState){
static Metro changeTimer = Metro(1);
static int changeMode = NORMAL; //the current mode (fading or normal)
static int currentPeriod = 0; //time since starting the fade
//only allow fade updates every 1ms
if(changeTimer.check()){
//check to see if this is there is a new command and set the mode to FADING
if(newCommand){
newCommand = false;
changeMode = FADING;
}
if(changeMode == FADING){
//check whether or not a fade is needed - if so update the channel velues
if((newState.red != currentState->red || newState.blue != currentState->blue || newState.green != currentState->green) || (currentPeriod <= currentState->fadePeriod)){
if(currentPeriod % newState.redRate == 0){
if(newState.red > currentState->red){currentState->red++;}
else if (newState.red < currentState->red){currentState->red--;}
}
if(currentPeriod % newState.greenRate == 0){
if(newState.green > currentState->green){currentState->green++;}
else if (newState.green < currentState->green){currentState->green--;}
}
if(currentPeriod % newState.blueRate == 0){
if(newState.blue > currentState->blue){currentState->blue++;}
else if (newState.blue < currentState->blue){currentState->blue--;}
}
//write to the analog pins
analogWrite(redPin, currentState->red);
analogWrite(greenPin, currentState->green);
analogWrite(bluePin, currentState->blue);
//increment the period
currentPeriod++;
return 1; //return 1 on mode being FADING
}
//if no fade is needed then reset the period and set the mode to NORMAL
else{
currentPeriod = 0;
changeMode = NORMAL;
return 0; //return 0 on mode being NORMAL
}
}
else if (changeMode == NORMAL){
return 0; //return 0 on mode being NORMAL
}
}
return -1; //return -1 on timer not set off
}
//calculates new information (color values, fade times, etc) for
//new color updates
void lightUpdater (lightState *newState, lightState currentState){
//calculate new vars only if there is a new command
if (newCommand){
//determine which kind of update this is
if(nextState.updateType == HSB){
//convert from HSB to RGB
int newRGB[3];
H2R_HSBtoRGBfloat(nextState.hue, nextState.saturation, nextState.brightness, newRGB);
newState->red = newRGB[0];
newState->green = newRGB[1];
newState->blue = newRGB[2];
//determine the RGB difference from the current values to new values (how far each channel needs to fade)
int redDiff = abs(newState->red - currentState.red);
int greenDiff = abs(newState->green - currentState.green);
int blueDiff = abs(newState->blue - currentState.blue);
//calculate the new fade times for each channel (how long to wait between fading up/down)
if(redDiff > 0){newState->redRate = (nextState.fadePeriod / redDiff);}
else{newState->redRate = nextState.fadePeriod;}
if(greenDiff > 0){newState->greenRate = (nextState.fadePeriod / greenDiff);}
else{newState->greenRate = nextState.fadePeriod;}
if(blueDiff > 0){newState->blueRate = (nextState.fadePeriod / blueDiff);}
else{newState->blueRate = nextState.fadePeriod;}
//set the total time to fade
newState->fadePeriod = nextState.fadePeriod;
}
else if(nextState.updateType == RGB){
//set new RGB values from update
newState->red = nextState.red;
newState->green = nextState.green;
newState->blue = nextState.blue;
//determine the RGB difference from the current values to new values (how far each channel needs to fade)
int redDiff = abs(newState->red - currentState.red);
int greenDiff = abs(newState->green - currentState.green);
int blueDiff = abs(newState->blue - currentState.blue);
//calculate the new fade times for each channel (how long to wait between fading up/down)
if(redDiff > 0){newState->redRate = (nextState.fadePeriod / redDiff) + 1;}
else{newState->redRate = nextState.fadePeriod;}
if(greenDiff > 0){newState->greenRate = (nextState.fadePeriod / greenDiff) + 1;}
else{newState->greenRate = nextState.fadePeriod;}
if(blueDiff > 0){newState->blueRate = (nextState.fadePeriod / blueDiff) + 1;}
else{newState->blueRate = nextState.fadePeriod;}
//set the total time to fade
newState->fadePeriod = nextState.fadePeriod;
}
}
}
//MQTT callback
void callback(char* topic, byte* payload, unsigned int length) {
//convert topic to string to make it easier to work with
String topicStr = topic;
char newPayload[40];
memcpy(newPayload, payload, length);
newPayload[length] = '\0';
//handle HSB updates
if(payload[0] == 'h'){
nextState.hue = atof(&newPayload[1]);
nextState.saturation = atof(&newPayload[7]);
nextState.brightness = atof(&newPayload[13]);
nextState.updateType = HSB;
nextState.fadePeriod = 2100;
newCommand = true;
superMode = SET;
}
//handle RGB updates
else if (payload[0] == 'r'){
int newRed = atoi(&newPayload[1]);
int newGreen = atoi(&newPayload[5]);
int newBlue = atoi(&newPayload[9]);
nextState.red = newRed;
nextState.green = newGreen;
nextState.blue = newBlue;
nextState.updateType = RGB;
newCommand = true;
nextState.fadePeriod = 2100;
superMode = SET;
}
//handle moodlight updates
else if(payload[0] == 'm'){
if(payload[1] == '1'){
superMode = MOOD;
nextState.fadePeriod = 10000;
newCommand = true;
}
else if(payload[1] == '0'){
superMode = SET;
nextState.fadePeriod = 2100;
newCommand = true;
}
}
//package up status message reply and send it back out to the status topic
strcpy(statusString, newPayload);
myESP.publish(statusTopic, statusString, true);
}
void colorTest(){
digitalWrite(redPin, HIGH); //red on
delay(500);
digitalWrite(redPin, LOW); //green on
digitalWrite(greenPin, HIGH);
delay(500);
digitalWrite(greenPin, LOW); //blue on
digitalWrite(bluePin, HIGH);
delay(500);
digitalWrite(redPin, HIGH); //all on
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(500);
digitalWrite(redPin, LOW); //all off
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
char *ftoa(char *a, double f, int precision)
{
long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
long heiltal = (long)f;
itoa(heiltal, a, 10);
while (*a != '\0') a++;
*a++ = '.';
long desimal = abs((long)((f - heiltal) * p[precision]));
itoa(desimal, a, 10);
return ret;
}
float map_double(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
================================================
FILE: examples/InputOutput/temperatureSensor_ds18b20/temperatureSensor_ds18b20.ino
================================================
/*
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This is a simple program that periodically (10 seconds) reads a ds18b20 temperature
sensor and publishes the result to an MQTT topic. Change the Topic/Hostname/OTA Password
and network settings to match your system.
*/
#include "ESPHelper.h"
#include <Metro.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TEMP_TOPIC "/your/mqtt/topic"
#define NETWORK_HOSTNAME "YOUR OTA HOSTNAME"
#define OTA_PASSWORD "YOUR OTA PASSWORD"
#define ONE_WIRE_BUS 2
#define BLINK_PIN 1
char* tempTopic = TEMP_TOPIC;
char* hostnameStr = NETWORK_HOSTNAME;
const int wireBus = ONE_WIRE_BUS;
const int blinkPin = BLINK_PIN;
//the current temperature
float currentTemp = 0;
//timer to set how often the sensor should publish to mqtt (in ms)
Metro publishTimer = Metro(10000);
//ds18b20 variables
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//set this info for your own network
netInfo homeNet = { .mqttHost = "YOUR MQTT-IP", //can be blank if not using MQTT
.mqttUser = "YOUR MQTT USERNAME", //can be blank
.mqttPass = "YOUR MQTT PASSWORD", //can be blank
.mqttPort = 1883, //default port for MQTT is 1883 - only chance if needed.
.ssid = "YOUR SSID",
.pass = "YOUR NETWORK PASS"};
ESPHelper myESP(&homeNet);
void setup() {
//setup ota on esphelper
myESP.OTA_enable();
myESP.OTA_setPassword(OTA_PASSWORD);
myESP.OTA_setHostnameWithVersion(hostnameStr);
//enable the connection heartbeat
myESP.enableHeartbeat(blinkPin);
//start ESPHelper
myESP.begin();
//start the dallas temperature sensor library
sensors.begin();
delay(500);
}
void loop(){
while(1){
if(myESP.loop() == FULL_CONNECTION){
//only read/publish the temperature if the timer is up
if(publishTimer.check()){
sensors.requestTemperatures(); // Send the command to get temperatures
currentTemp = sensors.getTempCByIndex(0); //get the temperature
//convert the float to a string
char temperature[10];
dtostrf(currentTemp,4,1,temperature);
//publish to mqtt
myESP.publish(tempTopic,temperature, true);
}
}
yield();
}
}
void callback(char* topic, uint8_t* payload, unsigned int length) {
}
================================================
FILE: keywords.txt
================================================
#######################################
# Syntax Coloring Map For ESPHelper
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
ESPHelper KEYWORD1
ESPHelperFS KEYWORD1
ESPHelperWebConfig KEYWORD1
netInfo KEYWORD1
subscription KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
useSecureClient KEYWORD2
broadcastMode KEYWORD2
disableBroadcast KEYWORD2
loop KEYWORD2
subscribe KEYWORD2
addSubscription KEYWORD2
removeSubscription KEYWORD2
unsubscribe KEYWORD2
publish KEYWORD2
setCallback KEYWORD2
setMQTTCallback KEYWORD2
setWifiCallback KEYWORD2
reconnect KEYWORD2
updateNetwork KEYWORD2
getSSID KEYWORD2
serSSID KEYWORD2
getPASS KEYWORD2
setPass KEYWORD2
getMQTTIP KEYWORD2
setMQTTIP KEYWORD2
getMQTTQOS KEYWORD2
setMQTTQOS KEYWORD2
setWill KEYWORD2
getIP KEYWORD2
getIPAddress KEYWORD2
getNetInfo KEYWORD2
setNetInfo KEYWORD2
setHopping KEYWORD2
listSubscriptions KEYWORD2
heartbeat KEYWORD2
enableHeartbeat KEYWORD2
disableHeartbeat KEYWORD2
OTA_enable KEYWORD2
OTA_disable KEYWORD2
OTA_begin KEYWORD2
OTA_setPassword KEYWORD2
OTA_setHostname KEYWORD2
OTA_setHostnameWithVersion KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
MAX_SUBSCRIPTIONS LITERAL1
DEFAULT_QOS LITERAL1
VERSION LITERAL1
================================================
FILE: library.json
================================================
{
"name": "ESPHelper",
"authors":
{
"name": "ItKindaWorks",
"email": "itkindaworksinc@gmail.com",
"url": "http://itkindaworks.com"
},
"repository":
{
"type": "git",
"url": "https://github.com/ItKindaWorks/ESPHelper"
},
"license": "GPL-3.0-or-later",
"keywords": "mqtt, iot, esp8266, esp32, ota",
"description": "A library to make using WiFi & MQTT on the ESP8266 & ESP32 easy.",
"version": "2.0.4",
"examples": "examples/*/*.ino",
"frameworks": "arduino",
"platforms": [
"espressif",
"espressif32"
],
"dependencies": {
"bblanchon/ArduinoJson": "@^7.0.4",
"itkindaworks/Metro": "@^1.0.1",
"knolleary/PubSubClient": "@2.8",
"powerbroker2/SafeString": "@^4.1.30",
"esp32async/ESPAsyncWebServer": "@ ^3.6.0"
}
}
================================================
FILE: src/ESPHelper.cpp
================================================
/*
ESPHelper.cpp
Copyright (c) 2019 ItKindaWorks Inc All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelper.h"
#include <WiFiClientSecure.h>
void printNetInfo(const NetInfo *net, const char* header, bool printMQTT, bool printWill){
debugPrintln(header);
debugPrint("Hostname: ");
debugPrintln(net->getHostname());
debugPrint("SSID: ");
debugPrintln(net->getSsid());
debugPrint("PASS: ");
debugPrintln(net->getPass());
if (printMQTT) {
debugPrint("MQTT Host: ");
debugPrintln(net->getMqttHost());
debugPrint("MQTT User: ");
debugPrintln(net->getMqttUser());
debugPrint("MQTT Pass: ");
debugPrintln(net->getMqttPass());
debugPrint("MQTT Port: ");
debugPrintln(net->getMqttPort());
}
if (printWill) {
debugPrint("Will Topic: ");
debugPrintln(net->getMqttWillTopic());
debugPrint("Will Message: ");
debugPrintln(net->getMqttWillMessage());
debugPrint("Will QoS: ");
debugPrintln(net->getMqttWillQoS());
debugPrint("Will Retain: ");
debugPrintln(net->getMqttWillRetain() ? "true" : "false");
}
}
/*
empty initializer wrapper
used for creating instances of ESPHelper that will be filled in later from a loaded config file
input: NA
output: NA
*/
ESPHelper::ESPHelper(){
_currentNet.setSsid("");
_currentNet.setPass("");
_currentNet.setMqttHost("");
_currentNet.setMqttUser("");
_currentNet.setMqttPass("");
_currentNet.setMqttPort(1883);
_currentNet.setMqttWillTopic("defaultWillTopic");
_currentNet.setMqttWillMessage("offline");
_currentNet.setMqttWillQoS (0);
_currentNet.setMqttWillRetain(true);
init();
}
/*
initializer wrapper with single NetInfo network
input: NetInfo ptr
output: NA
*/
ESPHelper::ESPHelper(const NetInfo *startingNet, bool storeLocal){
if (startingNet) {
startingNet->cloneTo(_currentNet, storeLocal);
}
//if the starting net is null then we set the default values and store locally
else {
_currentNet.setSsid("");
_currentNet.setPass("");
_currentNet.setMqttHost("");
_currentNet.setMqttUser("");
_currentNet.setMqttPass("");
_currentNet.setMqttPort(1883);
_currentNet.setMqttWillTopic("defaultWillTopic");
_currentNet.setMqttWillMessage("offline");
_currentNet.setMqttWillQoS (0);
_currentNet.setMqttWillRetain(true);
}
init();
}
/*
initialize the NetInfo data and reset wifi. set hopping and OTA to off
input:
char ptr for network SSID
char ptr for network Password
char ptr for MQTT broker IP (or hostname)
char ptr for MQTT username
char ptr for MQTT password
int for MQTT port
char ptr for MQTT last will topic
char ptr for MQTT last will message
int for MQTT will QOS
int for MQTT will retain
output: NA
*/
void ESPHelper::init(){
//diconnect from and previous wifi networks
WiFi.softAPdisconnect();
WiFi.disconnect();
//validate various bits of network/MQTT info
validateConfig();
}
/*
checks which parts of a NetInfo have been filled out
and updates internal flags noting which are set
input: NA
output: NA
*/
void ESPHelper::validateConfig(){
//network pass
if(_currentNet.getPass()[0] == '\0'){_passSet = false;}
else{_passSet = true;}
//ssid
if(_currentNet.getSsid()[0] == '\0'){_ssidSet = false;}
else{_ssidSet = true;}
//mqtt host
if(_currentNet.getMqttHost()[0] == '\0'){_mqttSet = false;}
else{_mqttSet = true;}
//mqtt port
if(_currentNet.getMqttPort() == 0){_currentNet.setMqttPort(1883);}
//mqtt username
if(_currentNet.getMqttUser()[0] == '\0'){_mqttUserSet = false;}
else{_mqttUserSet = true;}
//mqtt password
if(_currentNet.getMqttPass()[0] == '\0'){_mqttPassSet = false;}
else{_mqttPassSet = true;}
//Will Topic
if(_currentNet.getMqttWillTopic()[0] == '\0'){_willTopicSet = false;}
else{_willTopicSet = true;}
//Will Message
if(_currentNet.getMqttWillMessage()[0] == '\0'){_willMessageSet = false;}
else{_willMessageSet = true;}
}
bool ESPHelper::begin(const NetInfo *startingNet, bool storeLocal){
// If a starting net is provided
if (startingNet) {
startingNet->cloneTo(_currentNet, storeLocal);
}
//if the starting net is null then we set the default values and store locally
else {
_currentNet.setSsid("");
_currentNet.setPass("");
_currentNet.setMqttHost("");
_currentNet.setMqttUser("");
_currentNet.setMqttPass("");
_currentNet.setMqttPort(1883);
_currentNet.setMqttWillTopic("defaultWillTopic");
_currentNet.setMqttWillMessage("offline");
_currentNet.setMqttWillQoS (0);
_currentNet.setMqttWillRetain(true);
}
init();
return begin();
}
/*
start the wifi & mqtt systems and attempt connection (currently blocking)
return values from this function are somewhat legacy as data validation takes place elsewhere now
input: NA
output:
true on: ssid set
false on: ssid not set
*/
bool ESPHelper::begin(){
// Generate client name based on MAC address and last 8 bits of microsecond counter
#ifdef ESP8266
_clientName = "esp8266-";
#else
_clientName = "esp32-";
#endif
uint8_t mac[6];
WiFi.macAddress(mac);
_clientName += macToStr(mac);
//set the wifi mode to station
WiFi.mode(WIFI_STA);
//as long as the SSID has been set, then try to connect to the network
if(_ssidSet){
// printNetInfo(&_currentNet, "Pre wifi begin", _mqttSet, _willTopicSet);
if(_passSet){WiFi.begin(_currentNet.getSsid(), _currentNet.getPass());}
else{WiFi.begin(_currentNet.getSsid());}
WiFi.setAutoReconnect(true);
WiFi.setSleep(false);
//as long as an mqtt ip has been set create an instance of PubSub for client
if(_mqttSet){
client.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());
//set the mqtt message callback if needed
if(_mqttCallbackSet){client.setCallback(_mqttCallback);}
}
//define a dummy instance of mqtt so that it is instantiated if no mqtt ip is set
else{
client.setServer("192.0.2.0", _currentNet.getMqttPort());
}
//set the mqtt client to use the secure client if available
if(_useSecureClient){client.setClient(wifiClientSecure);}
else{client.setClient(wifiClient);}
//ota event handlers
ArduinoOTA.onStart([]() {/* ota start code */});
ArduinoOTA.onEnd([]() {
//give the arduino a bit of time to finish up any remaining network activity
delay(500);
//on ota end we disconnect from wifi cleanly before restarting.
WiFi.softAPdisconnect();
WiFi.disconnect();
int timeout = 0;
//max timeout of 2seconds before just dropping out and restarting
while(WiFi.status() != WL_DISCONNECTED && timeout < 200){
delay(10);
timeout++;
}
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {/* ota progress code */});
ArduinoOTA.onError([](ota_error_t error) {/* ota error code */});
//initially attempt to connect to wifi when we begin (but only block for 2 seconds before timing out)
int timeout = 0; //counter for begin connection attempts
while (((!client.connected() && _mqttSet) || WiFi.status() != WL_CONNECTED) && timeout < 200 ) { //max 2 sec before timeout
// printNetInfo(&_currentNet, "ESPHelper Begin reconnect loop", _mqttSet, _willTopicSet);
reconnect();
delay(10);
timeout++;
}
//attempt to start ota if needed
OTA_begin();
//mark the system as started and return
_hasBegun = true;
return true;
}
//if no ssid was set even then dont try to begin and return false
return false;
}
/*
end the instance of ESPHelper (shutdown wifi, ota, mqtt)
input: NA
output: NA
*/
void ESPHelper::end(){
OTA_disable();
client.disconnect();
delay(20);
WiFi.softAPdisconnect();
WiFi.disconnect();
int timeout = 0;
while(WiFi.status() != WL_DISCONNECTED && timeout < 200){
delay(10);
timeout++;
}
_connectionStatus = NO_CONNECTION;
}
/*
enables the use of a secure (SSL) connection to an MQTT broker.
(Make sure your mqtt port is set to one expecting a secure connection)
input: char ptr string for SSL fingerprint
output: NA
*/
void ESPHelper::useSecureClient(const char* fingerprint){
_fingerprint = fingerprint;
//fall back to wifi only connection if it was previously at full connection
//(because we just changed how the device is going to connect to the mqtt broker)
if(setConnectionStatus() == FULL_CONNECTION){
_connectionStatus = WIFI_ONLY;
}
//if use of secure connection is set retroactivly (after begin), then disconnect and set the new client
if(_hasBegun){
client.disconnect();
client.setClient(wifiClientSecure);
}
//flag use of secure client
_useSecureClient = true;
}
/*
enables and sets up broadcast mode rather than station mode. This allows users to create a network from the ESP
and upload using OTA even if there is no network already present. This disables all MQTT connections
input:
char ptr for SSID to broadcast
char ptr for network password
IPAddress instance for the ESP IP
output: NA
*/
void ESPHelper::broadcastMode(const char* ssid, const char* password, const IPAddress ip){
//disconnect from any previous wifi networks (max timeout of 2 seconds)
WiFi.softAPdisconnect();
WiFi.disconnect();
int timeout = 0;
while(WiFi.status() != WL_DISCONNECTED && timeout < 200){
delay(10);
timeout++;
}
//set the mode for access point
WiFi.mode(WIFI_AP);
//config the AP
WiFi.softAPConfig(ip, ip, IPAddress(255, 255, 255, 0));
//set the ssid and password
WiFi.softAP(ssid, password);
//run the wifi lost callback if we were previously connected to a network
if(_wifiLostCallbackSet && _connectionStatus >= WIFI_ONLY){
_wifiLostCallback();
}
//update the connection status
_connectionStatus = BROADCAST;
_broadcastIP = ip;
strcpy(_broadcastSSID, ssid);
strcpy(_broadcastPASS, password);
}
/*
disable broadcast mode and reset to station mode
(causes a call to begin - may want to change this in the future...)
input: NA
output: NA
*/
void ESPHelper::disableBroadcast(){
//disconnect from any previous wifi networks (max timeout of 2 seconds)
WiFi.softAPdisconnect();
WiFi.disconnect();
int timeout = 0;
while(WiFi.status() != WL_DISCONNECTED && timeout < 200){
delay(10);
timeout++;
}
_connectionStatus = NO_CONNECTION;
begin();
}
/*
main loop - should be called as often as possible - handles wifi/mqtt connection and mqtt handler
input: NA
output:
true on: network/server connected
false on: network or server disconnected
*/
int ESPHelper::loop(){
if(_ssidSet){
//check for good connections and attempt a reconnect if needed
if (((_mqttSet && !client.connected()) || setConnectionStatus() < WIFI_ONLY) && _connectionStatus != BROADCAST) {
reconnect();
}
//run the wifi loop as long as the connection status is at a minimum of BROADCAST
if(_connectionStatus >= BROADCAST){
//run the MQTT loop if we have a full connection
if(_connectionStatus == FULL_CONNECTION){client.loop();}
//check for whether we want to use OTA and whether the system is running
if(_useOTA && _OTArunning) {ArduinoOTA.handle();}
//if we want to use OTA but its not running yet, start it up.
else if(_useOTA && !_OTArunning){
OTA_begin();
ArduinoOTA.handle();
}
return _connectionStatus;
}
yield();
}
//return -1 for no connection because of bad network info
return -1;
}
/*
subscribe to a speicifc topic (does not add to topic list)
input:
char ptr to a topic to subscribe to
int for QOS of the subscription
output:
true on: subscription success
false on: subscription failed (either from PubSub lib or network is disconnected)
*/
bool ESPHelper::subscribe(const char* topic, int qos){
if(_connectionStatus == FULL_CONNECTION){
//set the return value to the output of subscribe
bool returnVal = client.subscribe(topic, qos);
//Serial.printf("Subscribe to: %s - %s\n", topic, returnVal == true ? "Success" : "Failure");
//loop mqtt client
client.loop();
return returnVal;
}
//if not fully connected return false
else{return false;}
}
/*
add a topic to the list of subscriptions and attempt to subscribe to the topic on the spot
input:
char ptr for a topic to subscibe to
output:
true on: subscription added to list (does not guarantee that the topic was subscribed to, only that it was added to the list)
false on: subscription not added to list
*/
bool ESPHelper::addSubscription(const char* topic){
//default return value is false
bool subscribed = false;
//loop throough finding the next available slot for a subscription and add it
for(int i = 0; i < MAX_SUBSCRIPTIONS; i++){
if(_subscriptions[i].isUsed == false){
_subscriptions[i].topic = topic;
_subscriptions[i].isUsed = true;
subscribed = true;
break;
}
}
//if added to the list, subscibe to the topic
if(subscribed){subscribe(topic, _qos);}
return subscribed;
}
/*
loops through list of subscriptions and attempts to subscribe to all topics
input: NA
output: NA
*/
void ESPHelper::resubscribe(){
debugPrintln("Resubscribing to all topics");
for(int i = 0; i < MAX_SUBSCRIPTIONS; i++){
if(_subscriptions[i].isUsed){
debugPrint("Topic: "); debugPrintln(_subscriptions[i].topic);
subscribe(_subscriptions[i].topic, _qos);
yield();
}
}
}
/*
attempts to remove a topic from the topic list
input:
char ptr to a topic to subscribe to
output:
true on: subscription removed from list (does not guarantee that the topic was unsubscribed from, only that it was removed from the list)
false on: topic was not found in list and therefore cannot be removed
*/
bool ESPHelper::removeSubscription(const char* topic){
bool returnVal = false;
createSafeString(topicStr, MAX_TOPIC_LENGTH);
//loop through all subscriptions
for(int i = 0; i < MAX_SUBSCRIPTIONS; i++){
//if an element is used, check for it being the one we want to remove
if(_subscriptions[i].isUsed){
createSafeString(subStr, MAX_TOPIC_LENGTH);
subStr = _subscriptions[i].topic;
if(subStr.equals(topicStr)){
//reset the used flag to false
_subscriptions[i].isUsed = false;
//unsubscribe
client.unsubscribe(_subscriptions[i].topic);
returnVal = true;
break;
}
}
}
return returnVal;
}
/*
manually unsubscribes from a topic (This is basically just a wrapper for the pubsubclient function)
input:
char ptr to topic to unsubscribe from
output
true on: sucessful unsubscription
false on: could not unsubscribe (generally b/c it was not subscribed anyways)
*/
bool ESPHelper::unsubscribe(const char* topic){
return client.unsubscribe(topic);
}
/*
publish to a specified topic
input:
char ptr to topic to publish to
char ptr to the payload to be published
output: NA
*/
void ESPHelper::publish(const char* topic, const char* payload){
publish(topic, payload, false);
}
/*
publish to a specified topic with a given retain level
input:
char ptr to topic to publish to
char ptr to the payload to be published
bool whether the MQTT broker should retain the message
output: NA
*/
void ESPHelper::publish(const char* topic, const char* payload, bool retain){
client.publish(topic, payload, retain);
}
bool ESPHelper::publishJson(const char* topic, JsonDocument& doc, bool retain){
const size_t MAX_CHUNK_SIZE = 128; // Define a suitable chunk size
//figure out the correct size
size_t dataSize = measureJsonPretty(doc);
if(dataSize < 1023){
//create & fill
uint8_t* buf = new uint8_t[dataSize+1];
if (!buf) {
return false; // Handle memory allocation failure
}
size_t payloadLength = serializeJsonPretty(doc, buf, dataSize+1);
if (payloadLength == 0) {
delete[] buf;
return false; // Handle serialization failure
}
size_t bytesSent = 0;
// Start publishing
if (!client.beginPublish(topic, dataSize, retain)) {
delete[] buf;
return false;
}
while (bytesSent < payloadLength) {
size_t chunkSize = min(payloadLength - bytesSent, MAX_CHUNK_SIZE);
size_t result = client.write((const uint8_t*)(buf + bytesSent), chunkSize);
if (result != chunkSize) {
delete[] buf;
client.endPublish(); // Ensure to end publish on error
return false; // Handle error
}
bytesSent += result;
}
//cleanup
delete[] buf;
buf = NULL;
return client.endPublish();
}
return false;
}
/*
set the callback function for MQTT
input:
function ptr that matches the MQTT callback function signature in pubsubclient
output: NA
*/
void ESPHelper::setMQTTCallback(MQTT_CALLBACK_SIGNATURE){
_mqttCallback = callback;
//only set the callback if using mqtt AND the system has already been started. Otherwise just save it for later
if(_hasBegun && _mqttSet) {
client.setCallback(_mqttCallback);
}
_mqttCallbackSet = true;
}
/*
legacy funtion - here for compatibility. Sets the callback function for MQTT (see function above)
input:
function ptr that matches the MQTT callback function signature in pubsubclient
output:
true (always)
*/
bool ESPHelper::setCallback(MQTT_CALLBACK_SIGNATURE){
setMQTTCallback(callback);
return true;
}
/*
sets a custom function to run when connection to wifi is established
input:
void function ptr with no params
output: NA
*/
void ESPHelper::setWifiCallback(void (*callback)()){
_wifiCallback = callback;
_wifiCallbackSet = true;
}
/*
sets a custom function to run when connection to wifi is lost
input:
void function ptr with no params
output: NA
*/
void ESPHelper::setWifiLostCallback(void (*callback)()){
_wifiLostCallback = callback;
_wifiLostCallbackSet = true;
}
/*
attempts to connect to wifi & mqtt server if not connected
input: NA
output: NA
*/
void ESPHelper::reconnect() {
if(reconnectMetro.check() && _connectionStatus != BROADCAST && setConnectionStatus() != FULL_CONNECTION){
debugPrintln("Attempting WiFi Connection...");
//attempt to connect to the wifi if connection is lost
if(WiFi.status() != WL_CONNECTED){
_connectionStatus = NO_CONNECTION;
#ifdef ESP32
reconnect();
#else
//WiFi.reconnect();
#endif
}
// make sure we are connected to WIFI before attemping to reconnect to MQTT
//----note---- maybe want to reset tryCount whenever we succeed at getting wifi connection?
if(WiFi.status() == WL_CONNECTED){
//if the wifi previously wasnt connected but now is, run the callback
if(_connectionStatus < WIFI_ONLY && _wifiCallbackSet){
_wifiCallback();
}
debugPrintln("\n---WIFI Connected!---");
_connectionStatus = WIFI_ONLY;
//attempt to connect to mqtt when we finally get connected to WiFi
if(_mqttSet){
static int timeout = 0; //allow a max of 5 mqtt connection attempts before timing out
if (!client.connected() && timeout < 5) {
debugPrint("Attemping MQTT connection");
client.disconnect();
client.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());
if(_useSecureClient){client.setClient(wifiClientSecure);}
else{client.setClient(wifiClient);}
int connected = 0;
//connect to mqtt with user/pass
if (_mqttUserSet && _willMessageSet && _willTopicSet) {
debugPrintln(" - Using user & last will");
debugPrintln(String("\t Client Name: " + String(_clientName.c_str())));
debugPrintln(String("\t User Name: " + String(_currentNet.getMqttUser())));
debugPrintln(String("\t Password: " + String(_currentNet.getMqttPass())));
debugPrintln(String("\t Will Topic: " + String(_currentNet.getMqttWillTopic())));
debugPrintln(String("\t Will QOS: " + String(_currentNet.getMqttWillQoS())));
debugPrintln(String("\t Will Retain?: " + String(_currentNet.getMqttWillRetain())));
debugPrintln(String("\t Will Message: " + String(_currentNet.getMqttWillMessage())));
connected = client.connect(
(char*) _clientName.c_str(),
_currentNet.getMqttUser(),
_currentNet.getMqttPass(),
_currentNet.getMqttWillTopic(),
_currentNet.getMqttWillQoS(),
_currentNet.getMqttWillRetain(),
_currentNet.getMqttWillMessage());
}
//connect to mqtt without credentials
else if (!_mqttUserSet && _willMessageSet && _willTopicSet) {
debugPrintln(" - Using last will");
debugPrintln(String("\t Client Name: " + String(_clientName.c_str())));
debugPrintln(String("\t Will Topic: " + String(_currentNet.getMqttWillTopic())));
debugPrintln(String("\t Will QOS: " + String(_currentNet.getMqttWillQoS())));
debugPrintln(String("\t Will Retain?: " + String(_currentNet.getMqttWillRetain())));
debugPrintln(String("\t Will Message: " + String(_currentNet.getMqttWillMessage())));
connected = client.connect(
(char*) _clientName.c_str(),
_currentNet.getMqttWillTopic(),
_currentNet.getMqttWillQoS(),
_currentNet.getMqttWillRetain(),
_currentNet.getMqttWillMessage()
);
} else if (_mqttUserSet && !_willMessageSet) {
debugPrintln(" - Using user");
debugPrintln(String("\t Client Name: " + String(_clientName.c_str())));
debugPrintln(String("\t User Name: " + String(_currentNet.getMqttUser())));
debugPrintln(String("\t Password: " + String(_currentNet.getMqttPass())));
connected = client.connect(
(char*) _clientName.c_str(),
_currentNet.getMqttUser(),
_currentNet.getMqttPass()
);
} else {
debugPrintln(" - Using default");
debugPrintln(String("\t Client Name: " + String(_clientName.c_str())));
connected = client.connect((char*) _clientName.c_str());
}
//if connected, subscribe to the topic(s) we want to be notified about
if (connected) {
debugPrintln(" -- Connected");
#if ESP_SDK_VERSION_MAJOR > 2
//if using https, verify the fingerprint of the server before setting full connection (return on fail)
if(_useSecureClient){
if (wifiClientSecure.verify(_fingerprint, _currentNet.mqttHost)) {
debugPrintln("Certificate Matches - SUCESS");
} else {
debugPrintln("Certificate Doesn't Match - FAIL");
return;
}
}
#else
if(_useSecureClient){debugPrintln("Certificate Not Supported on this SDK Version. Must use SDK 2.x.x");}
#endif
if(_mqttCallbackSet){
debugPrintln("Setting MQTT callback");
client.setCallback(_mqttCallback);
}
_connectionStatus = FULL_CONNECTION;
resubscribe();
timeout = 0;
}
else{
debugPrintln(" -- Failed");
}
timeout++;
}
else if (timeout >= 5) {
debugPrintln(" -- Failed to connect to MQTT after 5 attempts. Giving up.");
_connectionStatus = WIFI_ONLY;
}
}
}
//reset the reconnect metro
reconnectMetro.reset();
}
}
/*
internal function used to set _connectionStatus based on the WiFi & MQTT status
input: NA
output: NA
*/
int ESPHelper::setConnectionStatus(){
//assume no connection
int returnVal = NO_CONNECTION;
//make sure were not in broadcast mode
if(_connectionStatus != BROADCAST){
//if connected to wifi set the mode to wifi only and run the callback if needed
if(WiFi.status() == WL_CONNECTED){
if(_connectionStatus < WIFI_ONLY && _wifiCallbackSet){ //if the wifi previously wasnt connected but now is, run the callback
_wifiCallback();
}
returnVal = WIFI_ONLY;
//if mqtt is connected as well then set the status to full connection
if(client.connected()){
returnVal = FULL_CONNECTION;
}
}
//assuming above fails, then wifi is not connected.
//if the wifi is not connected and the wifi lost callback has been set, then call it
else if(_connectionStatus >= WIFI_ONLY && _wifiLostCallbackSet){
_wifiLostCallback();
}
}
else{
returnVal = BROADCAST;
}
//set the connection status and return
_connectionStatus = returnVal;
return returnVal;
}
/*
input:
output:
*/
void ESPHelper::updateNetwork(){
debugPrintln("\tDisconnecting from WiFi");
WiFi.disconnect();
debugPrintln("\tAttempting to begin on new network");
//set the wifi mode
WiFi.mode(WIFI_STA);
//connect to the network
if(_passSet && _ssidSet){WiFi.begin(_currentNet.getSsid(), _currentNet.getPass());}
else if(_ssidSet){WiFi.begin(_currentNet.getSsid());}
else{WiFi.begin("NO_SSID_SET");}
WiFi.setSleep(false);
//#ifdef ESP32
WiFi.setAutoReconnect(true);
//#endif
debugPrintln("\tSetting new MQTT server");
//setup the mqtt broker info
if(_mqttSet){client.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());}
else{client.setServer("192.0.2.0", 1883);}
debugPrintln("\tDone - Ready for next reconnect attempt");
}
/*
generate unique MQTT name from MAC addr
input:
uint8* (array) representing the ESP mac address
output:
string version of that mac address #
*/
String ESPHelper::macToStr(const uint8_t* mac){
char buf[18];
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(buf);
}
/*
return the current NetInfo state
input: NA
output:
NetInfo of the current network
*/
NetInfo* ESPHelper::getNetInfo(){
return &_currentNet;
}
/*
return the current SSID
input: NA
output:
char ptr referencing the current SSID
*/
const char* ESPHelper::getSSID(){
if(_ssidSet && _connectionStatus != BROADCAST){return _currentNet.getSsid();}
else if(_connectionStatus == BROADCAST){return _broadcastSSID;}
return "SSID NOT SET";
}
/*
set a new SSID - does not automatically disconnect from current network if already connected
input:
char ptr to the SSID to connect to
output: NA
*/
void ESPHelper::setSSID(const char* ssid){
_currentNet.setSsid(ssid);
_ssidSet = true;
}
/*
return the current network password
input: NA
output:
char ptr to the current network pass
*/
const char* ESPHelper::getPASS(){
if(_passSet && _connectionStatus != BROADCAST){return _currentNet.getPass();}
else if(_connectionStatus == BROADCAST){return _broadcastPASS;}
return "PASS NOT SET";
}
/*
set a new network password - does not automatically disconnect from current network if already connected
input:
char ptr to the new network pass to use
output: NA
*/
void ESPHelper::setPASS(const char* pass){
_currentNet.setPass(pass);
_passSet = true;
}
/*
return the current MQTT server IP
input: NA
output:
char ptr to the current MQTT IP or Hostname
*/
const char* ESPHelper::getMQTTIP(){
if(_mqttSet){return _currentNet.getMqttHost();}
return "MQTT IP NOT SET";
}
/*
set a new MQTT server IP or Hostname - does not automatically disconnect from current network/server if already connected
input:
char ptr to a new MQTT IP or Hostname str
output: NA
*/
void ESPHelper::setMQTTIP(const char* mqttIP){
_currentNet.setMqttHost(mqttIP);
_mqttSet = true;
}
/*
set a new MQTT server IP - does not automatically disconnect from current network/server if already connected
Includes MQTT user and Pass
input:
char ptr to a new MQTT IP or Hostname str
char ptr to MQTT username
char ptr to MQTT password
output: NA
*/
void ESPHelper::setMQTTIP(const char* mqttIP, const char* mqttUser, const char* mqttPass){
_currentNet.setMqttHost(mqttIP);
_currentNet.setMqttUser(mqttUser);
_currentNet.setMqttPass(mqttPass);
_mqttSet = true;
_mqttUserSet = true;
}
/*
set a new MQTT Will - does not automatically disconnect from current network/server if already connected
input:
char ptr to MQTT will topic
char ptr to MQTT will payload
output: NA
*/
void ESPHelper::setWill(const char *willTopic, const char *willMessage){
_currentNet.setMqttWillTopic(willTopic);
_currentNet.setMqttWillMessage(willMessage);
_willTopicSet = true;
_willMessageSet = true;
}
/*
set a new MQTT Will - does not automatically disconnect from current network/server if already connected
input:
char ptr to MQTT will topic
char ptr to MQTT will payload
int to MQTT will QOS
int to MQTT will retain
output: NA
*/
void ESPHelper::setWill(const char *willTopic, const char *willMessage, const int willQoS, const bool willRetain){
_currentNet.setMqttWillTopic(willTopic);
_currentNet.setMqttWillMessage(willMessage);
_currentNet.setMqttWillQoS(willQoS);
_currentNet.setMqttWillRetain(willRetain);
_willTopicSet = true;
_willMessageSet = true;
}
/*
return the QOS level for mqtt
input: NA
output:
int for current MQTT QOS
*/
int ESPHelper::getMQTTQOS(){
return _qos;
}
/*
set the QOS level for mqtt
input:
int for MQTT QOS level
output: NA
*/
void ESPHelper::setMQTTQOS(int qos){
_qos = qos;
}
/*
return the local IP address of the ESP as a string
input: NA
output:
String representing the current IP address of the ESP
*/
String ESPHelper::getIP(){
if(_connectionStatus != BROADCAST){
return WiFi.localIP().toString();
}
else{
return _broadcastIP.toString();
}
}
/*
return the local IP address of the ESP
input: NA
output:
IPAddress instance representing the current IP address of the ESP
*/
IPAddress ESPHelper::getIPAddress(){
if(_connectionStatus != BROADCAST){
return WiFi.localIP();
}
else{
return _broadcastIP;
}
}
/*
get the current connection status of ESPHelper
input: NA
output:
int for current ESPHelper connection status(refer to connStatus enum is sharedData.h)
*/
int ESPHelper::getStatus(){
return _connectionStatus;
}
/*
DEBUG ONLY - print the subscribed topics list to the serial line
input: NA
output: NA
*/
void ESPHelper::listSubscriptions(){
for(int i = 0; i < MAX_SUBSCRIPTIONS; i++){
if(_subscriptions[i].isUsed){
debugPrintln(_subscriptions[i].topic);
}
}
}
/*
enable use of OTA updates
input: NA
output: NA
*/
void ESPHelper::OTA_enable(){
_useOTA = true;
OTA_begin();
}
/*
begin the OTA subsystem but with a check for connectivity and enabled use of OTA
input: NA
output: NA
*/
void ESPHelper::OTA_begin(){
if(_connectionStatus >= BROADCAST && _useOTA){
ArduinoOTA.begin();
_OTArunning = true;
}
}
/*
disable use of OTA updates
input: NA
output: NA
*/
void ESPHelper::OTA_disable(){
_useOTA = false;
_OTArunning = false;
}
/*
set a password for OTA updates
input:
char ptr containing the OTA password to be used
output: NA
*/
void ESPHelper::OTA_setPassword(const char* pass){
ArduinoOTA.setPassword(pass);
}
/*
set the hostname of the ESP for OTA uploads
input:
char ptr containing the intended hostname
output: NA
*/
void ESPHelper::OTA_setHostname(const char* hostname){
strcpy(_hostname, hostname);
ArduinoOTA.setHostname(_hostname);
}
/*
set the hostname of the ESP for OTA uploads and append the ESPHelper version number
input:
char ptr containing the intended hostname
output: NA
*/
void ESPHelper::OTA_setHostnameWithVersion(const char* hostname){
strcpy(_hostname, hostname);
strcat(_hostname, "----");
strcat(_hostname, VERSION);
ArduinoOTA.setHostname(_hostname);
}
/*
returns the current ESPHelper hostname
input: NA
output:
char ptr containing the ESP hostname
*/
char* ESPHelper::getHostname(){
return _hostname;
}
/*
returns internal pubsubclient ptr (use with caution)
input: NA
output:
pubsubclient ptr
*/
PubSubClient* ESPHelper::getMQTTClient(){
return &client;
}
/*
sets a new buffer size for mqtt messages in/out
input: int bytes of how large the buffer should be
output:
true: success
false: failure
*/
bool ESPHelper::setMQTTBuffer(int size){
#if PUB_SUB_VERSION >= 28
return client.setBufferSize(size);
#else
return false;
#endif
}
================================================
FILE: src/ESPHelper.h
================================================
/*
ESPHelper.h
Copyright (c) 2019 ItKindaWorks Inc All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESP_HELPER_H
#define ESP_HELPER_H
#ifdef ESP32
#include <ESPmDNS.h>
#include <WiFi.h>
#endif
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#endif
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
// #include <StreamUtils.h>
#include <SafeString.h>
#include <WiFiClientSecure.h>
#include "sharedData.h"
#include "Metro.h"
#define PUB_SUB_VERSION 28
// #define DEBUG
#ifdef DEBUG
#define debugPrint(x) Serial.print(x) //debug on
#define debugPrintln(x) Serial.println(x) //debug on
#else
#define debugPrint(x) {;} //debug off
#define debugPrintln(x) {;} //debug off
#endif
void printNetInfo(const NetInfo *net, const char* header, bool printMQTT = true, bool printWill = true);
class ESPHelper{
public:
ESPHelper();
ESPHelper(const NetInfo *startingNet, bool storeLocal = true);
bool begin();
bool begin(const NetInfo *startingNet, bool storeLocal = true);
void end();
void useSecureClient(const char* fingerprint);
void broadcastMode(const char* ssid, const char* password, const IPAddress ip);
void disableBroadcast();
int loop();
bool subscribe(const char* topic, int qos);
bool addSubscription(const char* topic);
bool removeSubscription(const char* topic);
bool unsubscribe(const char* topic);
void publish(const char* topic, const char* payload);
void publish(const char* topic, const char* payload, bool retain);
boolean publishJson(const char* topic, JsonDocument& doc, bool retain);
bool setCallback(MQTT_CALLBACK_SIGNATURE);
void setMQTTCallback(MQTT_CALLBACK_SIGNATURE);
void setWifiCallback(void (*callback)());
void setWifiLostCallback(void (*callback)());
void reconnect();
void updateNetwork(); //manually disconnect and reconnecting to network/mqtt using current values (generally called after setting new network values)
const char* getSSID();
void setSSID(const char *ssid);
const char* getPASS();
void setPASS(const char *pass);
const char* getMQTTIP();
void setMQTTIP(const char *mqttIP);
void setMQTTIP(const char *mqttIP, const char *mqttUser, const char *mqttPass);
int getMQTTQOS();
void setMQTTQOS(int qos);
void setWill(const char *willTopic, const char *willMessage);
void setWill(const char *willTopic, const char *willMessage, const int willQoS, const bool willRetain);
String getIP();
IPAddress getIPAddress();
int getStatus();
NetInfo* getNetInfo();
void listSubscriptions();
void OTA_enable();
void OTA_disable();
void OTA_begin();
void OTA_setPassword(const char* pass);
void OTA_setHostname(const char* hostname);
void OTA_setHostnameWithVersion(const char* hostname);
char* getHostname();
PubSubClient* getMQTTClient();
bool setMQTTBuffer(int size);
String macToStr(const uint8_t* mac);
void resubscribe();
private:
void init();
void validateConfig();
int setConnectionStatus();
NetInfo _currentNet;
PubSubClient client;
Metro reconnectMetro = Metro(500);
WiFiClient wifiClient;
WiFiClientSecure wifiClientSecure;
const char* _fingerprint;
bool _useSecureClient = false;
String _clientName;
void (*_wifiCallback)();
bool _wifiCallbackSet = false;
void (*_wifiLostCallback)();
bool _wifiLostCallbackSet = false;
std::function<void(char*, uint8_t*, unsigned int)> _mqttCallback;
// #ifdef ESP8266
// std::function<void(char*, uint8_t*, unsigned int)> _mqttCallback;
// #endif
// #ifdef ESP32
// void(*_mqttCallback)(char*, uint8_t*, unsigned int) ;
// #endif
bool _mqttCallbackSet = false;
int _connectionStatus = NO_CONNECTION;
//AP mode variables
IPAddress _broadcastIP;
char _broadcastSSID[64];
char _broadcastPASS[64];
bool _ssidSet = false;
bool _passSet = false;
bool _mqttSet = false;
bool _mqttUserSet = false;
bool _mqttPassSet = false;
bool _willTopicSet = false;
bool _willMessageSet = false;
bool _useOTA = false;
bool _OTArunning = false;
bool _hasBegun = false;
subscription _subscriptions[MAX_SUBSCRIPTIONS];
char _hostname[64];
int _qos = DEFAULT_QOS;
IPAddress _apIP = IPAddress(192, 168, 1, 1);
};
#endif
================================================
FILE: src/ESPHelperWebConfig.cpp
================================================
/*
ESPHelperWebConfig.cpp
Copyright (c) 2017 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ESPHelperWebConfig.h"
ESPHelperWebConfig::ESPHelperWebConfig(int port, const char* URI){
_server = new AsyncWebServer(port);
_runningLocal = true;
createSafeStringFromCharArray(pageURI, _pageURI);
pageURI.clear();
pageURI.print(URI);
createSafeStringFromCharArray(resetURI, _resetURI);
resetURI.clear();
}
ESPHelperWebConfig::ESPHelperWebConfig(AsyncWebServer *server, const char* URI){
_server = server;
_runningLocal = false;
createSafeStringFromCharArray(pageURI, _pageURI);
pageURI.clear();
pageURI.print(URI);
createSafeStringFromCharArray(resetURI, _resetURI);
resetURI.clear();
}
ESPHelperWebConfig::~ESPHelperWebConfig(){
if(_runningLocal){
_server->end(); // Stop the server
delete _server;
}
_server = nullptr;
}
bool ESPHelperWebConfig::begin(const char* _hostname){
MDNS.begin(_hostname);
return begin();
}
bool ESPHelperWebConfig::begin(){
createSafeStringFromCharArray(resetURI, _resetURI);
createSafeStringFromCharArray(pageURI, _pageURI);
// Serial.printf("[ESPHelperWebConfig] Starting web config server on %s\n", pageURI.c_str());
//setup server handlers
//these handler function definitions use lambdas to pass the funtion... more information can be found here:
//https://stackoverflow.com/questions/39803135/c-unresolved-overloaded-function-type
_server->on(pageURI.c_str(), HTTP_GET, [this](AsyncWebServerRequest *request){
//send back the config page using the handleGet function as the template processor
request->send_P(200, "text/html", static_config_html, sizeof(static_config_html), [this](const String& var){
return handleGet(var);
});
});
_server->on(pageURI.c_str(), HTTP_POST, [this](AsyncWebServerRequest *request){
this->handlePost(request);
});
if(_resetSet){
// Serial.printf("[ESPHelperWebConfig] Starting reset on %s\n", resetURI.c_str());
//if the reset URI has been set then add a handler for it
_server->on(resetURI.c_str(), HTTP_POST, [this](AsyncWebServerRequest *request){
this->handleReset(request);
});
}
if(_runningLocal){
_server->begin(); // Actually start the server
}
return true;
}
void ESPHelperWebConfig::useConfig(NetInfo& config){
config.cloneTo(_config, false);
}
void ESPHelperWebConfig::fillConfig(bool preFill){
_preFill = preFill;
}
bool ESPHelperWebConfig::handle(){
// _server->handleClient();
return _configChanged;
}
NetInfo& ESPHelperWebConfig::getConfig(){
_configChanged = false;
return _config;
}
//main config page that allows user to enter in configuration info
String ESPHelperWebConfig::handleGet(const String& var){
if(var == "HELPER_PAGE_URI")
return _pageURI;
else if(var == "HELPER_HOSTNAME")
return _config.getHostname();
else if(var == "HELPER_SSID")
return _config.getSsid();
else if(var == "HELPER_MQTT_HOST")
return _config.getMqttHost();
else if(var == "HELPER_MQTT_USER")
return _config.getMqttUser();
else if(var == "HELPER_MQTT_PORT")
return String(_config.getMqttPort());
else if(var == "HELPER_MQTT_WILL_TOPIC")
return _config.getMqttWillTopic();
else if(var == "HELPER_MQTT_WILL_MESSAGE")
return _config.getMqttWillMessage();
else if(var == "HELPER_MQTT_WILL_QOS")
return String(_config.getMqttWillQoS());
else if(var == "HELPER_MQTT_WILL_RETAIN_0")
return _config.getMqttWillRetain() ? "" : "selected";
else if(var == "HELPER_MQTT_WILL_RETAIN_1")
return _config.getMqttWillRetain() ? "selected" : "";
return String();
}
// If a POST request is made to URI /config
void ESPHelperWebConfig::handlePost(AsyncWebServerRequest *request) {
//make sure that all the arguments exist and that at least an SSID and hostname have been entered
if( ! request->hasArg("ssid") || ! request->hasArg("netPass")
|| ! request->hasArg("hostname") || ! request->hasArg("mqttHost")
|| ! request->hasArg("mqttUser") || ! request->hasArg("mqttPass")
|| ! request->hasArg("mqttPort") || ! request->hasArg("otaPassword")
|| request->arg("ssid") == NULL || request->arg("hostname") == NULL){ // If the POST request doesn't have username and password data
request->send(400, "text/plain", "400: Invalid Request - Did you make sure to specify an SSID and Hostname?"); // The request is invalid, so send HTTP status 400
return;
}
//if there is an mqtt user/pass/port entered then there better also be a host!
if((request->arg("mqttUser") != NULL || request->arg("mqttPass") != NULL ||
request->arg("mqttPort") != NULL) && request->arg("mqttHost") == NULL){
request->send(400, "text/html",
String("<center>\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>\
<p><strong>400: Invalid Request - MQTT info specified without host</strong></p>\
<hr />\
<p><a href=" + String("config") + ">Open configuration page</a></p>").c_str());
return;
}
//convert the Strings returned by request->arg to char arrays that can be entered into NetInfo
if(request->arg("netPass").length() != 0 or _preFill == false){
_config.setPass(request->arg("netPass").c_str());
}
if(request->arg("mqttPass").length() != 0 or _preFill == false){
_config.setMqttPass(request->arg("mqttPass").c_str());
}
if(request->arg("otaPassword").length() != 0 or _preFill == false){
_config.setOtaPassword(request->arg("otaPassword").c_str());
}
_config.setSsid(request->arg("ssid").c_str());
_config.setHostname(request->arg("hostname").c_str());
_config.setMqttHost(request->arg("mqttHost").c_str());
_config.setMqttUser(request->arg("mqttUser").c_str());
//the port is special because it doesnt get stored as a string so we take care of that
if(request->arg("mqttPort") != NULL){_config.setMqttPort(request->arg("mqttPort").toInt());}
else{_config.setMqttPort(1883);}
// MQTT Will fields
if (request->hasArg("mqttWillTopic")) {
_config.setMqttWillTopic(request->arg("mqttWillTopic").c_str());
}
if (request->hasArg("mqttWillMessage")) {
_config.setMqttWillMessage(request->arg("mqttWillMessage").c_str());
}
if (request->hasArg("mqttWillQos")) {
_config.setMqttWillQoS(request->arg("mqttWillQos").toInt());
}
if (request->hasArg("mqttWillRetain")) {
_config.setMqttWillRetain(request->arg("mqttWillRetain").toInt() == 1);
}
//tell the user that the config is loaded in and the module is restarting
request->send(200, "text/html",
String("<center>\
<meta http-equiv=\"refresh\" content=\"10;url=/\"/>\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>\
<p><strong>Config info loaded</strong></p>\
<hr />\
<p><a href=\"/config\">Open configuration page</a></p>\
<p>Wait for the ESP8266 to restart with the new settings</p>\
<p>You will be redirected to the home page in 10 seconds.</p>"));
// printNetInfo(&_config, "[ESPHelperWeb Post]", true, true);
_configChanged = true;
}
void ESPHelperWebConfig::setFlashReset(const char* uri){
createSafeStringFromCharArray(resetURI, _resetURI);
resetURI.clear();
resetURI.print(uri);
_resetSet = true;
}
void ESPHelperWebConfig::handleReset(AsyncWebServerRequest *request){
//tell the user that the config is loaded in and the module is restarting
#warning "TODO: Implement flash reset from web config"
// _server->send(200, "text/plain", String("Resetting SPIFFS and restarting with default values"));
// LittleFS.format();
// ESP.restart();
}
void ESPHelperWebConfig::handleNotFound(AsyncWebServerRequest *request){
request->send(404, "text/plain", "404: Not found"); // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request
}
================================================
FILE: src/ESPHelperWebConfig.h
================================================
/*
ESPHelperWebConfig.h
Copyright (c) 2019 ItKindaWorks All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESPHELPER_WEBCONFIG_H
#define ESPHELPER_WEBCONFIG_H
#include "ESPHelper.h"
#ifdef ESP8266
#include <ESP8266mDNS.h>
#endif
#ifdef ESP32
#include <ESPmDNS.h>
#include <WiFi.h>
#endif
#include <ESPAsyncWebServer.h>
#include <WiFiClient.h>
#include "SafeString.h"
#include "config_html.h"
class ESPHelperWebConfig{
public:
ESPHelperWebConfig(int port, const char* URI); //constructor
ESPHelperWebConfig(AsyncWebServer *server, const char* URI);
~ESPHelperWebConfig(); //destructor
bool begin(const char* hostname);
bool begin();
void useConfig(NetInfo& config);
void fillConfig(bool preFill = true);
bool handle();
NetInfo& getConfig();
void setFlashReset(const char* uri);
private:
String handleGet(const String& var);
void handlePost(AsyncWebServerRequest *request);
void handleNotFound(AsyncWebServerRequest *request);
void handleReset(AsyncWebServerRequest *request);
AsyncWebServer *_server;
char _resetURI[64];
char _pageURI[64];
bool _preFill = false;
bool _resetSet = false;
NetInfo _config;
bool _runningLocal = false;
bool _configChanged = false;
};
#endif
================================================
FILE: src/config_html.h
================================================
#pragma once
inline unsigned char static_config_html[] PROGMEM = {
0x3c, 0x21, 0x64, 0x6f, 0x63, 0x74, 0x79, 0x70, 0x65, 0x20, 0x68, 0x74,
0x6d, 0x6c, 0x3e, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x20, 0x6c, 0x61, 0x6e,
0x67, 0x3d, 0x65, 0x6e, 0x3e, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x3d, 0x22, 0x77, 0x69, 0x64, 0x74,
0x68, 0x3d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x77, 0x69, 0x64,
0x74, 0x68, 0x2c, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x2d, 0x73,
0x63, 0x61, 0x6c, 0x65, 0x3d, 0x31, 0x2c, 0x75, 0x73, 0x65, 0x72, 0x2d,
0x73, 0x63, 0x61, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x3d, 0x6e, 0x6f, 0x22,
0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x76, 0x69, 0x65, 0x77, 0x70, 0x6f,
0x72, 0x74, 0x3e, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6d, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75,
0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c,
0x65, 0x3e, 0x3c, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3e, 0x62, 0x6f, 0x64,
0x79, 0x20, 0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75,
0x6e, 0x64, 0x2d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x30, 0x30,
0x64, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x66,
0x61, 0x6d, 0x69, 0x6c, 0x79, 0x3a, 0x76, 0x65, 0x72, 0x64, 0x61, 0x6e,
0x61, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30, 0x3b,
0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e,
0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x61,
0x69, 0x6e, 0x65, 0x72, 0x20, 0x7b, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c,
0x61, 0x79, 0x3a, 0x66, 0x6c, 0x65, 0x78, 0x3b, 0x20, 0x6a, 0x75, 0x73,
0x74, 0x69, 0x66, 0x79, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x3a, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20, 0x61, 0x6c, 0x69,
0x67, 0x6e, 0x2d, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x3a, 0x63, 0x65, 0x6e,
0x74, 0x65, 0x72, 0x3b, 0x20, 0x6d, 0x69, 0x6e, 0x2d, 0x68, 0x65, 0x69,
0x67, 0x68, 0x74, 0x3a, 0x31, 0x30, 0x30, 0x76, 0x68, 0x3b, 0x20, 0x7d,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f,
0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x7b, 0x20, 0x62,
0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x66,
0x66, 0x66, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a,
0x33, 0x32, 0x70, 0x78, 0x20, 0x32, 0x34, 0x70, 0x78, 0x3b, 0x20, 0x62,
0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73,
0x3a, 0x31, 0x32, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x78, 0x2d, 0x73,
0x68, 0x61, 0x64, 0x6f, 0x77, 0x3a, 0x30, 0x20, 0x32, 0x70, 0x78, 0x20,
0x31, 0x32, 0x70, 0x78, 0x20, 0x72, 0x67, 0x62, 0x61, 0x28, 0x30, 0x2c,
0x30, 0x2c, 0x30, 0x2c, 0x30, 0x2e, 0x31, 0x35, 0x29, 0x3b, 0x20, 0x6d,
0x69, 0x6e, 0x2d, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x33, 0x32, 0x30,
0x70, 0x78, 0x3b, 0x20, 0x6d, 0x61, 0x78, 0x2d, 0x77, 0x69, 0x64, 0x74,
0x68, 0x3a, 0x34, 0x30, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x74, 0x65, 0x78,
0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3a, 0x6c, 0x65, 0x66, 0x74,
0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20,
0x68, 0x33, 0x2c, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d,
0x62, 0x6f, 0x78, 0x20, 0x68, 0x34, 0x20, 0x7b, 0x20, 0x74, 0x65, 0x78,
0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3a, 0x63, 0x65, 0x6e, 0x74,
0x65, 0x72, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x2d, 0x74,
0x6f, 0x70, 0x3a, 0x30, 0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d,
0x62, 0x6f, 0x78, 0x20, 0x68, 0x72, 0x20, 0x7b, 0x20, 0x6d, 0x61, 0x72,
0x67, 0x69, 0x6e, 0x3a, 0x31, 0x38, 0x70, 0x78, 0x20, 0x30, 0x3b, 0x20,
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63,
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x69, 0x6e,
0x70, 0x75, 0x74, 0x2c, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
0x2d, 0x62, 0x6f, 0x78, 0x20, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x20,
0x7b, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x31, 0x30, 0x30, 0x25,
0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x2d, 0x62, 0x6f, 0x74,
0x74, 0x6f, 0x6d, 0x3a, 0x31, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x70, 0x61,
0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x36, 0x70, 0x78, 0x3b, 0x20, 0x62,
0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73,
0x3a, 0x34, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72,
0x3a, 0x31, 0x70, 0x78, 0x20, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x20, 0x23,
0x63, 0x63, 0x63, 0x3b, 0x20, 0x62, 0x6f, 0x78, 0x2d, 0x73, 0x69, 0x7a,
0x69, 0x6e, 0x67, 0x3a, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x62,
0x6f, 0x78, 0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f,
0x78, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65,
0x3d, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x5d, 0x20, 0x7b, 0x20, 0x77,
0x69, 0x64, 0x74, 0x68, 0x3a, 0x61, 0x75, 0x74, 0x6f, 0x3b, 0x20, 0x62,
0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x30,
0x30, 0x64, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72,
0x3a, 0x23, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65,
0x72, 0x3a, 0x6e, 0x6f, 0x6e, 0x65, 0x3b, 0x20, 0x63, 0x75, 0x72, 0x73,
0x6f, 0x72, 0x3a, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20,
0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x38, 0x70, 0x78, 0x20,
0x31, 0x38, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72,
0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3a, 0x34, 0x70, 0x78, 0x3b,
0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e,
0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x69,
0x6e, 0x70, 0x75, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x73, 0x75,
0x62, 0x6d, 0x69, 0x74, 0x5d, 0x3a, 0x68, 0x6f, 0x76, 0x65, 0x72, 0x20,
0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64,
0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x20, 0x7d, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e,
0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x70, 0x2c, 0x20, 0x2e,
0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x61,
0x20, 0x7b, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67,
0x6e, 0x3a, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20, 0x64, 0x69,
0x73, 0x70, 0x6c, 0x61, 0x79, 0x3a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3b,
0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x31, 0x30, 0x70, 0x78,
0x20, 0x30, 0x20, 0x30, 0x20, 0x30, 0x3b, 0x20, 0x7d, 0x3c, 0x2f, 0x73,
0x74, 0x79, 0x6c, 0x65, 0x3e, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x3c,
0x64, 0x69, 0x76, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x63, 0x65,
0x6e, 0x74, 0x65, 0x72, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
0x65, 0x72, 0x3e, 0x3c, 0x64, 0x69, 0x76, 0x20, 0x63, 0x6c, 0x61, 0x73,
0x73, 0x3d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78,
0x3e, 0x3c, 0x68, 0x33, 0x3e, 0x3c, 0x73, 0x70, 0x61, 0x6e, 0x20, 0x73,
0x74, 0x79, 0x6c, 0x65, 0x3d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23,
0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x3e, 0x3c, 0x73, 0x74, 0x72,
0x6f, 0x6e, 0x67, 0x3e, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x20,
0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x69,
0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3c, 0x2f, 0x73, 0x74,
0x72, 0x6f, 0x6e, 0x67, 0x3e, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e,
0x3c, 0x2f, 0x68, 0x33, 0x3e, 0x3c, 0x68, 0x72, 0x3e, 0x3c, 0x66, 0x6f,
0x72, 0x6d, 0x20, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x25, 0x48,
0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x50, 0x41, 0x47, 0x45, 0x5f, 0x55,
0x52, 0x49, 0x25, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3d, 0x50,
0x4f, 0x53, 0x54, 0x3e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x4e,
0x61, 0x6d, 0x65, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,
0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,
0x65, 0x72, 0x3d, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x48,
0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x20, 0x28, 0x52, 0x65,
0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78,
0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61,
0x6d, 0x65, 0x3d, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x20,
0x73, 0x69, 0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x48, 0x4f,
0x53, 0x54, 0x4e, 0x41, 0x4d, 0x45, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e,
0x20, 0x53, 0x53, 0x49, 0x44, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69,
0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f,
0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x53, 0x53, 0x49, 0x44, 0x20, 0x20,
0x28, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x29, 0x22, 0x20,
0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32,
0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x73, 0x73, 0x69, 0x64, 0x20, 0x73,
0x69, 0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x53, 0x53, 0x49,
0x44, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x53, 0x53, 0x49, 0x44,
0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a, 0x3c, 0x62,
0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,
0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x28, 0x55,
0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20, 0x56, 0x61,
0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e,
0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d,
0x6e, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x20, 0x73, 0x69, 0x7a, 0x65,
0x3d, 0x33, 0x32, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x70, 0x61, 0x73,
0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4f,
0x54, 0x41, 0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a,
0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70,
0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22,
0x28, 0x55, 0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20,
0x56, 0x61, 0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c,
0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x36, 0x20, 0x6e, 0x61, 0x6d,
0x65, 0x3d, 0x6f, 0x74, 0x61, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72,
0x64, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31, 0x38, 0x20, 0x74, 0x79,
0x70, 0x65, 0x3d, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e,
0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x68, 0x72, 0x3e, 0x3c, 0x68, 0x34, 0x3e,
0x3c, 0x73, 0x70, 0x61, 0x6e, 0x20, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d,
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37,
0x35, 0x3b, 0x3e, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x53, 0x65, 0x74, 0x74,
0x69, 0x6e, 0x67, 0x73, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e, 0x3c,
0x2f, 0x68, 0x34, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x48, 0x6f,
0x73, 0x74, 0x20, 0x28, 0x49, 0x50, 0x29, 0x3a, 0x3c, 0x62, 0x72, 0x3e,
0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65,
0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54,
0x20, 0x48, 0x6f, 0x73, 0x74, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65,
0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61, 0x6d, 0x65,
0x3d, 0x6d, 0x71, 0x74, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x20, 0x73, 0x69,
0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d,
0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54,
0x5f, 0x48, 0x4f, 0x53, 0x54, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20,
0x4d, 0x51, 0x54, 0x54, 0x20, 0x55, 0x73, 0x65, 0x72, 0x3a, 0x3c, 0x62,
0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,
0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51,
0x54, 0x54, 0x20, 0x55, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22,
0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31,
0x36, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x55,
0x73, 0x65, 0x72, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31, 0x36, 0x20,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45,
0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x55, 0x53, 0x45, 0x52, 0x25,
0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x50,
0x6f, 0x72, 0x74, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,
0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,
0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x50, 0x6f, 0x72,
0x74, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,
0x3d, 0x31, 0x30, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74,
0x74, 0x50, 0x6f, 0x72, 0x74, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31,
0x30, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c,
0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x50, 0x4f, 0x52,
0x54, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54,
0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a, 0x3c, 0x62,
0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,
0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x28, 0x55,
0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20, 0x56, 0x61,
0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e,
0x67, 0x74, 0x68, 0x3d, 0x31, 0x36, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d,
0x6d, 0x71, 0x74, 0x74, 0x50, 0x61, 0x73, 0x73, 0x20, 0x73, 0x69, 0x7a,
0x65, 0x3d, 0x31, 0x38, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x70, 0x61,
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x3c,
0x68, 0x72, 0x3e, 0x3c, 0x68, 0x34, 0x3e, 0x3c, 0x73, 0x70, 0x61, 0x6e,
0x20, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d, 0x63, 0x6f, 0x6c, 0x6f, 0x72,
0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x3e, 0x4d, 0x51,
0x54, 0x54, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x53, 0x65, 0x74, 0x74,
0x69, 0x6e, 0x67, 0x73, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e, 0x3c,
0x2f, 0x68, 0x34, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x54, 0x6f,
0x70, 0x69, 0x63, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,
0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,
0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x57, 0x69, 0x6c,
0x6c, 0x20, 0x54, 0x6f, 0x70, 0x69, 0x63, 0x22, 0x20, 0x6d, 0x61, 0x78,
0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x32, 0x38, 0x20, 0x6e,
0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x57, 0x69, 0x6c, 0x6c,
0x54, 0x6f, 0x70, 0x69, 0x63, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x36,
0x34, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c,
0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x57, 0x49, 0x4c,
0x4c, 0x5f, 0x54, 0x4f, 0x50, 0x49, 0x43, 0x25, 0x3e, 0x3c, 0x62, 0x72,
0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x4d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75,
0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65,
0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x57, 0x69, 0x6c, 0x6c,
0x20, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x20, 0x6d, 0x61,
0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x32, 0x38, 0x20,
0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x57, 0x69, 0x6c,
0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x73, 0x69, 0x7a,
0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25,
0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f,
0x57, 0x49, 0x4c, 0x4c, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45,
0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20,
0x51, 0x6f, 0x53, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,
0x75, 0x74, 0x20, 0x6d, 0x61, 0x78, 0x3d, 0x32, 0x20, 0x6d, 0x69, 0x6e,
0x3d, 0x30, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74,
0x57, 0x69, 0x6c, 0x6c, 0x51, 0x6f, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65,
0x3d, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51,
0x54, 0x54, 0x5f, 0x57, 0x49, 0x4c, 0x4c, 0x5f, 0x51, 0x4f, 0x53, 0x25,
0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x52,
0x65, 0x74, 0x61, 0x69, 0x6e, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x73,
0x65, 0x6c, 0x65, 0x63, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d,
0x71, 0x74, 0x74, 0x57, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x74, 0x61, 0x69,
0x6e, 0x3e, 0x3c, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x25, 0x68,
0x65, 0x6c, 0x70, 0x65, 0x72, 0x5f, 0x6d, 0x71, 0x74, 0x74, 0x5f, 0x77,
0x69, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x74, 0x61, 0x69, 0x6e, 0x5f, 0x30,
0x25, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x30, 0x3e, 0x46, 0x61,
0x6c, 0x73, 0x65, 0x3c, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x25,
0x68, 0x65, 0x6c, 0x70, 0x65, 0x72, 0x5f, 0x6d, 0x71, 0x74, 0x74, 0x5f,
0x77, 0x69, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x74, 0x61, 0x69, 0x6e, 0x5f,
0x31, 0x25, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x31, 0x3e, 0x54,
0x72, 0x75, 0x65, 0x3c, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x3e,
0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0x50, 0x72, 0x65, 0x73, 0x73,
0x20, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x75,
0x70, 0x64, 0x61, 0x74, 0x65, 0x20, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36,
0x36, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x66, 0x69, 0x6c,
0x65, 0x3c, 0x2f, 0x70, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20,
0x74, 0x79, 0x70, 0x65, 0x3d, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x20,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74,
0x3e, 0x3c, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, 0x3c, 0x70, 0x3e, 0x3c,
0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x2f, 0x3e, 0x47, 0x6f, 0x20,
0x74, 0x6f, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x53, 0x74,
0x61, 0x74, 0x75, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61,
0x3e, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x3c, 0x2f, 0x64, 0x69, 0x76,
0x3e
};
inline unsigned int static_config_html_len = 2977;
================================================
FILE: src/sharedData.h
================================================
/*
sharedTypes.h
Copyright (c) 2019 ItKindaWorks Inc All right reserved.
github.com/ItKindaWorks
This file is part of ESPHelper
ESPHelper 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.
ESPHelper 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 ESPHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHARED_TYPES_H
#define SHARED_TYPES_H
#include <SafeString.h>
#define VERSION "2-0-4"
//Maximum number of subscriptions that can be auto-subscribed
//feel free to change this if you need more subsciptions
#define MAX_SUBSCRIPTIONS 25
#define DEFAULT_QOS 1; //at least once - devices are guarantee to get a message.
#define MAX_TOPIC_LENGTH 128
enum connStatus {NO_CONNECTION, BROADCAST, ROAMING, WIFI_ONLY, FULL_CONNECTION};
struct ESPHelperConf {
char mqttHost[32];
char mqttUser[16];
char mqttPass[16];
int mqttPort;
char ssid[32];
char pass[32];
char otaPassword[16];
char hostname[32];
char willTopic[128];
char willMessage[32];
int willQoS;
bool willRetain;
};
class NetInfo {
public:
/**
* @brief Construct a new NetInfo object with local storage
*
*/
explicit NetInfo() {
_conf = new ESPHelperConf();
_storeLocal = true;
clear();
}
/**
* @brief Construct a new NetInfo object with external storage
*
* @param externalConf Pointer to an existing ESPHelperConf object
*/
explicit NetInfo(ESPHelperConf& externalConf) {
_conf = &externalConf;
_storeLocal = false;
}
// Deleted copy operations for memory safety
NetInfo(const NetInfo& other) = delete;
NetInfo& operator=(const NetInfo& other) = delete;
/**
* @brief Destroy the Net Info object
*
*/
~NetInfo() {
if (_storeLocal && _conf != nullptr) {
delete _conf;
}
}
// ESPHelperConf* getRawConfPtr() const {
// return _conf;
// }
/* * @brief Use an external ESPHelperConf object for storage
*
* This method allows the NetInfo instance to use an existing ESPHelperConf object
* instead of managing its own memory. It is useful for sharing configurations.
*
* @param externalConf Pointer to an existing ESPHelperConf object
*/
void setExternalMemory(ESPHelperConf* externalConf) {
if (_storeLocal && _conf != externalConf) {
delete _conf;
}
_conf = externalConf;
_storeLocal = false;
}
/**
* @brief Clone the current configuration to another NetInfo object
*
* @param target The target NetInfo object to clone to
* @param storeLocal If true, the target will store a local copy of the configuration
*/
void cloneTo(NetInfo& target, bool storeLocal) const {
if (storeLocal) {
target.setToLocalCopy(*_conf);
} else {
target.setExternalMemory(_conf);
}
}
// const ESPHelperConf* getConfPointer() const { return _conf; }
void setMqttHost(const char* val) { safeCopy(_conf->mqttHost, val, sizeof(_conf->mqttHost)); }
void setMqttUser(const char* val) { safeCopy(_conf->mqttUser, val, sizeof(_conf->mqttUser)); }
void setMqttPass(const char* val) { safeCopy(_conf->mqttPass, val, sizeof(_conf->mqttPass)); }
void setSsid(const char* val) { safeCopy(_conf->ssid, val, sizeof(_conf->ssid)); }
void setPass(const char* val) { safeCopy(_conf->pass, val, sizeof(_conf->pass)); }
void setOtaPassword(const char* val) { safeCopy(_conf->otaPassword, val, sizeof(_conf->otaPassword)); }
void setHostname(const char* val) { safeCopy(_conf->hostname, val, sizeof(_conf->hostname)); }
void setMqttWillTopic(const char* val) { safeCopy(_conf->willTopic, val, sizeof(_conf->willTopic)); }
void setMqttWillMessage(const char* val) { safeCopy(_conf->willMessage, val, sizeof(_conf->willMessage)); }
void setMqttPort(int val) { _conf->mqttPort = val; }
void setMqttWillRetain(bool val) { _conf->willRetain = val; }
void setMqttWillQoS(int val) { _conf->willQoS = val; }
const char* getMqttHost() const { return _conf->mqttHost; }
const char* getMqttUser() const { return _conf->mqttUser; }
const char* getMqttPass() const { return _conf->mqttPass; }
const char* getSsid() const { return _conf->ssid; }
const char* getPass() const { return _conf->pass; }
const char* getOtaPassword() const { return _conf->otaPassword; }
const char* getHostname() const { return _conf->hostname; }
const char* getMqttWillTopic() const { return _conf->willTopic; }
const char* getMqttWillMessage() const { return _conf->willMessage; }
int getMqttPort() const { return _conf->mqttPort; }
int getMqttWillQoS() const { return _conf->willQoS; }
bool getMqttWillRetain() const { return _conf->willRetain; }
private:
//denotes whether the ESPHelperConf is stored in external memory or locally within this instance
bool _storeLocal = true;
ESPHelperConf* _conf = nullptr;
/* * @brief Safely copy a string to a destination buffer
*
* This method copies a string from source to destination, ensuring that the destination
* does not overflow. It also ensures that the destination is null-terminated.
*
* @param dest Pointer to the destination buffer
* @param src Pointer to the source string
* @param maxLen Maximum length of the destination buffer
*/
void safeCopy(char* dest, const char* src, size_t maxLen) {
if (src) {
strncpy(dest, src, maxLen - 1);
dest[maxLen - 1] = '\0';
} else if (dest && maxLen > 0) {
dest[0] = '\0';
}
}
/* * @brief Clear the configuration data
*
* This method resets all fields in the ESPHelperConf structure to their default values.
* It is useful for initializing or resetting the configuration.
*/
void clear() {
memset(_conf, 0, sizeof(ESPHelperConf));
_conf->mqttPort = 1883;
_conf->willQoS = 1;
_conf->willRetain = true;
}
/* * @brief Set the NetInfo to a local copy of the provided ESPHelperConf
*
* This method creates a local copy of the provided ESPHelperConf object.
* It is useful when you want to ensure that the NetInfo instance has its own copy
* of the configuration data.
*
* @param conf The ESPHelperConf object to copy from
*/
void setToLocalCopy(const ESPHelperConf& conf) {
if (!_storeLocal) {
_conf = new ESPHelperConf();
_storeLocal = true;
}
memcpy(_conf, &conf, sizeof(ESPHelperConf));
}
};
// typedef struct NetInfo NetInfo;
struct subscription{
bool isUsed = false;
const char* topic;
};
typedef struct subscription subscription;
#endif
================================================
FILE: static/config.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<title>System Configuration</title>
<style>
body { background-color:#00dfff; font-family:verdana; margin:0; }
.center-container { display:flex; justify-content:center; align-items:center; min-height:100vh; }
.config-box { background:#fff; padding:32px 24px; border-radius:12px; box-shadow:0 2px 12px rgba(0,0,0,0.15); min-width:320px; max-width:400px; text-align:left; }
.config-box h3, .config-box h4 { text-align:center; margin-top:0; }
.config-box hr { margin:18px 0; }
.config-box input, .config-box select { width:100%; margin-bottom:10px; padding:6px; border-radius:4px; border:1px solid #ccc; box-sizing:border-box; }
.config-box input[type=submit] { width:auto; background:#00dfff; color:#fff; border:none; cursor:pointer; padding:8px 18px; border-radius:4px; }
.config-box input[type=submit]:hover { background:#0a4f75; }
.config-box p, .config-box a { text-align:center; display:block; margin:10px 0 0 0; }
</style>
</head>
<body>
<div class="center-container">
<div class="config-box">
<h3><span style="color:#0a4f75;"><strong>ESP8266 System Configuration</strong></span></h3>
<hr />
<form action="%HELPER_PAGE_URI%" method="POST">
Device Name:<br>
<input type="text" name="hostname" size="32" maxlength="32" placeholder="Device Hostname (Required)" value="%HELPER_HOSTNAME%"><br>
SSID:<br>
<input type="text" name="ssid" size="32" maxlength="32" placeholder="SSID (Required)" value="%HELPER_SSID%"><br>
SSID Password:<br>
<input type="password" name="netPass" size="32" maxlength="32" placeholder="(Use Stored Value)"><br>
OTA Password:<br>
<input type="password" name="otaPassword" size="18" maxlength="16" placeholder="(Use Stored Value)"><br>
<hr />
<h4><span style="color:#0a4f75;">MQTT Settings</span></h4>
MQTT Host (IP):<br>
<input type="text" name="mqttHost" size="32" maxlength="32" placeholder="MQTT Host" value="%HELPER_MQTT_HOST%"><br>
MQTT User:<br>
<input type="text" name="mqttUser" size="16" maxlength="16" placeholder="MQTT Username" value="%HELPER_MQTT_USER%"><br>
MQTT Port:<br>
<input type="text" name="mqttPort" size="10" maxlength="10" placeholder="MQTT Port" value="%HELPER_MQTT_PORT%"><br>
MQTT Password:<br>
<input type="password" name="mqttPass" size="18" maxlength="16" placeholder="(Use Stored Value)"><br>
<hr />
<h4><span style="color:#0a4f75;">MQTT Will Settings</span></h4>
Will Topic:<br>
<input type="text" name="mqttWillTopic" size="64" maxlength="128" placeholder="MQTT Will Topic" value="%HELPER_MQTT_WILL_TOPIC%"><br>
Will Message:<br>
<input type="text" name="mqttWillMessage" size="32" maxlength="128" placeholder="MQTT Will Message" value="%HELPER_MQTT_WILL_MESSAGE%"><br>
Will QoS:<br>
<input type="number" name="mqttWillQos" min="0" max="2" value="%HELPER_MQTT_WILL_QOS%"><br>
Will Retain:<br>
<select name="mqttWillRetain">
<option value="0" %HELPER_MQTT_WILL_RETAIN_0%>False</option>
<option value="1" %HELPER_MQTT_WILL_RETAIN_1%>True</option>
</select><br>
<p>Press Submit to update ESP8266 config file</p>
<input type="submit" value="Submit">
</form>
<p><a href="/">Go to Device Status Page</a></p>
</div>
</div>
</body>
</html>
================================================
FILE: web_to_header.py
================================================
import os
import subprocess
import shutil
import minify_html
STATIC_DIR = "static"
OUTPUT_DIR = "src"
def convert_file(source_path, dest_path):
if source_path.endswith(".html"):
print(f"\t[HTML->H] Minifying {source_path} to {dest_path}")
temp_path = source_path + ".tmp"
shutil.move(source_path, temp_path)
with open(temp_path, "r") as temp_file:
content = temp_file.read()
minified = minify_html.minify(content, minify_js=False, remove_processing_instructions=True)
with open(source_path, "w") as minified_file:
minified_file.write(minified)
with open(dest_path, "w") as out_file:
subprocess.run(["xxd", "-i", source_path], stdout=out_file)
os.remove(source_path) # Clean up the temporary file
shutil.move(temp_path, source_path) # Restore the original file name
else:
with open(dest_path, "w") as out_file:
subprocess.run(["xxd", "-i", source_path], stdout=out_file)
def post_process_file(file_path):
# Post-process to add PROGMEM to the array declaration
with open(file_path, "r") as file:
lines = file.readlines()
lines = ["#pragma once\n\n"] + lines # Add pragma once at the top
with open(file_path, "w") as file:
for line in lines:
if "[] =" in line:
line = line.replace("[] =", "[] PROGMEM =")
if "unsigned" in line:
line = line.replace("unsigned", "inline unsigned")
file.write(line)
def main():
# print("[HTML->H] Converting HTML/CSS/JS files to C header files...")
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
for filename in os.listdir(STATIC_DIR):
if filename.endswith(".html") or filename.endswith(".css") or filename.endswith(".js"):
input_file = os.path.join(STATIC_DIR, filename)
output_file = os.path.join(OUTPUT_DIR, filename.replace('.', '_') + ".h")
print(f"[HTML->H] Converting {input_file} -> {output_file}")
convert_file(input_file, output_file)
post_process_file(output_file)
if __name__ == "__main__":
main()
gitextract_xucz34ps/ ├── LICENSE ├── README.md ├── examples/ │ ├── AdvancedFeatures/ │ │ ├── MQTT_Will/ │ │ │ └── MQTT_Will.ino │ │ ├── arbitraryConfigKeys/ │ │ │ └── arbitraryConfigKeys.ino │ │ ├── configAndStatusApDemo/ │ │ │ └── configAndStatusApDemo.ino │ │ ├── configServerApDemo/ │ │ │ └── configServerApDemo.ino │ │ ├── configServerDemo/ │ │ │ └── configServerDemo.ino │ │ ├── multiNetwork/ │ │ │ └── multiNetwork.ino │ │ └── secureMQTT/ │ │ └── secureMQTT.ino │ ├── GettingStarted/ │ │ ├── Adafruit_IO/ │ │ │ └── Adafruit_IO.ino │ │ ├── OTA/ │ │ │ └── OTA.ino │ │ ├── RelayControlV2/ │ │ │ └── RelayControlV2.ino │ │ ├── basicUse/ │ │ │ └── basicUse.ino │ │ ├── basicUserPass/ │ │ │ └── basicUserPass.ino │ │ ├── buttonDemo/ │ │ │ └── buttonDemo.ino │ │ ├── relayControl/ │ │ │ └── relayControl.ino │ │ └── wifiCallback/ │ │ └── wifiCallback.ino │ └── InputOutput/ │ ├── RGBLight/ │ │ └── RGBLight.ino │ └── temperatureSensor_ds18b20/ │ └── temperatureSensor_ds18b20.ino ├── keywords.txt ├── library.json ├── src/ │ ├── ESPHelper.cpp │ ├── ESPHelper.h │ ├── ESPHelperWebConfig.cpp │ ├── ESPHelperWebConfig.h │ ├── config_html.h │ └── sharedData.h ├── static/ │ └── config.html └── web_to_header.py
SYMBOL INDEX (36 symbols across 6 files)
FILE: src/ESPHelper.cpp
function printNetInfo (line 29) | void printNetInfo(const NetInfo *net, const char* header, bool printMQTT...
function String (line 958) | String ESPHelper::macToStr(const uint8_t* mac){
function NetInfo (line 975) | NetInfo* ESPHelper::getNetInfo(){
function String (line 1147) | String ESPHelper::getIP(){
function IPAddress (line 1165) | IPAddress ESPHelper::getIPAddress(){
function PubSubClient (line 1303) | PubSubClient* ESPHelper::getMQTTClient(){
FILE: src/ESPHelper.h
function class (line 69) | class ESPHelper{
FILE: src/ESPHelperWebConfig.cpp
function NetInfo (line 108) | NetInfo& ESPHelperWebConfig::getConfig(){
function String (line 118) | String ESPHelperWebConfig::handleGet(const String& var){
FILE: src/ESPHelperWebConfig.h
function class (line 47) | class ESPHelperWebConfig{
FILE: src/sharedData.h
type connStatus (line 43) | enum connStatus {NO_CONNECTION, BROADCAST, ROAMING, WIFI_ONLY, FULL_CONN...
type ESPHelperConf (line 45) | struct ESPHelperConf {
function class (line 60) | class NetInfo {
function explicit (line 78) | explicit NetInfo(ESPHelperConf& externalConf) {
function setExternalMemory (line 111) | void setExternalMemory(ESPHelperConf* externalConf) {
function cloneTo (line 125) | void cloneTo(NetInfo& target, bool storeLocal) const {
function setMqttHost (line 135) | void setMqttHost(const char* val) { safeCopy(_conf->mqttHost, val, sizeo...
function setMqttUser (line 136) | void setMqttUser(const char* val) { safeCopy(_conf->mqttUser, val, sizeo...
function setMqttPass (line 137) | void setMqttPass(const char* val) { safeCopy(_conf->mqttPass, val, sizeo...
function setSsid (line 138) | void setSsid(const char* val) { safeCopy(_conf->ssid, val, sizeof(_conf-...
function setPass (line 139) | void setPass(const char* val) { safeCopy(_conf->pass, val, sizeof(_conf-...
function setOtaPassword (line 140) | void setOtaPassword(const char* val) { safeCopy(_conf->otaPassword, val,...
function setHostname (line 141) | void setHostname(const char* val) { safeCopy(_conf->hostname, val, sizeo...
function setMqttWillTopic (line 142) | void setMqttWillTopic(const char* val) { safeCopy(_conf->willTopic, val,...
function setMqttWillMessage (line 143) | void setMqttWillMessage(const char* val) { safeCopy(_conf->willMessage, ...
function setMqttPort (line 144) | void setMqttPort(int val) { _conf->mqttPort = val; }
function setMqttWillRetain (line 145) | void setMqttWillRetain(bool val) { _conf->willRetain = val; }
function setMqttWillQoS (line 146) | void setMqttWillQoS(int val) { _conf->willQoS = val; }
function safeCopy (line 176) | void safeCopy(char* dest, const char* src, size_t maxLen) {
function clear (line 190) | void clear() {
function setToLocalCopy (line 208) | void setToLocalCopy(const ESPHelperConf& conf) {
type subscription (line 221) | struct subscription{
type subscription (line 225) | typedef struct subscription subscription;
FILE: web_to_header.py
function convert_file (line 11) | def convert_file(source_path, dest_path):
function post_process_file (line 38) | def post_process_file(file_path):
function main (line 54) | def main():
Condensed preview — 29 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (192K chars).
[
{
"path": "LICENSE",
"chars": 35146,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "README.md",
"chars": 2705,
"preview": "# ESPHelper\n\nESPHelper is a C++ library designed to simplify WiFi and MQTT connectivity for ESP8266 and ESP32 platforms."
},
{
"path": "examples/AdvancedFeatures/MQTT_Will/MQTT_Will.ino",
"chars": 3170,
"preview": "/* \nMQTT_Will.ino\nCopyright (c) 2018 Sk4zz All right reserved.\ngithub.com/Sk4zz\n\nThis file is part of ESPHelper\ngithu"
},
{
"path": "examples/AdvancedFeatures/arbitraryConfigKeys/arbitraryConfigKeys.ino",
"chars": 1963,
"preview": "/* \narbitraryConfigKeys.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is"
},
{
"path": "examples/AdvancedFeatures/configAndStatusApDemo/configAndStatusApDemo.ino",
"chars": 6788,
"preview": "/* \nconfigAndStatusAPDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file "
},
{
"path": "examples/AdvancedFeatures/configServerApDemo/configServerApDemo.ino",
"chars": 4971,
"preview": "/* \nconfigServerApDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is "
},
{
"path": "examples/AdvancedFeatures/configServerDemo/configServerDemo.ino",
"chars": 3144,
"preview": "/* \nconfigServerDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is pa"
},
{
"path": "examples/AdvancedFeatures/multiNetwork/multiNetwork.ino",
"chars": 2549,
"preview": "/* \nMultiNetwork.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part o"
},
{
"path": "examples/AdvancedFeatures/secureMQTT/secureMQTT.ino",
"chars": 2877,
"preview": "/* \n secureMQTT.ino\n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This "
},
{
"path": "examples/GettingStarted/Adafruit_IO/Adafruit_IO.ino",
"chars": 2737,
"preview": "/* \n Adafruit_IO.ino\n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This"
},
{
"path": "examples/GettingStarted/OTA/OTA.ino",
"chars": 1765,
"preview": "/* \nOTA.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelp"
},
{
"path": "examples/GettingStarted/RelayControlV2/RelayControlV2.ino",
"chars": 4127,
"preview": "/* \n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This file is part of ESP"
},
{
"path": "examples/GettingStarted/basicUse/basicUse.ino",
"chars": 1649,
"preview": "/* \nbasicUse.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ES"
},
{
"path": "examples/GettingStarted/basicUserPass/basicUserPass.ino",
"chars": 2689,
"preview": "/* \n basicUserPass.ino\n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n Th"
},
{
"path": "examples/GettingStarted/buttonDemo/buttonDemo.ino",
"chars": 3563,
"preview": "/* \n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This file is part of ESP"
},
{
"path": "examples/GettingStarted/relayControl/relayControl.ino",
"chars": 3084,
"preview": "/* \n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This file is part of Rel"
},
{
"path": "examples/GettingStarted/wifiCallback/wifiCallback.ino",
"chars": 1760,
"preview": "/* \nwifiCallback.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part o"
},
{
"path": "examples/InputOutput/RGBLight/RGBLight.ino",
"chars": 11821,
"preview": "/* \n wifiRGB.ino\n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This fil"
},
{
"path": "examples/InputOutput/temperatureSensor_ds18b20/temperatureSensor_ds18b20.ino",
"chars": 2971,
"preview": "/* \n Copyright (c) 2017 ItKindaWorks All right reserved.\n github.com/ItKindaWorks\n\n This file is part of ESP"
},
{
"path": "keywords.txt",
"chars": 1481,
"preview": "#######################################\n# Syntax Coloring Map For ESPHelper\n#######################################\n\n###"
},
{
"path": "library.json",
"chars": 876,
"preview": "{\n \"name\": \"ESPHelper\",\n \"authors\":\n {\n \"name\": \"ItKindaWorks\",\n \"email\": \"itkindaworksinc@gmail."
},
{
"path": "src/ESPHelper.cpp",
"chars": 31864,
"preview": "/*\n ESPHelper.cpp\n Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n github.com/ItKindaWorks\n\n This f"
},
{
"path": "src/ESPHelper.h",
"chars": 4886,
"preview": "/*\n ESPHelper.h\n Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n github.com/ItKindaWorks\n\n This fil"
},
{
"path": "src/ESPHelperWebConfig.cpp",
"chars": 8516,
"preview": "/*\nESPHelperWebConfig.cpp\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part"
},
{
"path": "src/ESPHelperWebConfig.h",
"chars": 1930,
"preview": "/*\nESPHelperWebConfig.h\nCopyright (c) 2019 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part o"
},
{
"path": "src/config_html.h",
"chars": 18481,
"preview": "#pragma once\n\ninline unsigned char static_config_html[] PROGMEM = {\n 0x3c, 0x21, 0x64, 0x6f, 0x63, 0x74, 0x79, 0x70, 0x"
},
{
"path": "src/sharedData.h",
"chars": 6780,
"preview": "/*\n sharedTypes.h\n Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n github.com/ItKindaWorks\n\n This f"
},
{
"path": "static/config.html",
"chars": 3925,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-sca"
},
{
"path": "web_to_header.py",
"chars": 2263,
"preview": "import os\nimport subprocess\nimport shutil\nimport minify_html\n\n\n \nSTATIC_DIR = \"static\"\nOUTPUT_DIR = \"src\"\n\ndef conver"
}
]
About this extraction
This page contains the full source code of the ItKindaWorks/ESPHelper GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 29 files (176.3 KB), approximately 57.1k tokens, and a symbol index with 36 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.