Commit 6b9f6a5337c632b8c398e70602e2b7ef72a6a1d4

Authored by Jeroen88
0 parents

Update README

LICENSE 0 → 100644
  1 +++ a/LICENSE
  1 +GNU GENERAL PUBLIC LICENSE
  2 +
  3 +Version 3, 29 June 2007
  4 +
  5 +Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
  6 +
  7 +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
  8 +Preamble
  9 +
  10 +The GNU General Public License is a free, copyleft license for software and other kinds of works.
  11 +
  12 +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
  13 +
  14 +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
  15 +
  16 +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
  17 +
  18 +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
  19 +
  20 +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
  21 +
  22 +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
  23 +
  24 +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
  25 +
  26 +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
  27 +
  28 +The precise terms and conditions for copying, distribution and modification follow.
  29 +TERMS AND CONDITIONS
  30 +0. Definitions.
  31 +
  32 +“This License” refers to version 3 of the GNU General Public License.
  33 +
  34 +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
  35 +
  36 +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
  37 +
  38 +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
  39 +
  40 +A “covered work” means either the unmodified Program or a work based on the Program.
  41 +
  42 +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
  43 +
  44 +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
  45 +
  46 +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
  47 +1. Source Code.
  48 +
  49 +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
  50 +
  51 +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
  52 +
  53 +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
  54 +
  55 +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
  56 +
  57 +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
  58 +
  59 +The Corresponding Source for a work in source code form is that same work.
  60 +2. Basic Permissions.
  61 +
  62 +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
  63 +
  64 +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
  65 +
  66 +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
  67 +3. Protecting Users' Legal Rights From Anti-Circumvention Law.
  68 +
  69 +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
  70 +
  71 +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
  72 +4. Conveying Verbatim Copies.
  73 +
  74 +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
  75 +
  76 +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
  77 +5. Conveying Modified Source Versions.
  78 +
  79 +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
  80 +
  81 + a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
  82 + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
  83 + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
  84 + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
  85 +
  86 +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
  87 +6. Conveying Non-Source Forms.
  88 +
  89 +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
  90 +
  91 + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
  92 + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
  93 + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
  94 + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
  95 + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
  96 +
  97 +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
  98 +
  99 +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
  100 +
  101 +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
  102 +
  103 +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
  104 +
  105 +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
  106 +
  107 +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
  108 +7. Additional Terms.
  109 +
  110 +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
  111 +
  112 +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
  113 +
  114 +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
  115 +
  116 + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
  117 + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
  118 + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
  119 + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
  120 + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
  121 + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
  122 +
  123 +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
  124 +
  125 +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
  126 +
  127 +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
  128 +8. Termination.
  129 +
  130 +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
  131 +
  132 +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
  133 +
  134 +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
  135 +
  136 +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
  137 +9. Acceptance Not Required for Having Copies.
  138 +
  139 +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
  140 +10. Automatic Licensing of Downstream Recipients.
  141 +
  142 +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
  143 +
  144 +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
  145 +
  146 +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
  147 +11. Patents.
  148 +
  149 +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
  150 +
  151 +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
  152 +
  153 +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
  154 +
  155 +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
  156 +
  157 +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
  158 +
  159 +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
  160 +
  161 +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
  162 +
  163 +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
  164 +12. No Surrender of Others' Freedom.
  165 +
  166 +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
  167 +13. Use with the GNU Affero General Public License.
  168 +
  169 +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
  170 +14. Revised Versions of this License.
  171 +
  172 +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
  173 +
  174 +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
  175 +
  176 +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
  177 +
  178 +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
  179 +15. Disclaimer of Warranty.
  180 +
  181 +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  182 +16. Limitation of Liability.
  183 +
  184 +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  185 +17. Interpretation of Sections 15 and 16.
  186 +
  187 +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
  188 +
  189 +END OF TERMS AND CONDITIONS
... ...
README.md 0 → 100644
  1 +++ a/README.md
  1 +# OpenTherm Arduino ESP32/ESP8266 Library
  2 +
  3 +
... ...
examples/Basic_Thermostat/Basic_Thermostat.ino 0 → 100644
  1 +++ a/examples/Basic_Thermostat/Basic_Thermostat.ino
  1 +/*
  2 + * https://github.com/Jeroen88/EasyOpenTherm
  3 + * https://www.tindie.com/products/Metriot/OpenTherm-adapter/
  4 + *
  5 + * Basic_Thermostat is a program to demonstrate the main communication of a thermostat (master) with an OpenTherm compatible boiler (slave)
  6 + * Copyright (C) 2022 Jeroen Döll <info@metriot.nl>
  7 + *
  8 + * This program is free software: you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation, either version 3 of the License, or
  11 + * (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20 + *
  21 + * You need an OpenTherm controller that you can buy at my Tindie store,
  22 + * Connect the two boiler wires to the OpenTherm controller pins marked OT. The order is not important.
  23 + * Connect the OpenTherm controller to your microcontroller's power (3v3) and ground (GND) pins.
  24 + * Connect the OpenTherm TXD pin to the microcontroller's pin defined by #define OT_RX_PIN.
  25 + * Connect the OpenTherm RXD pin to the microcontroller's pin defined by #define OT_TX_PIN.
  26 + *
  27 + * Connect the BME280 temperature sensor SDA pin to the microcontroller's pin defined by #define I2C_SDA_PIN
  28 + * Connect the BME280 temperature sensor SCL pin to the microcontroller's pin defined by #define I2C_SCL_PIN
  29 + * Check your sensor's address, it may differ from the value defined by #define BME_ADDRESS (0x76)
  30 + * Install the Adafruit BME280 library
  31 + * Any other temperature sensor may be used, like a Dallas sensor, BME380, BMP380, BME680 if you adapt the program accordingly.
  32 + *
  33 + * Define the room temperature setpoint (desired room temperature) using #define ROOM_TEMPERATURE_SETPOINT. In a real application this should be settable.
  34 + * Eventually define the maximum central heating boiler temperature setpoint using #define CH_MAX_SETPOINT.
  35 + *
  36 + * Compile and upload the program as normal. If the temperature measured by your sensor is lower than the ROOM_TEMPERATURE_SETPOINT this thermostat program will actually begin to heat up your room
  37 +*/
  38 +
  39 +
  40 +#include <Arduino.h>
  41 +
  42 +#include <EasyOpenTherm.h>
  43 +
  44 +#define OT_RX_PIN (34)
  45 +#define OT_TX_PIN (17)
  46 +
  47 +#define BME_ADDRESS (0x76)
  48 +#define I2C_SDA_PIN (8)
  49 +#define I2C_SCL_PIN (9)
  50 +
  51 +
  52 +#define ROOM_TEMPERATURE_SETPOINT (18.5f) // The desired room temperature
  53 +#define CH_MAX_SETPOINT (60.0f) // If your house is well isolated and/or you have low temperature radiators this could be as low as 40.0f
  54 +#define CH_MIN_SETPOINT (10.0f) // If the boiler starts it will warm up untill at least this temperature (unless the desired room temperature is reached before)
  55 +
  56 +#define ENABLE_HEATING (true) // If the boiler supports Central Heating (CH), use the boiler for heating
  57 +#define ENABLE_COOLING (true) // If the boiler supports cooling, use the boiler for cooling
  58 +#define ENABLE_DOMESTIC_HOT_WATER (true) // If the boiler supports Domestic Hot Water (DHW), use the boiler for DHW
  59 +
  60 +#include <Wire.h>
  61 +#include <Adafruit_Sensor.h>
  62 +#include <Adafruit_BME280.h>
  63 +
  64 +Adafruit_BME280 bme; // I2C
  65 +
  66 +// Use a PID controller to calculate the CH setpoint. See e.g. https://en.wikipedia.org/wiki/PID_controller
  67 +float pid(float sp,
  68 + float pv,
  69 + float pv_last,
  70 + float & ierr,
  71 + float dt) {
  72 + float KP = 30;
  73 + float KI = 0.02;
  74 +
  75 + float error = sp - pv;
  76 + ierr = ierr + KI * error * dt;
  77 + float dpv = (pv - pv_last) / dt;
  78 + float P = KP * error;
  79 + float I = ierr;
  80 + float op = P + I;
  81 + // anti-reset windup
  82 + if ((op < CH_MIN_SETPOINT) || (op > CH_MAX_SETPOINT)) {
  83 + I = I - KI * error * dt;
  84 + op = max(CH_MIN_SETPOINT, min(CH_MAX_SETPOINT, op));
  85 + }
  86 + ierr = I;
  87 +
  88 + return op;
  89 +}
  90 +
  91 +
  92 +void setup() {
  93 + Serial.begin(115200);
  94 + delay(5000); // For debug only: give the Serial Monitor some time to connect to the native USB of the MCU for output
  95 + Serial.println("\n\nStarted");
  96 +
  97 + Serial.println(F("\n-- BME280 test --"));
  98 + Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
  99 +
  100 + bool status = bme.begin(BME_ADDRESS);
  101 + if (!status) {
  102 + Serial.println("Could not find a valid BME280 sensor, check wiring and address!");
  103 + while (1);
  104 + }
  105 + Serial.println("-- Temperature sensor present --");
  106 +
  107 + bme.setSampling();
  108 +
  109 + Serial.println("Setup done, start loop...");
  110 +}
  111 +
  112 +
  113 +void loop() {
  114 + // Create an OpenTherm thermostat (boiler is slave) with OT_RX_PIN to receive data from boiler and OT_TX_PIN to send data to boiler
  115 + // Only one OpenTherm object may be created!
  116 + static OpenTherm thermostat(OT_RX_PIN, OT_TX_PIN);
  117 +
  118 + // static variables used by the PID controller
  119 + static time_t previousTimestamp = millis(); // Previous timestamp
  120 + static float previousTemperature = bme.readTemperature(); // Previous temperature
  121 + static float ierr = 0; // Integral error
  122 +
  123 +
  124 + time_t timestamp = millis();
  125 + if(timestamp - previousTimestamp > 1000) {
  126 + float roomTemperature = bme.readTemperature(); // Read the sensor to get the current room temperature
  127 + Serial.printf("Room temperature is %.02f *C, room temperature setpoint is %.02f *C\n", roomTemperature, ROOM_TEMPERATURE_SETPOINT);
  128 +
  129 + float dt = (timestamp - previousTimestamp) / 1000.0; // Time between measurements in seconds
  130 + float CHSetpoint = pid(ROOM_TEMPERATURE_SETPOINT, roomTemperature, previousTemperature, ierr, dt);
  131 + previousTimestamp = timestamp;
  132 + previousTemperature = roomTemperature;
  133 +
  134 + Serial.printf("New CH setpoint computed by PID is %.02f\n", CHSetpoint);
  135 +
  136 +
  137 + // First try to connect to the boiler to read it's capabilities. The boiler returns an 8 bit slaveFlags and each bit has a meaning. The bits are defined in enum class OpenTherm::CONFIGURATION_FLAGS
  138 + // The slaveMemberIDCode identifies the manufacturer of the boiler
  139 + uint8_t slaveFlags;
  140 + uint8_t slaveMemberIDCode;
  141 + if(thermostat.read(OpenTherm::READ_DATA_ID::SLAVE_CONFIGURATION, slaveFlags, slaveMemberIDCode)) { // Mandatory support
  142 + Serial.printf("Slave configuration flags is 0x%02x, slave member ID is %d (0x%02x)\n", slaveFlags, slaveMemberIDCode, slaveMemberIDCode);
  143 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_DHW_PRESENT)) Serial.println("DHW present"); else Serial.println("DHW not present");
  144 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_CONTROL_TYPE)) Serial.println("Control type on/off"); else Serial.println("Control type modulating");
  145 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_COOLING)) Serial.println("Cooling supprted"); else Serial.println("Cooling not supported");
  146 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_DHW)) Serial.println("DHW storage tank"); else Serial.println("DHW instantaneous or not-specified");
  147 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_LOW_OFF_PUMP_CTRL)) Serial.println("Low off and pump control not allowed"); else Serial.println("Low off and pump control allowed");
  148 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_CH2_PRESENT)) Serial.println("CH2 present"); else Serial.println("CH2 not present");
  149 + } else {
  150 + slaveFlags = 0;
  151 +
  152 + if(thermostat.error() == OpenTherm::ERROR_CODES::UNKNOWN_DATA_ID) {
  153 + // Valid data is received but the for boilers mandatory DATA-ID OpenTherm::READ_DATA_ID::SLAVE_CONFIGURATION is not recognised. This is not a boiler but another device!
  154 + Serial.println("Your remote device is not a boiler");
  155 + } else {
  156 + // No data or invalid data received
  157 + Serial.println("Failed to get slave configuration; is a boiler connected?");
  158 + }
  159 +
  160 + // Wait 5 secs and try again
  161 + delay(5000);
  162 + return;
  163 + }
  164 +
  165 + // Tell the boiler the desired CH boiler water temperature
  166 + // This is done by writing this value to DATA-ID OpenTherm::WRITE_DATA_ID::CONTROL_SETPOINT_CH
  167 + if(thermostat.write(OpenTherm::WRITE_DATA_ID::CONTROL_SETPOINT_CH, CHSetpoint)) {
  168 + Serial.printf("CH temperature setpoint set to %.01f *C\n", CHSetpoint);
  169 + } else {
  170 + Serial.printf("Failed to set CH temperature setpoint to %.01f *C\n", CHSetpoint);
  171 + }
  172 +
  173 + // Tell the boiler the current room temperature (optional?)
  174 + // This is done by writing this value to DATA-ID OpenTherm::WRITE_DATA_ID::ROOM_TEMPERATURE
  175 + if(thermostat.write(OpenTherm::WRITE_DATA_ID::ROOM_TEMPERATURE, roomTemperature)) {
  176 + Serial.printf("Room temperature set to %.02f *C\n", roomTemperature);
  177 + } else {
  178 + Serial.println("Failed to set room temperature to sensor value");
  179 + }
  180 +
  181 +
  182 + // masterFlags is used to tell the slave (the boiler) what available services (Central heating, cooling, domestic hot water) it wants to make use of, if present
  183 + // The meaning of each bit is defined in enum class OpenTherm::STATUS_FLAGS
  184 + // ENABLE_DOMESTIC_HOT_WATER is a #define. If defined 'true' then domestic hot water is enabled if it is available in the boiler. The prevoiuosly read slaveFlags are used to detect this capability
  185 + uint8_t masterFlags;
  186 + if(ENABLE_DOMESTIC_HOT_WATER && (slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_DHW))) {
  187 + Serial.println("Enable DHW");
  188 + masterFlags |= uint8_t(OpenTherm::STATUS_FLAGS::MASTER_DHW_ENABLE);
  189 + }
  190 +
  191 + // ENABLE_HEATING is a #define. If defined 'true' then central heating is enabled.
  192 +// if(roomTemperature < ROOM_TEMPERATURE_SETPOINT && ENABLE_HEATING) {
  193 + if(ENABLE_HEATING) {
  194 + Serial.println("Enable central heating");
  195 + masterFlags |= uint8_t(OpenTherm::STATUS_FLAGS::MASTER_CH_ENABLE);
  196 + }
  197 +
  198 + // ENABLE_COOLING is a #define. If defined 'true' then cooling is enabled. slaveFlags is used to detect the capability
  199 +// if(roomTemperature > ROOM_TEMPERATURE_SETPOINT && ENABLE_COOLING && (slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_COOLING))) {
  200 + if(ENABLE_COOLING && (slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_COOLING))) {
  201 + Serial.println("Enable cooling");
  202 + masterFlags |= uint8_t(OpenTherm::STATUS_FLAGS::MASTER_COOLING_ENABLE);
  203 + }
  204 +
  205 + // Enable Outside Temperature Compensation by default
  206 + masterFlags |= uint8_t(OpenTherm::STATUS_FLAGS::MASTER_OTC_ENABLE);
  207 +
  208 + // Send masterFlags to the boiler to request services. Using statusFlags the boiler returns if it is in fault status, if it is in central heating status or domestic hot water, if it's flame is burning, etc.
  209 + Serial.println("Request services from the boiler and check it's status...");
  210 + uint8_t statusFlags;
  211 + if(thermostat.status(masterFlags, statusFlags)) { // Mandatory support
  212 + Serial.printf("Flags is 0x%02x\n", statusFlags);
  213 +
  214 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_FAULT_INDICATION)) Serial.println("FAULT NOTIFICATION");
  215 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_CH_MODE)) Serial.println("CH MODE");
  216 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_DHW_MODE)) Serial.println("DHW MODE");
  217 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_FLAME_STATUS)) Serial.println("FLAME");
  218 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_COOLING_STATUS)) Serial.println("COOLING");
  219 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_CH2_MODE)) Serial.println("CH2 ACTIVE");
  220 + if(statusFlags & uint8_t(OpenTherm::STATUS_FLAGS::SLAVE_DIAGNOSTIC_IND)) Serial.println("DIAGNOSTICS INDICATION");
  221 + } else {
  222 + Serial.println("Failed to get status");
  223 + }
  224 + }
  225 +}
