[
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>."
  },
  {
    "path": "README.md",
    "content": "# ESPHelper\n\nESPHelper 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.\n\n## Features\n\n- **Automatic WiFi and MQTT Connection Management:** Handles connecting, reconnecting, and resubscribing to MQTT topics.\n- **MQTT Topic Subscription Management:** Add, remove, and auto-resubscribe to topics.\n- **OTA Updates:** Easily enable/disable OTA, set OTA password and hostname.\n- **Broadcast Mode:** Create an access point for configuration or OTA when no WiFi is available.\n- **Web Configuration:** Optional web interface for device configuration ([`ESPHelperWebConfig`](src/ESPHelperWebConfig.h)).\n- **Callback Support:** Set custom callbacks for WiFi connection, WiFi loss, and MQTT messages.\n- **Secure MQTT:** Supports SSL/TLS connections to MQTT brokers.\n\n## Requirements\n\nMake sure you have these libraries installed:\n* [Metro](https://github.com/ItKindaWorks/ESPHelper_Metro)\n* [PubSubClient](https://github.com/knolleary/pubsubclient) (Current Supported Version - 2.8)\n* [ArduinoJson](https://github.com/bblanchon/ArduinoJson) (Current Supported Version - 7.0.4)\n* [SafeString](https://github.com/PowerBroker2/SafeString) (Current Supported Version - 4.1.30)\n\n In addition to those libraries, make sure that you have the ESP core files installed for your platform.\n * [ESP8266 Arduino Core](https://github.com/esp8266/Arduino)\n * [ESP32 Arduino Core](https://github.com/espressif/arduino-esp32)\n\n## Getting Started\n\nSee the [examples/GettingStarted](examples/GettingStarted/) folder for usage examples.\n\n### Basic Usage\n\n```cpp\n#include \"ESPHelper.h\"\n\nESPHelper helper;\n\nvoid setup() {\n    helper.setSSID(\"yourSSID\");\n    helper.setPASS(\"yourPassword\");\n    helper.setMQTTIP(\"mqtt.example.com\");\n    helper.begin();\n}\n\nvoid loop() {\n    helper.loop();\n}\n```\n\nUseful Methods:\n---------------\n\n* *bool begin();*\n\tInitialize the system (must be called once).\n\n* *int loop();*\n    must be called as often as possible to maintain connections and run the various subsystems\n\n* *bool subscribe(char\\* topic);*\n    subscribe to a given MQTT topic (will NOT auto re-subscribe on connection lost)\n\n* *bool addSubscription(char\\* topic);*\n    add a topic to the subscription list (will auto re-subscribe on connection lost)\n\n* *bool removeSubscription(char\\* topic);*\n    remove a topic from the subscription list and unsubscribe\n\n* *void publish(char\\* topic, char\\* payload);*\n    publish a given MQTT message to a given topic\n\n### ToDo\n\n* Implement callback for lost WiFi connection\n\n"
  },
  {
    "path": "examples/AdvancedFeatures/MQTT_Will/MQTT_Will.ino",
    "content": "/*    \nMQTT_Will.ino\nCopyright (c) 2018 Sk4zz All right reserved.\ngithub.com/Sk4zz\n\nThis file is part of ESPHelper\ngithub.com/ItKindaWorks\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n#include <ESP8266WiFi.h>\n#include <PubSubClient.h>\n#include \"ESPHelper.h\"\n\n#define INTERNAL_LED 2        //Set Pin Number for the internal LED this is for ESP-12E\n#define STATUS_TOPIC \"test/status\"        //Set the default topic to publish status messages\n\n\n// Update these with values suitable for your network.\nnetInfo homeNet = {  .mqttHost = \"192.168.2.3\",     //can be blank if not using MQTT\n          .mqttUser = \"\",   //can be blank\n          .mqttPass = \"\",   //can be blank\n          .mqttPort = 1883,         //default port for MQTT is 1883 - only chance if needed.\n          .ssid = \"\",\n          .pass = \"\",\n          .otaPassword = \"\",  //password for OTA flashing. can be left blank\n          .hostname =\"ESP8266\",     //Hostname of the board\n          .willTopic = STATUS_TOPIC,      //Topic for Last Will\n          .willMessage = \"offline\",       //Last Will message\n          .willQoS = 1,                   //QoS of last will message\n          .willRetain = 1};               //Retain flag for last will message\n\nESPHelper myESP(&homeNet);\n\nbool MQTT_Connection;\n\nbool checkMqttConnection() {\n  // Check if the Connection status has changed.\n  // If Status changed to FULL_CONNECTION publish \"online\" status message on STATUS_TOPIC\n  // Toggle the INTERNAL_LED\n  if( MQTT_Connection != (myESP.getStatus() == FULL_CONNECTION) ){\n    MQTT_Connection = (myESP.getStatus() == FULL_CONNECTION);\n    if (MQTT_Connection) {\n      Serial.print(\"Full Connection established. publishing status on Topic \");\n      Serial.println(STATUS_TOPIC);\n      myESP.publish(STATUS_TOPIC, \"online\", true);      \n    }\n    digitalWrite(INTERNAL_LED, !MQTT_Connection);\n  }  \n}\n\n\nvoid setup() {\n  Serial.begin(115200);\n\n  pinMode(INTERNAL_LED, OUTPUT);     // Initialize the INTERNAL_LED pin as an output\n  digitalWrite(INTERNAL_LED, HIGH);   // Switch INTERNAL_LED OFF\n  MQTT_Connection = false;\n  \n  myESP.OTA_enable();\n  myESP.addSubscription(\"test/incoming\");\n  myESP.setMQTTCallback(callback);\n  myESP.begin();\n}\n\n\nvoid callback(char* topic, byte* payload, unsigned int length) {\n  Serial.print(\"Message arrived [\");\n  Serial.print(topic);\n  Serial.print(\"] \");\n  for (int i = 0; i < length; i++) {\n    Serial.print((char)payload[i]);\n  }\n  Serial.println();\n}\n\nvoid loop() {\n  myESP.loop();  //run the loop() method as often as possible - this keeps the network services running\n\n  checkMqttConnection();\n  \n  yield();\n}\n"
  },
  {
    "path": "examples/AdvancedFeatures/arbitraryConfigKeys/arbitraryConfigKeys.ino",
    "content": "/*    \narbitraryConfigKeys.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelperFS.h\"\n\n//filename and json key to use in the demo\nconst char* file = \"/test.json\";\nconst char* keyName = \"count\";\n\nvoid setup(void){\n  Serial.begin(115200);\n\n  //load the filesystem and initialize the key to 0 (then close the FS)\n  //Note: Although it is not strictly necessary to close the FS it is still a good idea\n  //to only have the FS open as long as it is needed and then close it again to prevent\n  //possible data corruption. It does make things a bit slower but it's also safer.\n  ESPHelperFS::begin();\n  ESPHelperFS::addKey(keyName, \"0\", file);\n  ESPHelperFS::end();\n}\n\nvoid loop(void){\n\n  //load the FS and load the config file key\n  ESPHelperFS::begin();\n  String value = ESPHelperFS::loadKey(keyName, file);\n\n  \n\n  //convert the string to int and increment the counter\n  int counter = value.toInt();\n  counter++;\n\n  //print out the new value of the counter\n  Serial.print(\"Counter = \");\n  Serial.println(counter);\n\n  //convert the key back to a char string for saving\n  char dataOut[5];\n  sprintf(dataOut, \"%d\", counter);\n\n  //save the updated key and close the filesystem\n  ESPHelperFS::addKey(keyName, dataOut, file);\n  ESPHelperFS::end();\n\n  //wait for a second\n  delay(1000);\n}\n"
  },
  {
    "path": "examples/AdvancedFeatures/configAndStatusApDemo/configAndStatusApDemo.ino",
    "content": "/*    \nconfigAndStatusAPDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"ESPHelperFS.h\"\n#include \"ESPHelperWebConfig.h\"\n#include \"Metro.h\"\n\n\n//enable this to allow the device to reset if it goes into broadcast mode\n//for more than a set amount of time (3 min by default). This is useful\n//in environments where the device has a weak network signal and experiences\n//occasional dropouts. \nbool BROADCAST_TIMEOUT_EN = false;\n\nnetInfo config;\nESPHelper myESP;\n\n\n//setup a server on port 80 (http). We use an external server here because we want more than just a config page \n//but also a status page or anything else that we want to display\nESP8266WebServer server(80);\nESPHelperWebConfig configPage(&server, \"/config\");\n\n//defualt net info for unconfigured devices\nnetInfo homeNet = { .mqttHost = \"YOUR MQTT-IP\",     //can be blank if not using MQTT\n          .mqttUser = \"YOUR MQTT USERNAME\",   //can be blank\n          .mqttPass = \"YOUR MQTT PASSWORD\",   //can be blank\n          .mqttPort = 1883,         //default port for MQTT is 1883 - only chance if needed.\n          .ssid = \"YOUR SSID\", \n          .pass = \"YOUR NETWORK PASS\",\n          .otaPassword = \"YOUR OTA PASS\",\n          .hostname = \"NEW-ESP8266\"}; \n\n//timeout before starting AP mode for configuration\nMetro connectTimeout = Metro(20000);\nMetro broadcastModeTimeout = Metro(180000);\nbool timeout = false;\n\n//AP moade setup info\nconst char* broadcastSSID = \"ESP-Hotspot\";\nconst char* broadcastPASS = \"\";\nIPAddress broadcastIP = {192, 168, 1, 1};\n\n\n\n\nvoid setup(void){\n  Serial.begin(115200);\n\n  //print some debug\n  Serial.println(\"Starting Up - Please Wait...\");\n  delay(100);\n\n  //startup the wifi and web server (more in the lines below)\n  startWifi();\n\n  //setup the http server and config page (fillConfig will take the netInfo file and use that for\n  //default values)\n  configPage.fillConfig(&config);\n  configPage.begin(config.hostname);\n\n  // Actually start the server (again this would be done automatically\n  //if we were just using the config page and didnt use an external server...)\n  server.begin();\n  server.on(\"/\", HTTP_GET, handleStatus);\n}\n\n\n\nvoid loop(void){\n  //get the current status of ESPHelper\n  int espHelperStatus = myESP.loop();\n  manageESPHelper(espHelperStatus);\n\n  if(espHelperStatus >= FULL_CONNECTION){\n    //regular loop code goes here\n  }\n\n\n  delay(5);\n}\n\n\n\n\n\n\n\n\n\n\n\n//ESPHelper & config setup and runtime handler functions\n\n\n\nvoid manageESPHelper(int wifiStatus){\n  if (BROADCAST_TIMEOUT_EN && wifiStatus == BROADCAST && broadcastModeTimeout.check())\n  {\n     Serial.println(\"BROADCAST mode timeout and reset ESP\");\n     ESP.reset();\n     delay(5000);\n  } \n  //if the unit is broadcasting or connected to wifi then reset the timeout vars\n  if(wifiStatus == BROADCAST || wifiStatus >= WIFI_ONLY){\n    connectTimeout.reset();\n    timeout = false;\n  }\n  //otherwise check for a timeout condition and handle setting up broadcast\n  else if(wifiStatus < WIFI_ONLY){\n    checkForWifiTimeout();\n  }\n  //handle saving a new network config\n  if(configPage.handle()){\n    Serial.println(\"Saving new network config and restarting...\");\n    myESP.saveConfigFile(configPage.getConfig(), \"/netConfig.json\");\n    delay(500);\n    ESP.restart();\n  }\n}\n\n\n\nvoid startWifi(){\n  loadConfig();\n\n  //setup other ESPHelper info and enable OTA updates\n  myESP.setHopping(false);\n  myESP.OTA_setPassword(config.otaPassword);\n  myESP.OTA_setHostnameWithVersion(config.hostname);\n  myESP.OTA_enable();\n\n  Serial.println(\"Connecting to network\");\n  delay(10);\n  //connect to wifi before proceeding. If cannot connect then switch to ap mode and create a network to config from\n  while(myESP.loop() < WIFI_ONLY){\n    checkForWifiTimeout();\n    if(timeout){return;}\n    delay(10);\n  }\n\n  Serial.println(\"Sucess!\");\n  Serial.println(String(\"To connect to this device go to \" + String(myESP.getIP())));\n}\n\n//attempt to load a network configuration from the filesystem\nvoid loadConfig(){\n  //check for a good config file and start ESPHelper with the file stored on the ESP\n  if(ESPHelperFS::begin()){\n    Serial.println(\"Filesystem loaded - Loading Config\");\n    if(ESPHelperFS::validateConfig(\"/netConfig.json\") == GOOD_CONFIG){\n      Serial.println(\"Config loaded\");\n      delay(10);\n      myESP.begin(\"/netConfig.json\");\n    }\n\n    //if no good config can be loaded (no file/corruption/etc.) then \n    //attempt to generate a new config and restart the module\n    else{\n      Serial.println(\"Could not load config - saving new config from default values and restarting\");\n      delay(10);\n      ESPHelperFS::createConfig(&homeNet, \"/netConfig.json\");\n      ESPHelperFS::end();\n      ESP.restart();\n    }\n  }\n  \n  //if the filesystem cannot be started, just fail over to the \n  //built in network config hardcoded in here\n  else{\n    Serial.println(\"Could not load filesystem, proceeding with default config values\");\n    delay(10);\n    myESP.begin(&homeNet);\n  }\n\n  //load the netInfo from espHelper for use in the config page\n  config = myESP.getNetInfo();\n}\n\n\n//function that checks for no network connection for a period of time \n//and starting up AP mode when that time has elapsed\nvoid checkForWifiTimeout(){\n  if(connectTimeout.check() && !timeout){\n      Serial.println(\"Network Connection timeout - starting broadcast (AP) mode...\");\n      timeout = true;\n      myESP.broadcastMode(broadcastSSID, broadcastPASS, broadcastIP);\n      myESP.OTA_setPassword(config.otaPassword);\n      myESP.OTA_setHostnameWithVersion(config.hostname);\n      myESP.OTA_enable();\n      broadcastModeTimeout.reset();\n    }\n}\n\n\n//main config page that allows user to enter in configuration info\nvoid handleStatus() {      \n  server.send(200, \"text/html\", \\\n  String(\"<html>\\\n  <header>\\\n  <title>Device Info</title>\\\n  </header>\\\n  <body>\\\n    <p><strong>System Status</strong></br>\\\n    Device Name: \" + String(myESP.getHostname()) + \"</br>\\\n    Connected SSID: \" + String(myESP.getSSID()) + \"</br>\\\n    Device IP: \" + String(myESP.getIP()) + \"</br>\\\n    Uptime (ms): \" + String(millis()) + \"</p>\\\n  </body>\\\n  </html>\"));\n}\n\n\n"
  },
  {
    "path": "examples/AdvancedFeatures/configServerApDemo/configServerApDemo.ino",
    "content": "/*    \nconfigServerApDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"ESPHelperFS.h\"\n#include \"ESPHelperWebConfig.h\"\n#include \"Metro.h\"\n\nnetInfo config;\nESPHelper myESP;\nESPHelperWebConfig configPage(80, \"/\");\n\nnetInfo homeNet = { .mqttHost = \"YOUR MQTT-IP\",     //can be blank if not using MQTT\n          .mqttUser = \"YOUR MQTT USERNAME\",   //can be blank\n          .mqttPass = \"YOUR MQTT PASSWORD\",   //can be blank\n          .mqttPort = 1883,         //default port for MQTT is 1883 - only chance if needed.\n          .ssid = \"YOUR SSID\", \n          .pass = \"YOUR NETWORK PASS\",\n          .otaPassword = \"YOUR OTA PASS\",\n          .hostname = \"NEW-ESP8266\"}; \n\nMetro connectTimeout = Metro(20000);\nbool timeout = false;\n\nconst char* broadcastSSID = \"ESP-Hotspot\";\nconst char* broadcastPASS = \"\";\nIPAddress broadcastIP = {192, 168, 1, 1};\n\n\n\nvoid setup(void){\n  Serial.begin(115200);\n\n  //print some debug\n  Serial.println(\"Starting Up - Please Wait...\");\n  delay(100);\n\n  //startup the wifi and web server\n  startWifi();\n  configPage.begin(config.hostname);\n}\n\n\n\nvoid loop(void){\n  //get the current status of ESPHelper\n  int espHelperStatus = myESP.loop();\n  manageESPHelper(espHelperStatus);\n\n  if(espHelperStatus >= FULL_CONNECTION){\n    //regular loop code goes here\n  }\n\n\n  delay(5);\n}\n\n\n\n\n\n\n\n\n\n\n\n//ESPHelper & config setup and runtime handler functions\n\n\n\nvoid manageESPHelper(int wifiStatus){\n  //if the unit is broadcasting or connected to wifi then reset the timeout vars\n  if(wifiStatus == BROADCAST || wifiStatus >= WIFI_ONLY){\n    connectTimeout.reset();\n    timeout = false;\n  }\n  //otherwise check for a timeout condition and handle setting up broadcast\n  else if(wifiStatus < WIFI_ONLY){\n    checkForWifiTimeout();\n  }\n  //handle saving a new network config\n  if(configPage.handle()){\n    Serial.println(\"Saving new network config and restarting...\");\n    myESP.saveConfigFile(configPage.getConfig(), \"/netConfig.json\");\n    delay(500);\n    ESP.restart();\n  }\n}\n\n\n\nvoid startWifi(){\n  loadConfig();\n\n  //setup other ESPHelper info and enable OTA updates\n  myESP.setHopping(false);\n  myESP.OTA_setPassword(config.otaPassword);\n  myESP.OTA_setHostnameWithVersion(config.hostname);\n  myESP.OTA_enable();\n\n  Serial.println(\"Connecting to network\");\n  delay(10);\n  //connect to wifi before proceeding. If cannot connect then switch to ap mode and create a network to config from\n  while(myESP.loop() < WIFI_ONLY){\n    checkForWifiTimeout();\n    if(timeout){return;}\n    delay(10);\n  }\n\n  Serial.println(\"Sucess!\");\n  Serial.println(String(\"To connect to this device go to \" + String(myESP.getIP())));\n}\n\n//attempt to load a network configuration from the filesystem\nvoid loadConfig(){\n  //check for a good config file and start ESPHelper with the file stored on the ESP\n  if(ESPHelperFS::begin()){\n    Serial.println(\"Filesystem loaded - Loading Config\");\n    if(ESPHelperFS::validateConfig(\"/netConfig.json\") == GOOD_CONFIG){\n      Serial.println(\"Config loaded\");\n      delay(10);\n      myESP.begin(\"/netConfig.json\");\n    }\n\n    //if no good config can be loaded (no file/corruption/etc.) then \n    //attempt to generate a new config and restart the module\n    else{\n      Serial.println(\"Could not load config - saving new config from default values and restarting\");\n      delay(10);\n      ESPHelperFS::createConfig(&homeNet, \"/netConfig.json\");\n      ESPHelperFS::end();\n      ESP.restart();\n    }\n  }\n  \n  //if the filesystem cannot be started, just fail over to the \n  //built in network config hardcoded in here\n  else{\n    Serial.println(\"Could not load filesystem, proceeding with default config values\");\n    delay(10);\n    myESP.begin(&homeNet);\n  }\n\n  //load the netInfo from espHelper\n  config = myESP.getNetInfo();\n}\n\n\n//function that checks for no network connection for a period of time \n//and starting up AP mode when that time has elapsed\nvoid checkForWifiTimeout(){\n  if(connectTimeout.check() && !timeout){\n      Serial.println(\"Network Connection timeout - starting broadcast (AP) mode...\");\n      timeout = true;\n      myESP.broadcastMode(broadcastSSID, broadcastPASS, broadcastIP);\n      myESP.OTA_setPassword(config.otaPassword);\n      myESP.OTA_setHostnameWithVersion(config.hostname);\n      myESP.OTA_enable();\n    }\n}\n\n\n"
  },
  {
    "path": "examples/AdvancedFeatures/configServerDemo/configServerDemo.ino",
    "content": "/*    \nconfigServerDemo.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"ESPHelperFS.h\"\n#include \"ESPHelperWebConfig.h\"\n\nnetInfo config;\nESPHelper myESP;\nESPHelperWebConfig configPage(80, \"/\");\n\nnetInfo homeNet = { .mqttHost = \"YOUR MQTT-IP\",     //can be blank if not using MQTT\n          .mqttUser = \"YOUR MQTT USERNAME\",   //can be blank\n          .mqttPass = \"YOUR MQTT PASSWORD\",   //can be blank\n          .mqttPort = 1883,         //default port for MQTT is 1883 - only chance if needed.\n          .ssid = \"YOUR SSID\", \n          .pass = \"YOUR NETWORK PASS\",\n          .otaPassword = \"YOUR OTA PASS\",\n          .hostname = \"NEW-ESP8266\"}; \n\nvoid setup(void){\n  loadConfig();\n\n  //setup other ESPHelper info and enable OTA updates\n  myESP.setHopping(false);\n  myESP.OTA_setPassword(config.otaPassword);\n  myESP.OTA_setHostnameWithVersion(config.hostname);\n  myESP.OTA_enable();\n\n  //startup the config page\n  configPage.begin(config.hostname);\n}\n\nvoid loop(void){\n  if(myESP.loop() >= FULL_CONNECTION){\n    //regular loop code goes here\n  }\n\n\n\n\n  //handle saving a new network config\n  if(configPage.handle()){\n    Serial.println(\"Saving new network config and restarting...\");\n    myESP.saveConfigFile(configPage.getConfig(), \"/netConfig.json\");\n    delay(500);\n    ESP.restart();\n  }\n\n  delay(5);\n}\n\n\n\n\n//attempt to load a network configuration from the filesystem\nvoid loadConfig(){\n  //check for a good config file and start ESPHelper with the file stored on the ESP\n  if(ESPHelperFS::begin()){\n    Serial.println(\"Filesystem loaded - Loading Config\");\n    if(ESPHelperFS::validateConfig(\"/netConfig.json\") == GOOD_CONFIG){\n      Serial.println(\"Config loaded\");\n      delay(10);\n      myESP.begin(\"/netConfig.json\");\n    }\n\n    //if no good config can be loaded (no file/corruption/etc.) then \n    //attempt to generate a new config and restart the module\n    else{\n      Serial.println(\"Could not load config - saving new config from default values and restarting\");\n      delay(10);\n      ESPHelperFS::createConfig(&homeNet, \"/netConfig.json\");\n      ESPHelperFS::end();\n      ESP.restart();\n    }\n  }\n  \n  //if the filesystem cannot be started, just fail over to the \n  //built in network config hardcoded in here\n  else{\n    Serial.println(\"Could not load filesystem, proceeding with default config values\");\n    delay(10);\n    myESP.begin(&homeNet);\n  }\n\n  //load the netInfo from espHelper\n  config = myESP.getNetInfo();\n}\n"
  },
  {
    "path": "examples/AdvancedFeatures/multiNetwork/multiNetwork.ino",
    "content": "/*    \nMultiNetwork.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n\n\n//set this info for your own network\nnetInfo homeNet1 = {.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\t\t\t\t\t\nnetInfo homeNet2 = {.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nnetInfo homeNet3 = {.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nnetInfo *knownNetworks[3] = {\n\t&homeNet1,\n\t&homeNet2,\n\t&homeNet3\n};\n\nESPHelper myESP(knownNetworks, 3);   \n\nvoid setup() {\n\t\n\tSerial.begin(115200);\t//start the serial line\n\tdelay(500);\n\n\tSerial.println(\"Starting Up, Please Wait...\");\n\n\t// myESP.setHopping(false);\t//uncomment to prevent hopping between networks in network array\n\n\tmyESP.addSubscription(\"/test\");\n\tmyESP.setMQTTCallback(callback);\n\tmyESP.begin();\n\t\n\tSerial.println(\"Initialization Finished.\");\n}\n\nvoid loop(){\n\tmyESP.loop();\t//run the loop() method as often as possible - this keeps the network services running\n\n\t//Put application code here\n\n\tyield();\n}\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\t//put mqtt callback code here\n}"
  },
  {
    "path": "examples/AdvancedFeatures/secureMQTT/secureMQTT.ino",
    "content": "/*    \n    secureMQTT.ino\n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"Metro.h\"\n\n#define SSID            \"YOUR SSID\"\n#define NETWORK_PASS    \"YOUR NETWORK PASS\"\n\n#define MQTT_HOST       \"MQTT_HOST\"\n#define MQTT_USERNAME   \"YOUR_MQTT_USERNAME\"\n#define MQTT_PASS       \"YOUR_MQTT_PASSWORD\"\n#define MQTT_PORT       1883\n#define MQTT_TOPIC      \"/test\"\n\n//SHA1 fingerprint for the host that you want to connect to.\nconst char* fingerprint = \"11:22:33:44:55:66:77:88:99:AA:BB:CC:EE:FF:11:22:33:44:55:66\";\n\n\n//Metro timer for 5 second intervals (used to time publishing to MQTT)\nMetro postMetro = Metro(5000);\n\n\nnetInfo homeNet = { .mqttHost = MQTT_HOST,\n                    .mqttUser = MQTT_USERNAME,   \n                    .mqttPass = MQTT_PASS,\n                    .mqttPort = MQTT_PORT,                   //default port for MQTT is 1883 - only change if needed.\n                    .ssid = SSID, \n                    .pass = NETWORK_PASS};\n\nESPHelper myESP(&homeNet);\n\n\nint counter = 0;\n\n\nvoid setup() {\n\tSerial.begin(115200);\n\n    //setup ESPHelper\n    myESP.useSecureClient(fingerprint);\n    myESP.setMQTTCallback(callback);\n    myESP.addSubscription(MQTT_TOPIC);\n\tmyESP.begin();\n}\n\n\nvoid loop(){\n\n    //check and make sure that we have a full connection to both WIFI and MQTT\n    //and only post if the timer has gone off\n    if(myESP.loop() == FULL_CONNECTION && postMetro.check()){\n        //print to the serial line\n        Serial.print(counter);\n        Serial.println(\" Sent\");\n\n        //generate a string from our counter variable\n        char pubString[10];\n        itoa(counter, pubString, 10);\n\n        //publish the data to MQTT\n        myESP.publish(MQTT_TOPIC, pubString);\n\n        //increment the counter\n        counter++;  \n    }\n\n\n    yield();\n}\n\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\n    //generate a new payload string that is null terminated\n    char newPayload[40];\n    memcpy(newPayload, payload, length);\n    newPayload[length] = '\\0';\n\n    //print that info back out the the serial line\n    Serial.print(newPayload);\n    Serial.println(\" Received\");\n}\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "examples/GettingStarted/Adafruit_IO/Adafruit_IO.ino",
    "content": "/*    \n    Adafruit_IO.ino\n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"Metro.h\"\n\n#define SSID            \"YOUR SSID\"\n#define NETWORK_PASS    \"YOUR NETWORK PASS\"\n\n#define AIO_USERNAME    \"YOUR_AIO_USERNAME\"\n#define AIO_KEY         \"YOUR_AIO_KEY\"\n#define AIO_FEED        \"AIO_FEED_NAME\"\n\n\n//Metro timer for 5 second intervals (used to time publishing to MQTT)\nMetro postMetro = Metro(5000);\n\n\nnetInfo homeNet = { .mqttHost = \"io.adafruit.com\",         //can be blank if not using MQTT\n                    .mqttUser = AIO_USERNAME,   //can be blank\n                    .mqttPass = AIO_KEY,   //can be blank\n                    .mqttPort = 1883,                   //default port for MQTT is 1883 - only chance if needed.\n                    .ssid = SSID, \n                    .pass = NETWORK_PASS};\n\nESPHelper myESP(&homeNet);\n\n\nint counter = 0;\n\n\nvoid setup() {\n\tSerial.begin(115200);\n\n    //setup ESPHelper\n    myESP.setMQTTCallback(callback);\n    myESP.addSubscription(AIO_USERNAME\"/feeds/\"AIO_FEED);\n\tmyESP.begin();\n\t\n\t\n}\n\n\nvoid loop(){\n\n    //check and make sure that we have a full connection to both WIFI and MQTT\n    //and only post if the timer has gone off\n    if(myESP.loop() == FULL_CONNECTION && postMetro.check()){\n        //print to the serial line\n        Serial.print(counter);\n        Serial.println(\" Sent\");\n\n        //generate a string from our counter variable\n        char pubString[10];\n        itoa(counter, pubString, 10);\n\n        //publish the data to MQTT\n        myESP.publish(AIO_USERNAME\"/feeds/\"AIO_FEED, pubString);\n\n        //increment the counter\n        counter++;  \n    }\n\n\n    yield();\n}\n\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\n    //generate a new payload string that is null terminated\n    char newPayload[40];\n    memcpy(newPayload, payload, length);\n    newPayload[length] = '\\0';\n\n    //print that info back out the the serial line\n    Serial.print(newPayload);\n    Serial.println(\" Received\");\n}\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "examples/GettingStarted/OTA/OTA.ino",
    "content": "/*    \nOTA.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\t\n\tSerial.begin(115200);\t//start the serial line\n\tdelay(500);\n\n\tSerial.println(\"Starting Up, Please Wait...\");\n\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(\"SET OTA PASSWORD\");\n\tmyESP.OTA_setHostnameWithVersion(\"SET OTA HOSTNAME\");\n\n\tmyESP.addSubscription(\"/test\");\n\n\tmyESP.setMQTTCallback(callback);\n\tmyESP.begin();\n\t\n\tSerial.println(\"Initialization Finished.\");\n}\n\nvoid loop(){\n\tmyESP.loop();  //run the loop() method as often as possible - this keeps the network services running\n\n\t//Put application code here\n\n\tyield();\n}\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\t//put mqtt callback code here\n}"
  },
  {
    "path": "examples/GettingStarted/RelayControlV2/RelayControlV2.ino",
    "content": "/*    \n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n\n#define TOPIC \"/your/mqtt/topic\"\n#define STATUS TOPIC \"/status\"\t//dont change this - this is for the status topic which is whatever your mqtt topic is plus /status (ex /home/light/status)\n\n#define NETWORK_HOSTNAME \"YOUR OTA HOST NAME\"\n#define OTA_PASSWORD \"YOUR OTA PASSWORD\"\n\n#define RELAY_PIN 3\t\t//rx pin on esp\n#define BLINK_PIN 1\t\t//tx/led on esp-01\n#define BUTTON_PIN 0\n\n\nchar* relayTopic = TOPIC;\nchar* statusTopic = STATUS;\nchar* hostnameStr = NETWORK_HOSTNAME;\nchar* otaPassword = OTA_PASSWORD;\n\n//initialized the pins\nconst int buttonPin = BUTTON_PIN;\nconst int relayPin = RELAY_PIN;\nconst int blinkPin = BLINK_PIN;\n\n//this is the current state of the relay\nbool currentState = false;\n\n//flag to mark when a rising edge has been detected\nbool risingEdge = false;\n\n//keeps track of the previous button state for edge detection\nbool lastButtonState = false;\n\n//set this info for your own network\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\n\nvoid setup() {\n\n\t//setup Arduino OTA\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(otaPassword);\n\tmyESP.OTA_setHostnameWithVersion(hostnameStr);\n\n\t//enable the connection heartbeat\n\tmyESP.enableHeartbeat(blinkPin);\n\n\t//add a subscription to the relatTopic\n\tmyESP.addSubscription(relayTopic);\n\n\t//add in the MQTT callback\n\tmyESP.setMQTTCallback(callback);\n\n\t//start ESPHelper\n\tmyESP.begin();\n\n\t//set the button as an input\n \tpinMode(buttonPin, INPUT);\n\n \t//set the relay pin as an output and set to off\n \tpinMode(relayPin, OUTPUT);\n \tdigitalWrite(relayPin, LOW);\n}\n\n\t\nvoid loop(){\n\tif(myESP.loop() == FULL_CONNECTION){\n\n\t\t//read the state of the button (LOW is pressed)\n\t\tbool buttonState = digitalRead(buttonPin);\n\n\t\t//if the button is pressed (LOW) and previously was not pressed(HIGH)\n\t\tif(buttonState == LOW && lastButtonState == HIGH){\t\n\n\t\t\t//debounce the signal and if the button is still pressed, mark as a rising edge\n\t\t\tdelay(50);\n\t\t\tif(digitalRead(buttonPin) == LOW){\n\t\t\t\tlastButtonState = LOW;\t\t\t\n\t\t\t\trisingEdge = true;\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t\t//else if  the button is not pressed and set lastButtonState to HIGH and reset the rising edge flag\n\t\telse if(buttonState == HIGH){\t\t\n\t\t\tlastButtonState = HIGH;\n\t\t\trisingEdge = false;\n\t\t}\n\n\n\t\t//rising edge detected\n\t\tif(risingEdge){\n\n\t\t\t//set the state to the opposite of the current state\n\t\t\tsetState(!currentState);\n\n\t\t\t//reset the rising edge flag\n\t\t\trisingEdge = false;\n\t\t\t\n\t\t}\n\t}\n\tyield();\n}\n\n\nvoid callback(char* topic, byte* payload, unsigned int length) {\n\tif(payload[0] == '1'){\n\t\tsetState(true);\n\t}\n\telse{\n\t\tsetState(false);\n\t}\n}\n\n//sets a new state for the relay and publishes to MQTT\nvoid setState(bool newState){\n\n\t//dont do anything unless the newState and currentState are different\n\tif(newState != currentState){\n\n\t\t//set the current state\n\t\tcurrentState = newState;\n\n\t\t//publish to the MQTT status topic\n\t\tif(currentState){myESP.publish(statusTopic, \"1\", true);}\n\t\telse{myESP.publish(statusTopic, \"0\", true);}\n\n\t\t//set the relay on or off\n\t\tdigitalWrite(relayPin, currentState);\n\t}\n}\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "examples/GettingStarted/basicUse/basicUse.ino",
    "content": "/*    \nbasicUse.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\t\n\tSerial.begin(115200);\t//start the serial line\n\tdelay(500);\n\n\tSerial.println(\"Starting Up, Please Wait...\");\n\n\tmyESP.addSubscription(\"/test\");\n\n\tmyESP.setMQTTCallback(callback);\n\tmyESP.begin();\n\t\n\tSerial.println(\"Initialization Finished.\");\n}\n\nvoid loop(){\n\tmyESP.loop();  //run the loop() method as often as possible - this keeps the network services running\n\n\t//Put application code here\n\n\tyield();\n}\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\t//put mqtt callback code here\n}"
  },
  {
    "path": "examples/GettingStarted/basicUserPass/basicUserPass.ino",
    "content": "/*    \n    basicUserPass.ino\n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n#include \"Metro.h\"\n\n#define SSID            \"YOUR SSID\"\n#define NETWORK_PASS    \"YOUR NETWORK PASS\"\n\n#define MQTT_HOST       \"MQTT_HOST\"\n#define MQTT_USERNAME   \"YOUR_MQTT_USERNAME\"\n#define MQTT_PASS       \"YOUR_MQTT_PASSWORD\"\n#define MQTT_PORT       1883\n#define MQTT_TOPIC      \"/test\"\n\n\n//Metro timer for 5 second intervals (used to time publishing to MQTT)\nMetro postMetro = Metro(5000);\n\n\nnetInfo homeNet = { .mqttHost = MQTT_HOST,\n                    .mqttUser = MQTT_USERNAME,   \n                    .mqttPass = MQTT_PASS,\n                    .mqttPort = MQTT_PORT,                   //default port for MQTT is 1883 - only change if needed.\n                    .ssid = SSID, \n                    .pass = NETWORK_PASS};\n\nESPHelper myESP(&homeNet);\n\n\nint counter = 0;\n\n\nvoid setup() {\n\tSerial.begin(115200);\n\n    //setup ESPHelper\n    myESP.setMQTTCallback(callback);\n    myESP.addSubscription(MQTT_TOPIC);\n\tmyESP.begin();\n}\n\n\nvoid loop(){\n\n    //check and make sure that we have a full connection to both WIFI and MQTT\n    //and only post if the timer has gone off\n    if(myESP.loop() == FULL_CONNECTION && postMetro.check()){\n        //print to the serial line\n        Serial.print(counter);\n        Serial.println(\" Sent\");\n\n        //generate a string from our counter variable\n        char pubString[10];\n        itoa(counter, pubString, 10);\n\n        //publish the data to MQTT\n        myESP.publish(MQTT_TOPIC, pubString);\n\n        //increment the counter\n        counter++;  \n    }\n\n\n    yield();\n}\n\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\n    //generate a new payload string that is null terminated\n    char newPayload[40];\n    memcpy(newPayload, payload, length);\n    newPayload[length] = '\\0';\n\n    //print that info back out the the serial line\n    Serial.print(newPayload);\n    Serial.println(\" Received\");\n}\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "examples/GettingStarted/buttonDemo/buttonDemo.ino",
    "content": "/*    \n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n/*\n\tThis is a simple demo of an MQTT enabled button. A button is attahed\n\tto pin 0 with a pull-up resistor and each time the button is pressed,\n\tit toggles the state and publishes the new state to the MQTT broker.\n\tIt is also subscribed to the same topic that it publishes to so that\n\tthe state of the toggle can be updated from the MQTT side.\n*/\n#include \"ESPHelper.h\"\n\n#define TOPIC \"/your/mqtt/topic\"\n#define NETWORK_HOSTNAME \"YOUR OTA HOSTNAME\"\n#define OTA_PASSWORD \"YOUR OTA PASSWORD\"\n\n#define BUTTON_PIN 0\t//button on pin 0 with pull up resistor (pulled low on press)\n#define BLINK_PIN 1\n\n\nchar* buttonTopic = TOPIC;\nchar* hostnameStr = NETWORK_HOSTNAME;\n\nconst int buttonPin = BUTTON_PIN;\nconst int blinkPin = BLINK_PIN;\n\nbool currentState = false;\n\nbool lastButtonState = false;\n\n//set this info for your own network\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\t//setup ota on esphelper\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(OTA_PASSWORD);\n\tmyESP.OTA_setHostnameWithVersion(hostnameStr);\n\t\n\t//enable the connection heartbeat\n\tmyESP.enableHeartbeat(blinkPin);\n\n\t//subscribe to the button topic (this allows outside control of the state of the switch)\n\tmyESP.addSubscription(buttonTopic);\t\n\n\t//setup the mqtt callback function\n\tmyESP.setMQTTCallback(callback);\n\n\t//start ESPHelper\n\tmyESP.begin();\n\n\t//set the button pin as an input\n \tpinMode(buttonPin, INPUT);\n}\n\n\t\nvoid loop(){\n\tif(myESP.loop() == FULL_CONNECTION){\n\n\t\t//read the button (low on press, high on release)\n\t\tbool buttonState = digitalRead(buttonPin);\n\n\t\t//if the button is pressed (LOW) and previously was not pressed(HIGH)\n\t\tif(buttonState == LOW && lastButtonState == HIGH){\n\t\t\t//invert the current state\n\t\t\tcurrentState = !currentState;\n\n\t\t\t//publish to mqtt based on current state\n\t\t\tif(currentState){\n\t\t\t\tmyESP.publish(buttonTopic, \"1\", true);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tmyESP.publish(buttonTopic, \"0\", true);\n\t\t\t}\n\n\t\t\t//set the lastButtonState to LOW to prevent multiple triggers\n\t\t\tlastButtonState = LOW;\n\n\t\t\t//wait half a second (poor mans debounce)\n\t\t\tdelay(500);\n\t\t}\n\n\t\t//else if  the button is not pressed and set lastButtonState to HIGH\n\t\telse if(buttonState == HIGH){lastButtonState = HIGH;}\n\t}\n\tyield();\n}\n\n\nvoid callback(char* topic, byte* payload, unsigned int length) {\n\n\t//if the payload is '1' then set the state to true\n\tif(payload[0] == '1'){\n\t\tcurrentState = true;\n\t}\n\n\t//otherwise set the current state to false\n\telse{\n\t\tcurrentState = false;\n\t}\n}\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "examples/GettingStarted/relayControl/relayControl.ino",
    "content": "/*    \n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of RelayControl\n\n    RelayControl is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    RelayControl is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with RelayControl.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n/*\n\tThis is a simple MQTT relay/light controller program for the ESP8266.\n\tBy sending a '1' or '0' to the relayTopic the relayPin can be toggled\n\ton or off. This program also posts a status update to the status topic\n\twhich is the relayTopic plus \"/status\" (ex. if the relayTopic\n\tis \"/home/light\" then the statusTopic would be \"home/light/status\")\n*/\n\n#include \"ESPHelper.h\"\n\n#define TOPIC \"/your/mqtt/topic\"\n#define STATUS TOPIC \"/status\"\t//dont change this - this is for the status topic which is whatever your mqtt topic is plus /status (ex /home/light/status)\n\n#define NETWORK_HOSTNAME \"YOUR OTA HOST NAME\"\n#define OTA_PASSWORD \"YOUR OTA PASSWORD\"\n\n#define RELAY_PIN 3\t\t//rx pin on esp\n#define BLINK_PIN 1\t\t//tx/led on esp-01\n\n\nchar* relayTopic = TOPIC;\nchar* statusTopic = STATUS;\nchar* hostnameStr = NETWORK_HOSTNAME;\n\nconst int relayPin = RELAY_PIN;\nconst int blinkPin = BLINK_PIN;\t\t//tx pin on esp\n\n//set this info for your own network\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\t//setup ota\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(OTA_PASSWORD);\n\tmyESP.OTA_setHostnameWithVersion(hostnameStr);\n\t\n\n\t//setup the rest of ESPHelper\n\tmyESP.enableHeartbeat(blinkPin);\t//comment out to disable the heartbeat\n\tmyESP.addSubscription(relayTopic);\t//add the relay topic to the subscription list\n\tmyESP.setMQTTCallback(callback);\n\tmyESP.begin();\n\t\n\n\tpinMode(relayPin, OUTPUT);\n    delay(100);\n}\n\n\nvoid loop(){\n\t//loop ESPHelper and wait for commands from mqtt\n\tmyESP.loop();\n\tyield();\n}\n\n\n//mqtt callback\nvoid callback(char* topic, byte* payload, unsigned int length) {\n\tString topicStr = topic;\n\n\t//if the payload from mqtt was 1, turn the relay on and update the status topic with 1\n\tif(payload[0] == '1'){\n\t\tdigitalWrite(relayPin, HIGH);\n\t\tmyESP.publish(statusTopic, \"1\",true);\n\t}\n\n\t//else turn the relay off and update the status topic with 0\n\telse if (payload[0] == '0'){\n\t\tdigitalWrite(relayPin, LOW);\n\t\tmyESP.publish(statusTopic, \"0\", true);\n\t}\n\n}\n"
  },
  {
    "path": "examples/GettingStarted/wifiCallback/wifiCallback.ino",
    "content": "/*    \nwifiCallback.ino\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#include \"ESPHelper.h\"\n\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\t\n\tSerial.begin(115200);\t//start the serial line\n\tdelay(500);\n\n\tSerial.println(\"Starting Up, Please Wait...\");\n\n\tmyESP.addSubscription(\"/test\");\n\tmyESP.setWifiCallback(wifiCallback);\n\tmyESP.setMQTTCallback(MQTTcallback);\n\tmyESP.begin();\n\t\n\t\n\tSerial.println(\"Initialization Finished.\");\n}\n\nvoid loop(){\n\tmyESP.loop();  //run the loop() method as often as possible - this keeps the network services running\n\n\t//Put application code here\n\n\tyield();\n}\n\nvoid MQTTcallback(char* topic, uint8_t* payload, unsigned int length) {\n\t//put mqtt callback code here\n}\n\nvoid wifiCallback(){\n\tSerial.println(\"WiFi Connected!\");\n}"
  },
  {
    "path": "examples/InputOutput/RGBLight/RGBLight.ino",
    "content": "/*    \n    wifiRGB.ino\n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of wifiRGB\n\n    wifiRGB is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    wifiRGB is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with wifiRGB.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n/*\n\tThis is an MQTT RGB light controller program for the ESP8266.\n\tThe light can be controlled in one of three ways. You can send\n\tan HSB update, RGB update, or moodlight mode on/off.\n\tAll updates must be formatted correctly, see below:\n\n\tex RGB string:\t\t\t\"r255,050,000\"    \t(r = 255, g = 050, b = 000)\n\tex HSB string:\t\t\t\"h1.00,0.50,0.01\"\t(h = 1.00, s = 0.50, b = 0.01)\n\tex moodlight string:\t\"m1\"\t\t\t\t(moodlight activate)\n\n\tThis program also posts a status update to the status topic\n\twhich is the lightTopic plus \"/status\" (ex. if the lightTopic\n\tis \"/home/RGBlight\" then the statusTopic would be \"home/RGBlight/status\")\n*/\n\n#include \"ESPHelper.h\"\n#include <HSBColor.h>\n#include \"Metro.h\"\n\n#define TOPIC \"/your/mqtt/topic\"\n#define STATUS TOPIC \"/status\"\n#define NETWORK_HOSTNAME \"YOUR OTA HOSTNAME\"\n#define OTA_PASSWORD \"YOUR OTA PASSWORD\"\n\n#define RED_PIN 12\t\t\n#define GREEN_PIN 13\n#define BLUE_PIN 14\n\ntypedef struct lightState{\n\tdouble hue;\n\tdouble saturation;\n\tdouble brightness;\n\tint red;\n\tint redRate;\n\tint green;\n\tint greenRate;\n\tint blue;\n\tint blueRate;\n\tint fadePeriod;\n\tint updateType;\n};\n\ntypedef struct timer {\n\tunsigned long previousTime;\n\tint interval;\n};\n\n\n\nenum superModes {SET, MOOD};\nenum moodColors{RED, GREEN, BLUE};\nenum modes {NORMAL, FADING};\nenum updateTypes{HSB, RGB, POWER};\n\n\nlightState nextState;\n\nint superMode = SET;\t//overall mode of the light (moodlight, network controlled, etc)\nboolean newCommand = false;\n\n\nchar* lightTopic = TOPIC;\nchar* statusTopic = STATUS;\nchar* hostnameStr = NETWORK_HOSTNAME;\n\nconst int redPin = RED_PIN;\nconst int greenPin = GREEN_PIN;\nconst int bluePin = BLUE_PIN;\n\nchar statusString[50];\t//string containing the current setting for the light\n\n\n//set this info for your own network\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\n\nvoid setup() {\n\t//initialize the light as an output and set to LOW (off)\n\tpinMode(redPin, OUTPUT);\n\tpinMode(bluePin, OUTPUT);\n\tpinMode(greenPin, OUTPUT);\n\n\t//all off\n\tdigitalWrite(redPin, LOW);\t//all off\n\tdigitalWrite(greenPin, LOW);\n\tdigitalWrite(bluePin, LOW);\n\n\tdelay(1000);\n\n\tcolorTest();\n\n\t//setup ota on esphelper\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(OTA_PASSWORD);\n\tmyESP.OTA_setHostnameWithVersion(hostnameStr);\n\n\t//subscribe to the lighttopic\n\tmyESP.setMQTTCallback(callback);\n\tmyESP.addSubscription(lightTopic);\n\tmyESP.begin();\n}\n\n\n\nvoid loop(){\n\tstatic bool connected = false; //keeps track of connection state to reset from MOOD to SET when network connection is made\n\n\n\tif(myESP.loop() == FULL_CONNECTION){\n\n\t\t//if the light was previously not connected to wifi and mqtt, update the status topic with the light being off\n\t\tif(!connected){\n\t\t\tconnected = true;\t//we have reconnected so now we dont need to flag the setting anymore\n\t\t\tmyESP.publish(statusTopic, \"h0.00,0.00,0.00\t\", true);\n\t\t}\n\n\t\tlightHandler();\n\t}\n\n\t\n\tyield();\n}\n\n\nvoid lightHandler(){\n\t//new and current lightStates\n\tstatic lightState newState;\n\tstatic lightState currentState;\n\n\tstatic int currentMoodColor = 0;\t//the current moodlight chosen color\n\n\tstatic int isFading = 0;\n\n\n\t//if the super mode is mood light and the light isnt currently fading,\n\t//then change to a new color and start a new fade\n\tif(superMode == MOOD && isFading == 0){\n\t\tif(currentMoodColor == RED){\n\t\t\tnextState.red = 0;\n\t\t\tnextState.green = 1023;\n\t\t\tnextState.blue = 0;\n\t\t\tnextState.updateType = RGB;\n\t\t\tnewCommand = true;\n\t\t\tcurrentMoodColor = GREEN;\n\n\t\t}\n\t\telse if(currentMoodColor == GREEN){\n\t\t\tnextState.red = 0;\n\t\t\tnextState.green = 0;\n\t\t\tnextState.blue = 1023;\n\t\t\tnextState.updateType = RGB;\n\t\t\tnewCommand = true;\n\t\t\tcurrentMoodColor = BLUE;\n\t\t}\n\t\telse if(currentMoodColor == BLUE){\n\t\t\tnextState.red = 1023;\n\t\t\tnextState.green = 0;\n\t\t\tnextState.blue = 0;\n\t\t\tnextState.updateType = RGB;\n\t\t\tnewCommand = true;\n\t\t\tcurrentMoodColor = RED;\n\t\t}\n\t}\n\n\tlightUpdater(&newState, currentState);\n\tisFading = lightChanger(newState, &currentState);\n\n}\n\n\n//this function actually changes the light values and does the fading\n//returns 1 if fading\n//returns 0 if not fading\n//returns -1 if the timer doesnt get triggered\nint lightChanger(lightState newState, lightState *currentState){\n\tstatic Metro changeTimer = Metro(1);\n\n\tstatic int changeMode = NORMAL;\t\t//the current mode (fading or normal)\n\tstatic int currentPeriod = 0;\t\t//time since starting the fade\n\t\n\n\t//only allow fade updates every 1ms\n\tif(changeTimer.check()){\n\n\t\t//check to see if this is there is a new command and set the mode to FADING\n\t\tif(newCommand){\n\t\t\tnewCommand = false;\n\t\t\tchangeMode = FADING;\n\t\t}\n\n\n\t\t\n\t\tif(changeMode == FADING){\n\n\t\t\t//check whether or not a fade is needed - if so update the channel velues\n\t\t\tif((newState.red != currentState->red || newState.blue != currentState->blue || newState.green != currentState->green) || (currentPeriod <= currentState->fadePeriod)){\n\n\t\t\t\tif(currentPeriod % newState.redRate == 0){\n\t\t\t\t\tif(newState.red > currentState->red){currentState->red++;}\n\t\t\t\t\telse if (newState.red < currentState->red){currentState->red--;}\n\t\t\t\t}\n\n\t\t\t\tif(currentPeriod % newState.greenRate == 0){\n\t\t\t\t\tif(newState.green > currentState->green){currentState->green++;}\n\t\t\t\t\telse if (newState.green < currentState->green){currentState->green--;}\n\t\t\t\t}\n\n\t\t\t\tif(currentPeriod % newState.blueRate == 0){\n\t\t\t\t\tif(newState.blue > currentState->blue){currentState->blue++;}\n\t\t\t\t\telse if (newState.blue < currentState->blue){currentState->blue--;}\n\t\t\t\t}\n\n\t\t\t\t//write to the analog pins\n\t\t\t\tanalogWrite(redPin, currentState->red);\n\t\t\t\tanalogWrite(greenPin, currentState->green);\n\t\t\t\tanalogWrite(bluePin, currentState->blue);\n\n\t\t\t\t//increment the period\n\t\t\t\tcurrentPeriod++;\n\t\t\t\treturn 1;\t//return 1 on mode being FADING\n\t\t\t}\n\n\t\t\t//if no fade is needed then reset the period and set the mode to NORMAL\n\t\t\telse{\n\t\t\t\tcurrentPeriod = 0;\n\t\t\t\tchangeMode = NORMAL;\n\t\t\t\treturn 0;\t//return 0 on mode being NORMAL\n\t\t\t}\n\n\t\t}\n\n\n\t\telse if (changeMode == NORMAL){\n\t\t\treturn 0;\t//return 0 on mode being NORMAL\n\t\t}\n\t\n\t}\n\n\treturn -1;\t//return -1 on timer not set off\n\n}\n\n//calculates new information (color values, fade times, etc) for \n//new color updates\nvoid lightUpdater (lightState *newState, lightState currentState){\n\n\t//calculate new vars only if there is a new command\n\tif (newCommand){\n\n\t\t//determine which kind of update this is\n\t\tif(nextState.updateType == HSB){\n\n\t\t\t//convert from HSB to RGB\n\t\t\tint newRGB[3];\n\t\t\tH2R_HSBtoRGBfloat(nextState.hue, nextState.saturation, nextState.brightness, newRGB);\n\t\t\tnewState->red = newRGB[0];\n\t\t\tnewState->green = newRGB[1];\n\t\t\tnewState->blue = newRGB[2];\n\n\t\t\t//determine the RGB difference from the current values to new values (how far each channel needs to fade)\n\t\t\tint redDiff = abs(newState->red - currentState.red);\n\t\t\tint greenDiff = abs(newState->green - currentState.green);\n\t\t\tint blueDiff = abs(newState->blue - currentState.blue);\n\n\t\t\t//calculate the new fade times for each channel (how long to wait between fading up/down)\n\t\t\tif(redDiff > 0){newState->redRate = (nextState.fadePeriod / redDiff);}\n\t\t\telse{newState->redRate = nextState.fadePeriod;}\n\n\t\t\tif(greenDiff > 0){newState->greenRate = (nextState.fadePeriod / greenDiff);}\n\t\t\telse{newState->greenRate = nextState.fadePeriod;}\n\n\t\t\tif(blueDiff > 0){newState->blueRate = (nextState.fadePeriod / blueDiff);}\n\t\t\telse{newState->blueRate = nextState.fadePeriod;}\n\n\t\t\t//set the total time to fade\n\t\t\tnewState->fadePeriod = nextState.fadePeriod;\n\n\t\t}\n\t\telse if(nextState.updateType == RGB){\n\n\t\t\t//set new RGB values from update\n\t\t\tnewState->red = nextState.red;\n\t\t\tnewState->green = nextState.green;\n\t\t\tnewState->blue = nextState.blue;\n\n\t\t\t//determine the RGB difference from the current values to new values (how far each channel needs to fade)\n\t\t\tint redDiff = abs(newState->red - currentState.red);\n\t\t\tint greenDiff = abs(newState->green - currentState.green);\n\t\t\tint blueDiff = abs(newState->blue - currentState.blue);\n\n\t\t\t//calculate the new fade times for each channel (how long to wait between fading up/down)\n\t\t\tif(redDiff > 0){newState->redRate = (nextState.fadePeriod / redDiff) + 1;}\n\t\t\telse{newState->redRate = nextState.fadePeriod;}\n\n\t\t\tif(greenDiff > 0){newState->greenRate = (nextState.fadePeriod / greenDiff) + 1;}\n\t\t\telse{newState->greenRate = nextState.fadePeriod;}\n\n\t\t\tif(blueDiff > 0){newState->blueRate = (nextState.fadePeriod / blueDiff) + 1;}\n\t\t\telse{newState->blueRate = nextState.fadePeriod;}\n\n\t\t\t//set the total time to fade\n\t\t\tnewState->fadePeriod = nextState.fadePeriod;\n\n\t\t}\n\t}\n\n}\n\n\n\n//MQTT callback\nvoid callback(char* topic, byte* payload, unsigned int length) {\n\n\t//convert topic to string to make it easier to work with\n\tString topicStr = topic; \n\n\tchar newPayload[40];\n\tmemcpy(newPayload, payload, length);\n\tnewPayload[length] = '\\0';\n\n\t//handle HSB updates\n\tif(payload[0] == 'h'){\n\t\tnextState.hue = atof(&newPayload[1]);\n\t\tnextState.saturation = atof(&newPayload[7]);\n\t\tnextState.brightness = atof(&newPayload[13]);\n\n\t\tnextState.updateType = HSB;\n\t\tnextState.fadePeriod = 2100;\n\t\tnewCommand = true;\n\t\tsuperMode = SET;\n\n\t}\n\n\t//handle RGB updates\n\telse if (payload[0] == 'r'){\n\t\tint newRed = atoi(&newPayload[1]);\n\t\tint newGreen = atoi(&newPayload[5]);\n\t\tint newBlue = atoi(&newPayload[9]);\n\n\t\tnextState.red = newRed;\n\t\tnextState.green = newGreen;\n\t\tnextState.blue = newBlue;\n\n\t\tnextState.updateType = RGB;\n\t\tnewCommand = true;\n\t\tnextState.fadePeriod = 2100;\n\t\tsuperMode = SET;\n\t}\n\n\t//handle moodlight updates\n\telse if(payload[0] == 'm'){\n\n\t\tif(payload[1] == '1'){\n\t\t\tsuperMode = MOOD;\n\t\t\tnextState.fadePeriod = 10000;\n\t\t\tnewCommand = true;\n\t\t}\n\t\telse if(payload[1] == '0'){\n\t\t\tsuperMode = SET;\n\t\t\tnextState.fadePeriod = 2100;\n\t\t\tnewCommand = true;\n\t\t}\n\t}\n\n\n\t//package up status message reply and send it back out to the status topic\n\tstrcpy(statusString, newPayload);\n\tmyESP.publish(statusTopic, statusString, true);\n}\n\n\n\n\nvoid colorTest(){\n\tdigitalWrite(redPin, HIGH);\t//red on\n\tdelay(500);\n\tdigitalWrite(redPin, LOW);\t//green on\n\tdigitalWrite(greenPin, HIGH);\n\tdelay(500);\n\tdigitalWrite(greenPin, LOW);\t//blue on\n\tdigitalWrite(bluePin, HIGH);\n\tdelay(500);\n\n\tdigitalWrite(redPin, HIGH);\t//all on\n\tdigitalWrite(greenPin, HIGH);\n\tdigitalWrite(bluePin, HIGH);\n\tdelay(500);\n\tdigitalWrite(redPin, LOW);\t//all off\n\tdigitalWrite(greenPin, LOW);\n\tdigitalWrite(bluePin, LOW);\n}\n\n\nchar *ftoa(char *a, double f, int precision)\n{\n long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};\n \n char *ret = a;\n long heiltal = (long)f;\n itoa(heiltal, a, 10);\n while (*a != '\\0') a++;\n *a++ = '.';\n long desimal = abs((long)((f - heiltal) * p[precision]));\n itoa(desimal, a, 10);\n return ret;\n}\n\n\n\n\nfloat map_double(double x, double in_min, double in_max, double out_min, double out_max)\n{\n  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;\n}\n\n\n"
  },
  {
    "path": "examples/InputOutput/temperatureSensor_ds18b20/temperatureSensor_ds18b20.ino",
    "content": "/*    \n    Copyright (c) 2017 ItKindaWorks All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n/*\n\tThis is a simple program that periodically (10 seconds) reads a ds18b20 temperature\n\tsensor and publishes the result to an MQTT topic. Change the Topic/Hostname/OTA Password \n\tand network settings to match your system.\n*/\n\n#include \"ESPHelper.h\"\n#include <Metro.h>\n#include <OneWire.h>\n#include <DallasTemperature.h>\n\n#define TEMP_TOPIC \"/your/mqtt/topic\"\n#define NETWORK_HOSTNAME \"YOUR OTA HOSTNAME\"\n#define OTA_PASSWORD \"YOUR OTA PASSWORD\"\n\n#define ONE_WIRE_BUS 2\n#define BLINK_PIN 1\n\nchar* tempTopic = TEMP_TOPIC;\nchar* hostnameStr = NETWORK_HOSTNAME;\nconst int wireBus = ONE_WIRE_BUS;\nconst int blinkPin = BLINK_PIN;\n\n\n//the current temperature\nfloat currentTemp = 0;\n\n//timer to set how often the sensor should publish to mqtt (in ms)\nMetro publishTimer = Metro(10000);\n\n//ds18b20 variables\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&oneWire);\n\n//set this info for your own network\nnetInfo homeNet = {\t.mqttHost = \"YOUR MQTT-IP\",\t\t\t//can be blank if not using MQTT\n\t\t\t\t\t.mqttUser = \"YOUR MQTT USERNAME\", \t//can be blank\n\t\t\t\t\t.mqttPass = \"YOUR MQTT PASSWORD\", \t//can be blank\n\t\t\t\t\t.mqttPort = 1883,\t\t\t\t\t//default port for MQTT is 1883 - only chance if needed.\n\t\t\t\t\t.ssid = \"YOUR SSID\", \n\t\t\t\t\t.pass = \"YOUR NETWORK PASS\"};\n\nESPHelper myESP(&homeNet);\n\nvoid setup() {\n\n\t//setup ota on esphelper\n\tmyESP.OTA_enable();\n\tmyESP.OTA_setPassword(OTA_PASSWORD);\n\tmyESP.OTA_setHostnameWithVersion(hostnameStr);\n\t\n\t//enable the connection heartbeat\n\tmyESP.enableHeartbeat(blinkPin);\n\n\t//start ESPHelper\n\tmyESP.begin();\n\n\t//start the dallas temperature sensor library\n\tsensors.begin();\n\tdelay(500);\t\n}\n\nvoid loop(){\n\t\n\n\twhile(1){\n\t\tif(myESP.loop() == FULL_CONNECTION){\n\n\t\t\t//only read/publish the temperature if the timer is up\n\t\t\tif(publishTimer.check()){\n\n\t\t\t\tsensors.requestTemperatures(); // Send the command to get temperatures\n\t\t\t\tcurrentTemp = sensors.getTempCByIndex(0);\t//get the temperature\n\n\t\t\t\t//convert the float to a string\n\t\t\t\tchar temperature[10];\n\t\t\t\tdtostrf(currentTemp,4,1,temperature);\n\n\t\t\t\t//publish to mqtt\n\t\t\t\tmyESP.publish(tempTopic,temperature, true);\t\n\t\t\t}\n\t\t}\n\n\t\tyield();\n\t}\n\t\n}\n\n\nvoid callback(char* topic, uint8_t* payload, unsigned int length) {\n\n}\n\n\n\n\n\n\n\n"
  },
  {
    "path": "keywords.txt",
    "content": "#######################################\n# Syntax Coloring Map For ESPHelper\n#######################################\n\n#######################################\n# Datatypes (KEYWORD1)\n#######################################\n\nESPHelper\tKEYWORD1\nESPHelperFS\tKEYWORD1\nESPHelperWebConfig\tKEYWORD1\nnetInfo\tKEYWORD1\nsubscription \tKEYWORD1\n\n#######################################\n# Methods and Functions (KEYWORD2)\n#######################################\n\nbegin \tKEYWORD2\nend \tKEYWORD2\nuseSecureClient \tKEYWORD2\nbroadcastMode \tKEYWORD2\ndisableBroadcast \tKEYWORD2\nloop \tKEYWORD2\nsubscribe \tKEYWORD2\naddSubscription \tKEYWORD2\nremoveSubscription \tKEYWORD2\nunsubscribe \tKEYWORD2\npublish \tKEYWORD2\nsetCallback\tKEYWORD2\nsetMQTTCallback \tKEYWORD2\nsetWifiCallback \tKEYWORD2\nreconnect \tKEYWORD2\nupdateNetwork \tKEYWORD2\ngetSSID\tKEYWORD2\nserSSID\tKEYWORD2\ngetPASS\tKEYWORD2\nsetPass\tKEYWORD2\ngetMQTTIP\tKEYWORD2\nsetMQTTIP\tKEYWORD2\ngetMQTTQOS \tKEYWORD2\nsetMQTTQOS \tKEYWORD2\nsetWill\tKEYWORD2\ngetIP\tKEYWORD2\ngetIPAddress \tKEYWORD2\ngetNetInfo\tKEYWORD2\nsetNetInfo\tKEYWORD2\nsetHopping\tKEYWORD2\nlistSubscriptions\tKEYWORD2\nheartbeat \tKEYWORD2\nenableHeartbeat\tKEYWORD2\ndisableHeartbeat\tKEYWORD2\nOTA_enable\tKEYWORD2\nOTA_disable\tKEYWORD2\nOTA_begin\tKEYWORD2\nOTA_setPassword\tKEYWORD2\nOTA_setHostname\tKEYWORD2\nOTA_setHostnameWithVersion \tKEYWORD2\n\n#######################################\n# Constants (LITERAL1)\n#######################################\n\nMAX_SUBSCRIPTIONS \tLITERAL1\nDEFAULT_QOS \tLITERAL1\nVERSION \tLITERAL1\n"
  },
  {
    "path": "library.json",
    "content": "{\n    \"name\": \"ESPHelper\",\n    \"authors\":\n    {\n        \"name\": \"ItKindaWorks\",\n        \"email\": \"itkindaworksinc@gmail.com\",\n        \"url\": \"http://itkindaworks.com\"\n    },\n    \"repository\":\n    {\n        \"type\": \"git\",\n        \"url\": \"https://github.com/ItKindaWorks/ESPHelper\"\n    },\n    \"license\": \"GPL-3.0-or-later\",\n    \"keywords\": \"mqtt, iot, esp8266, esp32, ota\",\n    \"description\": \"A library to make using WiFi & MQTT on the ESP8266 & ESP32 easy.\",\n    \"version\": \"2.0.4\",\n    \"examples\": \"examples/*/*.ino\",\n    \"frameworks\": \"arduino\",\n    \"platforms\": [\n        \"espressif\",\n        \"espressif32\"\n    ],\n    \"dependencies\": {\n        \"bblanchon/ArduinoJson\": \"@^7.0.4\",\n        \"itkindaworks/Metro\": \"@^1.0.1\",\n        \"knolleary/PubSubClient\": \"@2.8\",\n        \"powerbroker2/SafeString\": \"@^4.1.30\",\n        \"esp32async/ESPAsyncWebServer\": \"@ ^3.6.0\"\n    }\n    \n}"
  },
  {
    "path": "src/ESPHelper.cpp",
    "content": "/*\n    ESPHelper.cpp\n    Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n#include \"ESPHelper.h\"\n#include <WiFiClientSecure.h>\n\n\n\n\nvoid printNetInfo(const NetInfo *net, const char* header, bool printMQTT, bool printWill){\n\tdebugPrintln(header);\n\tdebugPrint(\"Hostname: \");\n\tdebugPrintln(net->getHostname());\n\tdebugPrint(\"SSID: \");\n\tdebugPrintln(net->getSsid());\n\tdebugPrint(\"PASS: \");\n\tdebugPrintln(net->getPass());\n\tif (printMQTT) {\n\t\tdebugPrint(\"MQTT Host: \");\n\t\tdebugPrintln(net->getMqttHost());\n\t\tdebugPrint(\"MQTT User: \");\n\t\tdebugPrintln(net->getMqttUser());\n\t\tdebugPrint(\"MQTT Pass: \");\n\t\tdebugPrintln(net->getMqttPass());\n\t\tdebugPrint(\"MQTT Port: \");\n\t\tdebugPrintln(net->getMqttPort());\n\t}\n\tif (printWill) {\n\t\tdebugPrint(\"Will Topic: \");\n\t\tdebugPrintln(net->getMqttWillTopic());\n\t\tdebugPrint(\"Will Message: \");\n\t\tdebugPrintln(net->getMqttWillMessage());\n\t\tdebugPrint(\"Will QoS: \");\n\t\tdebugPrintln(net->getMqttWillQoS());\n\t\tdebugPrint(\"Will Retain: \");\n\t\tdebugPrintln(net->getMqttWillRetain() ? \"true\" : \"false\");\n\t}\n}\n\n/*\nempty initializer wrapper\nused for creating instances of ESPHelper that will be filled in later from a loaded config file\n\ninput: NA\noutput: NA\n*/\nESPHelper::ESPHelper(){\n\t_currentNet.setSsid(\"\");\n\t_currentNet.setPass(\"\");\n\t_currentNet.setMqttHost(\"\");\n\t_currentNet.setMqttUser(\"\");\n\t_currentNet.setMqttPass(\"\");\n\t_currentNet.setMqttPort(1883);\n\t_currentNet.setMqttWillTopic(\"defaultWillTopic\");\n\t_currentNet.setMqttWillMessage(\"offline\");\n\t_currentNet.setMqttWillQoS (0);\n\t_currentNet.setMqttWillRetain(true);\n\tinit();\n}\n\n\n/*\ninitializer wrapper with single NetInfo network\n\ninput: NetInfo ptr\noutput: NA\n*/\nESPHelper::ESPHelper(const NetInfo *startingNet, bool storeLocal){\n\tif (startingNet) {\n\t\tstartingNet->cloneTo(_currentNet, storeLocal);\n\t} \n\t//if the starting net is null then we set the default values and store locally\n\telse {\n\t\t_currentNet.setSsid(\"\");\n\t\t_currentNet.setPass(\"\");\n\t\t_currentNet.setMqttHost(\"\");\n\t\t_currentNet.setMqttUser(\"\");\n\t\t_currentNet.setMqttPass(\"\");\n\t\t_currentNet.setMqttPort(1883);\n\t\t_currentNet.setMqttWillTopic(\"defaultWillTopic\");\n\t\t_currentNet.setMqttWillMessage(\"offline\");\n\t\t_currentNet.setMqttWillQoS (0);\n\t\t_currentNet.setMqttWillRetain(true);\n\t}\n\t\n\tinit();\n\t\n}\n\n\n\n\n/*\ninitialize the NetInfo data and reset wifi. set hopping and OTA to off\n\ninput: \n\tchar ptr for network SSID\n\tchar ptr for network Password\n\tchar ptr for MQTT broker IP (or hostname)\n\tchar ptr for MQTT username\n\tchar ptr for MQTT password\n\tint for MQTT port\n\tchar ptr for MQTT last will topic\n\tchar ptr for MQTT last will message\n\tint for MQTT will QOS\n\tint for MQTT will retain\noutput: NA\n*/\nvoid ESPHelper::init(){\n\t//diconnect from and previous wifi networks\n    WiFi.softAPdisconnect();\n\tWiFi.disconnect();\n\t\n\t//validate various bits of network/MQTT info\n\tvalidateConfig();\n}\n\n\n\n/*\nchecks which parts of a NetInfo have been filled out\nand updates internal flags noting which are set\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::validateConfig(){\n\t//network pass\n\tif(_currentNet.getPass()[0] == '\\0'){_passSet = false;}\n\telse{_passSet = true;}\n\n\t//ssid\n\tif(_currentNet.getSsid()[0] == '\\0'){_ssidSet = false;}\n\telse{_ssidSet = true;}\n\n\t//mqtt host\n\tif(_currentNet.getMqttHost()[0] == '\\0'){_mqttSet = false;}\n\telse{_mqttSet = true;}\n\n\t//mqtt port\n  \tif(_currentNet.getMqttPort() == 0){_currentNet.setMqttPort(1883);}\n\n  \t//mqtt username\n\tif(_currentNet.getMqttUser()[0] == '\\0'){_mqttUserSet = false;}\n\telse{_mqttUserSet = true;}\n\n\t//mqtt password\n\tif(_currentNet.getMqttPass()[0] == '\\0'){_mqttPassSet = false;}\n\telse{_mqttPassSet = true;}\n\n\t//Will Topic\n\tif(_currentNet.getMqttWillTopic()[0] == '\\0'){_willTopicSet = false;}\n\telse{_willTopicSet = true;}\n\n\t//Will Message\n\tif(_currentNet.getMqttWillMessage()[0] == '\\0'){_willMessageSet = false;}\n\telse{_willMessageSet = true;}\n\n}\n\n\n\nbool ESPHelper::begin(const NetInfo *startingNet, bool storeLocal){\n\t// If a starting net is provided\n\tif (startingNet) {\n\t\tstartingNet->cloneTo(_currentNet, storeLocal);\n\t} \n\n\t//if the starting net is null then we set the default values and store locally\n\telse {\n\t\t_currentNet.setSsid(\"\");\n\t\t_currentNet.setPass(\"\");\n\t\t_currentNet.setMqttHost(\"\");\n\t\t_currentNet.setMqttUser(\"\");\n\t\t_currentNet.setMqttPass(\"\");\n\t\t_currentNet.setMqttPort(1883);\n\t\t_currentNet.setMqttWillTopic(\"defaultWillTopic\");\n\t\t_currentNet.setMqttWillMessage(\"offline\");\n\t\t_currentNet.setMqttWillQoS (0);\n\t\t_currentNet.setMqttWillRetain(true);\n\t}\n\n\tinit();\n\treturn begin();\n}\n\n\n/*\nstart the wifi & mqtt systems and attempt connection (currently blocking)\nreturn values from this function are somewhat legacy as data validation takes place elsewhere now\n\ninput: NA\noutput:\n\ttrue on: ssid set \n\tfalse on: ssid not set\n*/\nbool ESPHelper::begin(){\n\n\t// Generate client name based on MAC address and last 8 bits of microsecond counter\n\t#ifdef ESP8266\n\t_clientName = \"esp8266-\";\n\t#else\n\t_clientName = \"esp32-\";\n\t#endif\n\tuint8_t mac[6];\n\tWiFi.macAddress(mac);\n\t_clientName += macToStr(mac);\n\n\t//set the wifi mode to station\n\tWiFi.mode(WIFI_STA);\n\n\t//as long as the SSID has been set, then try to connect to the network\n\tif(_ssidSet){\n\n\t\t// printNetInfo(&_currentNet, \"Pre wifi begin\", _mqttSet, _willTopicSet);\n\t\tif(_passSet){WiFi.begin(_currentNet.getSsid(), _currentNet.getPass());}\n\t\telse{WiFi.begin(_currentNet.getSsid());}\n\n\t\tWiFi.setAutoReconnect(true);\n\t\tWiFi.setSleep(false);\n\t\t\n\n\t\t//as long as an mqtt ip has been set create an instance of PubSub for client\n\t\tif(_mqttSet){\n\t\t\tclient.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());\n\n\t\t\t//set the mqtt message callback if needed\n\t\t\tif(_mqttCallbackSet){client.setCallback(_mqttCallback);}\n\t\t}\n\n\t\t//define a dummy instance of mqtt so that it is instantiated if no mqtt ip is set\n\t\telse{\n\t\t\tclient.setServer(\"192.0.2.0\", _currentNet.getMqttPort());\n\t\t}\n\n\n\t\t//set the mqtt client to use the secure client if available\n\t\tif(_useSecureClient){client.setClient(wifiClientSecure);}\n\t\telse{client.setClient(wifiClient);}\n\n\n\t\t//ota event handlers\n\t\tArduinoOTA.onStart([]() {/* ota start code */});\n\t\tArduinoOTA.onEnd([]() {\n\t\t\t//give the arduino a bit of time to finish up any remaining network activity\n\t\t\tdelay(500);\n\t\t\t//on ota end we disconnect from wifi cleanly before restarting.\n\t\t\tWiFi.softAPdisconnect();\n\t\t\tWiFi.disconnect();\n\t\t\tint timeout = 0;\n\t\t\t//max timeout of 2seconds before just dropping out and restarting\n\t\t\twhile(WiFi.status() != WL_DISCONNECTED && timeout < 200){\n\t\t\t\tdelay(10);\n\t\t\t\ttimeout++;\n\t\t\t}\n\t\t});\n\t\tArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {/* ota progress code */});\n\t\tArduinoOTA.onError([](ota_error_t error) {/* ota error code */});\n\n\n\t\t//initially attempt to connect to wifi when we begin (but only block for 2 seconds before timing out)\n\t\tint timeout = 0;\t//counter for begin connection attempts\n\t\twhile (((!client.connected() && _mqttSet) || WiFi.status() != WL_CONNECTED) && timeout < 200 ) {\t//max 2 sec before timeout\n\t\t\t// printNetInfo(&_currentNet, \"ESPHelper Begin reconnect loop\", _mqttSet, _willTopicSet);\n\t\t\treconnect();\n\t\t\tdelay(10);\n\t\t\ttimeout++;\n\t\t}\n\n\t\t//attempt to start ota if needed\n\t\tOTA_begin();\n\n\t\t//mark the system as started and return\n\t\t_hasBegun = true;\n\t\treturn true;\n\t}\n\n\t//if no ssid was set even then dont try to begin and return false\n\treturn false;\n}\n\n\n/*\nend the instance of ESPHelper (shutdown wifi, ota, mqtt)\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::end(){\n\tOTA_disable();\n\tclient.disconnect();\n\tdelay(20);\n\tWiFi.softAPdisconnect();\n\tWiFi.disconnect();\n\n\tint timeout = 0;\n\twhile(WiFi.status() != WL_DISCONNECTED && timeout < 200){\n\t\tdelay(10);\n\t\ttimeout++;\n\t}\n\n\t_connectionStatus = NO_CONNECTION;\n\n}\n\n\n\n\n/*\nenables the use of a secure (SSL) connection to an MQTT broker.\n(Make sure your mqtt port is set to one expecting a secure connection)\n\ninput: char ptr string for SSL fingerprint\noutput: NA\n*/\nvoid ESPHelper::useSecureClient(const char* fingerprint){\n\t_fingerprint = fingerprint;\n\n\t//fall back to wifi only connection if it was previously at full connection\n\t//(because we just changed how the device is going to connect to the mqtt broker)\n\tif(setConnectionStatus() == FULL_CONNECTION){\n\t\t_connectionStatus = WIFI_ONLY;\n\t}\n\n\t//if use of secure connection is set retroactivly (after begin), then disconnect and set the new client\n\tif(_hasBegun){\n\t\tclient.disconnect();\n\t\tclient.setClient(wifiClientSecure);\n\t}\n\n\n\t//flag use of secure client\n\t_useSecureClient = true;\n}\n\n\n/*\nenables and sets up broadcast mode rather than station mode. This allows users to create a network from the ESP\nand upload using OTA even if there is no network already present. This disables all MQTT connections\n\ninput: \n\tchar ptr for SSID to broadcast\n\tchar ptr for network password\n\tIPAddress instance for the ESP IP\n\noutput: NA\n*/\nvoid ESPHelper::broadcastMode(const char* ssid, const char* password, const IPAddress ip){\n\t//disconnect from any previous wifi networks (max timeout of 2 seconds)\n\tWiFi.softAPdisconnect();\n\tWiFi.disconnect();\n\tint timeout = 0;\n\twhile(WiFi.status() != WL_DISCONNECTED && timeout < 200){\n\t\tdelay(10);\n\t\ttimeout++;\n\t}\n\t//set the mode for access point\n\tWiFi.mode(WIFI_AP);\n\t//config the AP\n\tWiFi.softAPConfig(ip, ip, IPAddress(255, 255, 255, 0));\n\t//set the ssid and password\n\tWiFi.softAP(ssid, password);\n\n\t//run the wifi lost callback if we were previously connected to a network\n\tif(_wifiLostCallbackSet && _connectionStatus >= WIFI_ONLY){\n\t\t_wifiLostCallback();\n\t}\n\n\t//update the connection status\n\t_connectionStatus = BROADCAST;\n\t_broadcastIP = ip;\n\tstrcpy(_broadcastSSID, ssid);\n\tstrcpy(_broadcastPASS, password);\n\n\n\n}\n\n\n/*\ndisable broadcast mode and reset to station mode \n(causes a call to begin - may want to change this in the future...)\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::disableBroadcast(){\n\t//disconnect from any previous wifi networks (max timeout of 2 seconds)\n\tWiFi.softAPdisconnect();\n\tWiFi.disconnect();\n\tint timeout = 0;\n\twhile(WiFi.status() != WL_DISCONNECTED && timeout < 200){\n\t\tdelay(10);\n\t\ttimeout++;\n\t}\n\t_connectionStatus = NO_CONNECTION;\n\tbegin();\n}\n\n\n/*\nmain loop - should be called as often as possible - handles wifi/mqtt connection and mqtt handler\n\ninput: NA\noutput:\n\ttrue on: network/server connected\n\tfalse on: network or server disconnected\n*/\nint ESPHelper::loop(){\n\tif(_ssidSet){\n\n\t\t//check for good connections and attempt a reconnect if needed\n\t\tif (((_mqttSet && !client.connected()) || setConnectionStatus() < WIFI_ONLY) && _connectionStatus != BROADCAST) {\n\t\t\treconnect();\n\t\t}\n\n\t\t//run the wifi loop as long as the connection status is at a minimum of BROADCAST\n\t\tif(_connectionStatus >= BROADCAST){\n\n\t\t\t//run the MQTT loop if we have a full connection\n\t\t\tif(_connectionStatus == FULL_CONNECTION){client.loop();}\n\n\t\t\t//check for whether we want to use OTA and whether the system is running\n\t\t\tif(_useOTA && _OTArunning) {ArduinoOTA.handle();}\n\n\t\t\t//if we want to use OTA but its not running yet, start it up.\n\t\t\telse if(_useOTA && !_OTArunning){\n\t\t\t\tOTA_begin();\n\t\t\t\tArduinoOTA.handle();\n\t\t\t}\n\n\t\t\treturn _connectionStatus;\n\t\t}\n\n\t\tyield();\n\t}\n\n\t//return -1 for no connection because of bad network info\n\treturn -1;\n}\n\n\n/*\nsubscribe to a speicifc topic (does not add to topic list)\n\ninput:\n\tchar ptr to a topic to subscribe to\n\tint for QOS of the subscription\noutput:\n\ttrue on: subscription success\n\tfalse on: subscription failed (either from PubSub lib or network is disconnected)\n*/\nbool ESPHelper::subscribe(const char* topic, int qos){\n\tif(_connectionStatus == FULL_CONNECTION){\n\t\t//set the return value to the output of subscribe\n\t\tbool returnVal = client.subscribe(topic, qos);\n\t\t//Serial.printf(\"Subscribe to: %s - %s\\n\", topic, returnVal == true ? \"Success\" : \"Failure\");\n\t\t//loop mqtt client\n\t\tclient.loop();\n\t\treturn returnVal;\n\t}\n\n\t//if not fully connected return false\n\telse{return false;}\n}\n\n/*\nadd a topic to the list of subscriptions and attempt to subscribe to the topic on the spot\n\ninput:\n\tchar ptr for a topic to subscibe to\noutput:\n\ttrue on: subscription added to list (does not guarantee that the topic was subscribed to, only that it was added to the list)\n\tfalse on: subscription not added to list\n*/\nbool ESPHelper::addSubscription(const char* topic){\n\t//default return value is false\n\tbool subscribed = false;\n\n\t//loop throough finding the next available slot for a subscription and add it\n\tfor(int i = 0; i < MAX_SUBSCRIPTIONS; i++){\n\t\tif(_subscriptions[i].isUsed == false){\n\t\t\t_subscriptions[i].topic = topic;\n\t\t\t_subscriptions[i].isUsed = true;\n\t\t\tsubscribed = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t//if added to the list, subscibe to the topic\n\tif(subscribed){subscribe(topic, _qos);}\n\n\treturn subscribed;\n}\n\n\n/*\nloops through list of subscriptions and attempts to subscribe to all topics\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::resubscribe(){\n\tdebugPrintln(\"Resubscribing to all topics\");\n\tfor(int i = 0; i < MAX_SUBSCRIPTIONS; i++){\n\t\tif(_subscriptions[i].isUsed){\n\t\t\tdebugPrint(\"Topic: \"); debugPrintln(_subscriptions[i].topic);\n\t\t\tsubscribe(_subscriptions[i].topic, _qos);\n\t\t\tyield();\n\t\t}\n\t}\n}\n\n\n/*\nattempts to remove a topic from the topic list\n\ninput:\n\tchar ptr to a topic to subscribe to\noutput:\n\ttrue on: subscription removed from list (does not guarantee that the topic was unsubscribed from, only that it was removed from the list)\n\tfalse on: topic was not found in list and therefore cannot be removed\n*/\nbool ESPHelper::removeSubscription(const char* topic){\n\tbool returnVal = false;\n\tcreateSafeString(topicStr, MAX_TOPIC_LENGTH);\n\n\t//loop through all subscriptions\n\tfor(int i = 0; i < MAX_SUBSCRIPTIONS; i++){\n\t\t//if an element is used, check for it being the one we want to remove\n\t\tif(_subscriptions[i].isUsed){\n\t\t\tcreateSafeString(subStr, MAX_TOPIC_LENGTH);\n\t\t\tsubStr = _subscriptions[i].topic;\n\t\t\tif(subStr.equals(topicStr)){\n\t\t\t\t//reset the used flag to false\n\t\t\t\t_subscriptions[i].isUsed = false;\n\n\t\t\t\t//unsubscribe\n\t\t\t\tclient.unsubscribe(_subscriptions[i].topic);\n\t\t\t\treturnVal = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn returnVal;\n}\n\n\n/*\nmanually unsubscribes from a topic (This is basically just a wrapper for the pubsubclient function)\n\ninput: \n\tchar ptr to topic to unsubscribe from\noutput\n\ttrue on: sucessful unsubscription\n\tfalse on: could not unsubscribe (generally b/c it was not subscribed anyways)\n\n*/\nbool ESPHelper::unsubscribe(const char* topic){\n\treturn client.unsubscribe(topic);\n}\n\n\n/*\npublish to a specified topic\n\ninput:\n\tchar ptr to topic to publish to\n\tchar ptr to the payload to be published\noutput: NA\n*/\nvoid ESPHelper::publish(const char* topic, const char* payload){\n\tpublish(topic, payload, false);\n}\n\n\n/*\npublish to a specified topic with a given retain level\n\ninput:\n\tchar ptr to topic to publish to\n\tchar ptr to the payload to be published\n\tbool whether the MQTT broker should retain the message\noutput: NA\n*/\nvoid ESPHelper::publish(const char* topic, const char* payload, bool retain){\n\tclient.publish(topic, payload, retain);\n}\n\n\n\nbool ESPHelper::publishJson(const char* topic, JsonDocument& doc, bool retain){\n\n\tconst size_t MAX_CHUNK_SIZE = 128; // Define a suitable chunk size\n\t\n\t//figure out the correct size\n\tsize_t dataSize = measureJsonPretty(doc);\n\n\tif(dataSize < 1023){\n\t\t//create & fill\n\t\tuint8_t* buf = new uint8_t[dataSize+1];\n\t\tif (!buf) {\n\t\t\treturn false; // Handle memory allocation failure\n\t\t}\n\t\tsize_t payloadLength = serializeJsonPretty(doc, buf, dataSize+1);\n\t\tif (payloadLength == 0) {\n\t\t\tdelete[] buf;\n\t\t\treturn false; // Handle serialization failure\n\t\t}\n\t\tsize_t bytesSent = 0;\n\n\t\t// Start publishing\n\t\tif (!client.beginPublish(topic, dataSize, retain)) {\n\t\t\tdelete[] buf;\n\t\t\treturn false;\n\t\t}\n\n\t\twhile (bytesSent < payloadLength) {\n\t\t\tsize_t chunkSize = min(payloadLength - bytesSent, MAX_CHUNK_SIZE);\n\t\t\tsize_t result = client.write((const uint8_t*)(buf + bytesSent), chunkSize);\n\t\t\tif (result != chunkSize) {\n\t\t\t\tdelete[] buf;\n\t\t\t\tclient.endPublish(); // Ensure to end publish on error\n\t\t\t\treturn false; // Handle error\n\t\t\t}\n\t\t\tbytesSent += result;\n\t\t}\n\n\t\t//cleanup\n\t\tdelete[] buf;\n\t\tbuf = NULL;\n\n\t\treturn client.endPublish();\n\t}\n\t\n\treturn false;\n}\n\n\n\n/*\nset the callback function for MQTT\n\ninput:\n\tfunction ptr that matches the MQTT callback function signature in pubsubclient\noutput: NA\n*/\nvoid ESPHelper::setMQTTCallback(MQTT_CALLBACK_SIGNATURE){\n\t_mqttCallback = callback;\n\n\t//only set the callback if using mqtt AND the system has already been started. Otherwise just save it for later\n\tif(_hasBegun && _mqttSet) {\n\t\tclient.setCallback(_mqttCallback);\n\t}\n\t_mqttCallbackSet = true;\n}\n\n\n/*\nlegacy funtion - here for compatibility. Sets the callback function for MQTT (see function above)\n\ninput:\n\tfunction ptr that matches the MQTT callback function signature in pubsubclient\noutput: \n\ttrue (always)\n*/\nbool ESPHelper::setCallback(MQTT_CALLBACK_SIGNATURE){\n\tsetMQTTCallback(callback);\n\treturn true;\n}\n\n\n/*\nsets a custom function to run when connection to wifi is established\n\ninput:\n\tvoid function ptr with no params\noutput: NA\n*/\nvoid ESPHelper::setWifiCallback(void (*callback)()){\n\t_wifiCallback = callback;\n\t_wifiCallbackSet = true;\n}\n\n\n/*\nsets a custom function to run when connection to wifi is lost\n\ninput:\n\tvoid function ptr with no params\noutput: NA\n*/\nvoid ESPHelper::setWifiLostCallback(void (*callback)()){\n\t_wifiLostCallback = callback;\n\t_wifiLostCallbackSet = true;\n}\n\n\n/*\nattempts to connect to wifi & mqtt server if not connected\n\ninput: NA\t\noutput: NA\n*/\nvoid ESPHelper::reconnect() {\n\n\n\tif(reconnectMetro.check() && _connectionStatus != BROADCAST && setConnectionStatus() != FULL_CONNECTION){\n\t\tdebugPrintln(\"Attempting WiFi Connection...\");\n\t\t//attempt to connect to the wifi if connection is lost\n\t\tif(WiFi.status() != WL_CONNECTED){\n\t\t\t_connectionStatus = NO_CONNECTION;\n\n\t\t\t#ifdef ESP32\n\t\t\treconnect();\n\t\t\t#else\n\t\t\t//WiFi.reconnect();\n\t\t\t#endif\n\n\t\t}\n\n\t\t// make sure we are connected to WIFI before attemping to reconnect to MQTT\n\t\t//----note---- maybe want to reset tryCount whenever we succeed at getting wifi connection?\n\t\tif(WiFi.status() == WL_CONNECTED){\n\t\t\t//if the wifi previously wasnt connected but now is, run the callback\n\t\t\tif(_connectionStatus < WIFI_ONLY && _wifiCallbackSet){\n\t\t\t\t_wifiCallback();\n\t\t\t}\n\n\n\t\t\tdebugPrintln(\"\\n---WIFI Connected!---\");\n\t\t\t_connectionStatus = WIFI_ONLY;\n\n\n\t\t\t//attempt to connect to mqtt when we finally get connected to WiFi\n\t\t\tif(_mqttSet){\n\n\t\t\t\tstatic int timeout = 0;\t//allow a max of 5 mqtt connection attempts before timing out\n\t\t\t\tif (!client.connected() && timeout < 5) {\n\t\t\t\t\tdebugPrint(\"Attemping MQTT connection\");\n\t\t\t\t\t\n\t\t\t\t\tclient.disconnect();\n\t\t\t\t\tclient.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\tif(_useSecureClient){client.setClient(wifiClientSecure);}\n\t\t\t\t\telse{client.setClient(wifiClient);}\n\n\n\t\t\t\t\tint connected = 0;\n\n\t\t\t\t\t//connect to mqtt with user/pass\n\t\t\t\t\tif (_mqttUserSet && _willMessageSet && _willTopicSet) {\n\t\t\t\t\t\tdebugPrintln(\" - Using user & last will\");\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Client Name: \" + String(_clientName.c_str())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t User Name: \" + String(_currentNet.getMqttUser())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Password: \" + String(_currentNet.getMqttPass())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Topic: \" + String(_currentNet.getMqttWillTopic())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will QOS: \" + String(_currentNet.getMqttWillQoS())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Retain?: \" + String(_currentNet.getMqttWillRetain())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Message: \" + String(_currentNet.getMqttWillMessage())));\n\t\t\t\t\t\tconnected = client.connect(\n\t\t\t\t\t\t\t(char*) _clientName.c_str(),\n\t\t\t\t\t\t\t _currentNet.getMqttUser(), \n\t\t\t\t\t\t\t _currentNet.getMqttPass(), \n\t\t\t\t\t\t\t _currentNet.getMqttWillTopic(), \n\t\t\t\t\t\t\t _currentNet.getMqttWillQoS(), \n\t\t\t\t\t\t\t _currentNet.getMqttWillRetain(), \n\t\t\t\t\t\t\t _currentNet.getMqttWillMessage());\n\t\t\t\t\t}\n\n\t\t\t\t\t//connect to mqtt without credentials\n\t\t\t\t\telse if (!_mqttUserSet && _willMessageSet && _willTopicSet) {\n\t\t\t\t\t\tdebugPrintln(\" - Using last will\");\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Client Name: \" + String(_clientName.c_str())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Topic: \" + String(_currentNet.getMqttWillTopic())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will QOS: \" + String(_currentNet.getMqttWillQoS())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Retain?: \" + String(_currentNet.getMqttWillRetain())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Will Message: \" + String(_currentNet.getMqttWillMessage())));\n\t\t\t\t\t\tconnected = client.connect(\n\t\t\t\t\t\t\t(char*) _clientName.c_str(), \n\t\t\t\t\t\t\t_currentNet.getMqttWillTopic(), \n\t\t\t\t\t\t\t_currentNet.getMqttWillQoS(), \n\t\t\t\t\t\t\t_currentNet.getMqttWillRetain(), \n\t\t\t\t\t\t\t_currentNet.getMqttWillMessage()\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (_mqttUserSet && !_willMessageSet) {\n\t\t\t\t\t\tdebugPrintln(\" - Using user\");\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Client Name: \" + String(_clientName.c_str())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t User Name: \" + String(_currentNet.getMqttUser())));\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Password: \" + String(_currentNet.getMqttPass())));\n\t\t\t\t\t\tconnected = client.connect(\n\t\t\t\t\t\t\t(char*) _clientName.c_str(), \n\t\t\t\t\t\t\t_currentNet.getMqttUser(), \n\t\t\t\t\t\t\t_currentNet.getMqttPass()\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdebugPrintln(\" - Using default\");\n\t\t\t\t\t\tdebugPrintln(String(\"\\t Client Name: \" + String(_clientName.c_str())));\n\t\t\t\t\t\tconnected = client.connect((char*) _clientName.c_str());\n\t\t\t\t\t}\n\n\t\t\t\t\t//if connected, subscribe to the topic(s) we want to be notified about\n\t\t\t\t\tif (connected) {\n\t\t\t\t\t\tdebugPrintln(\" -- Connected\");\n\n\t\t\t\t\t\t#if ESP_SDK_VERSION_MAJOR > 2\n\t\t\t\t\t\t//if using https, verify the fingerprint of the server before setting full connection (return on fail)\n\t\t\t\t\t\tif(_useSecureClient){\n\t\t\t\t\t\t\tif (wifiClientSecure.verify(_fingerprint, _currentNet.mqttHost)) {\n\t\t\t\t\t\t\t\tdebugPrintln(\"Certificate Matches - SUCESS\");\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdebugPrintln(\"Certificate Doesn't Match - FAIL\");\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t#else\n\t\t\t\t\t\tif(_useSecureClient){debugPrintln(\"Certificate Not Supported on this SDK Version. Must use SDK 2.x.x\");}\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\tif(_mqttCallbackSet){\n\t\t\t\t\t\t\tdebugPrintln(\"Setting MQTT callback\");\n\t\t\t\t\t\t\tclient.setCallback(_mqttCallback);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t_connectionStatus = FULL_CONNECTION;\n\t\t\t\t\t\tresubscribe();\n\t\t\t\t\t\ttimeout = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tdebugPrintln(\" -- Failed\");\n\t\t\t\t\t}\n\t\t\t\t\ttimeout++;\n\n\t\t\t\t}\n\t\t\t\telse if (timeout >= 5) {\n\t\t\t\t\tdebugPrintln(\" -- Failed to connect to MQTT after 5 attempts. Giving up.\");\n\t\t\t\t\t_connectionStatus = WIFI_ONLY;\n\t\t\t\t}\n\t\t\t}\n\n\n\t\t}\n\n\t\t//reset the reconnect metro\n\t\treconnectMetro.reset();\n\t}\n}\n\n\n/*\ninternal function used to set _connectionStatus based on the WiFi & MQTT status\n\ninput: NA\noutput: NA\n*/\nint ESPHelper::setConnectionStatus(){\n\n\t//assume no connection\n\tint returnVal = NO_CONNECTION;\n\n\t//make sure were not in broadcast mode\n\tif(_connectionStatus != BROADCAST){\n\n\t\t//if connected to wifi set the mode to wifi only and run the callback if needed\n\t\tif(WiFi.status() == WL_CONNECTED){\n\t\t\tif(_connectionStatus < WIFI_ONLY && _wifiCallbackSet){\t//if the wifi previously wasnt connected but now is, run the callback\n\t\t\t\t_wifiCallback();\n\t\t\t}\n\t\t\treturnVal = WIFI_ONLY;\n\n\t\t\t//if mqtt is connected as well then set the status to full connection\n\t\t\tif(client.connected()){\n\t\t\t\treturnVal = FULL_CONNECTION;\n\t\t\t}\n\t\t}\n\n\t\t//assuming above fails, then wifi is not connected.\n\t\t//if the wifi is not connected and the wifi lost callback has been set, then call it\n\t\telse if(_connectionStatus >= WIFI_ONLY && _wifiLostCallbackSet){\n\t\t\t_wifiLostCallback();\n\t\t}\n\t}\n\n\n\telse{\n\t\treturnVal = BROADCAST;\n\t}\n\n\t//set the connection status and return\n\t_connectionStatus = returnVal;\n\treturn returnVal;\n}\n\n\n\n/*\ninput:\n\t\noutput:\n*/\nvoid ESPHelper::updateNetwork(){\n\tdebugPrintln(\"\\tDisconnecting from WiFi\");\n\tWiFi.disconnect();\n\tdebugPrintln(\"\\tAttempting to begin on new network\");\n\t\n\t//set the wifi mode\n\tWiFi.mode(WIFI_STA);\n\n\t//connect to the network\n\tif(_passSet && _ssidSet){WiFi.begin(_currentNet.getSsid(), _currentNet.getPass());}\n\telse if(_ssidSet){WiFi.begin(_currentNet.getSsid());}\n\telse{WiFi.begin(\"NO_SSID_SET\");}\n\t\n\tWiFi.setSleep(false);\n\t//#ifdef ESP32\n\tWiFi.setAutoReconnect(true);\n\t//#endif\n\n\tdebugPrintln(\"\\tSetting new MQTT server\");\n\t//setup the mqtt broker info\n\tif(_mqttSet){client.setServer(_currentNet.getMqttHost(), _currentNet.getMqttPort());}\n\telse{client.setServer(\"192.0.2.0\", 1883);}\n\n\tdebugPrintln(\"\\tDone - Ready for next reconnect attempt\");\n}\n\n\n/*\ngenerate unique MQTT name from MAC addr\n\ninput:\n\tuint8* (array) representing the ESP mac address \n\t\noutput:\n\tstring version of that mac address #\n*/\nString ESPHelper::macToStr(const uint8_t* mac){\n\n  char buf[18];\n  snprintf(buf, sizeof(buf), \"%02X:%02X:%02X:%02X:%02X:%02X\",\n\t\t   mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);\n  return String(buf);\n}\n\n\n\n/*\nreturn the current NetInfo state\n\ninput: NA\noutput:\n\tNetInfo of the current network\n*/\nNetInfo* ESPHelper::getNetInfo(){\n\treturn &_currentNet;\n}\n\n\n/*\nreturn the current SSID\n\ninput: NA\noutput:\n\tchar ptr referencing the current SSID\t\n*/\nconst char* ESPHelper::getSSID(){\n\tif(_ssidSet && _connectionStatus != BROADCAST){return _currentNet.getSsid();}\n\telse if(_connectionStatus == BROADCAST){return _broadcastSSID;}\n\treturn \"SSID NOT SET\";\n}\n\n\n/*\nset a new SSID - does not automatically disconnect from current network if already connected\n\ninput:\n\tchar ptr to the SSID to connect to\noutput: NA\n*/\nvoid ESPHelper::setSSID(const char* ssid){\n\t_currentNet.setSsid(ssid);\n\t_ssidSet = true;\n}\n\n\n/*\nreturn the current network password\n\ninput: NA\noutput:\n\tchar ptr to the current network pass\n*/\nconst char* ESPHelper::getPASS(){\n\tif(_passSet && _connectionStatus != BROADCAST){return _currentNet.getPass();}\n\telse if(_connectionStatus == BROADCAST){return _broadcastPASS;}\n\treturn \"PASS NOT SET\";\n}\n\n\n/*\nset a new network password - does not automatically disconnect from current network if already connected\n\ninput:\n\tchar ptr to the new network pass to use\noutput: NA\n*/\nvoid ESPHelper::setPASS(const char* pass){\n\t_currentNet.setPass(pass);\n\t_passSet = true;\n}\n\n\n/*\nreturn the current MQTT server IP\n\ninput: NA\noutput:\n\tchar ptr to the current MQTT IP or Hostname\n*/\nconst char* ESPHelper::getMQTTIP(){\n\tif(_mqttSet){return _currentNet.getMqttHost();}\n\treturn \"MQTT IP NOT SET\";\n}\n\n\n/*\nset a new MQTT server IP or Hostname - does not automatically disconnect from current network/server if already connected\n\ninput:\n\tchar ptr to a new MQTT IP or Hostname str\noutput: NA\n*/\nvoid ESPHelper::setMQTTIP(const char* mqttIP){\n\t_currentNet.setMqttHost(mqttIP);\n\t_mqttSet = true;\n}\n\n\n/*\nset a new MQTT server IP - does not automatically disconnect from current network/server if already connected\nIncludes MQTT user and Pass\n\ninput:\n\tchar ptr to a new MQTT IP or Hostname str\n\tchar ptr to MQTT username\n\tchar ptr to MQTT password\noutput: NA\n*/\nvoid ESPHelper::setMQTTIP(const char* mqttIP, const char* mqttUser, const char* mqttPass){\n\t_currentNet.setMqttHost(mqttIP);\n\t_currentNet.setMqttUser(mqttUser);\n\t_currentNet.setMqttPass(mqttPass);\n\t_mqttSet = true;\n\t_mqttUserSet = true;\n}\n\n\n/*\nset a new MQTT Will - does not automatically disconnect from current network/server if already connected\n\ninput:\n\tchar ptr to MQTT will topic\n\tchar ptr to MQTT will payload\noutput: NA\n*/\t\nvoid ESPHelper::setWill(const char *willTopic, const char *willMessage){\n\t_currentNet.setMqttWillTopic(willTopic);\n\t_currentNet.setMqttWillMessage(willMessage);\n\t_willTopicSet = true;\n\t_willMessageSet = true;\n}\n\n\n/*\nset a new MQTT Will - does not automatically disconnect from current network/server if already connected\n\ninput:\n\tchar ptr to MQTT will topic\n\tchar ptr to MQTT will payload\n\tint to MQTT will QOS\n\tint to MQTT will retain \noutput: NA\n*/\nvoid ESPHelper::setWill(const char *willTopic, const char *willMessage, const int willQoS, const bool willRetain){\n\t_currentNet.setMqttWillTopic(willTopic);\n\t_currentNet.setMqttWillMessage(willMessage);\n\t_currentNet.setMqttWillQoS(willQoS);\n\t_currentNet.setMqttWillRetain(willRetain);\n\t_willTopicSet = true;\n\t_willMessageSet = true;\n}\n\n\n/*\nreturn the QOS level for mqtt\n\ninput: NA\noutput:\n\tint for current MQTT QOS\n*/\nint ESPHelper::getMQTTQOS(){\n\treturn _qos;\n\n}\n\n\n/*\nset the QOS level for mqtt\n\ninput:\n\tint for MQTT QOS level\noutput: NA\n*/\nvoid ESPHelper::setMQTTQOS(int qos){\n\t_qos = qos;\n}\n\n\n/*\nreturn the local IP address of the ESP as a string\n\ninput: NA\noutput:\n\tString representing the current IP address of the ESP\n*/\nString ESPHelper::getIP(){\n\tif(_connectionStatus != BROADCAST){\n\t\treturn WiFi.localIP().toString();\n\t}\n\telse{\n\t\treturn _broadcastIP.toString();\n\t}\n\n}\n\n\n/*\nreturn the local IP address of the ESP\n\ninput: NA\noutput:\n \tIPAddress instance representing the current IP address of the ESP\n*/\nIPAddress ESPHelper::getIPAddress(){\n\tif(_connectionStatus != BROADCAST){\n\t\treturn WiFi.localIP();\n\t}\n\telse{\n\t\treturn _broadcastIP;\n\t}\n}\n\n\n/*\nget the current connection status of ESPHelper\n\ninput: NA\noutput:\n\tint for current ESPHelper connection status(refer to connStatus enum is sharedData.h)\n*/\nint ESPHelper::getStatus(){\n\treturn _connectionStatus;\n}\n\n\n\n\n/*\nDEBUG ONLY - print the subscribed topics list to the serial line\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::listSubscriptions(){\n\tfor(int i = 0; i < MAX_SUBSCRIPTIONS; i++){\n\t\tif(_subscriptions[i].isUsed){\n\t\t\tdebugPrintln(_subscriptions[i].topic);\n\t\t}\n\t}\n}\n\n\n\n/*\nenable use of OTA updates\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::OTA_enable(){\n\t_useOTA = true;\n\tOTA_begin();\n}\n\n\n/*\nbegin the OTA subsystem but with a check for connectivity and enabled use of OTA\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::OTA_begin(){\n\tif(_connectionStatus >= BROADCAST && _useOTA){\n\t\tArduinoOTA.begin();\n\t\t_OTArunning = true;\n\t}\n}\n\n\n/*\ndisable use of OTA updates\n\ninput: NA\noutput: NA\n*/\nvoid ESPHelper::OTA_disable(){\n\t_useOTA = false;\n\t_OTArunning = false;\n}\n\n\n/*\nset a password for OTA updates\n\ninput:\n\tchar ptr containing the OTA password to be used\noutput: NA\n*/\nvoid ESPHelper::OTA_setPassword(const char* pass){\n\tArduinoOTA.setPassword(pass);\n}\n\n\n/*\nset the hostname of the ESP for OTA uploads\n\ninput:\n\tchar ptr containing the intended hostname\noutput: NA\n*/\nvoid ESPHelper::OTA_setHostname(const char* hostname){\n\tstrcpy(_hostname, hostname);\n\tArduinoOTA.setHostname(_hostname);\n}\n\n\n/*\nset the hostname of the ESP for OTA uploads and append the ESPHelper version number\n\ninput:\n\tchar ptr containing the intended hostname\noutput: NA\n*/\nvoid ESPHelper::OTA_setHostnameWithVersion(const char* hostname){\n\tstrcpy(_hostname, hostname);\n\tstrcat(_hostname, \"----\");\n\tstrcat(_hostname, VERSION);\n\n\tArduinoOTA.setHostname(_hostname);\n}\n\n\n/*\nreturns the current ESPHelper hostname\n\ninput: NA\noutput: \n\tchar ptr containing the ESP hostname\n*/\nchar* ESPHelper::getHostname(){\n\treturn _hostname;\n}\n\n\n/*\nreturns internal pubsubclient ptr (use with caution)\n\ninput: NA\noutput: \n\tpubsubclient ptr\n*/\nPubSubClient* ESPHelper::getMQTTClient(){\n\treturn &client;\n}\n\n\n/*\nsets a new buffer size for mqtt messages in/out\n\ninput: int bytes of how large the buffer should be\noutput: \n\ttrue: success\n\tfalse: failure\n*/\nbool ESPHelper::setMQTTBuffer(int size){\n\t#if PUB_SUB_VERSION >= 28\n\t\treturn client.setBufferSize(size);\n\t#else\n\t\treturn false;\n\t#endif\n}\n"
  },
  {
    "path": "src/ESPHelper.h",
    "content": "/*\n    ESPHelper.h\n    Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n\n#ifndef ESP_HELPER_H\n#define ESP_HELPER_H\n\n#ifdef ESP32\n#include <ESPmDNS.h>\n#include <WiFi.h>\n#endif\n\n\n#ifdef ESP8266\n#include <ESP8266WiFi.h>\n#include <ESP8266mDNS.h>\n#include <WiFiUdp.h>\n#endif\n\n\n#include <ArduinoOTA.h>\n#include <PubSubClient.h>\n#include <ArduinoJson.h>\n// #include <StreamUtils.h>\n#include <SafeString.h>\n\n#include <WiFiClientSecure.h>\n\n#include \"sharedData.h\"\n#include \"Metro.h\"\n\n\n#define PUB_SUB_VERSION 28\n\n\n// #define DEBUG\n\n#ifdef DEBUG\n\t#define debugPrint(x) Serial.print(x) //debug on\n\t#define debugPrintln(x) Serial.println(x) //debug on\n#else\n\t#define debugPrint(x) {;} //debug off\n\t#define debugPrintln(x) {;} //debug off\n#endif\n\n\nvoid printNetInfo(const NetInfo *net, const char* header, bool printMQTT = true, bool printWill = true);\n\n\nclass ESPHelper{\n\npublic:\n\tESPHelper();\n\tESPHelper(const NetInfo *startingNet, bool storeLocal = true);\n\n\tbool begin();\n\tbool begin(const NetInfo *startingNet, bool storeLocal = true);\n\tvoid end();\n\n\tvoid useSecureClient(const char* fingerprint);\n\n\tvoid broadcastMode(const char* ssid, const char* password, const IPAddress ip);\n\tvoid disableBroadcast();\n\n\tint loop();\n\n\tbool subscribe(const char* topic, int qos);\n\tbool addSubscription(const char* topic);\n\tbool removeSubscription(const char* topic);\n\tbool unsubscribe(const char* topic);\n\n\tvoid publish(const char* topic, const char* payload);\n\tvoid publish(const char* topic, const char* payload, bool retain);\n\tboolean publishJson(const char* topic, JsonDocument& doc, bool retain);\n\n\n\tbool setCallback(MQTT_CALLBACK_SIGNATURE);\n\tvoid setMQTTCallback(MQTT_CALLBACK_SIGNATURE);\n\n\tvoid setWifiCallback(void (*callback)());\n\tvoid setWifiLostCallback(void (*callback)());\n\n\tvoid reconnect();\n\n\tvoid updateNetwork();\t//manually disconnect and reconnecting to network/mqtt using current values (generally called after setting new network values)\n\n\tconst char* getSSID();\n\tvoid setSSID(const char *ssid);\n\n\tconst char* getPASS();\n\tvoid setPASS(const char *pass);\n\n\tconst char* getMQTTIP();\n\tvoid setMQTTIP(const char *mqttIP);\n\tvoid setMQTTIP(const char *mqttIP, const char *mqttUser, const char *mqttPass);\n\n\tint getMQTTQOS();\n\tvoid setMQTTQOS(int qos);\n\n\tvoid setWill(const char *willTopic, const char *willMessage);\n\tvoid setWill(const char *willTopic, const char *willMessage, const int willQoS, const bool willRetain);\n\n\tString getIP();\n\tIPAddress getIPAddress();\n\n\tint getStatus();\n\n\n\tNetInfo* getNetInfo();\n\n\tvoid listSubscriptions();\n\n\tvoid OTA_enable();\n\tvoid OTA_disable();\n\tvoid OTA_begin();\n\tvoid OTA_setPassword(const char* pass);\n\tvoid OTA_setHostname(const char* hostname);\n\tvoid OTA_setHostnameWithVersion(const char* hostname);\n\tchar* getHostname();\n\tPubSubClient* getMQTTClient();\n\tbool setMQTTBuffer(int size);\n\n\tString macToStr(const uint8_t* mac);\n\n\tvoid resubscribe();\n\nprivate:\n\n\tvoid init();\n\tvoid validateConfig();\n\n\t\n\n\tint setConnectionStatus();\n\n\tNetInfo _currentNet;\n\n\tPubSubClient client;\n\n\tMetro reconnectMetro = Metro(500);\n\n\tWiFiClient wifiClient;\n\tWiFiClientSecure wifiClientSecure;\n\tconst char* _fingerprint;\n\tbool _useSecureClient = false;\n\n\n\tString _clientName;\n\n\tvoid (*_wifiCallback)();\n\tbool _wifiCallbackSet = false;\n\n\tvoid (*_wifiLostCallback)();\n\tbool _wifiLostCallbackSet = false;\n\n\tstd::function<void(char*, uint8_t*, unsigned int)> _mqttCallback;\n// #ifdef ESP8266\n// \tstd::function<void(char*, uint8_t*, unsigned int)> _mqttCallback;\n// #endif\n// #ifdef ESP32\n// \tvoid(*_mqttCallback)(char*, uint8_t*, unsigned int) ;\n// #endif\n\n\tbool _mqttCallbackSet = false;\n\n\tint _connectionStatus = NO_CONNECTION;\n\n\t//AP mode variables\n\tIPAddress _broadcastIP;\n\tchar _broadcastSSID[64];\n\tchar _broadcastPASS[64];\n\n\tbool _ssidSet = false;\n\tbool _passSet = false;\n\tbool _mqttSet = false;\n\tbool _mqttUserSet = false;\n  \tbool _mqttPassSet = false;\n\tbool _willTopicSet = false;\n  \tbool _willMessageSet = false;\n\n\tbool _useOTA = false;\n\tbool _OTArunning = false;\n\n\n\tbool _hasBegun = false;\n\n\n\tsubscription _subscriptions[MAX_SUBSCRIPTIONS];\n\n\tchar _hostname[64];\n\n\tint _qos = DEFAULT_QOS;\n\n\tIPAddress _apIP = IPAddress(192, 168, 1, 1);\n\n\n};\n\n#endif\n"
  },
  {
    "path": "src/ESPHelperWebConfig.cpp",
    "content": "/*\nESPHelperWebConfig.cpp\nCopyright (c) 2017 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n#include \"ESPHelperWebConfig.h\"\n\n\nESPHelperWebConfig::ESPHelperWebConfig(int port, const char* URI){\n  _server = new AsyncWebServer(port);\n  _runningLocal = true;\n  createSafeStringFromCharArray(pageURI, _pageURI);\n  pageURI.clear();\n  pageURI.print(URI);\n  createSafeStringFromCharArray(resetURI, _resetURI);\n  resetURI.clear();\n}\n\nESPHelperWebConfig::ESPHelperWebConfig(AsyncWebServer *server, const char* URI){\n  _server = server;\n  _runningLocal = false;\n  createSafeStringFromCharArray(pageURI, _pageURI);\n  pageURI.clear();\n  pageURI.print(URI);\n  createSafeStringFromCharArray(resetURI, _resetURI);\n  resetURI.clear();\n}\n\nESPHelperWebConfig::~ESPHelperWebConfig(){\n  if(_runningLocal){\n    _server->end(); // Stop the server\n    delete _server;\n  }\n  _server = nullptr;\n}\n\n\nbool ESPHelperWebConfig::begin(const char* _hostname){\n  MDNS.begin(_hostname);\n  return begin();\n}\n\nbool ESPHelperWebConfig::begin(){\n  createSafeStringFromCharArray(resetURI, _resetURI);\n  createSafeStringFromCharArray(pageURI, _pageURI);\n  // Serial.printf(\"[ESPHelperWebConfig] Starting web config server on %s\\n\", pageURI.c_str());\n  \n\n  //setup server handlers\n  //these handler function definitions use lambdas to pass the funtion... more information can be found here:\n  //https://stackoverflow.com/questions/39803135/c-unresolved-overloaded-function-type\n\n  _server->on(pageURI.c_str(), HTTP_GET, [this](AsyncWebServerRequest *request){ \n    //send back the config page using the handleGet function as the template processor\n    request->send_P(200, \"text/html\", static_config_html, sizeof(static_config_html), [this](const String& var){\n      return handleGet(var);\n    });\n  });    \n\n  _server->on(pageURI.c_str(), HTTP_POST, [this](AsyncWebServerRequest *request){ \n    this->handlePost(request); \n  }); \n\n  if(_resetSet){\n    // Serial.printf(\"[ESPHelperWebConfig] Starting reset on %s\\n\", resetURI.c_str());\n    //if the reset URI has been set then add a handler for it\n    _server->on(resetURI.c_str(), HTTP_POST, [this](AsyncWebServerRequest *request){ \n      this->handleReset(request); \n    });\n  }\n\n  if(_runningLocal){\n    _server->begin(); // Actually start the server\n  }\n\n\n\treturn true;\n}\n\nvoid ESPHelperWebConfig::useConfig(NetInfo& config){\n  config.cloneTo(_config, false);\n}\n\nvoid ESPHelperWebConfig::fillConfig(bool preFill){\n  _preFill = preFill;\n}\n\nbool ESPHelperWebConfig::handle(){\n\t// _server->handleClient();\n\treturn _configChanged;\n}\n\nNetInfo& ESPHelperWebConfig::getConfig(){\n  _configChanged = false;\n  return _config;\n}\n\n\n\n\n\n//main config page that allows user to enter in configuration info\nString ESPHelperWebConfig::handleGet(const String& var){\n\n  if(var == \"HELPER_PAGE_URI\")\n    return _pageURI;\n  else if(var == \"HELPER_HOSTNAME\")\n    return _config.getHostname();\n  else if(var == \"HELPER_SSID\")\n    return _config.getSsid();\n  else if(var == \"HELPER_MQTT_HOST\")\n    return _config.getMqttHost();\n  else if(var == \"HELPER_MQTT_USER\")\n    return _config.getMqttUser();\n  else if(var == \"HELPER_MQTT_PORT\")\n    return String(_config.getMqttPort());\n  else if(var == \"HELPER_MQTT_WILL_TOPIC\")\n    return _config.getMqttWillTopic();\n  else if(var == \"HELPER_MQTT_WILL_MESSAGE\")\n    return _config.getMqttWillMessage();\n  else if(var == \"HELPER_MQTT_WILL_QOS\")\n    return String(_config.getMqttWillQoS());\n  else if(var == \"HELPER_MQTT_WILL_RETAIN_0\")\n    return _config.getMqttWillRetain() ? \"\" : \"selected\";\n  else if(var == \"HELPER_MQTT_WILL_RETAIN_1\")\n    return _config.getMqttWillRetain() ? \"selected\" : \"\";\n\n  return String();\n}\n\n// If a POST request is made to URI /config\nvoid ESPHelperWebConfig::handlePost(AsyncWebServerRequest *request) {\n\n  //make sure that all the arguments exist and that at least an SSID and hostname have been entered\n  if( ! request->hasArg(\"ssid\") || ! request->hasArg(\"netPass\")\n      || ! request->hasArg(\"hostname\") || ! request->hasArg(\"mqttHost\")\n      || ! request->hasArg(\"mqttUser\") || ! request->hasArg(\"mqttPass\")\n      || ! request->hasArg(\"mqttPort\") || ! request->hasArg(\"otaPassword\")\n      || request->arg(\"ssid\") == NULL || request->arg(\"hostname\") == NULL){ // If the POST request doesn't have username and password data\n\n    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\n    return;\n  }\n\n  //if there is an mqtt user/pass/port entered then there better also be a host!\n  if((request->arg(\"mqttUser\") != NULL || request->arg(\"mqttPass\") != NULL ||\n   request->arg(\"mqttPort\") != NULL) && request->arg(\"mqttHost\") == NULL){\n\n   request->send(400, \"text/html\",\n   String(\"<center>\\\n   <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=no\\\"/>\\\n   <p><strong>400: Invalid Request - MQTT info specified without host</strong></p>\\\n   <hr />\\\n   <p><a href=\" + String(\"config\") + \">Open configuration page</a></p>\").c_str());\n    return;\n  }\n\n  //convert the Strings returned by request->arg to char arrays that can be entered into NetInfo\n\n  if(request->arg(\"netPass\").length() != 0 or _preFill == false){\n    _config.setPass(request->arg(\"netPass\").c_str());\n  }\n  if(request->arg(\"mqttPass\").length() != 0 or _preFill == false){\n    _config.setMqttPass(request->arg(\"mqttPass\").c_str());\n  }\n  if(request->arg(\"otaPassword\").length() != 0 or _preFill == false){\n    _config.setOtaPassword(request->arg(\"otaPassword\").c_str());\n  }\n\n  _config.setSsid(request->arg(\"ssid\").c_str());\n  _config.setHostname(request->arg(\"hostname\").c_str());\n  _config.setMqttHost(request->arg(\"mqttHost\").c_str());\n  _config.setMqttUser(request->arg(\"mqttUser\").c_str());\n\n  //the port is special because it doesnt get stored as a string so we take care of that\n  if(request->arg(\"mqttPort\") != NULL){_config.setMqttPort(request->arg(\"mqttPort\").toInt());}\n  else{_config.setMqttPort(1883);}\n\n  // MQTT Will fields\n  if (request->hasArg(\"mqttWillTopic\")) {\n    _config.setMqttWillTopic(request->arg(\"mqttWillTopic\").c_str());\n  }\n  if (request->hasArg(\"mqttWillMessage\")) {\n    _config.setMqttWillMessage(request->arg(\"mqttWillMessage\").c_str());\n  }\n  if (request->hasArg(\"mqttWillQos\")) {\n    _config.setMqttWillQoS(request->arg(\"mqttWillQos\").toInt());\n  }\n  if (request->hasArg(\"mqttWillRetain\")) {\n    _config.setMqttWillRetain(request->arg(\"mqttWillRetain\").toInt() == 1);\n  }\n\n  //tell the user that the config is loaded in and the module is restarting\n  request->send(200, \"text/html\",\n    String(\"<center>\\\n    <meta http-equiv=\\\"refresh\\\" content=\\\"10;url=/\\\"/>\\\n    <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=no\\\"/>\\\n    <p><strong>Config info loaded</strong></p>\\\n    <hr />\\\n    <p><a href=\\\"/config\\\">Open configuration page</a></p>\\\n    <p>Wait for the ESP8266 to restart with the new settings</p>\\\n    <p>You will be redirected to the home page in 10 seconds.</p>\"));\n  \n  \n\n  // printNetInfo(&_config, \"[ESPHelperWeb Post]\", true, true);\n\n  _configChanged = true;\n}\n\nvoid ESPHelperWebConfig::setFlashReset(const char* uri){\n  createSafeStringFromCharArray(resetURI, _resetURI);\n  resetURI.clear();\n  resetURI.print(uri);\n  _resetSet = true;\n}\n\nvoid ESPHelperWebConfig::handleReset(AsyncWebServerRequest *request){\n  //tell the user that the config is loaded in and the module is restarting\n  #warning \"TODO: Implement flash reset from web config\"\n  // _server->send(200, \"text/plain\", String(\"Resetting SPIFFS and restarting with default values\"));\n\n  // LittleFS.format();\n  // ESP.restart();\n}\n\nvoid ESPHelperWebConfig::handleNotFound(AsyncWebServerRequest *request){\n  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\n}\n"
  },
  {
    "path": "src/ESPHelperWebConfig.h",
    "content": "/*\nESPHelperWebConfig.h\nCopyright (c) 2019 ItKindaWorks All right reserved.\ngithub.com/ItKindaWorks\n\nThis file is part of ESPHelper\n\nESPHelper is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nESPHelper is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n\n#ifndef ESPHELPER_WEBCONFIG_H\n#define ESPHELPER_WEBCONFIG_H\n\n\n#include \"ESPHelper.h\"\n\n#ifdef ESP8266\n#include <ESP8266mDNS.h>\n#endif\n\n#ifdef ESP32\n#include <ESPmDNS.h>\n#include <WiFi.h>\n#endif\n\n#include <ESPAsyncWebServer.h>\n#include <WiFiClient.h>\n#include \"SafeString.h\"\n\n#include \"config_html.h\"\n\n\n\nclass ESPHelperWebConfig{\n\npublic:\n\tESPHelperWebConfig(int port, const char* URI);  //constructor\n    ESPHelperWebConfig(AsyncWebServer *server, const char* URI);\n    ~ESPHelperWebConfig();  //destructor\n\n    bool begin(const char* hostname);\n    bool begin();\n\n    void useConfig(NetInfo& config);\n\n    void fillConfig(bool preFill = true);\n\n    bool handle();\n\n    NetInfo& getConfig();\n\n    void setFlashReset(const char* uri);\n\n\nprivate:\n    String handleGet(const String& var);\n    void handlePost(AsyncWebServerRequest *request);\n    void handleNotFound(AsyncWebServerRequest *request);\n    void handleReset(AsyncWebServerRequest *request);\n\n    AsyncWebServer *_server;\n    \n    char _resetURI[64];\n    char _pageURI[64];\n\n    bool _preFill = false;\n\n    bool _resetSet = false;\n\n    NetInfo _config;\n    bool _runningLocal = false;\n    bool _configChanged = false;\n\n\n};\n\n#endif\n"
  },
  {
    "path": "src/config_html.h",
    "content": "#pragma once\n\ninline unsigned char static_config_html[] PROGMEM = {\n  0x3c, 0x21, 0x64, 0x6f, 0x63, 0x74, 0x79, 0x70, 0x65, 0x20, 0x68, 0x74,\n  0x6d, 0x6c, 0x3e, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x20, 0x6c, 0x61, 0x6e,\n  0x67, 0x3d, 0x65, 0x6e, 0x3e, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x63,\n  0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x3d, 0x22, 0x77, 0x69, 0x64, 0x74,\n  0x68, 0x3d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x77, 0x69, 0x64,\n  0x74, 0x68, 0x2c, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x2d, 0x73,\n  0x63, 0x61, 0x6c, 0x65, 0x3d, 0x31, 0x2c, 0x75, 0x73, 0x65, 0x72, 0x2d,\n  0x73, 0x63, 0x61, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x3d, 0x6e, 0x6f, 0x22,\n  0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x76, 0x69, 0x65, 0x77, 0x70, 0x6f,\n  0x72, 0x74, 0x3e, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x53, 0x79,\n  0x73, 0x74, 0x65, 0x6d, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75,\n  0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c,\n  0x65, 0x3e, 0x3c, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3e, 0x62, 0x6f, 0x64,\n  0x79, 0x20, 0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75,\n  0x6e, 0x64, 0x2d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x30, 0x30,\n  0x64, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x66,\n  0x61, 0x6d, 0x69, 0x6c, 0x79, 0x3a, 0x76, 0x65, 0x72, 0x64, 0x61, 0x6e,\n  0x61, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30, 0x3b,\n  0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e,\n  0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x61,\n  0x69, 0x6e, 0x65, 0x72, 0x20, 0x7b, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c,\n  0x61, 0x79, 0x3a, 0x66, 0x6c, 0x65, 0x78, 0x3b, 0x20, 0x6a, 0x75, 0x73,\n  0x74, 0x69, 0x66, 0x79, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,\n  0x3a, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20, 0x61, 0x6c, 0x69,\n  0x67, 0x6e, 0x2d, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x3a, 0x63, 0x65, 0x6e,\n  0x74, 0x65, 0x72, 0x3b, 0x20, 0x6d, 0x69, 0x6e, 0x2d, 0x68, 0x65, 0x69,\n  0x67, 0x68, 0x74, 0x3a, 0x31, 0x30, 0x30, 0x76, 0x68, 0x3b, 0x20, 0x7d,\n  0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f,\n  0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x7b, 0x20, 0x62,\n  0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x66,\n  0x66, 0x66, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a,\n  0x33, 0x32, 0x70, 0x78, 0x20, 0x32, 0x34, 0x70, 0x78, 0x3b, 0x20, 0x62,\n  0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73,\n  0x3a, 0x31, 0x32, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x78, 0x2d, 0x73,\n  0x68, 0x61, 0x64, 0x6f, 0x77, 0x3a, 0x30, 0x20, 0x32, 0x70, 0x78, 0x20,\n  0x31, 0x32, 0x70, 0x78, 0x20, 0x72, 0x67, 0x62, 0x61, 0x28, 0x30, 0x2c,\n  0x30, 0x2c, 0x30, 0x2c, 0x30, 0x2e, 0x31, 0x35, 0x29, 0x3b, 0x20, 0x6d,\n  0x69, 0x6e, 0x2d, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x33, 0x32, 0x30,\n  0x70, 0x78, 0x3b, 0x20, 0x6d, 0x61, 0x78, 0x2d, 0x77, 0x69, 0x64, 0x74,\n  0x68, 0x3a, 0x34, 0x30, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x74, 0x65, 0x78,\n  0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3a, 0x6c, 0x65, 0x66, 0x74,\n  0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,\n  0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20,\n  0x68, 0x33, 0x2c, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d,\n  0x62, 0x6f, 0x78, 0x20, 0x68, 0x34, 0x20, 0x7b, 0x20, 0x74, 0x65, 0x78,\n  0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3a, 0x63, 0x65, 0x6e, 0x74,\n  0x65, 0x72, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x2d, 0x74,\n  0x6f, 0x70, 0x3a, 0x30, 0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20,\n  0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d,\n  0x62, 0x6f, 0x78, 0x20, 0x68, 0x72, 0x20, 0x7b, 0x20, 0x6d, 0x61, 0x72,\n  0x67, 0x69, 0x6e, 0x3a, 0x31, 0x38, 0x70, 0x78, 0x20, 0x30, 0x3b, 0x20,\n  0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63,\n  0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x69, 0x6e,\n  0x70, 0x75, 0x74, 0x2c, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,\n  0x2d, 0x62, 0x6f, 0x78, 0x20, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x20,\n  0x7b, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x31, 0x30, 0x30, 0x25,\n  0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x2d, 0x62, 0x6f, 0x74,\n  0x74, 0x6f, 0x6d, 0x3a, 0x31, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x70, 0x61,\n  0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x36, 0x70, 0x78, 0x3b, 0x20, 0x62,\n  0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73,\n  0x3a, 0x34, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72,\n  0x3a, 0x31, 0x70, 0x78, 0x20, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x20, 0x23,\n  0x63, 0x63, 0x63, 0x3b, 0x20, 0x62, 0x6f, 0x78, 0x2d, 0x73, 0x69, 0x7a,\n  0x69, 0x6e, 0x67, 0x3a, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2d, 0x62,\n  0x6f, 0x78, 0x3b, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,\n  0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f,\n  0x78, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65,\n  0x3d, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x5d, 0x20, 0x7b, 0x20, 0x77,\n  0x69, 0x64, 0x74, 0x68, 0x3a, 0x61, 0x75, 0x74, 0x6f, 0x3b, 0x20, 0x62,\n  0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x30,\n  0x30, 0x64, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72,\n  0x3a, 0x23, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65,\n  0x72, 0x3a, 0x6e, 0x6f, 0x6e, 0x65, 0x3b, 0x20, 0x63, 0x75, 0x72, 0x73,\n  0x6f, 0x72, 0x3a, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20,\n  0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x38, 0x70, 0x78, 0x20,\n  0x31, 0x38, 0x70, 0x78, 0x3b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72,\n  0x2d, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3a, 0x34, 0x70, 0x78, 0x3b,\n  0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e,\n  0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x69,\n  0x6e, 0x70, 0x75, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x73, 0x75,\n  0x62, 0x6d, 0x69, 0x74, 0x5d, 0x3a, 0x68, 0x6f, 0x76, 0x65, 0x72, 0x20,\n  0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64,\n  0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x20, 0x7d, 0x0a,\n  0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x63, 0x6f, 0x6e,\n  0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x70, 0x2c, 0x20, 0x2e,\n  0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78, 0x20, 0x61,\n  0x20, 0x7b, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2d, 0x61, 0x6c, 0x69, 0x67,\n  0x6e, 0x3a, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x3b, 0x20, 0x64, 0x69,\n  0x73, 0x70, 0x6c, 0x61, 0x79, 0x3a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3b,\n  0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x31, 0x30, 0x70, 0x78,\n  0x20, 0x30, 0x20, 0x30, 0x20, 0x30, 0x3b, 0x20, 0x7d, 0x3c, 0x2f, 0x73,\n  0x74, 0x79, 0x6c, 0x65, 0x3e, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x3c,\n  0x64, 0x69, 0x76, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x63, 0x65,\n  0x6e, 0x74, 0x65, 0x72, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,\n  0x65, 0x72, 0x3e, 0x3c, 0x64, 0x69, 0x76, 0x20, 0x63, 0x6c, 0x61, 0x73,\n  0x73, 0x3d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x62, 0x6f, 0x78,\n  0x3e, 0x3c, 0x68, 0x33, 0x3e, 0x3c, 0x73, 0x70, 0x61, 0x6e, 0x20, 0x73,\n  0x74, 0x79, 0x6c, 0x65, 0x3d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23,\n  0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x3e, 0x3c, 0x73, 0x74, 0x72,\n  0x6f, 0x6e, 0x67, 0x3e, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x20,\n  0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x69,\n  0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3c, 0x2f, 0x73, 0x74,\n  0x72, 0x6f, 0x6e, 0x67, 0x3e, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e,\n  0x3c, 0x2f, 0x68, 0x33, 0x3e, 0x3c, 0x68, 0x72, 0x3e, 0x3c, 0x66, 0x6f,\n  0x72, 0x6d, 0x20, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x25, 0x48,\n  0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x50, 0x41, 0x47, 0x45, 0x5f, 0x55,\n  0x52, 0x49, 0x25, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3d, 0x50,\n  0x4f, 0x53, 0x54, 0x3e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x4e,\n  0x61, 0x6d, 0x65, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,\n  0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,\n  0x65, 0x72, 0x3d, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x48,\n  0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x20, 0x28, 0x52, 0x65,\n  0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78,\n  0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61,\n  0x6d, 0x65, 0x3d, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x20,\n  0x73, 0x69, 0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75,\n  0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x48, 0x4f,\n  0x53, 0x54, 0x4e, 0x41, 0x4d, 0x45, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e,\n  0x20, 0x53, 0x53, 0x49, 0x44, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69,\n  0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f,\n  0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x53, 0x53, 0x49, 0x44, 0x20, 0x20,\n  0x28, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x29, 0x22, 0x20,\n  0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32,\n  0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x73, 0x73, 0x69, 0x64, 0x20, 0x73,\n  0x69, 0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65,\n  0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x53, 0x53, 0x49,\n  0x44, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x53, 0x53, 0x49, 0x44,\n  0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a, 0x3c, 0x62,\n  0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,\n  0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x28, 0x55,\n  0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20, 0x56, 0x61,\n  0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e,\n  0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d,\n  0x6e, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x20, 0x73, 0x69, 0x7a, 0x65,\n  0x3d, 0x33, 0x32, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x70, 0x61, 0x73,\n  0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4f,\n  0x54, 0x41, 0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a,\n  0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70,\n  0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22,\n  0x28, 0x55, 0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20,\n  0x56, 0x61, 0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c,\n  0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x36, 0x20, 0x6e, 0x61, 0x6d,\n  0x65, 0x3d, 0x6f, 0x74, 0x61, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72,\n  0x64, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31, 0x38, 0x20, 0x74, 0x79,\n  0x70, 0x65, 0x3d, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e,\n  0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x68, 0x72, 0x3e, 0x3c, 0x68, 0x34, 0x3e,\n  0x3c, 0x73, 0x70, 0x61, 0x6e, 0x20, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d,\n  0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37,\n  0x35, 0x3b, 0x3e, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x53, 0x65, 0x74, 0x74,\n  0x69, 0x6e, 0x67, 0x73, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e, 0x3c,\n  0x2f, 0x68, 0x34, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x48, 0x6f,\n  0x73, 0x74, 0x20, 0x28, 0x49, 0x50, 0x29, 0x3a, 0x3c, 0x62, 0x72, 0x3e,\n  0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65,\n  0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54,\n  0x20, 0x48, 0x6f, 0x73, 0x74, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65,\n  0x6e, 0x67, 0x74, 0x68, 0x3d, 0x33, 0x32, 0x20, 0x6e, 0x61, 0x6d, 0x65,\n  0x3d, 0x6d, 0x71, 0x74, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x20, 0x73, 0x69,\n  0x7a, 0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d,\n  0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54,\n  0x5f, 0x48, 0x4f, 0x53, 0x54, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20,\n  0x4d, 0x51, 0x54, 0x54, 0x20, 0x55, 0x73, 0x65, 0x72, 0x3a, 0x3c, 0x62,\n  0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,\n  0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51,\n  0x54, 0x54, 0x20, 0x55, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22,\n  0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31,\n  0x36, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x55,\n  0x73, 0x65, 0x72, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31, 0x36, 0x20,\n  0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45,\n  0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x55, 0x53, 0x45, 0x52, 0x25,\n  0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x50,\n  0x6f, 0x72, 0x74, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,\n  0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,\n  0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x50, 0x6f, 0x72,\n  0x74, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,\n  0x3d, 0x31, 0x30, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74,\n  0x74, 0x50, 0x6f, 0x72, 0x74, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x31,\n  0x30, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c,\n  0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x50, 0x4f, 0x52,\n  0x54, 0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x4d, 0x51, 0x54, 0x54,\n  0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a, 0x3c, 0x62,\n  0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x70, 0x6c, 0x61,\n  0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x28, 0x55,\n  0x73, 0x65, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x20, 0x56, 0x61,\n  0x6c, 0x75, 0x65, 0x29, 0x22, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x65, 0x6e,\n  0x67, 0x74, 0x68, 0x3d, 0x31, 0x36, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d,\n  0x6d, 0x71, 0x74, 0x74, 0x50, 0x61, 0x73, 0x73, 0x20, 0x73, 0x69, 0x7a,\n  0x65, 0x3d, 0x31, 0x38, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x70, 0x61,\n  0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x3c,\n  0x68, 0x72, 0x3e, 0x3c, 0x68, 0x34, 0x3e, 0x3c, 0x73, 0x70, 0x61, 0x6e,\n  0x20, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d, 0x63, 0x6f, 0x6c, 0x6f, 0x72,\n  0x3a, 0x23, 0x30, 0x61, 0x34, 0x66, 0x37, 0x35, 0x3b, 0x3e, 0x4d, 0x51,\n  0x54, 0x54, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x53, 0x65, 0x74, 0x74,\n  0x69, 0x6e, 0x67, 0x73, 0x3c, 0x2f, 0x73, 0x70, 0x61, 0x6e, 0x3e, 0x3c,\n  0x2f, 0x68, 0x34, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x54, 0x6f,\n  0x70, 0x69, 0x63, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,\n  0x75, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64,\n  0x65, 0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x57, 0x69, 0x6c,\n  0x6c, 0x20, 0x54, 0x6f, 0x70, 0x69, 0x63, 0x22, 0x20, 0x6d, 0x61, 0x78,\n  0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x32, 0x38, 0x20, 0x6e,\n  0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x57, 0x69, 0x6c, 0x6c,\n  0x54, 0x6f, 0x70, 0x69, 0x63, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x3d, 0x36,\n  0x34, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c,\n  0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f, 0x57, 0x49, 0x4c,\n  0x4c, 0x5f, 0x54, 0x4f, 0x50, 0x49, 0x43, 0x25, 0x3e, 0x3c, 0x62, 0x72,\n  0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x4d, 0x65, 0x73, 0x73, 0x61,\n  0x67, 0x65, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75,\n  0x74, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65,\n  0x72, 0x3d, 0x22, 0x4d, 0x51, 0x54, 0x54, 0x20, 0x57, 0x69, 0x6c, 0x6c,\n  0x20, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x20, 0x6d, 0x61,\n  0x78, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3d, 0x31, 0x32, 0x38, 0x20,\n  0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74, 0x57, 0x69, 0x6c,\n  0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x73, 0x69, 0x7a,\n  0x65, 0x3d, 0x33, 0x32, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x25,\n  0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51, 0x54, 0x54, 0x5f,\n  0x57, 0x49, 0x4c, 0x4c, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45,\n  0x25, 0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20,\n  0x51, 0x6f, 0x53, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x69, 0x6e, 0x70,\n  0x75, 0x74, 0x20, 0x6d, 0x61, 0x78, 0x3d, 0x32, 0x20, 0x6d, 0x69, 0x6e,\n  0x3d, 0x30, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d, 0x71, 0x74, 0x74,\n  0x57, 0x69, 0x6c, 0x6c, 0x51, 0x6f, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65,\n  0x3d, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75,\n  0x65, 0x3d, 0x25, 0x48, 0x45, 0x4c, 0x50, 0x45, 0x52, 0x5f, 0x4d, 0x51,\n  0x54, 0x54, 0x5f, 0x57, 0x49, 0x4c, 0x4c, 0x5f, 0x51, 0x4f, 0x53, 0x25,\n  0x3e, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x57, 0x69, 0x6c, 0x6c, 0x20, 0x52,\n  0x65, 0x74, 0x61, 0x69, 0x6e, 0x3a, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x73,\n  0x65, 0x6c, 0x65, 0x63, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x6d,\n  0x71, 0x74, 0x74, 0x57, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x74, 0x61, 0x69,\n  0x6e, 0x3e, 0x3c, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x25, 0x68,\n  0x65, 0x6c, 0x70, 0x65, 0x72, 0x5f, 0x6d, 0x71, 0x74, 0x74, 0x5f, 0x77,\n  0x69, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x74, 0x61, 0x69, 0x6e, 0x5f, 0x30,\n  0x25, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x30, 0x3e, 0x46, 0x61,\n  0x6c, 0x73, 0x65, 0x3c, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x25,\n  0x68, 0x65, 0x6c, 0x70, 0x65, 0x72, 0x5f, 0x6d, 0x71, 0x74, 0x74, 0x5f,\n  0x77, 0x69, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x74, 0x61, 0x69, 0x6e, 0x5f,\n  0x31, 0x25, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x31, 0x3e, 0x54,\n  0x72, 0x75, 0x65, 0x3c, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x3e,\n  0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0x50, 0x72, 0x65, 0x73, 0x73,\n  0x20, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x75,\n  0x70, 0x64, 0x61, 0x74, 0x65, 0x20, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36,\n  0x36, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x66, 0x69, 0x6c,\n  0x65, 0x3c, 0x2f, 0x70, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20,\n  0x74, 0x79, 0x70, 0x65, 0x3d, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x20,\n  0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74,\n  0x3e, 0x3c, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, 0x3c, 0x70, 0x3e, 0x3c,\n  0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x2f, 0x3e, 0x47, 0x6f, 0x20,\n  0x74, 0x6f, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x53, 0x74,\n  0x61, 0x74, 0x75, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61,\n  0x3e, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x3c, 0x2f, 0x64, 0x69, 0x76,\n  0x3e\n};\ninline unsigned int static_config_html_len = 2977;\n"
  },
  {
    "path": "src/sharedData.h",
    "content": "/*\n    sharedTypes.h\n    Copyright (c) 2019 ItKindaWorks Inc All right reserved.\n    github.com/ItKindaWorks\n\n    This file is part of ESPHelper\n\n    ESPHelper is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    ESPHelper is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with ESPHelper.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n\n#ifndef SHARED_TYPES_H\n#define SHARED_TYPES_H\n\n#include <SafeString.h>\n\n\n#define VERSION \"2-0-4\"\n\n\n\n//Maximum number of subscriptions that can be auto-subscribed\n//feel free to change this if you need more subsciptions\n#define MAX_SUBSCRIPTIONS 25\n\n#define DEFAULT_QOS 1;\t//at least once - devices are guarantee to get a message.\n\n#define MAX_TOPIC_LENGTH 128\n\n\nenum connStatus {NO_CONNECTION, BROADCAST, ROAMING, WIFI_ONLY, FULL_CONNECTION};\n\nstruct ESPHelperConf {\n\tchar mqttHost[32];\n\tchar mqttUser[16];\n\tchar mqttPass[16];\n\tint mqttPort;\n\tchar ssid[32];\n\tchar pass[32];\n\tchar otaPassword[16];\n\tchar hostname[32];\n\tchar willTopic[128];\n\tchar willMessage[32];\n\tint willQoS;\n\tbool willRetain;\n};\n\nclass NetInfo {\npublic:\n\n\t/**\n\t * @brief Construct a new NetInfo object with local storage\n\t * \n\t */\n\texplicit NetInfo() {\n\t\t_conf = new ESPHelperConf();\n\t\t_storeLocal = true;\n\t\tclear();\n\t}\n\n\t/**\n\t * @brief Construct a new NetInfo object with external storage\n\t * \n\t * @param externalConf Pointer to an existing ESPHelperConf object\n\t */\n\texplicit NetInfo(ESPHelperConf& externalConf) {\n\t\t_conf = &externalConf;\n\t\t_storeLocal = false;\n\t}\n\n\t// Deleted copy operations for memory safety\n\tNetInfo(const NetInfo& other) = delete;\n\tNetInfo& operator=(const NetInfo& other) = delete;\n\n\t/**\n\t * @brief Destroy the Net Info object\n\t * \n\t */\n\t~NetInfo() {\n\t\tif (_storeLocal && _conf != nullptr) {\n\t\t\tdelete _conf;\n\t\t}\n\t}\n\n\n\t\n\n\t// ESPHelperConf* getRawConfPtr() const {\n\t// \treturn _conf;\n\t// }\n\n\t/* * @brief Use an external ESPHelperConf object for storage\n\t * \n\t * This method allows the NetInfo instance to use an existing ESPHelperConf object\n\t * instead of managing its own memory. It is useful for sharing configurations.\n\t * \n\t * @param externalConf Pointer to an existing ESPHelperConf object\n\t */\n\tvoid setExternalMemory(ESPHelperConf* externalConf) {\n\t\tif (_storeLocal && _conf != externalConf) {\n\t\t\tdelete _conf;\n\t\t}\n\t\t_conf = externalConf;\n\t\t_storeLocal = false;\n\t}\n\n\t/**\n\t * @brief Clone the current configuration to another NetInfo object\n\t * \n\t * @param target The target NetInfo object to clone to\n\t * @param storeLocal If true, the target will store a local copy of the configuration\n\t */\n\tvoid cloneTo(NetInfo& target, bool storeLocal) const {\n\t\tif (storeLocal) {\n\t\t\ttarget.setToLocalCopy(*_conf);\n\t\t} else {\n\t\t\ttarget.setExternalMemory(_conf);\n\t\t}\n\t}\n\n\t// const ESPHelperConf* getConfPointer() const { return _conf; }\n\n\tvoid setMqttHost(const char* val) { safeCopy(_conf->mqttHost, val, sizeof(_conf->mqttHost)); }\n\tvoid setMqttUser(const char* val) { safeCopy(_conf->mqttUser, val, sizeof(_conf->mqttUser)); }\n\tvoid setMqttPass(const char* val) { safeCopy(_conf->mqttPass, val, sizeof(_conf->mqttPass)); }\n\tvoid setSsid(const char* val) { safeCopy(_conf->ssid, val, sizeof(_conf->ssid)); }\n\tvoid setPass(const char* val) { safeCopy(_conf->pass, val, sizeof(_conf->pass)); }\n\tvoid setOtaPassword(const char* val) { safeCopy(_conf->otaPassword, val, sizeof(_conf->otaPassword)); }\n\tvoid setHostname(const char* val) { safeCopy(_conf->hostname, val, sizeof(_conf->hostname)); }\n\tvoid setMqttWillTopic(const char* val) { safeCopy(_conf->willTopic, val, sizeof(_conf->willTopic)); }\n\tvoid setMqttWillMessage(const char* val) { safeCopy(_conf->willMessage, val, sizeof(_conf->willMessage)); }\n\tvoid setMqttPort(int val) { _conf->mqttPort = val; }\n\tvoid setMqttWillRetain(bool val) { _conf->willRetain = val; }\n\tvoid setMqttWillQoS(int val) { _conf->willQoS = val; }\n\n\tconst char* getMqttHost() const { return _conf->mqttHost; }\n\tconst char* getMqttUser() const { return _conf->mqttUser; }\n\tconst char* getMqttPass() const { return _conf->mqttPass; }\n\tconst char* getSsid() const { return _conf->ssid; }\n\tconst char* getPass() const { return _conf->pass; }\n\tconst char* getOtaPassword() const { return _conf->otaPassword; }\n\tconst char* getHostname() const { return _conf->hostname; }\n\tconst char* getMqttWillTopic() const { return _conf->willTopic; }\n\tconst char* getMqttWillMessage() const { return _conf->willMessage; }\n\tint getMqttPort() const { return _conf->mqttPort; }\n\tint getMqttWillQoS() const { return _conf->willQoS; }\n\tbool getMqttWillRetain() const { return _conf->willRetain; }\n\nprivate:\n\n\t//denotes whether the ESPHelperConf is stored in external memory or locally within this instance\n\tbool _storeLocal = true;\n\tESPHelperConf* _conf = nullptr;\n\n\t/* * @brief Safely copy a string to a destination buffer\n\t * \n\t * This method copies a string from source to destination, ensuring that the destination\n\t * does not overflow. It also ensures that the destination is null-terminated.\n\t * \n\t * @param dest Pointer to the destination buffer\n\t * @param src Pointer to the source string\n\t * @param maxLen Maximum length of the destination buffer\n\t */\n\tvoid safeCopy(char* dest, const char* src, size_t maxLen) {\n\t\tif (src) {\n\t\t\tstrncpy(dest, src, maxLen - 1);\n\t\t\tdest[maxLen - 1] = '\\0';\n\t\t} else if (dest && maxLen > 0) {\n\t\t\tdest[0] = '\\0';\n\t\t}\n\t}\n\n\t/* * @brief Clear the configuration data\n\t * \n\t * This method resets all fields in the ESPHelperConf structure to their default values.\n\t * It is useful for initializing or resetting the configuration.\n\t */\n\tvoid clear() {\n\t\tmemset(_conf, 0, sizeof(ESPHelperConf));\n\t\t_conf->mqttPort = 1883;\n\t\t_conf->willQoS = 1;\n\t\t_conf->willRetain = true;\n\t}\n\n\n\t\n\n\t/* * @brief Set the NetInfo to a local copy of the provided ESPHelperConf\n\t * \n\t * This method creates a local copy of the provided ESPHelperConf object.\n\t * It is useful when you want to ensure that the NetInfo instance has its own copy\n\t * of the configuration data.\n\t * \n\t * @param conf The ESPHelperConf object to copy from\n\t */\n\tvoid setToLocalCopy(const ESPHelperConf& conf) {\n\t\tif (!_storeLocal) {\n\t\t\t_conf = new ESPHelperConf();\n\t\t\t_storeLocal = true;\n\t\t}\n\t\tmemcpy(_conf, &conf, sizeof(ESPHelperConf));\n\t}\n\n\t\n};\n// typedef struct NetInfo NetInfo;\n\n\nstruct subscription{\n\tbool isUsed = false;\n\tconst char* topic;\n};\ntypedef struct subscription subscription;\n\n\n\n\n#endif"
  },
  {
    "path": "static/config.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>\n    <title>System Configuration</title>\n    <style>\n        body { background-color:#00dfff; font-family:verdana; margin:0; }\n        .center-container { display:flex; justify-content:center; align-items:center; min-height:100vh; }\n        .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; }\n        .config-box h3, .config-box h4 { text-align:center; margin-top:0; }\n        .config-box hr { margin:18px 0; }\n        .config-box input, .config-box select { width:100%; margin-bottom:10px; padding:6px; border-radius:4px; border:1px solid #ccc; box-sizing:border-box; }\n        .config-box input[type=submit] { width:auto; background:#00dfff; color:#fff; border:none; cursor:pointer; padding:8px 18px; border-radius:4px; }\n        .config-box input[type=submit]:hover { background:#0a4f75; }\n        .config-box p, .config-box a { text-align:center; display:block; margin:10px 0 0 0; }\n    </style>\n</head>\n<body>\n    <div class=\"center-container\">\n        <div class=\"config-box\">\n            <h3><span style=\"color:#0a4f75;\"><strong>ESP8266 System Configuration</strong></span></h3>\n            <hr />\n            <form action=\"%HELPER_PAGE_URI%\" method=\"POST\">\n                Device Name:<br>\n                <input type=\"text\" name=\"hostname\" size=\"32\" maxlength=\"32\" placeholder=\"Device Hostname  (Required)\" value=\"%HELPER_HOSTNAME%\"><br>\n                SSID:<br>\n                <input type=\"text\" name=\"ssid\" size=\"32\" maxlength=\"32\" placeholder=\"SSID  (Required)\" value=\"%HELPER_SSID%\"><br>\n                SSID Password:<br>\n                <input type=\"password\" name=\"netPass\" size=\"32\" maxlength=\"32\" placeholder=\"(Use Stored Value)\"><br>\n                OTA Password:<br>\n                <input type=\"password\" name=\"otaPassword\" size=\"18\" maxlength=\"16\" placeholder=\"(Use Stored Value)\"><br>\n                <hr />\n                <h4><span style=\"color:#0a4f75;\">MQTT Settings</span></h4>\n                MQTT Host (IP):<br>\n                <input type=\"text\" name=\"mqttHost\" size=\"32\" maxlength=\"32\" placeholder=\"MQTT Host\" value=\"%HELPER_MQTT_HOST%\"><br>\n                MQTT User:<br>\n                <input type=\"text\" name=\"mqttUser\" size=\"16\" maxlength=\"16\" placeholder=\"MQTT Username\" value=\"%HELPER_MQTT_USER%\"><br>\n                MQTT Port:<br>\n                <input type=\"text\" name=\"mqttPort\" size=\"10\" maxlength=\"10\" placeholder=\"MQTT Port\" value=\"%HELPER_MQTT_PORT%\"><br>\n                MQTT Password:<br>\n                <input type=\"password\" name=\"mqttPass\" size=\"18\" maxlength=\"16\" placeholder=\"(Use Stored Value)\"><br>\n                <hr />\n                <h4><span style=\"color:#0a4f75;\">MQTT Will Settings</span></h4>\n                Will Topic:<br>\n                <input type=\"text\" name=\"mqttWillTopic\" size=\"64\" maxlength=\"128\" placeholder=\"MQTT Will Topic\" value=\"%HELPER_MQTT_WILL_TOPIC%\"><br>\n                Will Message:<br>\n                <input type=\"text\" name=\"mqttWillMessage\" size=\"32\" maxlength=\"128\" placeholder=\"MQTT Will Message\" value=\"%HELPER_MQTT_WILL_MESSAGE%\"><br>\n                Will QoS:<br>\n                <input type=\"number\" name=\"mqttWillQos\" min=\"0\" max=\"2\" value=\"%HELPER_MQTT_WILL_QOS%\"><br>\n                Will Retain:<br>\n                <select name=\"mqttWillRetain\">\n                    <option value=\"0\" %HELPER_MQTT_WILL_RETAIN_0%>False</option>\n                    <option value=\"1\" %HELPER_MQTT_WILL_RETAIN_1%>True</option>\n                </select><br>\n                <p>Press Submit to update ESP8266 config file</p>\n                <input type=\"submit\" value=\"Submit\">\n            </form>\n            <p><a href=\"/\">Go to Device Status Page</a></p>\n        </div>\n    </div>\n</body>\n</html>"
  },
  {
    "path": "web_to_header.py",
    "content": "import os\nimport subprocess\nimport shutil\nimport minify_html\n\n\n    \nSTATIC_DIR = \"static\"\nOUTPUT_DIR = \"src\"\n\ndef convert_file(source_path, dest_path):\n    if source_path.endswith(\".html\"):\n        print(f\"\\t[HTML->H] Minifying {source_path} to {dest_path}\")\n        temp_path = source_path + \".tmp\"  \n        shutil.move(source_path, temp_path)  \n        \n\n        with open(temp_path, \"r\") as temp_file:\n            content = temp_file.read()\n            minified = minify_html.minify(content, minify_js=False, remove_processing_instructions=True)\n\n            with open(source_path, \"w\") as minified_file:\n                minified_file.write(minified)\n\n        with open(dest_path, \"w\") as out_file:\n            subprocess.run([\"xxd\", \"-i\", source_path], stdout=out_file)\n        \n        os.remove(source_path)  # Clean up the temporary file\n        shutil.move(temp_path, source_path) # Restore the original file name\n\n\n    else:\n        with open(dest_path, \"w\") as out_file:\n            subprocess.run([\"xxd\", \"-i\", source_path], stdout=out_file)\n            \n    \n        \ndef post_process_file(file_path):\n    # Post-process to add PROGMEM to the array declaration\n    with open(file_path, \"r\") as file:\n        lines = file.readlines()\n    \n    lines = [\"#pragma once\\n\\n\"] + lines  # Add pragma once at the top\n\n    with open(file_path, \"w\") as file:\n        for line in lines:\n            if \"[] =\" in line:\n                line = line.replace(\"[] =\", \"[] PROGMEM =\")\n            if \"unsigned\" in line:\n                line = line.replace(\"unsigned\", \"inline unsigned\")\n            file.write(line)\n\n\ndef main():\n\n    # print(\"[HTML->H] Converting HTML/CSS/JS files to C header files...\")\n    if not os.path.exists(OUTPUT_DIR):\n        os.makedirs(OUTPUT_DIR)\n    for filename in os.listdir(STATIC_DIR):\n        if filename.endswith(\".html\") or filename.endswith(\".css\") or filename.endswith(\".js\"):\n            input_file = os.path.join(STATIC_DIR, filename)\n            output_file = os.path.join(OUTPUT_DIR, filename.replace('.', '_') + \".h\")\n            print(f\"[HTML->H] Converting {input_file} -> {output_file}\")\n            convert_file(input_file, output_file)\n            post_process_file(output_file)\n\nif __name__ == \"__main__\":\n    main()\n"
  }
]