... ...
examples/Test_Boiler_Communication/Test_Boiler_Communication.ino 0 → 100644
  1 +++ a/examples/Test_Boiler_Communication/Test_Boiler_Communication.ino
  1 +/*
  2 + * https://github.com/Jeroen88/EasyOpenTherm
  3 + * https://www.tindie.com/products/Metriot/OpenTherm-adapter/
  4 + *
  5 + * Test_Boiler_Communication is a program to test if your MCU can communicate with your OpenTherm compatible boiler
  6 + * Copyright (C) 2022 Jeroen Döll <info@metriot.nl>
  7 + *
  8 + * This program is free software: you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation, either version 3 of the License, or
  11 + * (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20 + *
  21 + * You need an OpenTherm controller that you can buy at my Tindie store,
  22 + * Connect the two boiler wires to the OpenTherm controller pins marked OT. The order is not important.
  23 + * Connect the OpenTherm controller to your microcontroller's power (3v3) and ground (GND) pins.
  24 + * Connect the OpenTherm TXD pin to the microcontroller's pin defined by #define OT_RX_PIN.
  25 + * Connect the OpenTherm RXD pin to the microcontroller's pin defined by #define OT_TX_PIN.
  26 +*/
  27 +
  28 +
  29 +
  30 +#include <Arduino.h>
  31 +
  32 +#include <EasyOpenTherm.h>
  33 +
  34 +
  35 +#define OT_RX_PIN (34)
  36 +#define OT_TX_PIN (17)
  37 +
  38 +
  39 +void setup() {
  40 + // put your setup code here, to run once:
  41 + Serial.begin(115200);
  42 + Serial.println("\n\nStarted");
  43 + delay(5000);
  44 +}
  45 +
  46 +
  47 +void loop() {
  48 + // put your main code here, to run repeatedly:
  49 + static OpenTherm master(OT_RX_PIN, OT_TX_PIN); // Create an OpenTherm master (is thermostat; boiler is slave) with GPIO34 to receive data from boiler and GPIO17 to send data to boiler
  50 +
  51 + // First try to connect to the boiler to read it's capabilities. The boiler returns an 8 bit slaveFlags and each bit has a meaning. The bits are defined in enum class OpenTherm::CONFIGURATION_FLAGS
  52 + // The slaveMemberIDCode identifies the manufacturer of the boiler
  53 + uint8_t slaveFlags;
  54 + uint8_t slaveMemberIDCode;
  55 + if(master.read(OpenTherm::READ_DATA_ID::SLAVE_CONFIGURATION, slaveFlags, slaveMemberIDCode)) { // Mandatory support
  56 + Serial.println("Your setup is working! A frame was send to the boiler and the boiler responded with a valid frame.");
  57 + Serial.printf("Slave configuration flags is 0x%02x, slave member ID is %d (0x%02x).\n", slaveFlags, slaveMemberIDCode, slaveMemberIDCode);
  58 + Serial.println("Here is the meanining of each bit in these flags:");
  59 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_DHW_PRESENT)) Serial.println("DHW present"); else Serial.println("DHW not present");
  60 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_CONTROL_TYPE)) Serial.println("Control type on/off"); else Serial.println("Control type modulating");
  61 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_COOLING)) Serial.println("Cooling supprted"); else Serial.println("Cooling not supported");
  62 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_DHW)) Serial.println("DHW storage tank"); else Serial.println("DHW instantaneous or not-specified");
  63 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_LOW_OFF_PUMP_CTRL)) Serial.println("Low off and pump control not allowed"); else Serial.println("Low off and pump control allowed");
  64 + if(slaveFlags & uint8_t(OpenTherm::CONFIGURATION_FLAGS::SLAVE_CH2_PRESENT)) Serial.println("CH2 present"); else Serial.println("CH2 not present");
  65 + } else {
  66 + slaveFlags = 0;
  67 +
  68 + if(master.error() == OpenTherm::ERROR_CODES::UNKNOWN_DATA_ID) {
  69 + // Valid data is received but the for boilers mandatory DATA-ID OpenTherm::READ_DATA_ID::SLAVE_CONFIGURATION is not recognised. This is not a boiler but another device!
  70 + Serial.println("Your setup is working correctly but the remote device is not a boiler.");
  71 + Serial.println("Look in EasyOpenTherm.h for the HVAC_SLAVE_CONFIGURATION or SOLAR_SLAVE_CONFIGURATION\n DATA-ID and the corresponding master and slave flags.");
  72 + } else {
  73 + // No data or invalid data received
  74 + Serial.println("Your setup is not working yet. Please check:");
  75 + Serial.println("Is the OpenTherm controller connected to the boiler using two wires? The order of the wires is not important.");
  76 + Serial.println("Is the OpenTherm controller correctly powered? The GND pin should be connected to the GND pin of the\n microcontroller and the 3v3 pin to the 3v3 pin of the microcontroller.");
  77 + Serial.printf("Is the OpenTherm controller TxD pin connected to the microcontroller's Rx pin as specified by\n #define OT_RX_PIN? Currently this pin is defined as %d.\n", OT_RX_PIN);
  78 + Serial.printf("Is the OpenTherm controller RxD pin connected to the microcontroller's Tx pin as specified by\n #define OT_TX_PIN? Currently this pin is defined as %d.\n", OT_TX_PIN);
  79 + Serial.printf("Is the microcontroller's Tx pin (currently pin %d} not an 'input only' pin?\n", OT_TX_PIN);
  80 + Serial.printf("Is in your software the OpenTherm object defined as OpenTherm master(OT_RX_PIN, OT_TX_PIN);\n Currently this expands to OpenTherm master(%d, %d);\n", OT_RX_PIN, OT_TX_PIN);
  81 + Serial.println("\n");
  82 + }
  83 + }
  84 +
  85 + // Wait 5 secs and try again
  86 + delay(5000);
  87 +}
... ...
keywords.txt 0 → 100644
  1 +++ a/keywords.txt
  1 +#######################################
  2 +# Syntax Coloring Map For OpenTherm
  3 +#######################################
  4 +
  5 +#######################################
  6 +# Datatypes (KEYWORD1)
  7 +#######################################
  8 +
  9 +OpenTherm KEYWORD1
  10 +OTDataLinkLayer KEYWORD1
  11 +OTPhysicalLayer KEYWORD1
  12 +READ_WRITE_DATA_ID KEYWORD1
  13 +READ_DATA_ID KEYWORD1
  14 +WRITE_DATA_ID KEYWORD1
  15 +STATUS_FLAGS KEYWORD1
  16 +MEMBER_IDS KEYWORD1
  17 +FAULT_FLAGS KEYWORD1
  18 +CONFIGURATION_FLAGS KEYWORD1
  19 +REMOTE_PARAMETER_FLAGS KEYWORD1
  20 +REMOTE_OVERRIDE_FLAGS KEYWORD1
  21 +REMOTE_COMMANDS KEYWORD1
  22 +HVAC_STATUS_FLAGS KEYWORD1
  23 +SOLAR_STATUS_FLAGS KEYWORD1
  24 +SOLAR_MODE_FLAGS_AND_MASKS KEYWORD1
  25 +SOLAR_SLAVE_CONFIGURATION_FLAGS KEYWORD1
  26 +ERROR_CODES KEYWORD1
  27 +MSG_TYPE KEYWORD1
  28 +
  29 +#######################################
  30 +# Methods and Functions (KEYWORD2)
  31 +#######################################
  32 +
  33 +status KEYWORD2
  34 +read KEYWORD2
  35 +write KEYWORD2
  36 +readWrite KEYWORD2
  37 +error KEYWORD2
  38 +
  39 +set KEYWORD2
  40 +parity KEYWORD2
  41 +type KEYWORD2
  42 +dataID KEYWORD2
  43 +value KEYWORD2
  44 +valueMSB KEYWORD2
  45 +valueLSB KEYWORD2
  46 +frame KEYWORD2
  47 +isValid KEYWORD2
  48 +dataInvalid KEYWORD2
  49 +unknownDataID KEYWORD2
  50 +send KEYWORD2
  51 +receive KEYWORD2
  52 +reset KEYWORD2
  53 +handleInterrupt KEYWORD2
  54 +
  55 +#######################################
  56 +# Instances (KEYWORD2)
  57 +#######################################
  58 +
  59 +#######################################
  60 +# Constants (LITERAL1)
  61 +#######################################
  62 +
  63 +STATUS LITERAL1
  64 +COMMAND_CODE LITERAL1
  65 +HVAC_STATUS LITERAL1
  66 +SOLAR_STATUS LITERAL1
  67 +
  68 +FAULT_FLAGS LITERAL1
  69 +OEM_DIAGNOSTIC LITERAL1
  70 +SLAVE_CONFIGURATION LITERAL1
  71 +OPENTHERM_VERSION_SLAVE LITERAL1
  72 +SLAVE_PRODUCT_VERSION LITERAL1
  73 +RELATIVE_MODULATION_LEVEL LITERAL1
  74 +CH_WATER_PRESSURE LITERAL1
  75 +DHW_FLOW_RATE LITERAL1
  76 +DAY_TIME LITERAL1
  77 +DATE LITERAL1
  78 +YEAR LITERAL1
  79 +BOILER_WATER_TEMP LITERAL1
  80 +DHW_TEMPERATURE LITERAL1
  81 +OUTSIDE_TEMPERATURE LITERAL1
  82 +RETURN_WATER_TEMPERATURE LITERAL1
  83 +SOLAR_STORE_TEMPERATURE LITERAL1
  84 +SOLAR_COLLECTOR_TEMPERATURE LITERAL1
  85 +FLOW_TEMPERATURE_CH2 LITERAL1
  86 +DHW2_TEMPERATURE LITERAL1
  87 +EXHAUST_TEMPERATURE LITERAL1
  88 +BURNER_STARTS LITERAL1
  89 +CH_PUMP_STARTS LITERAL1
  90 +DHW_PUMP_VALVE_STARTS LITERAL1
  91 +DHW_BURNER_STARTS LITERAL1
  92 +BURNER_OPERATION_HOURS LITERAL1
  93 +CH_PUMP_OPERATION_HOURS LITERAL1
  94 +DHW_PUMP_VALVE_OPERATION_HOURS LITERAL1
  95 +DHW_BURNER_OPERATION_HOURS LITERAL1
  96 +REMOTE_PARAMETER LITERAL1
  97 +DHW_SETPOINT_BOUNDS LITERAL1
  98 +CH_SETPOINT_BOUNDS LITERAL1
  99 +OTC_CURVE_BOUNDS LITERAL1
  100 +DHW_SETPOINT LITERAL1
  101 +MAX_CH_WATER_SETPOINT LITERAL1
  102 +OTC_CURVE_RATIO LITERAL1
  103 +NUMBER_OF_TSPS LITERAL1
  104 +TSP_COMMAND LITERAL1
  105 +FAULT_BUFFER_SIZE LITERAL1
  106 +FAULT_BUFFER_DATA LITERAL1
  107 +MAX_BOILER_CAPACITY_MIN_MOD_LEV LITERAL1
  108 +CH_SETPOINT_OVERRIDE LITERAL1
  109 +REMOTE_OVERRIDE_FUNCTION LITERAL1
  110 +BOILER_HEAT_EXCHANGER_TEMPERATURE LITERAL1
  111 +BOILER_FAN_SPEED_SETPOINT_VALUE LITERAL1
  112 +ELECTRICAL_CURRENT_BURNER_FLAME LITERAL1
  113 +HVAC_RELATIVE_VENT_SETPOINT LITERAL1
  114 +HVAC_FAULT_FLAGS LITERAL1
  115 +HVAC_OEM_DIAGNOSTIC_CODE LITERAL1
  116 +HVAC_SLAVE_CONFIGURATION LITERAL1
  117 +HVAC_OPENTHERM_VERSION_SLAVE LITERAL1
  118 +HVAC_SLAVE_PRODUCT_VERSION LITERAL1
  119 +HVAC_RELATIVE_VENTILATION LITERAL1
  120 +HVAC_RELATIVE_HUMIDITY_EXHAUST LITERAL1
  121 +HVAC_CO2_LEVEL_EXHAUST_AIR LITERAL1
  122 +HVAC_SUPPLY_INLET_TEMPERATURE LITERAL1
  123 +HVAC_SUPPLY_OUTLET_TEMPERATURE LITERAL1
  124 +HVAC_EXHAUST_INLET_TEMPERATURE LITERAL1
  125 +HVAC_EXHAUST_OUTLET_TEMPERATURE LITERAL1
  126 +HVAC_EXHAUST_FAN_SPEED LITERAL1
  127 +HVAC_SUPPLY_FAN_SPEED LITERAL1
  128 +HVAC_REMOTE_PARAMETER LITERAL1
  129 +HVAC_NOMINAL_RELATIVE_VENTILATION LITERAL1
  130 +HVAC_NUMBER_OF_TSPS LITERAL1
  131 +HVAC_TSP_COMMAND LITERAL1
  132 +HVAC_FAULT_BUFFER_SIZE LITERAL1
  133 +HVAC_FAULT_BUFFER_DATA LITERAL1
  134 +HVAC_RF_STRENGTH_BATTERY_LEVEL LITERAL1
  135 +HVAC_OPERATING_MODE LITERAL1
  136 +SOLAR_FAULT_FLAGS LITERAL1
  137 +SOLAR_SLAVE_CONFIGURATION LITERAL1
  138 +SOLAR_SLAVE_PRODUCT_VERSION LITERAL1
  139 +SOLAR_NUMBER_OF_TSPS LITERAL1
  140 +SOLAR_TSP_COMMAND LITERAL1
  141 +SOLAR_FAULT_BUFFER_SIZE LITERAL1
  142 +SOLAR_FAULT_BUFFER_DATA LITERAL1
  143 +PRODUCER_STARTS LITERAL1
  144 +PRODUCER_HOURS LITERAL1
  145 +PRODUCTION LITERAL1
  146 +CUMULATIVE_PRODUCTION LITERAL1
  147 +UNSUCCESSFUL_BURNER_STARTS LITERAL1
  148 +FLAME_SIGNAL_TOO_LOW LITERAL1
  149 +
  150 +CONTROL_SETPOINT_CH LITERAL1
  151 +CONTROL_SETPOINT_CH2 LITERAL1
  152 +MASTER_CONFIGURATION LITERAL1
  153 +OPENTHERM_VERSION_MASTER LITERAL1
  154 +MASTER_PRODUCT_VERSION LITERAL1
  155 +ROOM_SETPOINT LITERAL1
  156 +DAY_TIME LITERAL1
  157 +DATE LITERAL1
  158 +YEAR LITERAL1
  159 +ROOM_SETPOINT_CH2 LITERAL1
  160 +ROOM_TEMPERATURE LITERAL1
  161 +BURNER_STARTS LITERAL1
  162 +CH_PUMP_STARTS LITERAL1
  163 +DHW_PUMP_VALVE_STARTS LITERAL1
  164 +DHW_BURNER_STARTS LITERAL1
  165 +BURNER_OPERATION_HOURS LITERAL1
  166 +CH_PUMP_OPERATION_HOURS LITERAL1
  167 +DHW_PUMP_VALVE_OPERATION_HOURS LITERAL1
  168 +DHW_BURNER_OPERATION_HOURS LITERAL1
  169 +DHW_SETPOINT LITERAL1
  170 +MAX_CH_WATER_SETPOINT LITERAL1
  171 +OTC_CURVE_RATIO LITERAL1
  172 +TSP_COMMAND LITERAL1
  173 +COOLING_CONTROL LITERAL1
  174 +MAX_MODULATION_LEVEL LITERAL1
  175 +ROOM_TEMPERATURE_CH2 LITERAL1
  176 +
  177 +MASTER_CH_ENABLE LITERAL1
  178 +MASTER_DHW_ENABLE LITERAL1
  179 +MASTER_COOLING_ENABLE LITERAL1
  180 +MASTER_OTC_ENABLE LITERAL1
  181 +MASTER_CH2_ENABLE LITERAL1
  182 +SLAVE_FAULT_INDICATION LITERAL1
  183 +SLAVE_CH_MODE LITERAL1
  184 +SLAVE_DHW_MODE LITERAL1
  185 +SLAVE_FLAME_STATUS LITERAL1
  186 +SLAVE_COOLING_STATUS LITERAL1
  187 +SLAVE_CH2_MODE LITERAL1
  188 +SLAVE_DIAGNOSTIC_IND LITERAL1
  189 +
  190 +REMEHA LITERAL1
  191 +
  192 +SERVICE_REQUEST LITERAL1
  193 +LOCKOUT_RESET LITERAL1
  194 +LOW_WATER_PRESS LITERAL1
  195 +GAS_FLAME LITERAL1
  196 +AIR_PRESS LITERAL1
  197 +WATER_OVER_TEMP LITERAL1
  198 +
  199 +SLAVE_DHW_PRESENT LITERAL1
  200 +SLAVE_CONTROL_TYPE LITERAL1
  201 +SLAVE_COOLING LITERAL1
  202 +SLAVE_DHW LITERAL1
  203 +SLAVE_LOW_OFF_PUMP_CTRL LITERAL1
  204 +SLAVE_CH2_PRESENT LITERAL1
  205 +
  206 +TRANSFER_ENABLE_DHW_SETPOINT LITERAL1
  207 +TRANSFER_ENABLE_MAX_CH_SETPOINT LITERAL1
  208 +READ_WRITE_DHW_SETPOINT LITERAL1
  209 +READ_WRITE_MAX_CH_SETPOINT LITERAL1
  210 +
  211 +MANUAL_CHANGE_PRIORITY LITERAL1
  212 +REMOTE_CHANGE_PRIORITY LITERAL1
  213 +
  214 +BLOR LITERAL1
  215 +CHWF LITERAL1
  216 +
  217 +MASTER_VENTILATION_ENABLE LITERAL1
  218 +MASTER_BYPASS_POSTION LITERAL1
  219 +MASTER__BYPASS_MODE LITERAL1
  220 +MASTER_FREE_VENTILATION_MODE LITERAL1
  221 +SLAVE_FAULT_INDICATION LITERAL1
  222 +SLAVE_VENTILATION_MODE LITERAL1
  223 +SLAVE_BYPASS_STATUS LITERAL1
  224 +SLAVE_BYPASS_AUTOMATIC_STATUS LITERAL1
  225 +SLAVE_FREE_VENTILATION_MODE LITERAL1
  226 +SLAVE_DIAGNOSTIC_IND LITERAL1
  227 +
  228 +MASTER_MODE LITERAL1
  229 +SLAVE_FAULT_INDICATION LITERAL1
  230 +SLAVE_MODE LITERAL1
  231 +SLAVE_STATUS LITERAL1
  232 +
  233 +SYSTEM_TYPE LITERAL1
  234 +BYPASS LITERAL1
  235 +SPEED_CONTROL LITERAL1
  236 +
  237 +SLAVE_SYSTEM_TYPE LITERAL1
  238 +
  239 +OK LITERAL1
  240 +UNKNOWN_DATA_ID LITERAL1
  241 +INVALID_DATA LITERAL1
  242 +SEND_TIMEOUT LITERAL1
  243 +RECEIVE_TIMEOUT LITERAL1
  244 +PARITY_ERROR LITERAL1
  245 +UNKNOWN_ERROR LITERAL1
  246 +
  247 +MASTER_TO_SLAVE_READ_DATA LITERAL1
  248 +MASTER_TO_SLAVE_WRITE_DATA LITERAL1
  249 +MASTER_TO_SLAVE_INVALID_DATA LITERAL1
  250 +MASTER_TO_SLAVE_RESERVED LITERAL1
  251 +SLAVE_TO_MASTER_READ_ACK LITERAL1
  252 +SLAVE_TO_MASTER_WRITE_ACK LITERAL1
  253 +SLAVE_TO_MASTER_DATA_INVALID LITERAL1
  254 +SLAVE_TO_MASTER_UNKNOWN_DATA_ID LITERAL1
  255 +
... ...
library.properties 0 → 100644
  1 +++ a/library.properties
  1 +name=EasyOpenTherm
  2 +version=0.0.1
  3 +author=Jeroen Döll <info@metriot.nl>
  4 +maintainer=Jeroen Döll <info@metriot.nl>
  5 +sentence=OpenTherm Library to control Central Heating, HVAC or Solar systems using Arduino IDE and ESP32 / ESP8266 hardware.
  6 +paragraph=OpenTherm Library is based on OpenTherm protocol specification v2.2 and higher and works with all OpenTherm compatible boilers, HVACs and Solar systems
  7 +category=Device Control
  8 +url=https://github.com/Jeroen88/EasyOpenTherm
  9 +architectures=*
  10 +includes=EasyOpenTherm.h
... ...
src/EasyOpenTherm.cpp 0 → 100644
  1 +++ a/src/EasyOpenTherm.cpp
  1 +/*
  2 + * https://github.com/Jeroen88/EasyOpenTherm
  3 + * https://www.tindie.com/products/Metriot/OpenTherm-adapter/
  4 + *
  5 + * EasyOpenTherm is a library to communicate with OpenTherm compatible devices
  6 + * Copyright (C) 2022 Jeroen Döll <info@metriot.nl>
  7 + *
  8 + * This program is free software: you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation, either version 3 of the License, or
  11 + * (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20 +*/
  21 +
  22 +
  23 +#include "EasyOpenTherm.h"
  24 +
  25 +
  26 +
  27 +
  28 + OpenTherm::OpenTherm(uint8_t rxPin,
  29 + uint8_t txPin,
  30 + time_t timeoutMs,
  31 + bool master): _rxPin(rxPin), _txPin(txPin), _timeoutMs(timeoutMs), _master(master) {
  32 + _OTP = new OTPhysicalLayer(_rxPin, _txPin, master);
  33 +
  34 + if(!_OTP) Serial.println("OpenTherm Out of Memory, fail on assert()");
  35 + assert(_OTP != NULL); // check for Out of Memory
  36 +}
  37 +
  38 +
  39 + OpenTherm::~OpenTherm() {
  40 + delete _OTP;
  41 +}
  42 +
  43 +
  44 +bool OpenTherm::status(uint8_t & slaveFlags) {
  45 + uint8_t masterFlags = uint8_t(OpenTherm::STATUS_FLAGS::MASTER_CH_ENABLE) | uint8_t(OpenTherm::STATUS_FLAGS::MASTER_DHW_ENABLE) | uint8_t(OpenTherm::STATUS_FLAGS::MASTER_COOLING_ENABLE) | uint8_t(OpenTherm::STATUS_FLAGS::MASTER_OTC_ENABLE);
  46 +
  47 + return status(masterFlags, slaveFlags);
  48 +}
  49 +
  50 +
  51 +bool OpenTherm::status(uint8_t masterFlags,
  52 + uint8_t & slaveFlags) {
  53 + slaveFlags = 0x00; // See OpenTherm Protocol Specification v2.2 page 25
  54 + return readWrite(READ_WRITE_DATA_ID::STATUS, masterFlags, slaveFlags);
  55 +}
  56 +
  57 +
  58 +bool OpenTherm::read(READ_DATA_ID msgID,
  59 + uint16_t & value) {
  60 + OTDataLinkLayer data;
  61 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), 0x0000);
  62 +
  63 + if(_execute(data)) {
  64 + value = data.value();
  65 +
  66 + return true;
  67 + }
  68 +
  69 + return false;
  70 +}
  71 +
  72 +
  73 +bool OpenTherm::read(READ_DATA_ID msgID,
  74 + int16_t & value) { // signed integer
  75 + OTDataLinkLayer data;
  76 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), 0x0000);
  77 +
  78 + if(_execute(data)) {
  79 + value = int16_t(data.value());
  80 +
  81 + return true;
  82 + }
  83 +
  84 + return false;
  85 +}
  86 +
  87 +
  88 +bool OpenTherm::read(READ_DATA_ID msgID,
  89 + uint8_t & valueMSB,
  90 + uint8_t & valueLSB) {
  91 + OTDataLinkLayer data;
  92 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), 0x0000);
  93 +
  94 + if(_execute(data)) {
  95 + valueMSB = data.valueMSB();
  96 + valueLSB = data.valueLSB();
  97 +
  98 + return true;
  99 + }
  100 +
  101 + return false;
  102 +}
  103 +
  104 +
  105 +bool OpenTherm::read(READ_DATA_ID msgID,
  106 + int8_t & valueMSB, // signed intergers
  107 + int8_t & valueLSB) {
  108 + OTDataLinkLayer data;
  109 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), 0x0000);
  110 +
  111 + if(_execute(data)) {
  112 + valueMSB = int8_t(data.valueMSB());
  113 + valueLSB = int8_t(data.valueLSB());
  114 +
  115 + return true;
  116 + }
  117 +
  118 + return false;
  119 +}
  120 +
  121 +
  122 +bool OpenTherm::read(READ_DATA_ID msgID,
  123 + float & value) {
  124 + OTDataLinkLayer data;
  125 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), 0x0000);
  126 +
  127 + if(_execute(data)) {
  128 + value = float(data.value()) / 256.0;
  129 +
  130 + return true;
  131 + }
  132 +
  133 + return false;
  134 +}
  135 +
  136 +
  137 +bool OpenTherm::write(WRITE_DATA_ID msgID,
  138 + uint16_t value) {
  139 + OTDataLinkLayer data;
  140 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_WRITE_DATA, uint8_t(msgID), value);
  141 +
  142 + return _execute(data);
  143 +}
  144 +
  145 +
  146 +bool OpenTherm::write(WRITE_DATA_ID msgID,
  147 + uint8_t valueMSB,
  148 + uint8_t valueLSB) {
  149 + OTDataLinkLayer data;
  150 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_WRITE_DATA, uint8_t(msgID), valueMSB, valueLSB);
  151 +
  152 + return _execute(data);
  153 +}
  154 +
  155 +
  156 +bool OpenTherm::write(WRITE_DATA_ID msgID,
  157 + float value) {
  158 + OTDataLinkLayer data;
  159 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_WRITE_DATA, uint8_t(msgID), uint16_t(value * 256.0f));
  160 +
  161 + return _execute(data);
  162 +}
  163 +
  164 +
  165 +bool OpenTherm::readWrite(READ_WRITE_DATA_ID msgID,
  166 + uint8_t valueMSB,
  167 + uint8_t & valueLSB) {
  168 + OTDataLinkLayer data;
  169 + data.set(OTDataLinkLayer::MSG_TYPE::MASTER_TO_SLAVE_READ_DATA, uint8_t(msgID), valueMSB, valueLSB);
  170 +
  171 + if(_execute(data)) {
  172 + valueLSB = data.valueLSB();
  173 +
  174 + return true;
  175 + }
  176 +
  177 + return false;
  178 +}
  179 +
  180 +
  181 +OpenTherm::ERROR_CODES OpenTherm::error() {
  182 + return _lastError;
  183 +}
  184 +
  185 +
  186 +bool OpenTherm::_execute(OTDataLinkLayer & data) {
  187 + _lastError = ERROR_CODES::OK;
  188 +
  189 + time_t startMillis = millis();
  190 + for(;;) {
  191 + if(millis() - startMillis >= _timeoutMs) {
  192 + _lastError = ERROR_CODES::SEND_TIMEOUT;
  193 +
  194 + _OTP->reset();
  195 +
  196 + return false;
  197 + }
  198 +
  199 + if(_OTP->send(data.frame())) break;
  200 + }
  201 +
  202 + startMillis = millis();
  203 + for(;;) {
  204 + if(millis() - startMillis >= _timeoutMs) {
  205 + _lastError = ERROR_CODES::RECEIVE_TIMEOUT;
  206 + _OTP->reset();
  207 +
  208 + return false;
  209 + }
  210 +
  211 + uint32_t frame;
  212 + if(_OTP->receive(frame)) {
  213 + data.set(frame);
  214 +
  215 + if(data.isValid()) {
  216 +
  217 + return true;
  218 + } else {
  219 + if(data.parity()) _lastError = ERROR_CODES::PARITY_ERROR;
  220 + else if(data.dataInvalid()) _lastError = ERROR_CODES::INVALID_DATA;
  221 + else if(data.unknownDataID()) _lastError = ERROR_CODES::UNKNOWN_DATA_ID;
  222 + else _lastError = ERROR_CODES::UNKNOWN_ERROR;
  223 +
  224 + return false;
  225 + }
  226 + }
  227 + }
  228 +
  229 + return false;
  230 +}
  231 +
  232 +
  233 +
  234 +
  235 + OTDataLinkLayer::OTDataLinkLayer() {
  236 + _frame = 0;
  237 +}
  238 +
  239 + OTDataLinkLayer::OTDataLinkLayer(uint32_t frame) {
  240 + _frame = frame;
  241 +}
  242 +
  243 +
  244 +void OTDataLinkLayer::set(uint32_t frame) {
  245 + _frame = frame;
  246 +}
  247 +
  248 +
  249 +void OTDataLinkLayer::set(MSG_TYPE msgType,
  250 + uint8_t dataID,
  251 + uint16_t value) {
  252 + _frame = uint32_t(msgType) | (uint32_t(dataID) << 16) | uint32_t(value);
  253 + if(!_parity(_frame)) _frame |= 0x80000000;
  254 +}
  255 +
  256 +
  257 +void OTDataLinkLayer::set(MSG_TYPE msgType,
  258 + uint8_t dataID,
  259 + uint8_t valueMSB,
  260 + uint8_t valueLSB) {
  261 + _frame = uint32_t(msgType) | (uint32_t(dataID) << 16) | (uint32_t(valueMSB) << 8) | uint32_t(valueLSB);
  262 + if(!_parity(_frame)) _frame |= 0x80000000;
  263 +}
  264 +
  265 +
  266 +bool OTDataLinkLayer::parity() {
  267 + return _parity(_frame);
  268 +}
  269 +
  270 +OTDataLinkLayer::MSG_TYPE OTDataLinkLayer::type() {
  271 + return OTDataLinkLayer::MSG_TYPE(_frame & 0x70000000);
  272 +}
  273 +
  274 +
  275 +uint8_t OTDataLinkLayer::dataID() {
  276 + return uint8_t((_frame & 0xff0000) >> 16);
  277 +}
  278 +
  279 +
  280 +uint16_t OTDataLinkLayer::value() {
  281 + return uint16_t(_frame & 0xffff);
  282 +}
  283 +
  284 +
  285 +uint8_t OTDataLinkLayer::valueMSB() {
  286 + return uint8_t((_frame & 0xff00) >> 8);
  287 +}
  288 +
  289 +
  290 +uint8_t OTDataLinkLayer::valueLSB() {
  291 + return uint8_t(_frame & 0xff);
  292 +}
  293 +
  294 +
  295 +uint32_t OTDataLinkLayer::frame() {
  296 + return _frame;
  297 +}
  298 +
  299 +
  300 +bool OTDataLinkLayer::isValid() {
  301 + return parity() && (type() == MSG_TYPE::SLAVE_TO_MASTER_READ_ACK || type() == MSG_TYPE::SLAVE_TO_MASTER_WRITE_ACK || type() == MSG_TYPE::MASTER_TO_SLAVE_READ_DATA || type() == MSG_TYPE::MASTER_TO_SLAVE_WRITE_DATA);
  302 +}
  303 +
  304 +
  305 +bool OTDataLinkLayer::dataInvalid() {
  306 + return type() == MSG_TYPE::SLAVE_TO_MASTER_DATA_INVALID || type() == MSG_TYPE::MASTER_TO_SLAVE_INVALID_DATA;
  307 +}
  308 +
  309 +
  310 +bool OTDataLinkLayer::unknownDataID() {
  311 + return type() == MSG_TYPE::SLAVE_TO_MASTER_UNKNOWN_DATA_ID; // Slave does not select the DATA-ID, this function should not be called from a slave
  312 +}
  313 +
  314 +
  315 +// https://stackoverflow.com/questions/21617970/how-to-check-if-value-has-even-parity-of-bits-or-odd
  316 +bool OTDataLinkLayer::_parity(uint32_t frame) {
  317 + frame ^= frame >> 16;
  318 + frame ^= frame >> 8;
  319 + frame ^= frame >> 4;
  320 + frame ^= frame >> 2;
  321 + frame ^= frame >> 1;
  322 + return (~frame) & 1;
  323 +}
  324 +
  325 +
  326 +
  327 +
  328 +OTPhysicalLayer * OTPPtr = NULL;
  329 +
  330 +#if defined(ESP32)
  331 +void IRAM_ATTR OTPGenericISR() {
  332 +#elif defined(ESP8266)
  333 +void ICACHE_RAM_ATTR OTPGenericISR() {
  334 +#else
  335 +void OTPGenericISR() {
  336 +#endif
  337 + if(OTPPtr) OTPPtr->handleInterrupt();
  338 +}
  339 +
  340 +
  341 + OTPhysicalLayer::OTPhysicalLayer(uint8_t rxPin,
  342 + uint8_t txPin,
  343 + bool master): _rxPin(rxPin), _txPin(txPin), _master(master) {
  344 +
  345 + pinMode(_rxPin, INPUT);
  346 + pinMode(_txPin, OUTPUT);
  347 + digitalWrite(_txPin, HIGH); // idle
  348 +
  349 + if(OTPPtr != NULL) {
  350 + Serial.println("Only one instance of OTPhysicalLayer() may be active at the time. Executing will fail on an assert(false)");
  351 + }
  352 + assert(OTPPtr == NULL); // For now only one instance allowed, later a list OTPPtr could be a <list> and the ISR a timer ISR (this is needed because now the ISR is attached to a specific pin)
  353 + OTPPtr = this;
  354 +
  355 + attachInterrupt(digitalPinToInterrupt(_rxPin), OTPGenericISR, CHANGE);
  356 +}
  357 +
  358 +
  359 + OTPhysicalLayer::~OTPhysicalLayer() {
  360 + OTPPtr = NULL;
  361 +
  362 + detachInterrupt(digitalPinToInterrupt(_rxPin));
  363 +}
  364 +
  365 +
  366 +bool OTPhysicalLayer::send(uint32_t frame) {
  367 + if(_state != STATE::READY && _state != STATE::INVALID) {
  368 + return false;
  369 + }
  370 +
  371 + if(_state == STATE::READY && millis() - _lastReceivedTimestampMs < 100) {
  372 +
  373 + return false; // Wait at least 100 ms after receiving the final bit of the latest frame before sending a new frame
  374 + }
  375 +
  376 + sendBit(HIGH); // start bit
  377 +
  378 + uint32_t mask = 0x80000000UL;
  379 + while(mask) { // data bits
  380 + sendBit((frame & mask) ? HIGH : LOW);
  381 + mask >>= 1;
  382 + }
  383 +
  384 + sendBit(HIGH); // stop bit
  385 +
  386 + digitalWrite(_txPin, HIGH); // idle
  387 +
  388 + _frame = 0;
  389 + _state = STATE::WAITING;
  390 +
  391 + _lastSentTimestampMs = millis();
  392 +
  393 + return true;
  394 +}
  395 +
  396 +
  397 +bool OTPhysicalLayer::receive(uint32_t & frame) {
  398 + if(_state == STATE::INVALID) return false; // ::send() will set _state to STATE::WAITING
  399 +
  400 + if(_state != STATE::READY) { // ::handleInterrupt() will set _state to STATE::READY upon receiving a complete frame (including start and stop bits)
  401 + if(_master && millis() - _lastSentTimestampMs > 800) { // ::send() will set _lastSentTimestampMs to after sending the final bit. A slave never times out, it keeps on listning to the master
  402 + _state = STATE::INVALID; // timeout
  403 + }
  404 +
  405 + return false;
  406 + }
  407 +
  408 + frame = _frame; // _state == STATE::READY so a frame is available. The frame may be retrieved by calling ::receive() until the next ::send() is called
  409 +
  410 + return true;
  411 +}
  412 +
  413 +
  414 +void OTPhysicalLayer::reset() {
  415 + _state = STATE::INVALID;
  416 +}
  417 +
  418 +
  419 +void OTPhysicalLayer::sendBit(uint8_t val) {
  420 + digitalWrite(_txPin, (val == HIGH) ? LOW : HIGH);
  421 + delayMicroseconds(500);
  422 + digitalWrite(_txPin, (val == HIGH) ? HIGH : LOW);
  423 + delayMicroseconds(500);
  424 +}
  425 +
  426 +
  427 + void OTPhysicalLayer::handleInterrupt() {
  428 + static volatile uint32_t lastTimestamp;
  429 + static volatile uint32_t mask;
  430 +
  431 + if(_state == STATE::INVALID) return; // Start reception after _send() has set _state to STATE::WAITING
  432 + // ::handleInterrupt() passes from STATE_WATING to STATE::START_BIT, to STATE::RECEIVING for the data bits, to _state STATE::READY after the stop bit
  433 + if(_state == STATE::READY) {
  434 + if(!_master && digitalRead(_rxPin) == HIGH) {
  435 + _state = STATE::WAITING;
  436 + _frame = 0;
  437 + } else {
  438 +
  439 + return; // Nothing to do for a master in _state is STATE::READY
  440 + }
  441 + }
  442 +
  443 + uint32_t timestamp = micros();
  444 + if(_state == STATE::WAITING) { // First bit received after sending is the start bit. Init mask for first data bit (the most significant bit is send first)
  445 + if(digitalRead(_rxPin) == HIGH) { // start bit
  446 + lastTimestamp = timestamp;
  447 + mask = 0x80000000UL;
  448 + _state = STATE::START_BIT;
  449 +
  450 + } else {
  451 + _state = STATE::INVALID;
  452 + }
  453 + } else if(_state == STATE::START_BIT) { // First bit received after the start bit is the first data bit
  454 + if(timestamp - lastTimestamp < 750 && digitalRead(_rxPin) == LOW) {
  455 + lastTimestamp = timestamp;
  456 + _state = STATE::RECEIVING;
  457 + } else {
  458 + _state = STATE::INVALID;
  459 + }
  460 + } else if(_state == STATE::RECEIVING) { // Record all received data bits until mask == 0; then alle data bits are consumed and this must be the final stop bit. Set _state to STATE::READY signaliing that a frame is available
  461 + if(timestamp - lastTimestamp > 750) {
  462 + if(mask) { // data bit
  463 + if(digitalRead(_rxPin) == LOW) _frame |= mask;
  464 + lastTimestamp = timestamp;
  465 + mask >>= 1;
  466 + } else { // stop bit
  467 + _lastReceivedTimestampMs = millis();
  468 + _state = STATE::READY;
  469 + }
  470 + }
  471 + }
  472 +}
... ...
src/EasyOpenTherm.h 0 → 100644
  1 +++ a/src/EasyOpenTherm.h
  1 +/*
  2 + * https://github.com/Jeroen88/EasyOpenTherm
  3 + * https://www.tindie.com/products/Metriot/OpenTherm-adapter/
  4 + *
  5 + * EasyOpenTherm is a library to communicate with OpenTherm compatible devices
  6 + * Copyright (C) 2022 Jeroen Döll <info@metriot.nl>
  7 + *
  8 + * This program is free software: you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation, either version 3 of the License, or
  11 + * (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20 +*/
  21 +
  22 +
  23 +#pragma once
  24 +
  25 +#include <Arduino.h>
  26 +
  27 +
  28 +class OTDataLinkLayer; // Foreward declaration
  29 +class OTPhysicalLayer; // Foreward declaration
  30 +
  31 +
  32 +class OpenTherm {
  33 +public:
  34 + OpenTherm(uint8_t rxPin,
  35 + uint8_t txPin,
  36 + time_t timeoutMs = 900,
  37 + bool master = true);
  38 +
  39 + ~OpenTherm();
  40 +
  41 + bool status(uint8_t & slaveFlags);
  42 +
  43 + bool status(uint8_t masterFlags,
  44 + uint8_t & slaveFlags);
  45 +
  46 +
  47 + enum class READ_WRITE_DATA_ID {
  48 + // Class 1 : Control and Status Information
  49 + STATUS = 0, // flag8, flag8 Mandatory: Master status, slave status
  50 +
  51 + // Class 3 : Remote Commands
  52 + COMMAND_CODE = 4, // u8, u8 Command code / Response to command
  53 +
  54 + // Incomplete information for all DATA-IDs below. If these DATA-IDs are R, W or R/W is unknown. Also the data type is unknown and deducted from the name. These DATA-IDs are not ordered by class
  55 + // Where applicable and available flags and masks are also defined below
  56 +
  57 + // HVAC specific DATA-IDs (ventilation / heat recovery)
  58 + HVAC_STATUS = 70, // flag8, flag8 Master status, slave status
  59 +
  60 + // Solar specific DATA-IDs
  61 + SOLAR_STATUS = 101, // flag8, flag8? MSB Master Solar Storage Mode, LSB Slave Solar Storage Mode
  62 + };
  63 +
  64 +
  65 + enum class READ_DATA_ID {
  66 + // Class 1 : Control and Status Information
  67 + FAULT_FLAGS = 5, // flag8, u8 Application-specific fault flags and OEM fault code
  68 + OEM_DIAGNOSTIC = 115, // u16 An OEM-specific diagnostic/service code
  69 +
  70 + // Class 2 : Configuration Information
  71 + SLAVE_CONFIGURATION = 3, // flag8, u8 Mandatory: Slave Configuration Flags / MemberID Code of the slave
  72 + OPENTHERM_VERSION_SLAVE = 125, // f8.8 The implemented version of the OpenTherm Protocol Specification in the slave
  73 + SLAVE_PRODUCT_VERSION = 127, // u8, u8 The slave device product version number and type as defined by the manufacturer
  74 +
  75 + // Class 4 : Sensor and Informational Data
  76 + RELATIVE_MODULATION_LEVEL = 17, // f8.8 Mandatory: Percent modulation between min and max modulation levels. i.e. 0% = Minimum modulation level and 100% = Maximum modulation level (%)
  77 + CH_WATER_PRESSURE = 18, // f8.8 Water pressure of the boiler CH circuit (bar)
  78 + DHW_FLOW_RATE = 19, // f8.8 Water flow rate through the DHW circuit (l/min)
  79 + DAY_TIME = 20, // special, u8 Day of Week and Time of Day; special: bit 7,6,5 day of week (1=Monday, etc...., 0=no DoW info available); bit 4,3,2,1,0 hours, LSB is minutes
  80 + DATE = 21, // u8, u8 Calendar date: Month, Day of month
  81 + YEAR = 22, // u16 Calendar year; note : 1999-2099 will normally be sufficient
  82 + BOILER_WATER_TEMP = 25, // f8.8 Mandatory: Flow water temperature from boiler (°C)
  83 + DHW_TEMPERATURE = 26, // f8.8 Domestic hot water temperature (°C)
  84 + OUTSIDE_TEMPERATURE = 27, // f8.8 Outside air temperature (°C)
  85 + RETURN_WATER_TEMPERATURE = 28, // f8.8 Return water temperature to boiler (°C)
  86 + SOLAR_STORE_TEMPERATURE = 29, // f8.8 Solar storage temperature (°C)
  87 + SOLAR_COLLECTOR_TEMPERATURE = 30, // f8.8 Solar collector temperature (°C)
  88 + FLOW_TEMPERATURE_CH2 = 31, // f8.8 Flow water temperature of the second central heating circuit (°C)
  89 + DHW2_TEMPERATURE = 32, // f8.8 Domestic hot water temperature 2 (°C)
  90 + EXHAUST_TEMPERATURE = 33, // s16 Exhaust temperature (°C)
  91 + BURNER_STARTS = 116, // u16 Number of starts burner. Reset by writing zero is optional for slave
  92 + CH_PUMP_STARTS = 117, // u16 Number of starts CH pump. Reset by writing zero is optional for slave
  93 + DHW_PUMP_VALVE_STARTS = 118, // u16 Number of starts DHW pump/valve. Reset by writing zero is optional for slave
  94 + DHW_BURNER_STARTS = 119, // u16 Number of starts burner in DHW mode. Reset by writing zero is optional for slave
  95 + BURNER_OPERATION_HOURS = 120, // u16 Number of hours that burner is in operation (i.e. flame on). Reset by writing zero is optional for slave
  96 + CH_PUMP_OPERATION_HOURS = 121, // u16 Number of hours that CH pump has been running. Reset by writing zero is optional for slave
  97 + DHW_PUMP_VALVE_OPERATION_HOURS = 122, // u16 Number of hours that DHW pump has been running or DHW valve has been opened. Reset by writing zero is optional for slave
  98 + DHW_BURNER_OPERATION_HOURS = 123, // u16 Number of hours that burner is in operation during DHW mode. Reset by writing zero is optional for slave
  99 +
  100 + // Class 5 : Pre-Defined Remote Boiler Parameters
  101 + REMOTE_PARAMETER = 6, // flag8, flag8 Remote boiler parameter transfer-enable flags, read/write flags
  102 + DHW_SETPOINT_BOUNDS = 48, // s8, s8 Upper bound for adjustment of DHW setp (°C), Lower bound for adjustment of DHW setp (°C)
  103 + CH_SETPOINT_BOUNDS = 49, // s8, s8 Upper bound for adjustment of maxCH setp (°C), Lower bound for adjustment of maxCH setp (°C)
  104 + OTC_CURVE_BOUNDS = 50, // s8, s8 upp/low bnd
  105 + DHW_SETPOINT = 56, // f8.8 Domestic hot water temperature setpoint (Remote parameter 1) (°C)
  106 + MAX_CH_WATER_SETPOINT = 57, // f8.8 Maximum allowable CH water setpoint (Remote parameter 2) (°C)
  107 + OTC_CURVE_RATIO = 58, // f8.8 OTC heat curve ratio (Remote parameter 3) (°C)
  108 +
  109 + // Class 6 : Transparent Slave Parameters
  110 + NUMBER_OF_TSPS = 10, // u8, u8 Number of transparent-slave-parameter supported by the slave device, -Reserved-
  111 + TSP_COMMAND = 11, // u8, u8 Index number of following TSP, Value of the referenced TSP
  112 +
  113 + // Class 7 : Fault History Data
  114 + FAULT_BUFFER_SIZE = 12, // u8, u8 The size of the fault history buffer, -Reserved-
  115 + FAULT_BUFFER_DATA = 13, // u8, u8 Index number of Fault Buffer entry, Value of the referenced Fault Buffer entry
  116 +
  117 + // Class 8 : Control of Special Applications
  118 + MAX_BOILER_CAPACITY_MIN_MOD_LEV = 15, // u8, u8 MSB : max. boiler capacity (0..255kW), LSB : min. modulation level (0..100%) expressed as a percentage of the maximum capacity
  119 + CH_SETPOINT_OVERRIDE = 9, // f8.8 Remote override room setpoint (0 is no override, 1..30 is remote override room setpoint)
  120 + REMOTE_OVERRIDE_FUNCTION = 100, // flag8, u8 Bit 0: Manual change priority; bit 1: Program change priority, HSB -Reserved-
  121 +
  122 +
  123 + // Incomplete information for all DATA-IDs below. If these DATA-IDs are R, W or R/W is unknown. Also the data type is unknown and deducted from the name. These DATA-IDs are not ordered by class
  124 + // Where applicable and available flags and masks are also defined below
  125 +
  126 + // Boiler specific DATA-IDs
  127 + BOILER_HEAT_EXCHANGER_TEMPERATURE = 34, // f8.8 Boiler heat exchanger temperature (°C)
  128 + BOILER_FAN_SPEED_SETPOINT_VALUE = 35, // ? Boiler fan speed Setpoint and actual value
  129 + ELECTRICAL_CURRENT_BURNER_FLAME = 36, // ? Electrical current through burner flame (μA)
  130 +
  131 + // HVAC specific DATA-IDs (ventilation / heat recovery)
  132 + HVAC_RELATIVE_VENT_SETPOINT = 71, // f8.8 Relative ventilation position (0-100%)
  133 + HVAC_FAULT_FLAGS = 72, // flag8, u8 Application-specific fault flags and OEM fault code
  134 + HVAC_OEM_DIAGNOSTIC_CODE = 73, // u16 An OEM specific diagnostic/service code
  135 + HVAC_SLAVE_CONFIGURATION = 74, // flag8, u8 Slave Configuration Flags / MemberID Code of the slave
  136 + HVAC_OPENTHERM_VERSION_SLAVE = 75, // f8.8 The implemented version of the OpenTherm Protocol Specification in the slave
  137 + HVAC_SLAVE_PRODUCT_VERSION = 76, // u8, u8 The slave device product version number and type as defined by the manufacturer
  138 + HVAC_RELATIVE_VENTILATION = 77, // f8.8 Relative ventilation (0-100%)
  139 + HVAC_RELATIVE_HUMIDITY_EXHAUST = 78, // f8.8 Relative humidity exhaust air (0-100%)
  140 + HVAC_CO2_LEVEL_EXHAUST_AIR = 79, // ? CO2 level exhaust air (0-2000 ppm)
  141 + HVAC_SUPPLY_INLET_TEMPERATURE = 80, // f8.8 Supply inlet temperature (*C)
  142 + HVAC_SUPPLY_OUTLET_TEMPERATURE = 81, // f8.8 Supply outlet temperature (*C)
  143 + HVAC_EXHAUST_INLET_TEMPERATURE = 82, // f8.8 Exhaust inlet temperature (*C)
  144 + HVAC_EXHAUST_OUTLET_TEMPERATURE = 83, // f8.8 Exhaust outlet temperature (*C)
  145 + HVAC_EXHAUST_FAN_SPEED = 84, // u16? Exhaust fan speed (rpm)
  146 + HVAC_SUPPLY_FAN_SPEED = 85, // u16? Supply fan speed (rpm)
  147 + HVAC_REMOTE_PARAMETER = 86, // u8, u8? MSB Remote parameter transfer enable nominal ventilation value, LSB Remote parameter read/write nominal ventilation value
  148 + HVAC_NOMINAL_RELATIVE_VENTILATION = 87, // f8.8 Nominal relative value for ventilation (0-100%)
  149 + HVAC_NUMBER_OF_TSPS = 88, // u8, u8? Number of transparent-slave-parameter supported by the slave device, -Reserved-
  150 + HVAC_TSP_COMMAND = 89, // u8, u8 Index number of following TSP, Value of the referenced TSP
  151 + HVAC_FAULT_BUFFER_SIZE = 90, // u8, u8? The size of the fault history buffer
  152 + HVAC_FAULT_BUFFER_DATA = 91, // u8, u8 Index number of Fault Buffer entry, Value of the referenced Fault Buffer entry
  153 + HVAC_RF_STRENGTH_BATTERY_LEVEL = 98, // u8, u8? For a specific RF sensor RF strength and battery level
  154 + HVAC_OPERATING_MODE = 99, // ? Operating mode HC1, HC2 / Operating mode DHW
  155 +
  156 + // Solar specific DATA-IDs
  157 + SOLAR_FAULT_FLAGS = 102, // flag8, u8 Application-specific fault flags and OEM fault code
  158 + SOLAR_SLAVE_CONFIGURATION = 103, // flag8, u8 Slave Configuration Flags / MemberID Code of the slave
  159 + SOLAR_SLAVE_PRODUCT_VERSION = 104, // u8, u8 The slave device product version number and type as defined by the manufacturer
  160 + SOLAR_NUMBER_OF_TSPS = 105, // u8, u8? Number of transparent-slave-parameter supported by the slave device, -Reserved-
  161 + SOLAR_TSP_COMMAND = 106, // u8, u8 Index number of following TSP, Value of the referenced TSP
  162 + SOLAR_FAULT_BUFFER_SIZE = 107, // u8, u8? The size of the fault history buffer
  163 + SOLAR_FAULT_BUFFER_DATA = 108, // u8, u8 Index number of Fault Buffer entry, Value of the referenced Fault Buffer entry
  164 +
  165 + // Electricity specific DATA-IDs
  166 + PRODUCER_STARTS = 109, // u16 Electricity producer starts
  167 + PRODUCER_HOURS = 110, // u16 Electricity producer hours
  168 + PRODUCTION = 111, // u16 Electricity production
  169 + CUMULATIVE_PRODUCTION = 112, // u16 Electricity cumulative production
  170 +
  171 + // Boiler specific DATA-IDs
  172 + UNSUCCESSFUL_BURNER_STARTS = 113, // u16 Number of unsuccessful burner starts
  173 + FLAME_SIGNAL_TOO_LOW = 114, // u16 Number of times flame signal was too low
  174 + };
  175 +
  176 +
  177 + enum class WRITE_DATA_ID {
  178 + // Class 1 : Control and Status Information
  179 + CONTROL_SETPOINT_CH = 1, // f8.8 Mandatory: Control setpoint (CH water temperature setpoint) (°C)
  180 + CONTROL_SETPOINT_CH2 = 8, // f8.8 Control setpoint for 2nd CH circuit (°C)
  181 +
  182 + // Class 2 : Configuration Information
  183 + MASTER_CONFIGURATION = 2, // flag8, u8 Master Configuration Flags / MemberID Code of the master
  184 + OPENTHERM_VERSION_MASTER = 124, // f8.8 The implemented version of the OpenTherm Protocol Specification in the master
  185 + MASTER_PRODUCT_VERSION = 126, // u8, u8 The master device product version number and type as defined by the manufacturer
  186 +
  187 + // Class 4 : Sensor and Informational Data
  188 + ROOM_SETPOINT = 16, // f8.8 Current room temperature setpoint (°C)
  189 + DAY_TIME = 20, // special, u8 Day of Week and Time of Day; special: bit 7,6,5 day of week (1=Monday, etc...., 0=no DoW info available); bit 4,3,2,1,0 hours, LSB is minutes
  190 + DATE = 21, // u8, u8 Calendar date: Month, Day of month
  191 + YEAR = 22, // u16 Calendar year; note : 1999-2099 will normally be sufficient
  192 + ROOM_SETPOINT_CH2 = 23, // f8.8 Current room Setpoint for 2nd CH circuit (°C)
  193 + ROOM_TEMPERATURE = 24, // f8.8 Current sensed room temperature (°C)
  194 + BURNER_STARTS = 116, // u16 Number of starts burner. Reset by writing zero is optional for slave
  195 + CH_PUMP_STARTS = 117, // u16 Number of starts CH pump. Reset by writing zero is optional for slave
  196 + DHW_PUMP_VALVE_STARTS = 118, // u16 Number of starts DHW pump/valve. Reset by writing zero is optional for slave
  197 + DHW_BURNER_STARTS = 119, // u16 Number of starts burner in DHW mode. Reset by writing zero is optional for slave
  198 + BURNER_OPERATION_HOURS = 120, // u16 Number of hours that burner is in operation (i.e. flame on). Reset by writing zero is optional for slave
  199 + CH_PUMP_OPERATION_HOURS = 121, // u16 Number of hours that CH pump has been running. Reset by writing zero is optional for slave
  200 + DHW_PUMP_VALVE_OPERATION_HOURS = 122, // u16 Number of hours that DHW pump has been running or DHW valve has been opened. Reset by writing zero is optional for slave
  201 + DHW_BURNER_OPERATION_HOURS = 123, // u16 Number of hours that burner is in operation during DHW mode. Reset by writing zero is optional for slave
  202 +
  203 + // Class 5 : Pre-Defined Remote Boiler Parameters
  204 + DHW_SETPOINT = 56, // f8.8 Domestic hot water temperature setpoint (Remote parameter 1) (°C)
  205 + MAX_CH_WATER_SETPOINT = 57, // f8.8 Maximum allowable CH water setpoint (Remote parameter 2) (°C)
  206 + OTC_CURVE_RATIO = 58, // f8.8 OTC heat curve ratio (Remote parameter 3) (°C)
  207 +
  208 + // Class 6 : Transparent Slave Parameters
  209 + TSP_COMMAND = 11, // u8, u8 Index number of following TSP, Value of the referenced TSP
  210 +
  211 + // Class 8 : Control of Special Applications
  212 + COOLING_CONTROL = 7, // f8.8 Signal for cooling plant (%)
  213 + MAX_MODULATION_LEVEL = 14, // f8.8 Mandatory: Maximum relative boiler modulation level setting for sequencer and off-low & pump control applications (%)
  214 +
  215 +
  216 + // Incomplete information for DATA-IDs below. If these DATA-IDs are R, W or R/W is unknown. Also the data type is unknown and deducted from the name
  217 + // Boiler DATA-ID
  218 + ROOM_TEMPERATURE_CH2 = 37, // f8.8 Room temperature for second CH unit(°C)
  219 + };
  220 +
  221 +
  222 + enum class STATUS_FLAGS {
  223 + // Master is MSB
  224 + MASTER_CH_ENABLE = (0b00000001), // CH is Central Heating
  225 + MASTER_DHW_ENABLE = (0b00000010), // DHW is Domestic Hot Water
  226 + MASTER_COOLING_ENABLE = (0b00000100),
  227 + MASTER_OTC_ENABLE = (0b00001000), // OTC is Outside Temperature Compensation
  228 + MASTER_CH2_ENABLE = (0b00010000),
  229 +
  230 + // Slave is LSB
  231 + SLAVE_FAULT_INDICATION = (0b00000001),
  232 + SLAVE_CH_MODE = (0b00000010),
  233 + SLAVE_DHW_MODE = (0b00000100),
  234 + SLAVE_FLAME_STATUS = (0b00001000),
  235 + SLAVE_COOLING_STATUS = (0b00010000),
  236 + SLAVE_CH2_MODE = (0b00100000),
  237 + SLAVE_DIAGNOSTIC_IND = (0b01000000),
  238 + };
  239 +
  240 +
  241 + enum MEMBER_IDS: uint8_t { // May be extended with other manufacturer OpenTherm member IDs. Maybe incorrect
  242 + AWB = 2,
  243 + BRINK = 2,
  244 + ATAG = 4,
  245 + BROTJE = 4,
  246 + ELCO = 4,
  247 + GEMINOX = 4,
  248 + ITHO_DAALDEROP = 5,
  249 + IDEAL = 6,
  250 + BOSCH = 8,
  251 + HOVAL = 8,
  252 + FERROLI = 9,
  253 + REMEHA = 11,
  254 + DE_DIETRICH = 11,
  255 + UNICAL = 16,
  256 + BULEX = 24,
  257 + VAILLANT = 24,
  258 + BAXI = 27,
  259 + DAALDEROP = 29,
  260 + VIESSMANN = 33,
  261 + NEFIT = 131,
  262 + INTERGAS = 173,
  263 + };
  264 +
  265 +
  266 + enum class FAULT_FLAGS {
  267 + SERVICE_REQUEST = (0b00000001),
  268 + LOCKOUT_RESET = (0b00000010),
  269 + LOW_WATER_PRESS = (0b00000100),
  270 + GAS_FLAME = (0b00001000),
  271 + AIR_PRESS = (0b00010000),
  272 + WATER_OVER_TEMP = (0b00100000),
  273 + };
  274 +
  275 +
  276 + enum class CONFIGURATION_FLAGS {
  277 + SLAVE_DHW_PRESENT = (0b00000001),
  278 + SLAVE_CONTROL_TYPE = (0b00000010),
  279 + SLAVE_COOLING = (0b00000100),
  280 + SLAVE_DHW = (0b00001000),
  281 + SLAVE_LOW_OFF_PUMP_CTRL = (0b00010000),
  282 + SLAVE_CH2_PRESENT = (0b00100000),
  283 + };
  284 +
  285 +
  286 + enum class REMOTE_PARAMETER_FLAGS {
  287 + TRANSFER_ENABLE_DHW_SETPOINT = (0b00000001),
  288 + TRANSFER_ENABLE_MAX_CH_SETPOINT = (0b00000010),
  289 +
  290 + READ_WRITE_DHW_SETPOINT = (0b00000001),
  291 + READ_WRITE_MAX_CH_SETPOINT = (0b00000010),
  292 + };
  293 +
  294 +
  295 + enum class REMOTE_OVERRIDE_FLAGS {
  296 + MANUAL_CHANGE_PRIORITY = (0b00000001),
  297 + REMOTE_CHANGE_PRIORITY = (0b00000010),
  298 + };
  299 +
  300 +
  301 + enum class REMOTE_COMMANDS {
  302 + BLOR = (1), // Boiler Lock-out Reset command
  303 + CHWF = (2), // CH water filling
  304 + };
  305 +
  306 +
  307 + enum class HVAC_STATUS_FLAGS {
  308 + // Master is MSB
  309 + MASTER_VENTILATION_ENABLE = (0b00000001),
  310 + MASTER_BYPASS_POSTION = (0b00000010),
  311 + MASTER__BYPASS_MODE = (0b00000100),
  312 + MASTER_FREE_VENTILATION_MODE = (0b00001000),
  313 +
  314 + // Slave is LSB
  315 + SLAVE_FAULT_INDICATION = (0b00000001),
  316 + SLAVE_VENTILATION_MODE = (0b00000010),
  317 + SLAVE_BYPASS_STATUS = (0b00000100),
  318 + SLAVE_BYPASS_AUTOMATIC_STATUS = (0b00001000),
  319 + SLAVE_FREE_VENTILATION_MODE = (0b00010000),
  320 + SLAVE_DIAGNOSTIC_IND = (0b00100000),
  321 + };
  322 +
  323 +
  324 + enum class SOLAR_STATUS_FLAGS {
  325 + // Master is MSB
  326 + MASTER_MODE = (0b00000111),
  327 +
  328 + // Slave is LSB
  329 + SLAVE_FAULT_INDICATION = (0b00000001),
  330 + SLAVE_MODE = (0b00001110),
  331 + SLAVE_STATUS = (0b00110000),
  332 + };
  333 +
  334 +
  335 + enum class SOLAR_MODE_FLAGS_AND_MASKS {
  336 + SYSTEM_TYPE = (0b00000001),
  337 + BYPASS = (0b00000010),
  338 + SPEED_CONTROL = (0b00000100),
  339 + };
  340 +
  341 +
  342 + enum class SOLAR_SLAVE_CONFIGURATION_FLAGS {
  343 + SLAVE_SYSTEM_TYPE = (0b00000001),
  344 + };
  345 +
  346 +
  347 + enum class ERROR_CODES {
  348 + OK,
  349 + UNKNOWN_DATA_ID,
  350 + INVALID_DATA,
  351 + SEND_TIMEOUT,
  352 + RECEIVE_TIMEOUT,
  353 + PARITY_ERROR,
  354 + UNKNOWN_ERROR,
  355 + };
  356 +
  357 + bool read(READ_DATA_ID msgID,
  358 + uint16_t & value);
  359 +
  360 + bool read(READ_DATA_ID msgID,
  361 + int16_t & value);
  362 +
  363 + bool read(READ_DATA_ID msgID,
  364 + uint8_t & valueMSB,
  365 + uint8_t & valueLSB);
  366 +
  367 + bool read(READ_DATA_ID msgID,
  368 + int8_t & valueMSB,
  369 + int8_t & valueLSB);
  370 +
  371 + bool read(READ_DATA_ID msgID,
  372 + float & value);
  373 +
  374 + bool write(WRITE_DATA_ID msgID,
  375 + uint16_t value);
  376 +
  377 + bool write(WRITE_DATA_ID msgID,
  378 + uint8_t valueMSB,
  379 + uint8_t valueLSB);
  380 +
  381 + bool write(WRITE_DATA_ID msgID,
  382 + float value);
  383 +
  384 + bool readWrite(READ_WRITE_DATA_ID msgID,
  385 + uint8_t valueMSB,
  386 + uint8_t & valueLSB);
  387 +
  388 + ERROR_CODES error();
  389 +
  390 +private:
  391 + bool _execute(OTDataLinkLayer & data);
  392 +
  393 + OTPhysicalLayer * _OTP;
  394 +
  395 + uint8_t _rxPin;
  396 + uint8_t _txPin;
  397 +
  398 + time_t _timeoutMs;
  399 + bool _master;
  400 +
  401 + ERROR_CODES _lastError;
  402 +};
  403 +
  404 +
  405 +class OTDataLinkLayer {
  406 +public:
  407 + enum class MSG_TYPE {
  408 + MASTER_TO_SLAVE_READ_DATA = (0b0000000UL << 24), // value >> 28 := 0
  409 + MASTER_TO_SLAVE_WRITE_DATA = (0b0010000UL << 24), // value >> 28 := 1
  410 + MASTER_TO_SLAVE_INVALID_DATA = (0b0100000UL << 24), // value >> 28 := 2
  411 + MASTER_TO_SLAVE_RESERVED = (0b0110000UL << 24), // value >> 28 := 3
  412 +
  413 + SLAVE_TO_MASTER_READ_ACK = (0b1000000UL << 24), // value >> 28 := 4
  414 + SLAVE_TO_MASTER_WRITE_ACK = (0b1010000UL << 24), // value >> 28 := 5
  415 + SLAVE_TO_MASTER_DATA_INVALID = (0b1100000UL << 24), // value >> 28 := 6
  416 + SLAVE_TO_MASTER_UNKNOWN_DATA_ID = (0b1110000UL << 24) // value >> 28 := 7
  417 + };
  418 +
  419 + OTDataLinkLayer();
  420 +
  421 + OTDataLinkLayer(uint32_t frame);
  422 +
  423 + void set(uint32_t frame);
  424 +
  425 + void set(MSG_TYPE msgType,
  426 + uint8_t dataID,
  427 + uint16_t value);
  428 +
  429 + void set(MSG_TYPE msgType,
  430 + uint8_t dataID,
  431 + uint8_t valueMSB,
  432 + uint8_t valueLSB);
  433 +
  434 + bool parity();
  435 +
  436 + MSG_TYPE type();
  437 +
  438 + uint8_t dataID();
  439 +
  440 + uint16_t value();
  441 +
  442 + uint8_t valueMSB();
  443 +
  444 + uint8_t valueLSB();
  445 +
  446 + uint32_t frame();
  447 +
  448 + bool isValid();
  449 +
  450 + bool dataInvalid();
  451 +
  452 + bool unknownDataID();
  453 +
  454 +private:
  455 + uint32_t _frame;
  456 +
  457 + bool _parity(uint32_t frame);
  458 +
  459 +};
  460 +
  461 +
  462 +class OTPhysicalLayer {
  463 +public:
  464 + OTPhysicalLayer(uint8_t rxPin,
  465 + uint8_t txPin,
  466 + bool master);
  467 +
  468 + ~OTPhysicalLayer();
  469 +
  470 + bool send(uint32_t frame);
  471 +
  472 + bool receive(uint32_t & frame);
  473 +
  474 + void reset();
  475 +
  476 +#if defined(ESP32)
  477 + void IRAM_ATTR handleInterrupt();
  478 +#elif defined(ESP8266)
  479 + void ICACHE_RAM_ATTR handleInterrupt();
  480 +#else
  481 + void handleInterrupt();
  482 +#endif
  483 +
  484 +private:
  485 + void sendBit(uint8_t val);
  486 +
  487 + volatile uint32_t _frame;
  488 + uint32_t _lastSentTimestampMs;
  489 + volatile uint32_t _lastReceivedTimestampMs;
  490 +
  491 + uint8_t _rxPin;
  492 + uint8_t _txPin;
  493 + bool _master;
  494 +
  495 + enum class STATE {
  496 + INVALID,
  497 + READY,
  498 + WAITING,
  499 + START_BIT,
  500 + RECEIVING,
  501 + };
  502 +
  503 + volatile STATE _state = STATE::INVALID;
  504 +};
... ...