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

|
|
||||||
<br>
|
|
||||||
[](https://github.com/Laxilef/OTGateway/releases)
|
|
||||||
[](https://github.com/Laxilef/OTGateway/releases/latest)
|
|
||||||
[](LICENSE.txt)
|
|
||||||
[](https://t.me/otgateway)
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## Features
|
|
||||||
- Hot water temperature control
|
|
||||||
- Heating temperature control
|
|
||||||
- Smart heating temperature control modes:
|
|
||||||
- PID
|
|
||||||
- Equithermic curves - adjusts the temperature based on indoor and outdoor temperatures
|
|
||||||
- Hysteresis setting (for accurate maintenance of room temperature)
|
|
||||||
- Ability to connect an external sensors to monitor outdoor and indoor temperature ([compatible sensors](https://github.com/Laxilef/OTGateway/wiki/Compatibility#temperature-sensors))
|
|
||||||
- Emergency mode. If the Wi-Fi connection is lost or the gateway cannot connect to the MQTT server, the mode will turn on. This mode will automatically maintain the set temperature and prevent your home from freezing. In this mode it is also possible to use equithermal curves (weather-compensated control).
|
|
||||||
- Automatic error reset (not with all boilers)
|
|
||||||
- Diagnostics:
|
|
||||||
- The process of heating: works/does not work
|
|
||||||
- The process of heating water for hot water: working/not working
|
|
||||||
- Display of boiler errors
|
|
||||||
- Burner status (flame): on/off
|
|
||||||
- Burner modulation level in percent
|
|
||||||
- Pressure in the heating system
|
|
||||||
- Gateway status (depending on errors and connection status)
|
|
||||||
- Boiler connection status via OpenTherm interface
|
|
||||||
- The current temperature of the heat carrier (usually the return heat carrier)
|
|
||||||
- Set heat carrier temperature (depending on the selected mode)
|
|
||||||
- Current hot water temperature
|
|
||||||
- Auto tuning of PID and Equitherm parameters *(in development)*
|
|
||||||
- [Home Assistant](https://www.home-assistant.io/) integration via MQTT. The ability to create any automation for the boiler!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
All available information and instructions can be found in the wiki:
|
|
||||||
|
|
||||||
* [Home](https://github.com/Laxilef/OTGateway/wiki)
|
|
||||||
* [Quick Start](https://github.com/Laxilef/OTGateway/wiki#quick-start)
|
|
||||||
* [Build firmware](https://github.com/Laxilef/OTGateway/wiki#build-firmware)
|
|
||||||
* [Flash firmware via ESP Flash Download Tool](https://github.com/Laxilef/OTGateway/wiki#flash-firmware-via-esp-flash-download-tool)
|
|
||||||
* [HomeAsssistant settings](https://github.com/Laxilef/OTGateway/wiki#homeasssistant-settings)
|
|
||||||
* [External temperature sensors](https://github.com/Laxilef/OTGateway/wiki#external-temperature-sensors)
|
|
||||||
* [Reporting indoor/outdoor temperature from any Home Assistant sensor](https://github.com/Laxilef/OTGateway/wiki#reporting-indooroutdoor-temperature-from-any-home-assistant-sensor)
|
|
||||||
* [Reporting outdoor temperature from Home Assistant weather integration](https://github.com/Laxilef/OTGateway/wiki#reporting-outdoor-temperature-from-home-assistant-weather-integration)
|
|
||||||
* [DHW meter](https://github.com/Laxilef/OTGateway/wiki#dhw-meter)
|
|
||||||
* [Advanced Settings](https://github.com/Laxilef/OTGateway/wiki#advanced-settings)
|
|
||||||
* [Equitherm mode](https://github.com/Laxilef/OTGateway/wiki#equitherm-mode)
|
|
||||||
* [Ratios](https://github.com/Laxilef/OTGateway/wiki#ratios)
|
|
||||||
* [Fit coefficients](https://github.com/Laxilef/OTGateway/wiki#fit-coefficients)
|
|
||||||
* [PID mode](https://github.com/Laxilef/OTGateway/wiki#pid-mode)
|
|
||||||
* [Compatibility](https://github.com/Laxilef/OTGateway/wiki/Compatibility)
|
|
||||||
* [Boilers](https://github.com/Laxilef/OTGateway/wiki/Compatibility#boilers)
|
|
||||||
* [Boards](https://github.com/Laxilef/OTGateway/wiki/Compatibility#boards)
|
|
||||||
* [Temperature sensors](https://github.com/Laxilef/OTGateway/wiki/Compatibility#temperature-sensors)
|
|
||||||
* [FAQ & Troubleshooting](https://github.com/Laxilef/OTGateway/wiki/FAQ-&-Troubleshooting)
|
|
||||||
* [OT adapters](https://github.com/Laxilef/OTGateway/wiki/OT-adapters)
|
|
||||||
* [Adapters on sale](https://github.com/Laxilef/OTGateway/wiki/OT-adapters#adapters-on-sale)
|
|
||||||
* [DIY](https://github.com/Laxilef/OTGateway/wiki/OT-adapters#diy)
|
|
||||||
* [Files for production](https://github.com/Laxilef/OTGateway/wiki/OT-adapters#files-for-production)
|
|
||||||
* [Connection](https://github.com/Laxilef/OTGateway/wiki/OT-adapters#connection)
|
|
||||||
* [Leds on board](https://github.com/Laxilef/OTGateway/wiki/OT-adapters#leds-on-board)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
- [ESP8266Scheduler](https://github.com/nrwiersma/ESP8266Scheduler) (for ESP8266)
|
|
||||||
- [ESP32Scheduler](https://github.com/laxilef/ESP32Scheduler) (for ESP32)
|
|
||||||
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
|
|
||||||
- [OpenTherm Library](https://github.com/ihormelnyk/opentherm_library)
|
|
||||||
- [ArduinoMqttClient](https://github.com/arduino-libraries/ArduinoMqttClient)
|
|
||||||
- [ESPTelnet](https://github.com/LennartHennigs/ESPTelnet)
|
|
||||||
- [FileData](https://github.com/GyverLibs/FileData)
|
|
||||||
- [GyverPID](https://github.com/GyverLibs/GyverPID)
|
|
||||||
- [GyverBlinker](https://github.com/GyverLibs/GyverBlinker)
|
|
||||||
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library)
|
|
||||||
- [TinyLogger](https://github.com/laxilef/TinyLogger)
|
|
||||||
|
|
||||||
## Debug
|
|
||||||
To display DEBUG messages you must enable debug in settings (switch is disabled by default).
|
|
||||||
You can connect via Telnet to read messages. IP: ESP8266 ip, port: 23
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/*.priv.*
|
|
||||||
|
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 190 KiB |
@@ -1,16 +0,0 @@
|
|||||||
dhw_meter:
|
|
||||||
sensor:
|
|
||||||
- platform: integration
|
|
||||||
unique_id: hot_water_meter
|
|
||||||
name: hot_water_meter
|
|
||||||
source: sensor.opentherm_dhw_flow_rate
|
|
||||||
unit_time: min
|
|
||||||
method: left
|
|
||||||
round: 2
|
|
||||||
|
|
||||||
homeassistant:
|
|
||||||
customize:
|
|
||||||
sensor.hot_water_meter:
|
|
||||||
friendly_name: "Hot water"
|
|
||||||
device_class: "water"
|
|
||||||
icon: "mdi:water-pump"
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# Script for reporting outdoor temperature to the controller from home assistant weather integration
|
|
||||||
# Updated: 07.12.2023
|
|
||||||
|
|
||||||
alias: Report outdoor temp to controller from weather
|
|
||||||
description: ""
|
|
||||||
variables:
|
|
||||||
# The source weather from which we take the temperature
|
|
||||||
source_entity: "weather.home"
|
|
||||||
|
|
||||||
# Target entity number where we set the temperature
|
|
||||||
# If the prefix has not changed, then you do not need to change it
|
|
||||||
target_entity: "number.opentherm_outdoor_temp"
|
|
||||||
trigger:
|
|
||||||
- platform: time_pattern
|
|
||||||
seconds: /30
|
|
||||||
condition:
|
|
||||||
- condition: template
|
|
||||||
value_template: "{{ states(source_entity) != 'unavailable' and states(target_entity) != 'unavailable' }}"
|
|
||||||
action:
|
|
||||||
- if:
|
|
||||||
- condition: template
|
|
||||||
value_template: "{{ (state_attr(source_entity, 'temperature')|float(0) - states(target_entity)|float(0)) | abs | round(2) >= 0.1 }}"
|
|
||||||
then:
|
|
||||||
- service: number.set_value
|
|
||||||
data:
|
|
||||||
value: "{{ state_attr(source_entity, 'temperature')|float(0)|round(2) }}"
|
|
||||||
target:
|
|
||||||
entity_id: "{{ target_entity }}"
|
|
||||||
mode: single
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# Script for reporting indoor/outdoor temperature to the controller from any home assistant sensor
|
|
||||||
# Updated: 07.12.2023
|
|
||||||
|
|
||||||
alias: Report temp to controller
|
|
||||||
description: ""
|
|
||||||
variables:
|
|
||||||
# The source sensor from which we take the temperature
|
|
||||||
source_entity: "sensor.livingroom_temperature"
|
|
||||||
|
|
||||||
# Target entity number where we set the temperature
|
|
||||||
# To report indoor temperature: number.opentherm_indoor_temp
|
|
||||||
# To report outdoor temperature: number.opentherm_outdoor_temp
|
|
||||||
target_entity: "number.opentherm_indoor_temp"
|
|
||||||
trigger:
|
|
||||||
- platform: time_pattern
|
|
||||||
seconds: /30
|
|
||||||
condition:
|
|
||||||
- condition: template
|
|
||||||
value_template: "{{ states(source_entity) != 'unavailable' and states(target_entity) != 'unavailable' }}"
|
|
||||||
action:
|
|
||||||
- if:
|
|
||||||
- condition: template
|
|
||||||
value_template: "{{ (states(source_entity)|float(0) - states(target_entity)|float(0)) | abs | round(2) >= 0.01 }}"
|
|
||||||
then:
|
|
||||||
- service: number.set_value
|
|
||||||
data:
|
|
||||||
value: "{{ states(source_entity)|float(0)|round(2) }}"
|
|
||||||
target:
|
|
||||||
entity_id: "{{ target_entity }}"
|
|
||||||
mode: single
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="880" height="300" viewBox="0 0 880 300">
|
|
||||||
<g stroke="none" stroke-width="1" fill="none" fill-rule="oddeven">
|
|
||||||
<g transform="translate(440, 145)">
|
|
||||||
|
|
||||||
<text font-family="Helvetica Nue,Helvetica,Arial,sans-serif" font-size="25" font-weight="300" letter-spacing="1" text-anchor="end" fill="#444444">
|
|
||||||
<tspan x="-12" y="12">OPENTHERM GATEWAY</tspan>
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<line x1="0" y1="-12" x2="0" y2="18" stroke-width="1" stroke="#e1e1e1"/>
|
|
||||||
|
|
||||||
<text font-family="Helvetica Nue,Helvetica,Arial,sans-serif" font-size="15" font-weight="300" fill="#7e7e7e">
|
|
||||||
<tspan x="12" y="10">SMART CONTROLLER FOR BOILERS</tspan>
|
|
||||||
</text>
|
|
||||||
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 803 B |
|
Before Width: | Height: | Size: 675 KiB |
|
Before Width: | Height: | Size: 154 KiB |
@@ -1,230 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>OpenTherm Gateway</title>
|
|
||||||
<link rel="stylesheet" href="/static/pico.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/app.css"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<header class="container">
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/"><div class="logo">OpenTherm Gateway</div></a></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/Laxilef/OTGateway/wiki" role="button" class="secondary" target="_blank">Help</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Network</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div class="main-busy" aria-busy="true"></div>
|
|
||||||
<table class="main-table hidden">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Hostname:</th>
|
|
||||||
<td><b class="network-hostname"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">MAC:</th>
|
|
||||||
<td><b class="network-mac"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Connected:</th>
|
|
||||||
<td><input type="radio" class="network-connected" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">SSID:</th>
|
|
||||||
<td><b class="network-ssid"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Signal:</th>
|
|
||||||
<td><b class="network-signal"></b> %</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">IP:</th>
|
|
||||||
<td><b class="network-ip"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Subnet:</th>
|
|
||||||
<td><b class="network-subnet"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Gateway:</th>
|
|
||||||
<td><b class="network-gateway"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">DNS:</th>
|
|
||||||
<td><b class="network-dns"></b></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="grid">
|
|
||||||
<a href="/network.html" role="button">Network settings</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>System</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div class="system-busy" aria-busy="true"></div>
|
|
||||||
<table class="system-table hidden">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Version:</th>
|
|
||||||
<td><b class="version"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Build date:</th>
|
|
||||||
<td><b class="build-date"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Uptime:</th>
|
|
||||||
<td><b class="uptime-days"></b> days, <b class="uptime-hours"></b> hours, <b class="uptime-min"></b> min., <b class="uptime-sec"></b> sec.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Free memory:</th>
|
|
||||||
<td><b class="free-heap"></b> of <b class="total-heap"></b> bytes (min: <b class="min-free-heap"></b> bytes)<br>max free block: <b class="max-free-block-heap"></b> bytes (min: <b class="min-max-free-block-heap"></b> bytes)</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Last reset reason:</th>
|
|
||||||
<td><b class="reset-reason"></b></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<a href="/settings.html" role="button">Settings</a>
|
|
||||||
<a href="/upgrade.html" role="button">Upgrade</a>
|
|
||||||
<a href="/restart.html" role="button" class="secondary restart">Restart</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>States and sensors</h2>
|
|
||||||
<p>More information and settings can be found in your home assistant after setting up network and MQTT</p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div class="ot-busy" aria-busy="true"></div>
|
|
||||||
<table class="ot-table hidden">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">OpenTherm connected:</th>
|
|
||||||
<td><input type="radio" class="ot-connected" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">MQTT connected:</th>
|
|
||||||
<td><input type="radio" class="mqtt-connected" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Emergency:</th>
|
|
||||||
<td><input type="radio" class="ot-emergency" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Heating:</th>
|
|
||||||
<td><input type="radio" class="ot-heating" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">DHW:</th>
|
|
||||||
<td><input type="radio" class="ot-dhw" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Flame:</th>
|
|
||||||
<td><input type="radio" class="ot-flame" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Fault:</th>
|
|
||||||
<td><input type="radio" class="ot-fault" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Diagnostic:</th>
|
|
||||||
<td><input type="radio" class="ot-diagnostic" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">External pump:</th>
|
|
||||||
<td><input type="radio" class="ot-external-pump" aria-invalid="false" checked disabled /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Modulation:</th>
|
|
||||||
<td><b class="ot-modulation"></b> %</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Pressure:</th>
|
|
||||||
<td><b class="ot-pressure"></b> bar</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">DHW flow rate:</th>
|
|
||||||
<td><b class="ot-dhw-flow-rate"></b> l/min</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Fault code:</th>
|
|
||||||
<td><b class="ot-fault-code"></b></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Indoor temp:</th>
|
|
||||||
<td><b class="indoor-temp"></b> C</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Outdoor temp:</th>
|
|
||||||
<td><b class="outdoor-temp"></b> C</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Heating temp:</th>
|
|
||||||
<td><b class="heating-temp"></b> C</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Heating setpoint temp:</th>
|
|
||||||
<td><b class="heating-setpoint-temp"></b> C</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">DHW temp:</th>
|
|
||||||
<td><b class="dhw-temp"></b> C</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer class="container">
|
|
||||||
<small>
|
|
||||||
<b>Made by Laxilef</b>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/LICENSE" target="_blank" class="secondary">License</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/" target="_blank" class="secondary">Source code</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/wiki" target="_blank" class="secondary">Help</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/issues" target="_blank" class="secondary">Issue & questions</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank" class="secondary">Releases</a>
|
|
||||||
</small>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<script src="/static/app.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = async function () {
|
|
||||||
setTimeout(async function onLoadPage() {
|
|
||||||
await loadNetworkStatus();
|
|
||||||
await loadVars();
|
|
||||||
|
|
||||||
setTimeout(onLoadPage, 10000);
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Network - OpenTherm Gateway</title>
|
|
||||||
<link rel="stylesheet" href="/static/pico.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/app.css" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<header class="container">
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/"><div class="logo">OpenTherm Gateway</div></a></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/Laxilef/OTGateway/wiki" role="button" class="secondary" target="_blank">Help</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Network settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="network-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/network/settings" id="network-settings" class="hidden">
|
|
||||||
<label for="hostname">
|
|
||||||
Hostname
|
|
||||||
<input type="text" class="network-hostname" name="hostname" maxlength="24" pattern="[A-Za-z0-9]+[A-Za-z0-9\-]+[A-Za-z0-9]+" required>
|
|
||||||
</label>
|
|
||||||
<label for="network-use-dhcp">
|
|
||||||
<input type="checkbox" class="network-use-dhcp" name="useDhcp" value="true">
|
|
||||||
Use DHCP
|
|
||||||
</label>
|
|
||||||
<br>
|
|
||||||
<hr>
|
|
||||||
<label for="network-static-ip">
|
|
||||||
Static IP:
|
|
||||||
<input type="text" class="network-static-ip" name="staticConfig[ip]" value="true" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
|
|
||||||
</label>
|
|
||||||
<label for="network-static-gateway">
|
|
||||||
Static gateway:
|
|
||||||
<input type="text" class="network-static-gateway" name="staticConfig[gateway]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
|
|
||||||
</label>
|
|
||||||
<label for="network-static-subnet">
|
|
||||||
Static subnet:
|
|
||||||
<input type="text" class="network-static-subnet" name="staticConfig[subnet]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
|
|
||||||
</label>
|
|
||||||
<label for="network-static-dns">
|
|
||||||
Static DNS:
|
|
||||||
<input type="text" class="network-static-dns" name="staticConfig[dns]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
|
|
||||||
</label>
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h3>Available networks</h3>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<form action="/api/network/scan" id="network-scan">
|
|
||||||
<figure style="max-height: 25em;">
|
|
||||||
<table id="networks" role="grid">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">#</th>
|
|
||||||
<th scope="col">SSID</th>
|
|
||||||
<th scope="col">Signal</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody></tbody>
|
|
||||||
</table>
|
|
||||||
</figure>
|
|
||||||
<button type="submit">Refresh</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>WiFi settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
<div id="sta-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/network/settings" id="sta-settings" class="hidden">
|
|
||||||
<label for="sta-ssid">
|
|
||||||
SSID:
|
|
||||||
<input type="text" class="sta-ssid" name="sta[ssid]" maxlength="32" required>
|
|
||||||
</label>
|
|
||||||
<label for="sta-password">
|
|
||||||
Password:
|
|
||||||
<input type="password" class="sta-password" name="sta[password]" maxlength="64" required>
|
|
||||||
</label>
|
|
||||||
<label for="sta-channel">
|
|
||||||
Channel:
|
|
||||||
<input type="number" inputmode="numeric" class="sta-channel" name="sta[channel]" min="0" max="12" step="1" required>
|
|
||||||
<small>set 0 for auto select</small>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>AP settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
<div id="ap-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/network/settings" id="ap-settings" class="hidden">
|
|
||||||
<label for="ap-ssid">
|
|
||||||
SSID:
|
|
||||||
<input type="text" class="ap-ssid" name="ap[ssid]" maxlength="32" required>
|
|
||||||
</label>
|
|
||||||
<label for="ap-password">
|
|
||||||
Password:
|
|
||||||
<input type="text" class="ap-password" name="ap[password]" maxlength="64" required>
|
|
||||||
</label>
|
|
||||||
<label for="ap-channel">
|
|
||||||
Channel:
|
|
||||||
<input type="number" inputmode="numeric" class="ap-channel" name="ap[channel]" min="1" max="12" step="1" required>
|
|
||||||
</label>
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer class="container">
|
|
||||||
<small>
|
|
||||||
<b>Made by Laxilef</b>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/LICENSE" target="_blank" class="secondary">License</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/" target="_blank" class="secondary">Source code</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/wiki" target="_blank" class="secondary">Help</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/issues" target="_blank" class="secondary">Issue & questions</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank" class="secondary">Releases</a>
|
|
||||||
</small>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<script src="/static/app.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = async function () {
|
|
||||||
await loadNetworkSettings();
|
|
||||||
|
|
||||||
setupForm('#network-settings');
|
|
||||||
setupNetworkScanForm('#network-scan', '#networks');
|
|
||||||
setupForm('#sta-settings');
|
|
||||||
setupForm('#ap-settings');
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,353 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Settings - OpenTherm Gateway</title>
|
|
||||||
<link rel="stylesheet" href="/static/pico.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/app.css" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<header class="container">
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/"><div class="logo">OpenTherm Gateway</div></a></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/Laxilef/OTGateway/wiki" role="button" class="secondary" target="_blank">Help</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Portal settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="portal-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="portal-settings" class="hidden">
|
|
||||||
<div class="grid">
|
|
||||||
<label for="portal-login">
|
|
||||||
Login
|
|
||||||
<input type="text" class="portal-login" name="portal[login]" maxlength="12" required>
|
|
||||||
</label>
|
|
||||||
<label for="portal-password">
|
|
||||||
Password
|
|
||||||
<input type="password" class="portal-password" name="portal[password]" maxlength="32" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label for="portal-use-auth">
|
|
||||||
<input type="checkbox" class="portal-use-auth" name="portal[useAuth]" value="true">
|
|
||||||
Use auth
|
|
||||||
</label>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>OpenTherm settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="opentherm-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="opentherm-settings" class="hidden">
|
|
||||||
<div class="grid">
|
|
||||||
<label for="opentherm-in-gpio">
|
|
||||||
In GPIO
|
|
||||||
<input type="number" inputmode="numeric" class="opentherm-in-gpio" name="opentherm[inGpio]" min="0" max="254" step="1">
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-in-gpio">
|
|
||||||
Out GPIO
|
|
||||||
<input type="number" inputmode="numeric" class="opentherm-out-gpio" name="opentherm[outGpio]" min="0" max="254" step="1">
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-member-id-code">
|
|
||||||
Master MemberID code
|
|
||||||
<input type="number" inputmode="numeric" class="opentherm-member-id-code" name="opentherm[memberIdCode]" min="0" max="65535" step="1" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<fieldset>
|
|
||||||
<legend>Options</legend>
|
|
||||||
<label for="opentherm-dhw-present">
|
|
||||||
<input type="checkbox" class="opentherm-dhw-present" name="opentherm[dhwPresent]" value="true">
|
|
||||||
DHW present
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-sw-mode">
|
|
||||||
<input type="checkbox" class="opentherm-sw-mode" name="opentherm[summerWinterMode]" value="true">
|
|
||||||
Summer/winter mode
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-heating-ch2-enabled">
|
|
||||||
<input type="checkbox" class="opentherm-heating-ch2-enabled" name="opentherm[heatingCh2Enabled]" value="true">
|
|
||||||
Heating CH2 always enabled
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-heating-ch1-to-ch2">
|
|
||||||
<input type="checkbox" class="opentherm-heating-ch1-to-ch2" name="opentherm[heatingCh1ToCh2]" value="true">
|
|
||||||
Duplicate heating CH1 to CH2
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-dhw-to-ch2">
|
|
||||||
<input type="checkbox" class="opentherm-dhw-to-ch2" name="opentherm[dhwToCh2]" value="true">
|
|
||||||
Duplicate DHW to CH2
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-dhw-blocking">
|
|
||||||
<input type="checkbox" class="opentherm-dhw-blocking" name="opentherm[dhwBlocking]" value="true">
|
|
||||||
DHW blocking
|
|
||||||
</label>
|
|
||||||
<label for="opentherm-sync-modulation-with-heating">
|
|
||||||
<input type="checkbox" class="opentherm-sync-modulation-with-heating" name="opentherm[modulationSyncWithHeating]" value="true">
|
|
||||||
Sync modulation with heating
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>MQTT settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="mqtt-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="mqtt-settings" class="hidden">
|
|
||||||
<div class="grid">
|
|
||||||
<label for="mqtt-server">
|
|
||||||
Server
|
|
||||||
<input type="text" class="mqtt-server" name="mqtt[server]" maxlength="80" required>
|
|
||||||
</label>
|
|
||||||
<label for="mqtt-port">
|
|
||||||
Port
|
|
||||||
<input type="number" inputmode="numeric" class="mqtt-port" name="mqtt[port]" min="1" max="65535" step="1" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<label for="mqtt-user">
|
|
||||||
User
|
|
||||||
<input type="text" class="mqtt-user" name="mqtt[user]" maxlength="32" required>
|
|
||||||
</label>
|
|
||||||
<label for="mqtt-password">
|
|
||||||
Password
|
|
||||||
<input type="password" class="mqtt-password" name="mqtt[password]" maxlength="32">
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<label for="mqtt-prefix">
|
|
||||||
Prefix
|
|
||||||
<input type="text" class="mqtt-prefix" name="mqtt[prefix]" maxlength="32" required>
|
|
||||||
</label>
|
|
||||||
<label for="mqtt-interval">
|
|
||||||
Publish interval <small>(sec)</small>
|
|
||||||
<input type="number" inputmode="numeric" class="mqtt-interval" name="mqtt[interval]" min="3" max="60" step="1" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Outdoor sensor settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="outdoor-sensor-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="outdoor-sensor-settings" class="hidden">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Source type</legend>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="outdoor-sensor-type" name="sensors[outdoor][type]" value="0" />
|
|
||||||
From boiler via OpenTherm
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="outdoor-sensor-type" name="sensors[outdoor][type]" value="1" />
|
|
||||||
Manual via MQTT/API
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="outdoor-sensor-type" name="sensors[outdoor][type]" value="2" />
|
|
||||||
External (DS18B20)
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<label for="outdoor-sensor-gpio">
|
|
||||||
GPIO
|
|
||||||
<input type="number" inputmode="numeric" class="outdoor-sensor-gpio" name="sensors[outdoor][gpio]" min="0" max="254" step="1">
|
|
||||||
</label>
|
|
||||||
<label for="outdoor-sensor-offset">
|
|
||||||
Temp offset (calibration)
|
|
||||||
<input type="number" inputmode="numeric" class="outdoor-sensor-offset" name="sensors[outdoor][offset]" min="-20" max="20" step="0.01" required>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Indoor sensor settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="indoor-sensor-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="indoor-sensor-settings" class="hidden">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Source type</legend>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="indoor-sensor-type" name="sensors[indoor][type]" value="1" />
|
|
||||||
Manual via MQTT/API
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="indoor-sensor-type" name="sensors[indoor][type]" value="2" />
|
|
||||||
External (DS18B20)
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" class="indoor-sensor-type" name="sensors[indoor][type]" value="3" />
|
|
||||||
BLE device <i>(ONLY for some ESP32 which support BLE)</i>
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<label for="indoor-sensor-gpio">
|
|
||||||
GPIO
|
|
||||||
<input type="number" inputmode="numeric" class="indoor-sensor-gpio" name="sensors[indoor][gpio]" min="0" max="254" step="1">
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<label for="indoor-sensor-offset">
|
|
||||||
Temp offset (calibration)
|
|
||||||
<input type="number" inputmode="numeric" class="indoor-sensor-offset" name="sensors[indoor][offset]" min="-20" max="20" step="0.01" required>
|
|
||||||
</label>
|
|
||||||
<label for="indoor-sensor-ble-addresss">
|
|
||||||
BLE addresss
|
|
||||||
<input type="text" class="indoor-sensor-ble-addresss" name="sensors[indoor][bleAddresss]" pattern="([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}">
|
|
||||||
<small>ONLY for some ESP32 which support BLE</small>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>External pump settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="extpump-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="extpump-settings" class="hidden">
|
|
||||||
<label for="extpump-use">
|
|
||||||
<input type="checkbox" class="extpump-use" name="externalPump[use]" value="true">
|
|
||||||
Use external pump
|
|
||||||
</label>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<label for="extpump-gpio">
|
|
||||||
Relay GPIO
|
|
||||||
<input type="number" inputmode="numeric" class="extpump-gpio" name="externalPump[gpio]" min="0" max="254" step="1">
|
|
||||||
</label>
|
|
||||||
<label for="extpump-pc-time">
|
|
||||||
Post circulation time <small>(min)</small>
|
|
||||||
<input type="number" inputmode="numeric" class="extpump-pc-time" name="externalPump[postCirculationTime]" min="1" max="120" step="1" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<label for="extpump-as-interval">
|
|
||||||
Anti stuck interval <small>(days)</small>
|
|
||||||
<input type="number" inputmode="numeric" class="extpump-as-interval" name="externalPump[antiStuckInterval]" min="1" max="366" step="1" required>
|
|
||||||
</label>
|
|
||||||
<label for="extpump-as-time">
|
|
||||||
Anti stuck time <small>(min)</small>
|
|
||||||
<input type="number" inputmode="numeric" class="extpump-as-time" name="externalPump[antiStuckTime]" min="1" max="20" step="1" required>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>System settings</h2>
|
|
||||||
<p></p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<div id="system-settings-busy" aria-busy="true"></div>
|
|
||||||
<form action="/api/settings" id="system-settings" class="hidden">
|
|
||||||
<fieldset>
|
|
||||||
<label for="system-debug">
|
|
||||||
<input type="checkbox" class="system-debug" name="system[debug]" value="true">
|
|
||||||
Debug mode
|
|
||||||
</label>
|
|
||||||
<label for="system-use-serial">
|
|
||||||
<input type="checkbox" class="system-use-serial" name="system[useSerial]" value="true">
|
|
||||||
Enable serial port
|
|
||||||
</label>
|
|
||||||
<label for="system-use-telnet">
|
|
||||||
<input type="checkbox" class="system-use-telnet" name="system[useTelnet]" value="true">
|
|
||||||
Enable telnet
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<fieldset>
|
|
||||||
<mark>After changing this settings, the ESP must be restarted for the changes to take effect.</mark>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer class="container">
|
|
||||||
<small>
|
|
||||||
<b>Made by Laxilef</b>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/LICENSE" target="_blank" class="secondary">License</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/" target="_blank" class="secondary">Source code</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/wiki" target="_blank" class="secondary">Help</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/issues" target="_blank" class="secondary">Issue & questions</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank" class="secondary">Releases</a>
|
|
||||||
</small>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<script src="/static/app.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = async function () {
|
|
||||||
await loadSettings();
|
|
||||||
|
|
||||||
setupForm('#portal-settings');
|
|
||||||
setupForm('#opentherm-settings');
|
|
||||||
setupForm('#mqtt-settings');
|
|
||||||
setupForm('#outdoor-sensor-settings');
|
|
||||||
setupForm('#indoor-sensor-settings');
|
|
||||||
setupForm('#extpump-settings');
|
|
||||||
setupForm('#system-settings');
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Upgrade - OpenTherm Gateway</title>
|
|
||||||
<link rel="stylesheet" href="/static/pico.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/app.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<header class="container">
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/"><div class="logo">OpenTherm Gateway</div></a></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/Laxilef/OTGateway/wiki" role="button" class="secondary" target="_blank">Help</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Backup & restore</h2>
|
|
||||||
<p>
|
|
||||||
In this section you can save and restore a backup of ALL settings.
|
|
||||||
</p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<form action="/api/backup/restore" id="restore">
|
|
||||||
<label for="restore-file">
|
|
||||||
Settings file:
|
|
||||||
<input type="file" name="settings" id="restore-file" accept=".json">
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<button type="submit">Restore</button>
|
|
||||||
<button type="button" class="secondary" onclick="window.location='/api/backup/save';">Backup</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<div>
|
|
||||||
<hgroup>
|
|
||||||
<h2>Upgrade</h2>
|
|
||||||
<p>
|
|
||||||
In this section you can upgrade the firmware and filesystem of your device.<br>
|
|
||||||
Latest releases can be downloaded from the <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank">Releases page</a> of the project repository.
|
|
||||||
</p>
|
|
||||||
</hgroup>
|
|
||||||
|
|
||||||
<form action="/api/upgrade" id="upgrade">
|
|
||||||
<fieldset class="primary">
|
|
||||||
<label for="firmware-file">
|
|
||||||
Firmware:
|
|
||||||
<div class="grid">
|
|
||||||
<input type="file" name="firmware" id="firmware-file" accept=".bin">
|
|
||||||
<button type="button" class="upgrade-firmware-result hidden" disabled></button>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label for="filesystem-file">
|
|
||||||
Filesystem:
|
|
||||||
<div class="grid">
|
|
||||||
<input type="file" name="filesystem" id="filesystem-file" accept=".bin">
|
|
||||||
<button type="button" class="upgrade-filesystem-result hidden" disabled></button>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li><mark>After a successful upgrade the filesystem, ALL settings will be reset to default values! Save backup before upgrading.</mark></li>
|
|
||||||
<li><mark>After a successful upgrade, the device will automatically reboot after 10 seconds.</mark></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<button type="submit">Upgrade</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer class="container">
|
|
||||||
<small>
|
|
||||||
<b>Made by Laxilef</b>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/LICENSE" target="_blank" class="secondary">License</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/blob/master/" target="_blank" class="secondary">Source code</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/wiki" target="_blank" class="secondary">Help</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/issues" target="_blank" class="secondary">Issue & questions</a>
|
|
||||||
• <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank" class="secondary">Releases</a>
|
|
||||||
</small>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<script src="/static/app.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = async function () {
|
|
||||||
setupRestoreBackupForm('#restore');
|
|
||||||
setupUpgradeForm('#upgrade');
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# Name, Type, SubType, Offset, Size, Flags
|
|
||||||
nvs, data, nvs, 0x9000, 0x5000,
|
|
||||||
otadata, data, ota, 0xE000, 0x2000,
|
|
||||||
app0, app, ota_0, 0x10000, 0x1B0000,
|
|
||||||
app1, app, ota_1, 0x1C0000, 0x1B0000,
|
|
||||||
spiffs, data, spiffs, 0x370000, 0x80000,
|
|
||||||
coredump, data, coredump, 0x3F0000, 0x10000,
|
|
||||||
|
@@ -0,0 +1,326 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>OTGateway Web Flasher</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" />
|
||||||
|
<link rel="stylesheet" href="./styles.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header class="container">
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
<div class="logo">OpenTherm Gateway</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/Laxilef/OTGateway/wiki" role="button" class="secondary" target="_blank">Wiki</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="container">
|
||||||
|
<article>
|
||||||
|
<div>
|
||||||
|
<hgroup>
|
||||||
|
<h2>Web Flasher</h2>
|
||||||
|
<p></p>
|
||||||
|
</hgroup>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>
|
||||||
|
<span>Choose version</span>
|
||||||
|
<select name="fwVersion" disabled required>
|
||||||
|
<option selected value="0">Choose version...</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="fwBoardContainer hidden">
|
||||||
|
<span>Board</span>
|
||||||
|
<select name="fwBoard" required>
|
||||||
|
<option selected value="0">Choose board...</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="toolContainer hidden">
|
||||||
|
<hr />
|
||||||
|
<div>
|
||||||
|
<b>Status:</b> <span class="status">Not connected</span>
|
||||||
|
<br /><br />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="progress hidden">
|
||||||
|
<progress value="0" max="100"></progress>
|
||||||
|
<br /><br />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<button class="connect">💡 1. Connect</button>
|
||||||
|
<button class="flash" disabled>🚀 2. Flash</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="powered-by">
|
||||||
|
<small>
|
||||||
|
Powered by <a href="https://github.com/espressif/esptool-js/" target="_blank" class="secondary">espressif/esptool-js</a>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="container">
|
||||||
|
<small>
|
||||||
|
<b>Made by Laxilef</b>
|
||||||
|
• <a href="https://github.com/Laxilef/OTGateway/blob/master/LICENSE" target="_blank" class="secondary">License</a>
|
||||||
|
• <a href="https://github.com/Laxilef/OTGateway/blob/master/" target="_blank" class="secondary">Source code</a>
|
||||||
|
• <a href="https://github.com/Laxilef/OTGateway/wiki" target="_blank" class="secondary">Help</a>
|
||||||
|
• <a href="https://github.com/Laxilef/OTGateway/issues" target="_blank" class="secondary">Issues & questions</a>
|
||||||
|
• <a href="https://github.com/Laxilef/OTGateway/releases" target="_blank" class="secondary">Releases</a>
|
||||||
|
</small>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import { ESPLoader, Transport } from "https://unpkg.com/esptool-js/bundle.js";
|
||||||
|
|
||||||
|
let esploader = null;
|
||||||
|
const fwVersion = document.querySelector("[name='fwVersion']");
|
||||||
|
const fwBoardContainer = document.querySelector(".fwBoardContainer");
|
||||||
|
const fwBoard = document.querySelector("[name='fwBoard']");
|
||||||
|
const toolContainer = document.querySelector(".toolContainer");
|
||||||
|
const statusContainer = document.querySelector(".status");
|
||||||
|
const connectBtn = document.querySelector(".connect");
|
||||||
|
const flashBtn = document.querySelector(".flash");
|
||||||
|
const progressContainer = document.querySelector(".progress");
|
||||||
|
|
||||||
|
async function loadFwVersions() {
|
||||||
|
try {
|
||||||
|
fwVersion.disabled = true;
|
||||||
|
|
||||||
|
const response = await fetch("https://api.github.com/repos/Laxilef/OTGateway/releases", {
|
||||||
|
cache: "no-cache"
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
for (let release of data) {
|
||||||
|
const releaseDate = new Date(release.published_at).toLocaleDateString();
|
||||||
|
const option = document.createElement("option");
|
||||||
|
option.textContent = `${release.name} (${releaseDate})`;
|
||||||
|
option.value = release.id;
|
||||||
|
fwVersion.appendChild(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching releases:", error);
|
||||||
|
alert("Error fetching releases");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fwVersion.disabled = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadFwBoards(releaseId) {
|
||||||
|
let configUrl = null;
|
||||||
|
let files = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://api.github.com/repos/Laxilef/OTGateway/releases/${releaseId}/assets`, {
|
||||||
|
cache: "no-cache"
|
||||||
|
});
|
||||||
|
const assets = await response.json();
|
||||||
|
|
||||||
|
for (const file of assets) {
|
||||||
|
if (file.name == "webflasher.json") {
|
||||||
|
configUrl = file.browser_download_url;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
files.push({
|
||||||
|
"name": file.name,
|
||||||
|
"url": file.browser_download_url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching release:", error);
|
||||||
|
alert("Error fetching release");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configUrl) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (fwBoard.length > 1) {
|
||||||
|
fwBoard.remove(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`https://corsproxy.io/?url=${configUrl}`, {
|
||||||
|
cache: "no-cache"
|
||||||
|
});
|
||||||
|
const boards = await response.json();
|
||||||
|
|
||||||
|
for (let board of boards) {
|
||||||
|
let value = [];
|
||||||
|
for (let file of board.files) {
|
||||||
|
for (let sFile of files) {
|
||||||
|
if (file.name == sFile.name) {
|
||||||
|
value.push({
|
||||||
|
"address": file.address,
|
||||||
|
"name": file.name,
|
||||||
|
"url": sFile.url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const option = document.createElement("option");
|
||||||
|
option.textContent = board.name;
|
||||||
|
option.value = JSON.stringify(value);
|
||||||
|
fwBoard.appendChild(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching release config:", error);
|
||||||
|
alert("Error fetching release config");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fwVersion.addEventListener("change", async (element) => {
|
||||||
|
fwBoardContainer.classList.toggle("hidden", true);
|
||||||
|
toolContainer.classList.toggle("hidden", true);
|
||||||
|
|
||||||
|
if (element.target.value == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await loadFwBoards(element.target.value)) {
|
||||||
|
fwBoardContainer.classList.toggle("hidden", false);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
alert("This version is not supported by web flasher");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fwBoard.addEventListener("change", async (element) => {
|
||||||
|
if (element.target.value == 0) {
|
||||||
|
toolContainer.classList.toggle("hidden", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toolContainer.classList.toggle("hidden", false);
|
||||||
|
});
|
||||||
|
|
||||||
|
connectBtn.addEventListener("click", async () => {
|
||||||
|
connectBtn.disabled = true;
|
||||||
|
flashBtn.disabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
statusContainer.textContent = "Connecting...";
|
||||||
|
|
||||||
|
const device = await navigator.serial.requestPort({});
|
||||||
|
const transport = new Transport(device);
|
||||||
|
esploader = new ESPLoader({
|
||||||
|
transport: transport,
|
||||||
|
baudrate: parseInt(115200),
|
||||||
|
debugLogging: false,
|
||||||
|
});
|
||||||
|
const model = await esploader.main();
|
||||||
|
|
||||||
|
flashBtn.disabled = false;
|
||||||
|
statusContainer.textContent = `Connected to ${model}`;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
statusContainer.textContent = "Failed to connect to device! Maybe this browser is not supported?";
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
connectBtn.disabled = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
flashBtn.addEventListener("click", async () => {
|
||||||
|
connectBtn.disabled = true;
|
||||||
|
flashBtn.disabled = true;
|
||||||
|
progressContainer.classList.toggle("hidden", false);
|
||||||
|
|
||||||
|
const progressBar = progressContainer.querySelector("progress");
|
||||||
|
progressBar.removeAttribute("value");
|
||||||
|
progressBar.removeAttribute("max");
|
||||||
|
|
||||||
|
let files = JSON.parse(fwBoard[fwBoard.selectedIndex].value);
|
||||||
|
try {
|
||||||
|
statusContainer.textContent = "Downloading files...";
|
||||||
|
|
||||||
|
for (let file of files) {
|
||||||
|
const response = await fetch(`https://corsproxy.io/?url=${file.url}`, {
|
||||||
|
cache: "no-cache"
|
||||||
|
});
|
||||||
|
const firmwareArrayBuffer = await response.arrayBuffer();
|
||||||
|
const uint8Array = new Uint8Array(firmwareArrayBuffer);
|
||||||
|
file.data = "";
|
||||||
|
for (let i = 0; i < uint8Array.length; i++) {
|
||||||
|
file.data += String.fromCharCode(uint8Array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
statusContainer.textContent = "Failed to download files";
|
||||||
|
connectBtn.disabled = false;
|
||||||
|
flashBtn.disabled = false;
|
||||||
|
progressContainer.classList.toggle("hidden", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
statusContainer.textContent = "Erasing flash...";
|
||||||
|
|
||||||
|
await esploader.writeFlash({
|
||||||
|
fileArray: files,
|
||||||
|
flashSize: "keep",
|
||||||
|
eraseAll: true,
|
||||||
|
compress: true,
|
||||||
|
reportProgress: (fIndex, written, total) => {
|
||||||
|
progressBar.setAttribute("value", (written / total) * 100);
|
||||||
|
progressBar.setAttribute("max", 100);
|
||||||
|
statusContainer.textContent = `Flashing '${files[fIndex].name}'...`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
statusContainer.textContent = "Flashed successfully!";
|
||||||
|
|
||||||
|
try {
|
||||||
|
await esploader.hardReset();
|
||||||
|
} catch (error) { }
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
statusContainer.textContent = `Failed to write: ${error}`;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
connectBtn.disabled = false;
|
||||||
|
//flashBtn.disabled = false;
|
||||||
|
progressContainer.classList.toggle("hidden", true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await loadFwVersions();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
class BufferedWebServer {
|
|
||||||
public:
|
|
||||||
BufferedWebServer(WebServer* webServer, size_t bufferSize = 64) {
|
|
||||||
this->webServer = webServer;
|
|
||||||
this->bufferSize = bufferSize;
|
|
||||||
this->buffer = (uint8_t*)malloc(bufferSize * sizeof(*this->buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
~BufferedWebServer() {
|
|
||||||
free(this->buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(int code, const char* contentType, JsonDocument& content) {
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
if (!this->webServer->chunkedResponseModeStart(code, contentType)) {
|
|
||||||
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->webServer->setContentLength(measureJson(content));
|
|
||||||
#else
|
|
||||||
this->webServer->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
|
||||||
this->webServer->sendHeader(F("Content-Length"), String(measureJson(content)));
|
|
||||||
this->webServer->send(code, contentType, emptyString);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
serializeJson(content, *this);
|
|
||||||
this->flush();
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->webServer->chunkedResponseFinalize();
|
|
||||||
#else
|
|
||||||
this->webServer->sendContent(emptyString);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t write(uint8_t c) {
|
|
||||||
this->buffer[this->bufferPos++] = c;
|
|
||||||
|
|
||||||
if (this->bufferPos >= this->bufferSize) {
|
|
||||||
this->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t write(const uint8_t* buffer, size_t length) {
|
|
||||||
size_t written = 0;
|
|
||||||
while (written < length) {
|
|
||||||
size_t copySize = this->bufferSize - this->bufferPos;
|
|
||||||
if (written + copySize > length) {
|
|
||||||
copySize = length - written;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(this->buffer + this->bufferPos, buffer + written, copySize);
|
|
||||||
this->bufferPos += copySize;
|
|
||||||
|
|
||||||
if (this->bufferPos >= this->bufferSize) {
|
|
||||||
this->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
written += copySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
void flush() {
|
|
||||||
if (this->bufferPos == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->webServer->sendContent((const char*)this->buffer, this->bufferPos);
|
|
||||||
this->bufferPos = 0;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
WebServer* webServer = nullptr;
|
|
||||||
uint8_t* buffer;
|
|
||||||
size_t bufferSize = 64;
|
|
||||||
size_t bufferPos = 0;
|
|
||||||
};
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <OpenTherm.h>
|
|
||||||
|
|
||||||
class CustomOpenTherm : public OpenTherm {
|
|
||||||
public:
|
|
||||||
typedef std::function<void()> YieldCallback;
|
|
||||||
typedef std::function<void(unsigned long, byte)> BeforeSendRequestCallback;
|
|
||||||
typedef std::function<void(unsigned long, unsigned long, OpenThermResponseStatus, byte)> AfterSendRequestCallback;
|
|
||||||
|
|
||||||
CustomOpenTherm(int inPin = 4, int outPin = 5, bool isSlave = false) : OpenTherm(inPin, outPin, isSlave) {}
|
|
||||||
~CustomOpenTherm() {}
|
|
||||||
|
|
||||||
CustomOpenTherm* setYieldCallback(YieldCallback callback = nullptr) {
|
|
||||||
this->yieldCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomOpenTherm* setBeforeSendRequestCallback(BeforeSendRequestCallback callback = nullptr) {
|
|
||||||
this->beforeSendRequestCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomOpenTherm* setAfterSendRequestCallback(AfterSendRequestCallback callback = nullptr) {
|
|
||||||
this->afterSendRequestCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long sendRequest(unsigned long request, byte attempts = 5, byte _attempt = 0) {
|
|
||||||
_attempt++;
|
|
||||||
|
|
||||||
while (!this->isReady()) {
|
|
||||||
if (this->yieldCallback) {
|
|
||||||
this->yieldCallback();
|
|
||||||
} else {
|
|
||||||
::yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->process();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->beforeSendRequestCallback) {
|
|
||||||
this->beforeSendRequestCallback(request, _attempt);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long _response;
|
|
||||||
OpenThermResponseStatus _responseStatus = OpenThermResponseStatus::NONE;
|
|
||||||
if (!this->sendRequestAsync(request)) {
|
|
||||||
_response = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
while (true) {
|
|
||||||
this->process();
|
|
||||||
|
|
||||||
if (this->status == OpenThermStatus::READY || this->status == OpenThermStatus::DELAY) {
|
|
||||||
break;
|
|
||||||
} else if (this->yieldCallback) {
|
|
||||||
this->yieldCallback();
|
|
||||||
} else {
|
|
||||||
::yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_response = this->getLastResponse();
|
|
||||||
_responseStatus = this->getLastResponseStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->afterSendRequestCallback) {
|
|
||||||
this->afterSendRequestCallback(request, _response, _responseStatus, _attempt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_responseStatus == OpenThermResponseStatus::SUCCESS || _responseStatus == OpenThermResponseStatus::INVALID || _attempt >= attempts) {
|
|
||||||
return _response;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return this->sendRequest(request, attempts, _attempt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long setBoilerStatus(bool enableCentralHeating, bool enableHotWater, bool enableCooling, bool enableOutsideTemperatureCompensation, bool enableCentralHeating2, bool summerWinterMode, bool dhwBlocking) {
|
|
||||||
unsigned int data = enableCentralHeating
|
|
||||||
| (enableHotWater << 1)
|
|
||||||
| (enableCooling << 2)
|
|
||||||
| (enableOutsideTemperatureCompensation << 3)
|
|
||||||
| (enableCentralHeating2 << 4)
|
|
||||||
| (summerWinterMode << 5)
|
|
||||||
| (dhwBlocking << 6);
|
|
||||||
data <<= 8;
|
|
||||||
|
|
||||||
return this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::READ_DATA,
|
|
||||||
OpenThermMessageID::Status,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setHeatingCh1Temp(float temperature) {
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::TSet,
|
|
||||||
temperatureToData(temperature)
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setHeatingCh2Temp(float temperature) {
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::TsetCH2,
|
|
||||||
temperatureToData(temperature)
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setDhwTemp(float temperature) {
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::TdhwSet,
|
|
||||||
temperatureToData(temperature)
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendBoilerReset() {
|
|
||||||
unsigned int data = 1;
|
|
||||||
data <<= 8;
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::RemoteRequest,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendServiceReset() {
|
|
||||||
unsigned int data = 10;
|
|
||||||
data <<= 8;
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::RemoteRequest,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendWaterFilling() {
|
|
||||||
unsigned int data = 2;
|
|
||||||
data <<= 8;
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::RemoteRequest,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
// converters
|
|
||||||
float fromF88(unsigned long response) {
|
|
||||||
const byte valueLB = response & 0xFF;
|
|
||||||
const byte valueHB = (response >> 8) & 0xFF;
|
|
||||||
|
|
||||||
float value = (int8_t)valueHB;
|
|
||||||
return value + (float)valueLB / 256.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T> unsigned int toF88(T val) {
|
|
||||||
return (unsigned int)(val * 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t fromS16(unsigned long response) {
|
|
||||||
const byte valueLB = response & 0xFF;
|
|
||||||
const byte valueHB = (response >> 8) & 0xFF;
|
|
||||||
|
|
||||||
int16_t value = valueHB;
|
|
||||||
return ((value << 8) + valueLB);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
YieldCallback yieldCallback;
|
|
||||||
BeforeSendRequestCallback beforeSendRequestCallback;
|
|
||||||
AfterSendRequestCallback afterSendRequestCallback;
|
|
||||||
};
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#if defined(EQUITHERM_INTEGER)
|
|
||||||
// расчёты с целыми числами
|
|
||||||
typedef int datatype;
|
|
||||||
#else
|
|
||||||
// расчёты с float числами
|
|
||||||
typedef float datatype;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Equitherm {
|
|
||||||
public:
|
|
||||||
datatype targetTemp = 0;
|
|
||||||
datatype indoorTemp = 0;
|
|
||||||
datatype outdoorTemp = 0;
|
|
||||||
float Kn = 0.0;
|
|
||||||
float Kk = 0.0;
|
|
||||||
float Kt = 0.0;
|
|
||||||
|
|
||||||
Equitherm() = default;
|
|
||||||
|
|
||||||
// kn, kk, kt
|
|
||||||
Equitherm(float new_kn, float new_kk, float new_kt) {
|
|
||||||
Kn = new_kn;
|
|
||||||
Kk = new_kk;
|
|
||||||
Kt = new_kt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// лимит выходной величины
|
|
||||||
void setLimits(int min_output, int max_output) {
|
|
||||||
_minOut = min_output;
|
|
||||||
_maxOut = max_output;
|
|
||||||
}
|
|
||||||
|
|
||||||
// возвращает новое значение при вызове
|
|
||||||
datatype getResult() {
|
|
||||||
datatype output = getResultN() + getResultK() + getResultT();
|
|
||||||
output = constrain(output, _minOut, _maxOut); // ограничиваем выход
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _minOut = 20, _maxOut = 90;
|
|
||||||
|
|
||||||
// температура контура отопления в зависимости от наружной температуры
|
|
||||||
datatype getResultN() {
|
|
||||||
float a = (-0.21 * Kn) - 0.06; // a = -0,21k — 0,06
|
|
||||||
float b = (6.04 * Kn) + 1.98; // b = 6,04k + 1,98
|
|
||||||
float c = (-5.06 * Kn) + 18.06; // с = -5,06k + 18,06
|
|
||||||
float x = (-0.2 * outdoorTemp) + 5; // x = -0.2*t1 + 5
|
|
||||||
return (a * x * x) + (b * x) + c; // Tn = ax2 + bx + c
|
|
||||||
}
|
|
||||||
|
|
||||||
// поправка на желаемую комнатную температуру
|
|
||||||
datatype getResultK() {
|
|
||||||
return (targetTemp - 20) * Kk;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Расчет поправки (ошибки) термостата
|
|
||||||
datatype getResultT() {
|
|
||||||
return constrain((targetTemp - indoorTemp), -2, 2) * Kt;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "strings.h"
|
|
||||||
|
|
||||||
class HomeAssistantHelper {
|
|
||||||
public:
|
|
||||||
typedef std::function<void(const char*, bool)> PublishEventCallback;
|
|
||||||
|
|
||||||
HomeAssistantHelper() = default;
|
|
||||||
|
|
||||||
void setWriter() {
|
|
||||||
this->writer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setWriter(MqttWriter* writer) {
|
|
||||||
this->writer = writer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPublishEventCallback(PublishEventCallback callback) {
|
|
||||||
this->publishEventCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDevicePrefix(const char* value) {
|
|
||||||
this->devicePrefix = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceVersion(const char* value) {
|
|
||||||
this->deviceVersion = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceManufacturer(const char* value) {
|
|
||||||
this->deviceManufacturer = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceModel(const char* value) {
|
|
||||||
this->deviceModel = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceName(const char* value) {
|
|
||||||
this->deviceName = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceConfigUrl(const char* value) {
|
|
||||||
this->deviceConfigUrl = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publish(const char* topic, JsonDocument& doc) {
|
|
||||||
if (this->writer == nullptr) {
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_IDENTIFIERS)][0] = this->devicePrefix;
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_SW_VERSION)] = this->deviceVersion;
|
|
||||||
|
|
||||||
if (this->deviceManufacturer != nullptr) {
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_MANUFACTURER)] = this->deviceManufacturer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->deviceModel != nullptr) {
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_MODEL)] = this->deviceModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->deviceName != nullptr) {
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_NAME)] = this->deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->deviceConfigUrl != nullptr) {
|
|
||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_CONF_URL)] = this->deviceConfigUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool result = this->writer->publish(topic, doc, true);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publish(const char* topic) {
|
|
||||||
if (this->writer == nullptr) {
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool result = writer->publish(topic, nullptr, 0, true);
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
String getTopic(T category, T name, char nameSeparator = '/') {
|
|
||||||
String topic = "";
|
|
||||||
topic.concat(this->prefix);
|
|
||||||
topic.concat('/');
|
|
||||||
topic.concat(category);
|
|
||||||
topic.concat('/');
|
|
||||||
topic.concat(this->devicePrefix);
|
|
||||||
topic.concat(nameSeparator);
|
|
||||||
topic.concat(name);
|
|
||||||
topic.concat("/config");
|
|
||||||
return topic;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
String getDeviceTopic(T value, char separator = '/') {
|
|
||||||
String topic = "";
|
|
||||||
topic.concat(this->devicePrefix);
|
|
||||||
topic.concat(separator);
|
|
||||||
topic.concat(value);
|
|
||||||
return topic;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
String getObjectId(T value, char separator = '_') {
|
|
||||||
String topic = "";
|
|
||||||
topic.concat(this->devicePrefix);
|
|
||||||
topic.concat(separator);
|
|
||||||
topic.concat(value);
|
|
||||||
return topic;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PublishEventCallback publishEventCallback;
|
|
||||||
MqttWriter* writer = nullptr;
|
|
||||||
const char* prefix = "homeassistant";
|
|
||||||
const char* devicePrefix = "";
|
|
||||||
const char* deviceVersion = "1.0";
|
|
||||||
const char* deviceManufacturer = nullptr;
|
|
||||||
const char* deviceModel = nullptr;
|
|
||||||
const char* deviceName = nullptr;
|
|
||||||
const char* deviceConfigUrl = nullptr;
|
|
||||||
};
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef PROGMEM
|
|
||||||
#define PROGMEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char HA_ENTITY_BINARY_SENSOR[] PROGMEM = "binary_sensor";
|
|
||||||
const char HA_ENTITY_BUTTON[] PROGMEM = "button";
|
|
||||||
const char HA_ENTITY_FAN[] PROGMEM = "fan";
|
|
||||||
const char HA_ENTITY_CLIMATE[] PROGMEM = "climate";
|
|
||||||
const char HA_ENTITY_NUMBER[] PROGMEM = "number";
|
|
||||||
const char HA_ENTITY_SELECT[] PROGMEM = "select";
|
|
||||||
const char HA_ENTITY_SENSOR[] PROGMEM = "sensor";
|
|
||||||
const char HA_ENTITY_SWITCH[] PROGMEM = "switch";
|
|
||||||
|
|
||||||
const char HA_DEVICE[] PROGMEM = "device";
|
|
||||||
const char HA_IDENTIFIERS[] PROGMEM = "identifiers";
|
|
||||||
const char HA_SW_VERSION[] PROGMEM = "sw_version";
|
|
||||||
const char HA_MANUFACTURER[] PROGMEM = "manufacturer";
|
|
||||||
const char HA_MODEL[] PROGMEM = "model";
|
|
||||||
const char HA_NAME[] PROGMEM = "name";
|
|
||||||
const char HA_CONF_URL[] PROGMEM = "configuration_url";
|
|
||||||
const char HA_COMMAND_TOPIC[] PROGMEM = "command_topic";
|
|
||||||
const char HA_COMMAND_TEMPLATE[] PROGMEM = "command_template";
|
|
||||||
const char HA_ENABLED_BY_DEFAULT[] PROGMEM = "enabled_by_default";
|
|
||||||
const char HA_UNIQUE_ID[] PROGMEM = "unique_id";
|
|
||||||
const char HA_OBJECT_ID[] PROGMEM = "object_id";
|
|
||||||
const char HA_ENTITY_CATEGORY[] PROGMEM = "entity_category";
|
|
||||||
const char HA_STATE_TOPIC[] PROGMEM = "state_topic";
|
|
||||||
const char HA_VALUE_TEMPLATE[] PROGMEM = "value_template";
|
|
||||||
const char HA_OPTIONS[] PROGMEM = "options";
|
|
||||||
const char HA_AVAILABILITY[] PROGMEM = "availability";
|
|
||||||
const char HA_AVAILABILITY_MODE[] PROGMEM = "availability_mode";
|
|
||||||
const char HA_TOPIC[] PROGMEM = "topic";
|
|
||||||
const char HA_DEVICE_CLASS[] PROGMEM = "device_class";
|
|
||||||
const char HA_UNIT_OF_MEASUREMENT[] PROGMEM = "unit_of_measurement";
|
|
||||||
const char HA_ICON[] PROGMEM = "icon";
|
|
||||||
const char HA_MIN[] PROGMEM = "min";
|
|
||||||
const char HA_MAX[] PROGMEM = "max";
|
|
||||||
const char HA_STEP[] PROGMEM = "step";
|
|
||||||
const char HA_MODE[] PROGMEM = "mode";
|
|
||||||
const char HA_STATE_ON[] PROGMEM = "state_on";
|
|
||||||
const char HA_STATE_OFF[] PROGMEM = "state_off";
|
|
||||||
const char HA_PAYLOAD_ON[] PROGMEM = "payload_on";
|
|
||||||
const char HA_PAYLOAD_OFF[] PROGMEM = "payload_off";
|
|
||||||
const char HA_STATE_CLASS[] PROGMEM = "state_class";
|
|
||||||
const char HA_EXPIRE_AFTER[] PROGMEM = "expire_after";
|
|
||||||
const char HA_CURRENT_TEMPERATURE_TOPIC[] PROGMEM = "current_temperature_topic";
|
|
||||||
const char HA_CURRENT_TEMPERATURE_TEMPLATE[] PROGMEM = "current_temperature_template";
|
|
||||||
const char HA_TEMPERATURE_COMMAND_TOPIC[] PROGMEM = "temperature_command_topic";
|
|
||||||
const char HA_TEMPERATURE_COMMAND_TEMPLATE[] PROGMEM = "temperature_command_template";
|
|
||||||
const char HA_TEMPERATURE_STATE_TOPIC[] PROGMEM = "temperature_state_topic";
|
|
||||||
const char HA_TEMPERATURE_STATE_TEMPLATE[] PROGMEM = "temperature_state_template";
|
|
||||||
const char HA_MODE_COMMAND_TOPIC[] PROGMEM = "mode_command_topic";
|
|
||||||
const char HA_MODE_COMMAND_TEMPLATE[] PROGMEM = "mode_command_template";
|
|
||||||
const char HA_MODE_STATE_TOPIC[] PROGMEM = "mode_state_topic";
|
|
||||||
const char HA_MODE_STATE_TEMPLATE[] PROGMEM = "mode_state_template";
|
|
||||||
const char HA_MODES[] PROGMEM = "modes";
|
|
||||||
const char HA_ACTION_TOPIC[] PROGMEM = "action_topic";
|
|
||||||
const char HA_ACTION_TEMPLATE[] PROGMEM = "action_template";
|
|
||||||
const char HA_MIN_TEMP[] PROGMEM = "min_temp";
|
|
||||||
const char HA_MAX_TEMP[] PROGMEM = "max_temp";
|
|
||||||
const char HA_TEMP_STEP[] PROGMEM = "temp_step";
|
|
||||||
const char HA_PRESET_MODE_COMMAND_TOPIC[] PROGMEM = "preset_mode_command_topic";
|
|
||||||
const char HA_PRESET_MODE_COMMAND_TEMPLATE[] PROGMEM = "preset_mode_command_template";
|
|
||||||
const char HA_PRESET_MODE_STATE_TOPIC[] PROGMEM = "preset_mode_state_topic";
|
|
||||||
const char HA_PRESET_MODE_VALUE_TEMPLATE[] PROGMEM = "preset_mode_value_template";
|
|
||||||
const char HA_PRESET_MODES[] PROGMEM = "preset_modes";
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#include <WiFiClient.h>
|
|
||||||
|
|
||||||
class MqttWiFiClient : public WiFiClient {
|
|
||||||
public:
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
void flush() override {
|
|
||||||
if (this->connected()) {
|
|
||||||
WiFiClient::flush(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop() override {
|
|
||||||
this->abort();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
void setSync(bool) {}
|
|
||||||
|
|
||||||
bool getSync() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <MqttClient.h>
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
#include <mutex>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
class MqttWriter {
|
|
||||||
public:
|
|
||||||
typedef std::function<void()> YieldCallback;
|
|
||||||
typedef std::function<void(const char*, size_t, size_t, bool)> PublishEventCallback;
|
|
||||||
typedef std::function<void(size_t, size_t)> FlushEventCallback;
|
|
||||||
|
|
||||||
MqttWriter(MqttClient* client, size_t bufferSize = 64) {
|
|
||||||
this->client = client;
|
|
||||||
this->bufferSize = bufferSize;
|
|
||||||
this->buffer = (uint8_t*) malloc(bufferSize * sizeof(*this->buffer));
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
this->mutex = new std::mutex();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
~MqttWriter() {
|
|
||||||
free(this->buffer);
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
delete this->mutex;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
MqttWriter* setYieldCallback(YieldCallback callback = nullptr) {
|
|
||||||
this->yieldCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
MqttWriter* setPublishEventCallback(PublishEventCallback callback) {
|
|
||||||
this->publishEventCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
MqttWriter* setFlushEventCallback(FlushEventCallback callback) {
|
|
||||||
this->flushEventCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lock() {
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
if (!this->mutex->try_lock()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (this->isLocked()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->locked = true;
|
|
||||||
this->writeAfterLock = 0;
|
|
||||||
this->lockedTime = millis();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isLocked() {
|
|
||||||
return this->locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unlock() {
|
|
||||||
this->locked = false;
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
this->mutex->unlock();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publish(const char* topic, JsonDocument& doc, bool retained = false) {
|
|
||||||
if (!this->client->connected()) {
|
|
||||||
this->bufferPos = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!this->lock()) {
|
|
||||||
if (this->yieldCallback) {
|
|
||||||
this->yieldCallback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->bufferPos = 0;
|
|
||||||
size_t docSize = measureJson(doc);
|
|
||||||
size_t written = 0;
|
|
||||||
if (this->client->beginMessage(topic, docSize, retained)) {
|
|
||||||
serializeJson(doc, *this);
|
|
||||||
this->flush();
|
|
||||||
this->client->endMessage();
|
|
||||||
|
|
||||||
written = this->writeAfterLock;
|
|
||||||
}
|
|
||||||
this->unlock();
|
|
||||||
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, written, docSize, written == docSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
return written == docSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publish(const char* topic, const char* buffer, bool retained = false) {
|
|
||||||
return this->publish(topic, (const uint8_t*) buffer, strlen(buffer), retained);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publish(const char* topic, const uint8_t* buffer, size_t length, bool retained = false) {
|
|
||||||
if (!this->client->connected()) {
|
|
||||||
this->bufferPos = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!this->lock()) {
|
|
||||||
if (this->yieldCallback) {
|
|
||||||
this->yieldCallback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->bufferPos = 0;
|
|
||||||
size_t written = 0;
|
|
||||||
bool result = false;
|
|
||||||
if (!length || buffer == nullptr) {
|
|
||||||
result = this->client->beginMessage(topic, retained) && this->client->endMessage();
|
|
||||||
|
|
||||||
} else if (this->client->beginMessage(topic, length, retained)) {
|
|
||||||
this->write(buffer, length);
|
|
||||||
this->flush();
|
|
||||||
this->client->endMessage();
|
|
||||||
|
|
||||||
written = this->writeAfterLock;
|
|
||||||
result = written == length;
|
|
||||||
}
|
|
||||||
this->unlock();
|
|
||||||
|
|
||||||
if (this->publishEventCallback) {
|
|
||||||
this->publishEventCallback(topic, written, length, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t write(uint8_t c) {
|
|
||||||
this->buffer[this->bufferPos++] = c;
|
|
||||||
|
|
||||||
if (this->bufferPos >= this->bufferSize) {
|
|
||||||
this->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t write(const uint8_t* buffer, size_t length) {
|
|
||||||
size_t written = 0;
|
|
||||||
while (written < length) {
|
|
||||||
size_t copySize = this->bufferSize - this->bufferPos;
|
|
||||||
if (written + copySize > length) {
|
|
||||||
copySize = length - written;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(this->buffer + this->bufferPos, buffer + written, copySize);
|
|
||||||
this->bufferPos += copySize;
|
|
||||||
|
|
||||||
if (this->bufferPos >= this->bufferSize) {
|
|
||||||
this->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
written += copySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool flush() {
|
|
||||||
if (this->bufferPos == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->client->connected()) {
|
|
||||||
this->bufferPos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t length = this->bufferPos;
|
|
||||||
size_t written = this->client->write(this->buffer, length);
|
|
||||||
this->client->flush();
|
|
||||||
this->bufferPos = 0;
|
|
||||||
|
|
||||||
if (this->isLocked()) {
|
|
||||||
this->writeAfterLock += written;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->flushEventCallback) {
|
|
||||||
this->flushEventCallback(written, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
return written == length;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
YieldCallback yieldCallback;
|
|
||||||
PublishEventCallback publishEventCallback;
|
|
||||||
FlushEventCallback flushEventCallback;
|
|
||||||
MqttClient* client;
|
|
||||||
uint8_t* buffer;
|
|
||||||
size_t bufferSize = 64;
|
|
||||||
size_t bufferPos = 0;
|
|
||||||
bool locked = false;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
mutable std::mutex* mutex;
|
|
||||||
#endif
|
|
||||||
unsigned long lockedTime = 0;
|
|
||||||
size_t writeAfterLock = 0;
|
|
||||||
};
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
#include "NetworkConnection.h"
|
|
||||||
using namespace Network;
|
|
||||||
|
|
||||||
void Connection::setup(bool useDhcp) {
|
|
||||||
setUseDhcp(useDhcp);
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
wifi_set_event_handler_cb(Connection::onEvent);
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
WiFi.onEvent(Connection::onEvent);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::reset() {
|
|
||||||
status = Status::NONE;
|
|
||||||
disconnectReason = DisconnectReason::NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::setUseDhcp(bool value) {
|
|
||||||
useDhcp = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection::Status Connection::getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection::DisconnectReason Connection::getDisconnectReason() {
|
|
||||||
return disconnectReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
void Connection::onEvent(System_Event_t *event) {
|
|
||||||
switch (event->event) {
|
|
||||||
case EVENT_STAMODE_CONNECTED:
|
|
||||||
status = useDhcp ? Status::CONNECTING : Status::CONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::NONE;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVENT_STAMODE_GOT_IP:
|
|
||||||
status = Status::CONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVENT_STAMODE_DHCP_TIMEOUT:
|
|
||||||
status = Status::DISCONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::DHCP_TIMEOUT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVENT_STAMODE_DISCONNECTED:
|
|
||||||
status = Status::DISCONNECTED;
|
|
||||||
disconnectReason = convertDisconnectReason(event->event_info.disconnected.reason);
|
|
||||||
|
|
||||||
// https://github.com/esp8266/Arduino/blob/d5eb265f78bff9deb7063d10030a02d021c8c66c/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp#L231
|
|
||||||
if ((wifi_station_get_connect_status() == STATION_GOT_IP) && !wifi_station_get_reconnect_policy()) {
|
|
||||||
wifi_station_disconnect();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVENT_STAMODE_AUTHMODE_CHANGE:
|
|
||||||
// https://github.com/esp8266/Arduino/blob/d5eb265f78bff9deb7063d10030a02d021c8c66c/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp#L241
|
|
||||||
{
|
|
||||||
auto& src = event->event_info.auth_change;
|
|
||||||
if ((src.old_mode != AUTH_OPEN) && (src.new_mode == AUTH_OPEN)) {
|
|
||||||
status = Status::DISCONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::OTHER;
|
|
||||||
|
|
||||||
wifi_station_disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
void Connection::onEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
switch (event) {
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
|
||||||
status = useDhcp ? Status::CONNECTING : Status::CONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::NONE;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
|
||||||
status = Status::CONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
|
||||||
status = Status::DISCONNECTED;
|
|
||||||
disconnectReason = DisconnectReason::DHCP_TIMEOUT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
|
||||||
status = Status::DISCONNECTED;
|
|
||||||
disconnectReason = convertDisconnectReason(info.wifi_sta_disconnected.reason);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Connection::DisconnectReason Connection::convertDisconnectReason(uint8_t reason) {
|
|
||||||
switch (reason) {
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
case REASON_BEACON_TIMEOUT:
|
|
||||||
return DisconnectReason::BEACON_TIMEOUT;
|
|
||||||
|
|
||||||
case REASON_NO_AP_FOUND:
|
|
||||||
return DisconnectReason::NO_AP_FOUND;
|
|
||||||
|
|
||||||
case REASON_AUTH_FAIL:
|
|
||||||
return DisconnectReason::AUTH_FAIL;
|
|
||||||
|
|
||||||
case REASON_ASSOC_FAIL:
|
|
||||||
return DisconnectReason::ASSOC_FAIL;
|
|
||||||
|
|
||||||
case REASON_HANDSHAKE_TIMEOUT:
|
|
||||||
return DisconnectReason::HANDSHAKE_TIMEOUT;
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
case WIFI_REASON_BEACON_TIMEOUT:
|
|
||||||
return DisconnectReason::BEACON_TIMEOUT;
|
|
||||||
|
|
||||||
case WIFI_REASON_NO_AP_FOUND:
|
|
||||||
return DisconnectReason::NO_AP_FOUND;
|
|
||||||
|
|
||||||
case WIFI_REASON_AUTH_FAIL:
|
|
||||||
return DisconnectReason::AUTH_FAIL;
|
|
||||||
|
|
||||||
case WIFI_REASON_ASSOC_FAIL:
|
|
||||||
return DisconnectReason::ASSOC_FAIL;
|
|
||||||
|
|
||||||
case WIFI_REASON_HANDSHAKE_TIMEOUT:
|
|
||||||
return DisconnectReason::HANDSHAKE_TIMEOUT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default:
|
|
||||||
return DisconnectReason::OTHER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::useDhcp = false;
|
|
||||||
Connection::Status Connection::status = Status::NONE;
|
|
||||||
Connection::DisconnectReason Connection::disconnectReason = DisconnectReason::NONE;
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include "lwip/etharp.h"
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Network {
|
|
||||||
struct Connection {
|
|
||||||
enum class Status {
|
|
||||||
CONNECTED,
|
|
||||||
CONNECTING,
|
|
||||||
DISCONNECTED,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class DisconnectReason {
|
|
||||||
BEACON_TIMEOUT,
|
|
||||||
NO_AP_FOUND,
|
|
||||||
AUTH_FAIL,
|
|
||||||
ASSOC_FAIL,
|
|
||||||
HANDSHAKE_TIMEOUT,
|
|
||||||
DHCP_TIMEOUT,
|
|
||||||
OTHER,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Status status;
|
|
||||||
static DisconnectReason disconnectReason;
|
|
||||||
|
|
||||||
static void setup(bool useDhcp);
|
|
||||||
static void setUseDhcp(bool value);
|
|
||||||
static void reset();
|
|
||||||
static Status getStatus();
|
|
||||||
static DisconnectReason getDisconnectReason();
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
static void onEvent(System_Event_t *evt);
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
static void onEvent(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static DisconnectReason convertDisconnectReason(uint8_t reason);
|
|
||||||
static bool useDhcp;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,438 +0,0 @@
|
|||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include "lwip/etharp.h"
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <esp_wifi.h>
|
|
||||||
#endif
|
|
||||||
#include <NetworkConnection.h>
|
|
||||||
|
|
||||||
namespace Network {
|
|
||||||
class Manager {
|
|
||||||
public:
|
|
||||||
typedef std::function<void()> YieldCallback;
|
|
||||||
typedef std::function<void(unsigned int)> DelayCallback;
|
|
||||||
|
|
||||||
Manager() {
|
|
||||||
Connection::setup(this->useDhcp);
|
|
||||||
this->resetWifi();
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setYieldCallback(YieldCallback callback = nullptr) {
|
|
||||||
this->yieldCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setDelayCallback(DelayCallback callback = nullptr) {
|
|
||||||
this->delayCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setHostname(const char* value) {
|
|
||||||
this->hostname = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setApCredentials(const char* ssid, const char* password = nullptr, byte channel = 0) {
|
|
||||||
this->apName = ssid;
|
|
||||||
this->apPassword = password;
|
|
||||||
this->apChannel = channel;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setStaCredentials(const char* ssid = nullptr, const char* password = nullptr, byte channel = 0) {
|
|
||||||
this->staSsid = ssid;
|
|
||||||
this->staPassword = password;
|
|
||||||
this->staChannel = channel;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setUseDhcp(bool value) {
|
|
||||||
this->useDhcp = value;
|
|
||||||
Connection::setup(this->useDhcp);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setStaticConfig(const char* ip, const char* gateway, const char* subnet, const char* dns) {
|
|
||||||
this->staticIp.fromString(ip);
|
|
||||||
this->staticGateway.fromString(gateway);
|
|
||||||
this->staticSubnet.fromString(subnet);
|
|
||||||
this->staticDns.fromString(dns);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Manager* setStaticConfig(IPAddress &ip, IPAddress &gateway, IPAddress &subnet, IPAddress &dns) {
|
|
||||||
this->staticIp = ip;
|
|
||||||
this->staticGateway = gateway;
|
|
||||||
this->staticSubnet = subnet;
|
|
||||||
this->staticDns = dns;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasStaCredentials() {
|
|
||||||
return this->staSsid != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isConnected() {
|
|
||||||
return this->isStaEnabled() && Connection::getStatus() == Connection::Status::CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isConnecting() {
|
|
||||||
return this->isStaEnabled() && Connection::getStatus() == Connection::Status::CONNECTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isStaEnabled() {
|
|
||||||
return (WiFi.getMode() & WIFI_STA) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isApEnabled() {
|
|
||||||
return (WiFi.getMode() & WIFI_AP) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasApClients() {
|
|
||||||
if (!this->isApEnabled()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return WiFi.softAPgetStationNum() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
short int getRssi() {
|
|
||||||
return WiFi.RSSI();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress getApIp() {
|
|
||||||
return WiFi.softAPIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress getStaIp() {
|
|
||||||
return WiFi.localIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress getStaSubnet() {
|
|
||||||
return WiFi.subnetMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress getStaGateway() {
|
|
||||||
return WiFi.gatewayIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress getStaDns() {
|
|
||||||
return WiFi.dnsIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
String getStaMac() {
|
|
||||||
return WiFi.macAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* getStaSsid() {
|
|
||||||
return this->staSsid;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* getStaPassword() {
|
|
||||||
return this->staPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte getStaChannel() {
|
|
||||||
return this->staChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool resetWifi() {
|
|
||||||
// set policy manual for work 13 ch
|
|
||||||
{
|
|
||||||
wifi_country_t country = {"CN", 1, 13, WIFI_COUNTRY_POLICY_MANUAL};
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
wifi_set_country(&country);
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
esp_wifi_set_country(&country);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
WiFi.persistent(false);
|
|
||||||
WiFi.setAutoConnect(false);
|
|
||||||
WiFi.setAutoReconnect(false);
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
WiFi.setSleep(USE_BLE ? WIFI_PS_MIN_MODEM : WIFI_PS_NONE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
WiFi.softAPdisconnect();
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
/*if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
|
||||||
wifi_softap_dhcps_stop();
|
|
||||||
}*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
WiFi.disconnect(false, true);
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
/*if (wifi_station_dhcpc_status() == DHCP_STARTED) {
|
|
||||||
wifi_station_dhcpc_stop();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
wifi_station_dhcpc_set_maxtry(5);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return WiFi.mode(WIFI_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reconnect() {
|
|
||||||
this->reconnectFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool connect(bool force = false, unsigned int timeout = 1000u) {
|
|
||||||
if (this->isConnected() && !force) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force && !this->isApEnabled()) {
|
|
||||||
this->resetWifi();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/*#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
if (wifi_station_dhcpc_status() == DHCP_STARTED) {
|
|
||||||
wifi_station_dhcpc_stop();
|
|
||||||
}
|
|
||||||
#endif*/
|
|
||||||
|
|
||||||
WiFi.disconnect(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->hasStaCredentials()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->delayCallback(200);
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
if (this->setWifiHostname(this->hostname)) {
|
|
||||||
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->hostname);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!WiFi.mode((WiFiMode_t)(WiFi.getMode() | WIFI_STA))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->delayCallback(200);
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
if (this->setWifiHostname(this->hostname)) {
|
|
||||||
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->hostname);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->delayCallback(200);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!this->useDhcp) {
|
|
||||||
WiFi.config(this->staticIp, this->staticGateway, this->staticSubnet, this->staticDns);
|
|
||||||
}
|
|
||||||
|
|
||||||
WiFi.begin(this->staSsid, this->staPassword, this->staChannel);
|
|
||||||
|
|
||||||
unsigned long beginConnectionTime = millis();
|
|
||||||
while (millis() - beginConnectionTime < timeout) {
|
|
||||||
this->delayCallback(100);
|
|
||||||
|
|
||||||
Connection::Status status = Connection::getStatus();
|
|
||||||
if (status != Connection::Status::CONNECTING && status != Connection::Status::NONE) {
|
|
||||||
return status == Connection::Status::CONNECTED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (this->isConnected() && !this->hasStaCredentials()) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
|
|
||||||
this->resetWifi();
|
|
||||||
Connection::reset();
|
|
||||||
this->delayCallback(200);
|
|
||||||
|
|
||||||
} else if (this->isConnected() && !this->reconnectFlag) {
|
|
||||||
if (!this->connected) {
|
|
||||||
this->connectedTime = millis();
|
|
||||||
this->connected = true;
|
|
||||||
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_NETWORK),
|
|
||||||
F("Connected, downtime: %lu s., IP: %s, RSSI: %hhd"),
|
|
||||||
(millis() - this->disconnectedTime) / 1000,
|
|
||||||
WiFi.localIP().toString().c_str(),
|
|
||||||
WiFi.RSSI()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->isApEnabled() && millis() - this->connectedTime > this->reconnectInterval && !this->hasApClients()) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Stop AP because connected, start only STA"));
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
if (millis() - this->prevArpGratuitous > 60000) {
|
|
||||||
this->stationKeepAliveNow();
|
|
||||||
this->prevArpGratuitous = millis();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (this->connected) {
|
|
||||||
this->disconnectedTime = millis();
|
|
||||||
this->connected = false;
|
|
||||||
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_NETWORK),
|
|
||||||
F("Disconnected, reason: %d, uptime: %lu s."),
|
|
||||||
Connection::getDisconnectReason(),
|
|
||||||
(millis() - this->connectedTime) / 1000
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->hasStaCredentials() && !this->isApEnabled()) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("No STA credentials, start AP"));
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP_STA);
|
|
||||||
this->delayCallback(250);
|
|
||||||
WiFi.softAP(this->apName, this->apPassword, this->apChannel);
|
|
||||||
|
|
||||||
} else if (!this->isApEnabled() && millis() - this->disconnectedTime > this->failedConnectTimeout) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Disconnected for a long time, start AP"));
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP_STA);
|
|
||||||
this->delayCallback(250);
|
|
||||||
WiFi.softAP(this->apName, this->apPassword, this->apChannel);
|
|
||||||
|
|
||||||
} else if (this->isConnecting() && millis() - this->prevReconnectingTime > this->resetConnectionTimeout) {
|
|
||||||
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
|
|
||||||
this->resetWifi();
|
|
||||||
Connection::reset();
|
|
||||||
this->delayCallback(200);
|
|
||||||
|
|
||||||
} else if (!this->isConnecting() && this->hasStaCredentials() && (!this->prevReconnectingTime || millis() - this->prevReconnectingTime > this->reconnectInterval)) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Try connect..."));
|
|
||||||
|
|
||||||
this->reconnectFlag = false;
|
|
||||||
Connection::reset();
|
|
||||||
if (!this->connect(true, this->connectionTimeout)) {
|
|
||||||
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d"), Connection::getStatus(), Connection::getDisconnectReason());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->prevReconnectingTime = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte rssiToSignalQuality(short int rssi) {
|
|
||||||
return constrain(map(rssi, -100, -50, 0, 100), 0, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const unsigned int reconnectInterval = 5000;
|
|
||||||
const unsigned int failedConnectTimeout = 120000;
|
|
||||||
const unsigned int connectionTimeout = 15000;
|
|
||||||
const unsigned int resetConnectionTimeout = 30000;
|
|
||||||
|
|
||||||
YieldCallback yieldCallback = []() {
|
|
||||||
::yield();
|
|
||||||
};
|
|
||||||
DelayCallback delayCallback = [](unsigned int time) {
|
|
||||||
::delay(time);
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* hostname = "esp";
|
|
||||||
const char* apName = "ESP";
|
|
||||||
const char* apPassword = nullptr;
|
|
||||||
byte apChannel = 1;
|
|
||||||
|
|
||||||
const char* staSsid = nullptr;
|
|
||||||
const char* staPassword = nullptr;
|
|
||||||
byte staChannel = 0;
|
|
||||||
|
|
||||||
bool useDhcp = true;
|
|
||||||
IPAddress staticIp;
|
|
||||||
IPAddress staticGateway;
|
|
||||||
IPAddress staticSubnet;
|
|
||||||
IPAddress staticDns;
|
|
||||||
|
|
||||||
bool connected = false;
|
|
||||||
bool reconnectFlag = false;
|
|
||||||
unsigned long prevArpGratuitous = 0;
|
|
||||||
unsigned long prevReconnectingTime = 0;
|
|
||||||
unsigned long connectedTime = 0;
|
|
||||||
unsigned long disconnectedTime = 0;
|
|
||||||
|
|
||||||
|
|
||||||
bool setWifiHostname(const char* hostname) {
|
|
||||||
if (!this->isHostnameValid(hostname)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(WiFi.getHostname(), hostname) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return WiFi.setHostname(hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
* https://github.com/arendst/Tasmota/blob/e6515883f0ee5451931b6280ff847b117de5a231/tasmota/tasmota_support/support_wifi.ino#L1196
|
|
||||||
*/
|
|
||||||
static void stationKeepAliveNow(void) {
|
|
||||||
for (netif* interface = netif_list; interface != nullptr; interface = interface->next) {
|
|
||||||
if (
|
|
||||||
(interface->flags & NETIF_FLAG_LINK_UP)
|
|
||||||
&& (interface->flags & NETIF_FLAG_UP)
|
|
||||||
&& interface->num == STATION_IF
|
|
||||||
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
|
|
||||||
) {
|
|
||||||
etharp_gratuitous(interface);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief check RFC compliance
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
static bool isHostnameValid(const char* value) {
|
|
||||||
size_t len = strlen(value);
|
|
||||||
if (len > 24) {
|
|
||||||
return false;
|
|
||||||
} else if (value[len - 1] == '-') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
|
||||||
if (!isalnum(value[i]) && value[i] != '-') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
#include <FS.h>
|
|
||||||
|
|
||||||
|
|
||||||
class DynamicPage : public RequestHandler {
|
|
||||||
public:
|
|
||||||
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
|
|
||||||
typedef std::function<bool()> BeforeSendCallback;
|
|
||||||
typedef std::function<String(const char*)> TemplateCallback;
|
|
||||||
|
|
||||||
DynamicPage(const char* uri, FS* fs, const char* path, const char* cacheHeader = nullptr) {
|
|
||||||
this->uri = uri;
|
|
||||||
this->fs = fs;
|
|
||||||
this->path = path;
|
|
||||||
this->cacheHeader = cacheHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicPage* setCanHandleCallback(CanHandleCallback callback = nullptr) {
|
|
||||||
this->canHandleCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicPage* setBeforeSendCallback(BeforeSendCallback callback = nullptr) {
|
|
||||||
this->beforeSendCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicPage* setTemplateCallback(TemplateCallback callback = nullptr) {
|
|
||||||
this->templateCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool canHandle(HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool canHandle(HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
return uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
if (!this->canHandle(method, uri)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->beforeSendCallback && !this->beforeSendCallback()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = this->fs->open(this->path, "r");
|
|
||||||
if (!file) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} else if (file.isDirectory()) {
|
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->cacheHeader != nullptr) {
|
|
||||||
server.sendHeader("Cache-Control", this->cacheHeader);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
if (!server.chunkedResponseModeStart(200, F("text/html"))) {
|
|
||||||
server.send(505, F("text/html"), F("HTTP1.1 required"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
|
||||||
server.send(200, "text/html", emptyString);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint8_t* argStartPos = nullptr;
|
|
||||||
uint8_t* argEndPos = nullptr;
|
|
||||||
uint8_t argName[16];
|
|
||||||
size_t sizeArgName = 0;
|
|
||||||
bool argNameProcess = false;
|
|
||||||
while (file.available()) {
|
|
||||||
uint8_t buf[64];
|
|
||||||
size_t length = file.read(buf, sizeof(buf));
|
|
||||||
size_t offset = 0;
|
|
||||||
|
|
||||||
if (argNameProcess) {
|
|
||||||
argEndPos = (uint8_t*) memchr(buf, '}', length);
|
|
||||||
|
|
||||||
if (argEndPos != nullptr) {
|
|
||||||
size_t fullSizeArgName = sizeArgName + (argEndPos - buf);
|
|
||||||
if (fullSizeArgName < sizeof(argName)) {
|
|
||||||
// copy full arg name
|
|
||||||
if (argEndPos - buf > 0) {
|
|
||||||
memcpy(argName + sizeArgName, buf, argEndPos - buf);
|
|
||||||
}
|
|
||||||
argName[fullSizeArgName] = '\0';
|
|
||||||
|
|
||||||
// send arg value
|
|
||||||
String argValue = this->templateCallback((const char*) argName);
|
|
||||||
if (argValue.length()) {
|
|
||||||
server.sendContent(argValue.c_str());
|
|
||||||
|
|
||||||
} else if (fullSizeArgName > 0) {
|
|
||||||
server.sendContent("{");
|
|
||||||
server.sendContent((const char*) argName);
|
|
||||||
server.sendContent("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = size_t(argEndPos - buf + 1);
|
|
||||||
sizeArgName = 0;
|
|
||||||
argNameProcess = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argNameProcess) {
|
|
||||||
server.sendContent("{");
|
|
||||||
|
|
||||||
if (sizeArgName > 0) {
|
|
||||||
argName[sizeArgName] = '\0';
|
|
||||||
server.sendContent((const char*) argName);
|
|
||||||
}
|
|
||||||
|
|
||||||
argNameProcess = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
uint8_t* currentBuf = buf + offset;
|
|
||||||
size_t currentLength = length - offset;
|
|
||||||
|
|
||||||
argStartPos = (uint8_t*) memchr(currentBuf, '{', currentLength);
|
|
||||||
|
|
||||||
// send all content
|
|
||||||
if (argStartPos == nullptr) {
|
|
||||||
if (currentLength > 0) {
|
|
||||||
server.sendContent((const char*) currentBuf, currentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
argEndPos = (uint8_t*) memchr(argStartPos, '}', length - (argStartPos - buf));
|
|
||||||
if (argEndPos != nullptr) {
|
|
||||||
sizeArgName = argEndPos - argStartPos - 1;
|
|
||||||
|
|
||||||
// send all content if arg len > space
|
|
||||||
if (sizeArgName >= sizeof(argName)) {
|
|
||||||
if (currentLength > 0) {
|
|
||||||
server.sendContent((const char*) currentBuf, currentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// arg name
|
|
||||||
memcpy(argName, argStartPos + 1, sizeArgName);
|
|
||||||
argName[sizeArgName] = '\0';
|
|
||||||
|
|
||||||
// send arg value
|
|
||||||
String argValue = this->templateCallback((const char*) argName);
|
|
||||||
if (argValue.length()) {
|
|
||||||
// send content before var
|
|
||||||
if (argStartPos - buf > 0) {
|
|
||||||
server.sendContent((const char*) currentBuf, argStartPos - buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
server.sendContent(argValue.c_str());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
server.sendContent((const char*) currentBuf, argEndPos - currentBuf + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = size_t(argEndPos - currentBuf + 1);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sizeArgName = length - size_t(argStartPos - currentBuf) - 1;
|
|
||||||
|
|
||||||
// send all content if arg len > space
|
|
||||||
if (sizeArgName >= sizeof(argName)) {
|
|
||||||
if (currentLength) {
|
|
||||||
server.sendContent((const char*) currentBuf, currentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send content before var
|
|
||||||
if (argStartPos - buf > 0) {
|
|
||||||
server.sendContent((const char*) currentBuf, argStartPos - buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy arg name chunk
|
|
||||||
if (sizeArgName > 0) {
|
|
||||||
memcpy(argName, argStartPos + 1, sizeArgName);
|
|
||||||
}
|
|
||||||
|
|
||||||
argNameProcess = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
server.chunkedResponseFinalize();
|
|
||||||
#else
|
|
||||||
server.sendContent(emptyString);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
FS* fs = nullptr;
|
|
||||||
CanHandleCallback canHandleCallback;
|
|
||||||
BeforeSendCallback beforeSendCallback;
|
|
||||||
TemplateCallback templateCallback;
|
|
||||||
String eTag;
|
|
||||||
const char* uri = nullptr;
|
|
||||||
const char* path = nullptr;
|
|
||||||
const char* cacheHeader = nullptr;
|
|
||||||
};
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
#include <FS.h>
|
|
||||||
|
|
||||||
class StaticPage : public RequestHandler {
|
|
||||||
public:
|
|
||||||
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
|
|
||||||
typedef std::function<bool()> BeforeSendCallback;
|
|
||||||
|
|
||||||
StaticPage(const char* uri, FS* fs, const char* path, const char* cacheHeader = nullptr) {
|
|
||||||
this->uri = uri;
|
|
||||||
this->fs = fs;
|
|
||||||
this->path = path;
|
|
||||||
this->cacheHeader = cacheHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
StaticPage* setCanHandleCallback(CanHandleCallback callback = nullptr) {
|
|
||||||
this->canHandleCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
StaticPage* setBeforeSendCallback(BeforeSendCallback callback = nullptr) {
|
|
||||||
this->beforeSendCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool canHandle(HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool canHandle(HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
return method == HTTP_GET && uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
if (!this->canHandle(method, uri)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->beforeSendCallback && !this->beforeSendCallback()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
if (server._eTagEnabled) {
|
|
||||||
if (server._eTagFunction) {
|
|
||||||
this->eTag = (server._eTagFunction)(*this->fs, this->path);
|
|
||||||
|
|
||||||
} else if (this->eTag.isEmpty()) {
|
|
||||||
this->eTag = esp8266webserver::calcETag(*this->fs, this->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server.header("If-None-Match").equals(this->eTag.c_str())) {
|
|
||||||
server.send(304);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File file = this->fs->open(this->path, "r");
|
|
||||||
if (!file) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} else if (file.isDirectory()) {
|
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->cacheHeader != nullptr) {
|
|
||||||
server.sendHeader("Cache-Control", this->cacheHeader);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
if (server._eTagEnabled && this->eTag.length() > 0) {
|
|
||||||
server.sendHeader("ETag", this->eTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
server.streamFile(file, F("text/html"), method);
|
|
||||||
#else
|
|
||||||
server.streamFile(file, F("text/html"), 200);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
FS* fs = nullptr;
|
|
||||||
CanHandleCallback canHandleCallback;
|
|
||||||
BeforeSendCallback beforeSendCallback;
|
|
||||||
String eTag;
|
|
||||||
const char* uri = nullptr;
|
|
||||||
const char* path = nullptr;
|
|
||||||
const char* cacheHeader = nullptr;
|
|
||||||
};
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
class UpgradeHandler : public RequestHandler {
|
|
||||||
public:
|
|
||||||
enum class UpgradeType {
|
|
||||||
FIRMWARE = 0,
|
|
||||||
FILESYSTEM = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class UpgradeStatus {
|
|
||||||
NONE,
|
|
||||||
NO_FILE,
|
|
||||||
SUCCESS,
|
|
||||||
PROHIBITED,
|
|
||||||
ABORTED,
|
|
||||||
ERROR_ON_START,
|
|
||||||
ERROR_ON_WRITE,
|
|
||||||
ERROR_ON_FINISH
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
UpgradeType type;
|
|
||||||
UpgradeStatus status;
|
|
||||||
String error;
|
|
||||||
} UpgradeResult;
|
|
||||||
|
|
||||||
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
|
|
||||||
typedef std::function<bool(const String&)> CanUploadCallback;
|
|
||||||
typedef std::function<bool(UpgradeType)> BeforeUpgradeCallback;
|
|
||||||
typedef std::function<void(const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
|
|
||||||
|
|
||||||
UpgradeHandler(const char* uri) {
|
|
||||||
this->uri = uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpgradeHandler* setCanHandleCallback(CanHandleCallback callback = nullptr) {
|
|
||||||
this->canHandleCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpgradeHandler* setCanUploadCallback(CanUploadCallback callback = nullptr) {
|
|
||||||
this->canUploadCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpgradeHandler* setBeforeUpgradeCallback(BeforeUpgradeCallback callback = nullptr) {
|
|
||||||
this->beforeUpgradeCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpgradeHandler* setAfterUpgradeCallback(AfterUpgradeCallback callback = nullptr) {
|
|
||||||
this->afterUpgradeCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool canHandle(HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool canHandle(HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
return method == HTTP_POST && uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool canUpload(const String uri) override {
|
|
||||||
#else
|
|
||||||
bool canUpload(const String& uri) override {
|
|
||||||
#endif
|
|
||||||
return uri.equals(this->uri) && (!this->canUploadCallback || this->canUploadCallback(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String uri) override {
|
|
||||||
#else
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String& uri) override {
|
|
||||||
#endif
|
|
||||||
if (this->afterUpgradeCallback) {
|
|
||||||
this->afterUpgradeCallback(this->firmwareResult, this->filesystemResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->firmwareResult.status = UpgradeStatus::NONE;
|
|
||||||
this->firmwareResult.error.clear();
|
|
||||||
|
|
||||||
this->filesystemResult.status = UpgradeStatus::NONE;
|
|
||||||
this->filesystemResult.error.clear();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
void upload(WebServer& server, const String uri, HTTPUpload& upload) override {
|
|
||||||
#else
|
|
||||||
void upload(WebServer& server, const String& uri, HTTPUpload& upload) override {
|
|
||||||
#endif
|
|
||||||
UpgradeResult* result;
|
|
||||||
if (upload.name.equals("firmware")) {
|
|
||||||
result = &this->firmwareResult;
|
|
||||||
} else if (upload.name.equals("filesystem")) {
|
|
||||||
result = &this->filesystemResult;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result->status != UpgradeStatus::NONE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(result->type)) {
|
|
||||||
result->status = UpgradeStatus::PROHIBITED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!upload.filename.length()) {
|
|
||||||
result->status = UpgradeStatus::NO_FILE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upload.status == UPLOAD_FILE_START) {
|
|
||||||
// reset
|
|
||||||
if (Update.isRunning()) {
|
|
||||||
Update.end(false);
|
|
||||||
Update.clearError();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool begin = false;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
Update.runAsync(true);
|
|
||||||
|
|
||||||
if (result->type == UpgradeType::FIRMWARE) {
|
|
||||||
begin = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000, U_FLASH);
|
|
||||||
|
|
||||||
} else if (result->type == UpgradeType::FILESYSTEM) {
|
|
||||||
close_all_fs();
|
|
||||||
begin = Update.begin((size_t)FS_end - (size_t)FS_start, U_FS);
|
|
||||||
}
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
if (result->type == UpgradeType::FIRMWARE) {
|
|
||||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
|
|
||||||
|
|
||||||
} else if (result->type == UpgradeType::FILESYSTEM) {
|
|
||||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!begin || Update.hasError()) {
|
|
||||||
result->status = UpgradeStatus::ERROR_ON_START;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on start: %s"), upload.filename.c_str(), result->error.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', started"), upload.filename.c_str());
|
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
|
||||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
|
||||||
Update.end(false);
|
|
||||||
|
|
||||||
result->status = UpgradeStatus::ERROR_ON_WRITE;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(
|
|
||||||
FPSTR(L_PORTAL_OTA),
|
|
||||||
F("File '%s', on writing %d bytes: %s"),
|
|
||||||
upload.filename.c_str(), upload.totalSize, result->error.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', writed %d bytes"), upload.filename.c_str(), upload.totalSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_END) {
|
|
||||||
if (Update.end(true)) {
|
|
||||||
result->status = UpgradeStatus::SUCCESS;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s': finish"), upload.filename.c_str());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result->status = UpgradeStatus::ERROR_ON_FINISH;
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on finish: %s"), upload.filename.c_str(), result->error);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_ABORTED) {
|
|
||||||
Update.end(false);
|
|
||||||
result->status = UpgradeStatus::ABORTED;
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s': aborted"), upload.filename.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CanHandleCallback canHandleCallback;
|
|
||||||
CanUploadCallback canUploadCallback;
|
|
||||||
BeforeUpgradeCallback beforeUpgradeCallback;
|
|
||||||
AfterUpgradeCallback afterUpgradeCallback;
|
|
||||||
const char* uri = nullptr;
|
|
||||||
|
|
||||||
UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE};
|
|
||||||
UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE};
|
|
||||||
};
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is needed by the Arduino IDE because the ino file needs to be named as the directory name.
|
|
||||||
Don't worry, the Arduino compiler will "merge" all files, including src/main.cpp
|
|
||||||
*/
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[platformio]
|
|
||||||
;extra_configs = secrets.ini
|
|
||||||
extra_configs = secrets.default.ini
|
|
||||||
|
|
||||||
[env]
|
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
|
||||||
bblanchon/ArduinoJson@^7.0.3
|
|
||||||
;ihormelnyk/OpenTherm Library@^1.1.5
|
|
||||||
https://github.com/ihormelnyk/opentherm_library.git
|
|
||||||
arduino-libraries/ArduinoMqttClient@^0.1.8
|
|
||||||
lennarthennigs/ESP Telnet@^2.2
|
|
||||||
gyverlibs/FileData@^1.0.2
|
|
||||||
gyverlibs/GyverPID@^3.3.2
|
|
||||||
gyverlibs/GyverBlinker@^1.0
|
|
||||||
milesburton/DallasTemperature@^3.11.0
|
|
||||||
laxilef/TinyLogger@^1.1.0
|
|
||||||
build_flags =
|
|
||||||
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
|
||||||
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
|
||||||
-mtext-section-literals
|
|
||||||
-D MQTT_CLIENT_STD_FUNCTION_CALLBACK=1
|
|
||||||
;-D DEBUG_ESP_CORE -D DEBUG_ESP_WIFI -D DEBUG_ESP_PORT=Serial
|
|
||||||
-D USE_SERIAL=${secrets.use_serial}
|
|
||||||
-D USE_TELNET=${secrets.use_telnet}
|
|
||||||
-D DEBUG_BY_DEFAULT=${secrets.debug}
|
|
||||||
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
|
|
||||||
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
|
|
||||||
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
|
|
||||||
-D DEFAULT_STA_SSID='"${secrets.sta_ssid}"'
|
|
||||||
-D DEFAULT_STA_PASSWORD='"${secrets.sta_password}"'
|
|
||||||
-D DEFAULT_PORTAL_LOGIN='"${secrets.portal_login}"'
|
|
||||||
-D DEFAULT_PORTAL_PASSWORD='"${secrets.portal_password}"'
|
|
||||||
-D DEFAULT_MQTT_SERVER='"${secrets.mqtt_server}"'
|
|
||||||
-D DEFAULT_MQTT_PORT=${secrets.mqtt_port}
|
|
||||||
-D DEFAULT_MQTT_USER='"${secrets.mqtt_user}"'
|
|
||||||
-D DEFAULT_MQTT_PASSWORD='"${secrets.mqtt_password}"'
|
|
||||||
-D DEFAULT_MQTT_PREFIX='"${secrets.mqtt_prefix}"'
|
|
||||||
upload_speed = 921600
|
|
||||||
monitor_speed = 115200
|
|
||||||
monitor_filters = direct
|
|
||||||
board_build.flash_mode = dio
|
|
||||||
board_build.filesystem = littlefs
|
|
||||||
version = 1.4.0-rc.17
|
|
||||||
|
|
||||||
; Defaults
|
|
||||||
[esp8266_defaults]
|
|
||||||
platform = espressif8266
|
|
||||||
lib_deps =
|
|
||||||
${env.lib_deps}
|
|
||||||
nrwiersma/ESP8266Scheduler@^1.1
|
|
||||||
lib_ignore =
|
|
||||||
extra_scripts =
|
|
||||||
post:tools/build.py
|
|
||||||
build_flags = ${env.build_flags}
|
|
||||||
board_build.ldscript = eagle.flash.1m256.ld
|
|
||||||
;board_build.ldscript = eagle.flash.4m1m.ld
|
|
||||||
|
|
||||||
[esp32_defaults]
|
|
||||||
platform = espressif32@^6.5
|
|
||||||
board_build.partitions = esp32_partitions.csv
|
|
||||||
lib_deps =
|
|
||||||
${env.lib_deps}
|
|
||||||
laxilef/ESP32Scheduler@^1.0.1
|
|
||||||
lib_ignore =
|
|
||||||
extra_scripts =
|
|
||||||
post:tools/esp32.py
|
|
||||||
post:tools/build.py
|
|
||||||
build_flags =
|
|
||||||
${env.build_flags}
|
|
||||||
-D CORE_DEBUG_LEVEL=0
|
|
||||||
|
|
||||||
|
|
||||||
; Boards
|
|
||||||
[env:d1_mini]
|
|
||||||
platform = ${esp8266_defaults.platform}
|
|
||||||
board = d1_mini
|
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
|
||||||
-D LED_STATUS_GPIO=13
|
|
||||||
-D LED_OT_RX_GPIO=15
|
|
||||||
|
|
||||||
[env:d1_mini_lite]
|
|
||||||
platform = ${esp8266_defaults.platform}
|
|
||||||
board = d1_mini_lite
|
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
|
||||||
-D LED_STATUS_GPIO=13
|
|
||||||
-D LED_OT_RX_GPIO=15
|
|
||||||
|
|
||||||
[env:d1_mini_pro]
|
|
||||||
platform = ${esp8266_defaults.platform}
|
|
||||||
board = d1_mini_pro
|
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
|
||||||
-D LED_STATUS_GPIO=13
|
|
||||||
-D LED_OT_RX_GPIO=15
|
|
||||||
|
|
||||||
[env:s2_mini]
|
|
||||||
platform = ${esp32_defaults.platform}
|
|
||||||
board = lolin_s2_mini
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
lib_deps = ${esp32_defaults.lib_deps}
|
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=33
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=35
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=9
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=7
|
|
||||||
-D LED_STATUS_GPIO=11
|
|
||||||
-D LED_OT_RX_GPIO=12
|
|
||||||
|
|
||||||
[env:s3_mini]
|
|
||||||
platform = ${esp32_defaults.platform}
|
|
||||||
board = lolin_s3_mini
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
h2zero/NimBLE-Arduino@^1.4.1
|
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
|
||||||
-D DEFAULT_OT_IN_GPIO=35
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=36
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=12
|
|
||||||
-D LED_STATUS_GPIO=11
|
|
||||||
-D LED_OT_RX_GPIO=10
|
|
||||||
|
|
||||||
[env:c3_mini]
|
|
||||||
platform = ${esp32_defaults.platform}
|
|
||||||
board = lolin_c3_mini
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
h2zero/NimBLE-Arduino@^1.4.1
|
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_unflags =
|
|
||||||
-mtext-section-literals
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
|
||||||
-D DEFAULT_OT_IN_GPIO=8
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=10
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
|
||||||
-D LED_STATUS_GPIO=4
|
|
||||||
-D LED_OT_RX_GPIO=5
|
|
||||||
|
|
||||||
[env:nodemcu_32s]
|
|
||||||
platform = ${esp32_defaults.platform}
|
|
||||||
board = nodemcu-32s
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
h2zero/NimBLE-Arduino@^1.4.1
|
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
|
||||||
-D DEFAULT_OT_IN_GPIO=21
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=22
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=13
|
|
||||||
-D LED_STATUS_GPIO=2 ; 18
|
|
||||||
-D LED_OT_RX_GPIO=19
|
|
||||||
;-D WOKWI=1
|
|
||||||
|
|
||||||
[env:d1_mini32]
|
|
||||||
platform = ${esp32_defaults.platform}
|
|
||||||
board = wemos_d1_mini32
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
h2zero/NimBLE-Arduino@^1.4.1
|
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
|
||||||
-D DEFAULT_OT_IN_GPIO=21
|
|
||||||
-D DEFAULT_OT_OUT_GPIO=22
|
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=18
|
|
||||||
-D LED_STATUS_GPIO=2
|
|
||||||
-D LED_OT_RX_GPIO=19
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
[secrets]
|
|
||||||
use_serial = true
|
|
||||||
use_telnet = true
|
|
||||||
debug = true
|
|
||||||
hostname = opentherm
|
|
||||||
|
|
||||||
ap_ssid = OpenTherm Gateway
|
|
||||||
ap_password = otgateway123456
|
|
||||||
|
|
||||||
sta_ssid =
|
|
||||||
sta_password =
|
|
||||||
|
|
||||||
portal_login = admin
|
|
||||||
portal_password = admin
|
|
||||||
|
|
||||||
mqtt_server =
|
|
||||||
mqtt_port = 1883
|
|
||||||
mqtt_user =
|
|
||||||
mqtt_password =
|
|
||||||
mqtt_prefix = opentherm
|
|
||||||
@@ -1,337 +0,0 @@
|
|||||||
#include <Blinker.h>
|
|
||||||
|
|
||||||
extern Network::Manager* network;
|
|
||||||
extern MqttTask* tMqtt;
|
|
||||||
extern OpenThermTask* tOt;
|
|
||||||
extern FileData fsSettings, fsNetworkSettings;
|
|
||||||
extern ESPTelnetStream* telnetStream;
|
|
||||||
|
|
||||||
|
|
||||||
class MainTask : public Task {
|
|
||||||
public:
|
|
||||||
MainTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) {
|
|
||||||
this->blinker = new Blinker();
|
|
||||||
|
|
||||||
network->setDelayCallback([this](unsigned int time) {
|
|
||||||
this->delay(time);
|
|
||||||
})->setYieldCallback([this]() {
|
|
||||||
this->yield();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
~MainTask() {
|
|
||||||
delete this->blinker;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
enum class PumpStartReason {NONE, HEATING, ANTISTUCK};
|
|
||||||
|
|
||||||
Blinker* blinker = nullptr;
|
|
||||||
bool blinkerInitialized = false;
|
|
||||||
unsigned long firstFailConnect = 0;
|
|
||||||
unsigned long lastHeapInfo = 0;
|
|
||||||
unsigned int minFreeHeap = 0;
|
|
||||||
unsigned int minMaxFreeBlockHeap = 0;
|
|
||||||
unsigned long restartSignalTime = 0;
|
|
||||||
bool heatingEnabled = false;
|
|
||||||
unsigned long heatingDisabledTime = 0;
|
|
||||||
PumpStartReason extPumpStartReason = PumpStartReason::NONE;
|
|
||||||
unsigned long externalPumpStartTime = 0;
|
|
||||||
bool telnetStarted = false;
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "Main";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
#ifdef LED_STATUS_GPIO
|
|
||||||
pinMode(LED_STATUS_GPIO, OUTPUT);
|
|
||||||
digitalWrite(LED_STATUS_GPIO, LOW);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (GPIO_IS_VALID(settings.externalPump.gpio)) {
|
|
||||||
pinMode(settings.externalPump.gpio, OUTPUT);
|
|
||||||
digitalWrite(settings.externalPump.gpio, LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
network->loop();
|
|
||||||
|
|
||||||
if (fsSettings.tick() == FD_WRITE) {
|
|
||||||
Log.sinfoln(FPSTR(L_SETTINGS), F("Updated"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fsNetworkSettings.tick() == FD_WRITE) {
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK_SETTINGS), F("Updated"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vars.actions.restart) {
|
|
||||||
vars.actions.restart = false;
|
|
||||||
this->restartSignalTime = millis();
|
|
||||||
|
|
||||||
// save settings
|
|
||||||
fsSettings.updateNow();
|
|
||||||
|
|
||||||
// force save network settings
|
|
||||||
if (fsNetworkSettings.updateNow() == FD_FILE_ERR && LittleFS.begin()) {
|
|
||||||
fsNetworkSettings.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_MAIN), F("Restart signal received. Restart after 10 sec."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network->isConnected()) {
|
|
||||||
vars.sensors.rssi = WiFi.RSSI();
|
|
||||||
|
|
||||||
if (!this->telnetStarted && telnetStream != nullptr) {
|
|
||||||
telnetStream->begin(23, false);
|
|
||||||
this->telnetStarted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tMqtt->isEnabled() && strlen(settings.mqtt.server) > 0) {
|
|
||||||
tMqtt->enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->firstFailConnect != 0) {
|
|
||||||
this->firstFailConnect = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( Log.getLevel() != TinyLogger::Level::INFO && !settings.system.debug ) {
|
|
||||||
Log.setLevel(TinyLogger::Level::INFO);
|
|
||||||
|
|
||||||
} else if ( Log.getLevel() != TinyLogger::Level::VERBOSE && settings.system.debug ) {
|
|
||||||
Log.setLevel(TinyLogger::Level::VERBOSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (this->telnetStarted) {
|
|
||||||
telnetStream->stop();
|
|
||||||
this->telnetStarted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tMqtt->isEnabled()) {
|
|
||||||
tMqtt->disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.emergency.enable && !vars.states.emergency) {
|
|
||||||
if (this->firstFailConnect == 0) {
|
|
||||||
this->firstFailConnect = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (millis() - this->firstFailConnect > EMERGENCY_TIME_TRESHOLD) {
|
|
||||||
vars.states.emergency = true;
|
|
||||||
Log.sinfoln(FPSTR(L_MAIN), F("Emergency mode enabled"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->yield();
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LED_STATUS_GPIO
|
|
||||||
this->ledStatus(LED_STATUS_GPIO);
|
|
||||||
#endif
|
|
||||||
this->externalPump();
|
|
||||||
this->yield();
|
|
||||||
|
|
||||||
|
|
||||||
// telnet
|
|
||||||
if (this->telnetStarted) {
|
|
||||||
telnetStream->loop();
|
|
||||||
this->yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// anti memory leak
|
|
||||||
for (Stream* stream : Log.getStreams()) {
|
|
||||||
while (stream->available() > 0) {
|
|
||||||
stream->read();
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// heap info
|
|
||||||
this->heap();
|
|
||||||
|
|
||||||
|
|
||||||
// restart
|
|
||||||
if (this->restartSignalTime > 0 && millis() - this->restartSignalTime > 10000) {
|
|
||||||
this->restartSignalTime = 0;
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void heap() {
|
|
||||||
unsigned int freeHeap = getFreeHeap();
|
|
||||||
unsigned int maxFreeBlockHeap = getMaxFreeBlockHeap();
|
|
||||||
|
|
||||||
if (!this->restartSignalTime && (freeHeap < 2048 || maxFreeBlockHeap < 2048)) {
|
|
||||||
this->restartSignalTime = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!settings.system.debug) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t minFreeHeap = getFreeHeap(true);
|
|
||||||
size_t minFreeHeapDiff = 0;
|
|
||||||
if (minFreeHeap < this->minFreeHeap || this->minFreeHeap == 0) {
|
|
||||||
minFreeHeapDiff = this->minFreeHeap - minFreeHeap;
|
|
||||||
this->minFreeHeap = minFreeHeap;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t minMaxFreeBlockHeap = getMaxFreeBlockHeap(true);
|
|
||||||
size_t minMaxFreeBlockHeapDiff = 0;
|
|
||||||
if (minMaxFreeBlockHeap < this->minMaxFreeBlockHeap || this->minMaxFreeBlockHeap == 0) {
|
|
||||||
minMaxFreeBlockHeapDiff = this->minMaxFreeBlockHeap - minMaxFreeBlockHeap;
|
|
||||||
this->minMaxFreeBlockHeap = minMaxFreeBlockHeap;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (millis() - this->lastHeapInfo > 20000 || minFreeHeapDiff > 0 || minMaxFreeBlockHeapDiff > 0) {
|
|
||||||
Log.sverboseln(
|
|
||||||
FPSTR(L_MAIN),
|
|
||||||
F("Free heap size: %u of %u bytes (min: %u, diff: %u), max free block: %u (min: %u, diff: %u, frag: %hhu%%)"),
|
|
||||||
freeHeap, getTotalHeap(), this->minFreeHeap, minFreeHeapDiff, maxFreeBlockHeap, this->minMaxFreeBlockHeap, minMaxFreeBlockHeapDiff, getHeapFrag()
|
|
||||||
);
|
|
||||||
this->lastHeapInfo = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ledStatus(uint8_t gpio) {
|
|
||||||
uint8_t errors[4];
|
|
||||||
uint8_t errCount = 0;
|
|
||||||
static uint8_t errPos = 0;
|
|
||||||
static unsigned long endBlinkTime = 0;
|
|
||||||
static bool ledOn = false;
|
|
||||||
|
|
||||||
if (!this->blinkerInitialized) {
|
|
||||||
this->blinker->init(gpio);
|
|
||||||
this->blinkerInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!network->isConnected()) {
|
|
||||||
errors[errCount++] = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vars.states.otStatus) {
|
|
||||||
errors[errCount++] = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vars.states.fault) {
|
|
||||||
errors[errCount++] = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vars.states.emergency) {
|
|
||||||
errors[errCount++] = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this->blinker->ready()) {
|
|
||||||
endBlinkTime = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->blinker->running() && millis() - endBlinkTime >= 5000) {
|
|
||||||
if (errCount == 0) {
|
|
||||||
if (!ledOn) {
|
|
||||||
digitalWrite(gpio, HIGH);
|
|
||||||
ledOn = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (ledOn) {
|
|
||||||
digitalWrite(gpio, LOW);
|
|
||||||
ledOn = false;
|
|
||||||
endBlinkTime = millis();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errPos >= errCount) {
|
|
||||||
errPos = 0;
|
|
||||||
|
|
||||||
// end of error list
|
|
||||||
this->blinker->blink(10, 50, 50);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->blinker->blink(errors[errPos++], 300, 300);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->blinker->tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void externalPump() {
|
|
||||||
if (!vars.states.heating && this->heatingEnabled) {
|
|
||||||
this->heatingEnabled = false;
|
|
||||||
this->heatingDisabledTime = millis();
|
|
||||||
|
|
||||||
} else if (vars.states.heating && !this->heatingEnabled) {
|
|
||||||
this->heatingEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!settings.externalPump.use || !GPIO_IS_VALID(settings.externalPump.gpio)) {
|
|
||||||
if (vars.states.externalPump) {
|
|
||||||
if (GPIO_IS_VALID(settings.externalPump.gpio)) {
|
|
||||||
digitalWrite(settings.externalPump.gpio, LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.states.externalPump = false;
|
|
||||||
vars.parameters.extPumpLastEnableTime = millis();
|
|
||||||
|
|
||||||
Log.sinfoln("EXTPUMP", F("Disabled: use = off"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vars.states.externalPump && !this->heatingEnabled) {
|
|
||||||
if (this->extPumpStartReason == MainTask::PumpStartReason::HEATING && millis() - this->heatingDisabledTime > (settings.externalPump.postCirculationTime * 1000u)) {
|
|
||||||
digitalWrite(settings.externalPump.gpio, LOW);
|
|
||||||
|
|
||||||
vars.states.externalPump = false;
|
|
||||||
vars.parameters.extPumpLastEnableTime = millis();
|
|
||||||
|
|
||||||
Log.sinfoln("EXTPUMP", F("Disabled: expired post circulation time"));
|
|
||||||
|
|
||||||
} else if (this->extPumpStartReason == MainTask::PumpStartReason::ANTISTUCK && millis() - this->externalPumpStartTime >= (settings.externalPump.antiStuckTime * 1000u)) {
|
|
||||||
digitalWrite(settings.externalPump.gpio, LOW);
|
|
||||||
|
|
||||||
vars.states.externalPump = false;
|
|
||||||
vars.parameters.extPumpLastEnableTime = millis();
|
|
||||||
|
|
||||||
Log.sinfoln("EXTPUMP", F("Disabled: expired anti stuck time"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (vars.states.externalPump && this->heatingEnabled && this->extPumpStartReason == MainTask::PumpStartReason::ANTISTUCK) {
|
|
||||||
this->extPumpStartReason = MainTask::PumpStartReason::HEATING;
|
|
||||||
|
|
||||||
} else if (!vars.states.externalPump && this->heatingEnabled) {
|
|
||||||
vars.states.externalPump = true;
|
|
||||||
this->externalPumpStartTime = millis();
|
|
||||||
this->extPumpStartReason = MainTask::PumpStartReason::HEATING;
|
|
||||||
|
|
||||||
digitalWrite(settings.externalPump.gpio, HIGH);
|
|
||||||
|
|
||||||
Log.sinfoln("EXTPUMP", F("Enabled: heating on"));
|
|
||||||
|
|
||||||
} else if (!vars.states.externalPump && (vars.parameters.extPumpLastEnableTime == 0 || millis() - vars.parameters.extPumpLastEnableTime >= (settings.externalPump.antiStuckInterval * 1000ul))) {
|
|
||||||
vars.states.externalPump = true;
|
|
||||||
this->externalPumpStartTime = millis();
|
|
||||||
this->extPumpStartReason = MainTask::PumpStartReason::ANTISTUCK;
|
|
||||||
|
|
||||||
digitalWrite(settings.externalPump.gpio, HIGH);
|
|
||||||
|
|
||||||
Log.sinfoln("EXTPUMP", F("Enabled: anti stuck"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,505 +0,0 @@
|
|||||||
#include <MqttClient.h>
|
|
||||||
#include <MqttWiFiClient.h>
|
|
||||||
#include <MqttWriter.h>
|
|
||||||
#include "HaHelper.h"
|
|
||||||
|
|
||||||
extern FileData fsSettings;
|
|
||||||
|
|
||||||
class MqttTask : public Task {
|
|
||||||
public:
|
|
||||||
MqttTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) {
|
|
||||||
this->wifiClient = new MqttWiFiClient();
|
|
||||||
this->client = new MqttClient(this->wifiClient);
|
|
||||||
this->writer = new MqttWriter(this->client, 256);
|
|
||||||
this->haHelper = new HaHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
~MqttTask() {
|
|
||||||
delete this->haHelper;
|
|
||||||
|
|
||||||
if (this->client != nullptr) {
|
|
||||||
if (this->client->connected()) {
|
|
||||||
this->client->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this->client;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this->writer;
|
|
||||||
delete this->wifiClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
void disable() {
|
|
||||||
this->client->stop();
|
|
||||||
Task::disable();
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void enable() {
|
|
||||||
Task::enable();
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Enabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isConnected() {
|
|
||||||
return this->connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
MqttWiFiClient* wifiClient = nullptr;
|
|
||||||
MqttClient* client = nullptr;
|
|
||||||
HaHelper* haHelper = nullptr;
|
|
||||||
MqttWriter* writer = nullptr;
|
|
||||||
unsigned short readyForSendTime = 15000;
|
|
||||||
unsigned long lastReconnectTime = 0;
|
|
||||||
unsigned long connectedTime = 0;
|
|
||||||
unsigned long disconnectedTime = 0;
|
|
||||||
unsigned long prevPubVarsTime = 0;
|
|
||||||
unsigned long prevPubSettingsTime = 0;
|
|
||||||
bool connected = false;
|
|
||||||
bool newConnection = false;
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "Mqtt";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isReadyForSend() {
|
|
||||||
return millis() - this->connectedTime > this->readyForSendTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Started"));
|
|
||||||
|
|
||||||
// wificlient settings
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->wifiClient->setSync(true);
|
|
||||||
this->wifiClient->setNoDelay(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// client settings
|
|
||||||
this->client->setKeepAliveInterval(15000);
|
|
||||||
this->client->setTxPayloadSize(256);
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->client->setConnectionTimeout(1000);
|
|
||||||
#else
|
|
||||||
this->client->setConnectionTimeout(3000);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->client->onMessage([this] (void*, size_t length) {
|
|
||||||
String topic = this->client->messageTopic();
|
|
||||||
if (!length || length > 2048 || !topic.length()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t payload[length];
|
|
||||||
for (size_t i = 0; i < length && this->client->available(); i++) {
|
|
||||||
payload[i] = this->client->read();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->onMessage(topic.c_str(), payload, length);
|
|
||||||
});
|
|
||||||
|
|
||||||
// writer settings
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
this->writer->setYieldCallback([this] {
|
|
||||||
this->delay(10);
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->writer->setPublishEventCallback([this] (const char* topic, size_t written, size_t length, bool result) {
|
|
||||||
Log.straceln(FPSTR(L_MQTT), F("%s publish %u of %u bytes to topic: %s"), result ? F("Successfully") : F("Failed"), written, length, topic);
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//this->client->poll();
|
|
||||||
this->delay(250);
|
|
||||||
});
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->writer->setFlushEventCallback([this] (size_t, size_t) {
|
|
||||||
::delay(0);
|
|
||||||
|
|
||||||
if (this->wifiClient->connected()) {
|
|
||||||
this->wifiClient->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
::delay(0);
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ha helper settings
|
|
||||||
this->haHelper->setDevicePrefix(settings.mqtt.prefix);
|
|
||||||
this->haHelper->setDeviceVersion(PROJECT_VERSION);
|
|
||||||
this->haHelper->setDeviceModel(PROJECT_NAME);
|
|
||||||
this->haHelper->setDeviceName(PROJECT_NAME);
|
|
||||||
this->haHelper->setWriter(this->writer);
|
|
||||||
|
|
||||||
sprintf(buffer, CONFIG_URL, WiFi.localIP().toString().c_str());
|
|
||||||
this->haHelper->setDeviceConfigUrl(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (settings.mqtt.interval > 120) {
|
|
||||||
settings.mqtt.interval = 5;
|
|
||||||
fsSettings.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->connected && !this->client->connected()) {
|
|
||||||
this->connected = false;
|
|
||||||
this->onDisconnect();
|
|
||||||
|
|
||||||
} else if (!this->connected && millis() - this->lastReconnectTime >= MQTT_RECONNECT_INTERVAL) {
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Connecting to %s:%u..."), settings.mqtt.server, settings.mqtt.port);
|
|
||||||
|
|
||||||
this->haHelper->setDevicePrefix(settings.mqtt.prefix);
|
|
||||||
this->client->stop();
|
|
||||||
this->client->setId(networkSettings.hostname);
|
|
||||||
this->client->setUsernamePassword(settings.mqtt.user, settings.mqtt.password);
|
|
||||||
this->client->connect(settings.mqtt.server, settings.mqtt.port);
|
|
||||||
this->lastReconnectTime = millis();
|
|
||||||
this->yield();
|
|
||||||
|
|
||||||
} else if (!this->connected && this->client->connected()) {
|
|
||||||
this->connected = true;
|
|
||||||
this->onConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->connected && settings.emergency.enable && !vars.states.emergency && millis() - this->disconnectedTime > EMERGENCY_TIME_TRESHOLD) {
|
|
||||||
vars.states.emergency = true;
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Emergency mode enabled"));
|
|
||||||
|
|
||||||
} else if (this->connected && vars.states.emergency && millis() - this->connectedTime > 10000) {
|
|
||||||
vars.states.emergency = false;
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Emergency mode disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->connected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->client->poll();
|
|
||||||
|
|
||||||
// delay for publish data
|
|
||||||
if (!this->isReadyForSend()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// publish variables and status
|
|
||||||
if (this->newConnection || millis() - this->prevPubVarsTime > (settings.mqtt.interval * 1000u)) {
|
|
||||||
this->writer->publish(this->haHelper->getDeviceTopic("status").c_str(), "online", false);
|
|
||||||
this->publishVariables(this->haHelper->getDeviceTopic("state").c_str());
|
|
||||||
this->prevPubVarsTime = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
// publish settings
|
|
||||||
if (this->newConnection || millis() - this->prevPubSettingsTime > (settings.mqtt.interval * 10000u)) {
|
|
||||||
this->publishSettings(this->haHelper->getDeviceTopic("settings").c_str());
|
|
||||||
this->prevPubSettingsTime = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
// publish ha entities if not published
|
|
||||||
if (this->newConnection) {
|
|
||||||
this->publishHaEntities();
|
|
||||||
this->publishNonStaticHaEntities(true);
|
|
||||||
this->newConnection = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// publish non static ha entities
|
|
||||||
this->publishNonStaticHaEntities();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onConnect() {
|
|
||||||
this->connectedTime = millis();
|
|
||||||
this->newConnection = true;
|
|
||||||
unsigned long downtime = (millis() - this->disconnectedTime) / 1000;
|
|
||||||
Log.sinfoln(FPSTR(L_MQTT), F("Connected (downtime: %u s.)"), downtime);
|
|
||||||
|
|
||||||
this->client->subscribe(this->haHelper->getDeviceTopic("settings/set").c_str());
|
|
||||||
this->client->subscribe(this->haHelper->getDeviceTopic("state/set").c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void onDisconnect() {
|
|
||||||
this->disconnectedTime = millis();
|
|
||||||
|
|
||||||
unsigned long uptime = (millis() - this->connectedTime) / 1000;
|
|
||||||
Log.swarningln(FPSTR(L_MQTT), F("Disconnected (reason: %d uptime: %u s.)"), this->client->connectError(), uptime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onMessage(const char* topic, uint8_t* payload, size_t length) {
|
|
||||||
if (!length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.system.debug) {
|
|
||||||
Log.strace(FPSTR(L_MQTT_MSG), F("Topic: %s\r\n> "), topic);
|
|
||||||
if (Log.lock()) {
|
|
||||||
for (size_t i = 0; i < length; i++) {
|
|
||||||
if (payload[i] == 0) {
|
|
||||||
break;
|
|
||||||
} else if (payload[i] == 13) {
|
|
||||||
continue;
|
|
||||||
} else if (payload[i] == 10) {
|
|
||||||
Log.print("\r\n> ");
|
|
||||||
} else {
|
|
||||||
Log.print((char) payload[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.print("\r\n\n");
|
|
||||||
Log.flush();
|
|
||||||
Log.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
DeserializationError dErr = deserializeJson(doc, payload, length);
|
|
||||||
if (dErr != DeserializationError::Ok) {
|
|
||||||
Log.swarningln(FPSTR(L_MQTT_MSG), F("Error on deserialization: %s"), dErr.f_str());
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (doc.isNull() || !doc.size()) {
|
|
||||||
Log.swarningln(FPSTR(L_MQTT_MSG), F("Not valid json"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->haHelper->getDeviceTopic("state/set").equals(topic)) {
|
|
||||||
this->writer->publish(this->haHelper->getDeviceTopic("state/set").c_str(), nullptr, 0, true);
|
|
||||||
this->updateVariables(doc);
|
|
||||||
|
|
||||||
} else if (this->haHelper->getDeviceTopic("settings/set").equals(topic)) {
|
|
||||||
this->writer->publish(this->haHelper->getDeviceTopic("settings/set").c_str(), nullptr, 0, true);
|
|
||||||
this->updateSettings(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool updateSettings(JsonDocument& doc) {
|
|
||||||
bool changed = safeJsonToSettings(doc, settings);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
this->prevPubSettingsTime = 0;
|
|
||||||
fsSettings.update();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateVariables(JsonDocument& doc) {
|
|
||||||
bool changed = jsonToVars(doc, vars);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
this->prevPubVarsTime = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void publishHaEntities() {
|
|
||||||
// emergency
|
|
||||||
this->haHelper->publishSwitchEmergency();
|
|
||||||
this->haHelper->publishNumberEmergencyTarget();
|
|
||||||
this->haHelper->publishSwitchEmergencyUseEquitherm();
|
|
||||||
this->haHelper->publishSwitchEmergencyUsePid();
|
|
||||||
|
|
||||||
// heating
|
|
||||||
this->haHelper->publishSwitchHeating(false);
|
|
||||||
this->haHelper->publishSwitchHeatingTurbo();
|
|
||||||
this->haHelper->publishNumberHeatingHysteresis();
|
|
||||||
this->haHelper->publishSensorHeatingSetpoint(false);
|
|
||||||
this->haHelper->publishSensorBoilerHeatingMinTemp(false);
|
|
||||||
this->haHelper->publishSensorBoilerHeatingMaxTemp(false);
|
|
||||||
this->haHelper->publishNumberHeatingMinTemp(false);
|
|
||||||
this->haHelper->publishNumberHeatingMaxTemp(false);
|
|
||||||
this->haHelper->publishNumberHeatingMaxModulation(false);
|
|
||||||
|
|
||||||
// pid
|
|
||||||
this->haHelper->publishSwitchPid();
|
|
||||||
this->haHelper->publishNumberPidFactorP();
|
|
||||||
this->haHelper->publishNumberPidFactorI();
|
|
||||||
this->haHelper->publishNumberPidFactorD();
|
|
||||||
this->haHelper->publishNumberPidDt(false);
|
|
||||||
this->haHelper->publishNumberPidMinTemp(false);
|
|
||||||
this->haHelper->publishNumberPidMaxTemp(false);
|
|
||||||
|
|
||||||
// equitherm
|
|
||||||
this->haHelper->publishSwitchEquitherm();
|
|
||||||
this->haHelper->publishNumberEquithermFactorN();
|
|
||||||
this->haHelper->publishNumberEquithermFactorK();
|
|
||||||
this->haHelper->publishNumberEquithermFactorT();
|
|
||||||
|
|
||||||
// tuning
|
|
||||||
this->haHelper->publishSwitchTuning();
|
|
||||||
this->haHelper->publishSelectTuningRegulator();
|
|
||||||
|
|
||||||
// states
|
|
||||||
this->haHelper->publishBinSensorStatus();
|
|
||||||
this->haHelper->publishBinSensorOtStatus();
|
|
||||||
this->haHelper->publishBinSensorHeating();
|
|
||||||
this->haHelper->publishBinSensorFlame();
|
|
||||||
this->haHelper->publishBinSensorFault();
|
|
||||||
this->haHelper->publishBinSensorDiagnostic();
|
|
||||||
|
|
||||||
// sensors
|
|
||||||
this->haHelper->publishSensorModulation(false);
|
|
||||||
this->haHelper->publishSensorPressure(false);
|
|
||||||
this->haHelper->publishSensorFaultCode();
|
|
||||||
this->haHelper->publishSensorRssi(false);
|
|
||||||
this->haHelper->publishSensorUptime(false);
|
|
||||||
|
|
||||||
// temperatures
|
|
||||||
this->haHelper->publishNumberIndoorTemp();
|
|
||||||
this->haHelper->publishSensorHeatingTemp();
|
|
||||||
|
|
||||||
// buttons
|
|
||||||
this->haHelper->publishButtonRestart(false);
|
|
||||||
this->haHelper->publishButtonResetFault();
|
|
||||||
this->haHelper->publishButtonResetDiagnostic();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publishNonStaticHaEntities(bool force = false) {
|
|
||||||
static byte _heatingMinTemp, _heatingMaxTemp, _dhwMinTemp, _dhwMaxTemp = 0;
|
|
||||||
static bool _isStupidMode, _editableOutdoorTemp, _editableIndoorTemp, _dhwPresent = false;
|
|
||||||
|
|
||||||
bool published = false;
|
|
||||||
bool isStupidMode = !settings.pid.enable && !settings.equitherm.enable;
|
|
||||||
byte heatingMinTemp = isStupidMode ? settings.heating.minTemp : 10;
|
|
||||||
byte heatingMaxTemp = isStupidMode ? settings.heating.maxTemp : 30;
|
|
||||||
bool editableOutdoorTemp = settings.sensors.outdoor.type == SensorType::MANUAL;
|
|
||||||
bool editableIndoorTemp = settings.sensors.indoor.type == SensorType::MANUAL;
|
|
||||||
|
|
||||||
if (force || _dhwPresent != settings.opentherm.dhwPresent) {
|
|
||||||
_dhwPresent = settings.opentherm.dhwPresent;
|
|
||||||
|
|
||||||
if (_dhwPresent) {
|
|
||||||
this->haHelper->publishSwitchDhw(false);
|
|
||||||
this->haHelper->publishSensorBoilerDhwMinTemp(false);
|
|
||||||
this->haHelper->publishSensorBoilerDhwMaxTemp(false);
|
|
||||||
this->haHelper->publishNumberDhwMinTemp(false);
|
|
||||||
this->haHelper->publishNumberDhwMaxTemp(false);
|
|
||||||
this->haHelper->publishBinSensorDhw();
|
|
||||||
this->haHelper->publishSensorDhwTemp();
|
|
||||||
this->haHelper->publishSensorDhwFlowRate(false);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->haHelper->deleteSwitchDhw();
|
|
||||||
this->haHelper->deleteSensorBoilerDhwMinTemp();
|
|
||||||
this->haHelper->deleteSensorBoilerDhwMaxTemp();
|
|
||||||
this->haHelper->deleteNumberDhwMinTemp();
|
|
||||||
this->haHelper->deleteNumberDhwMaxTemp();
|
|
||||||
this->haHelper->deleteBinSensorDhw();
|
|
||||||
this->haHelper->deleteSensorDhwTemp();
|
|
||||||
this->haHelper->deleteNumberDhwTarget();
|
|
||||||
this->haHelper->deleteClimateDhw();
|
|
||||||
this->haHelper->deleteSensorDhwFlowRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force || _heatingMinTemp != heatingMinTemp || _heatingMaxTemp != heatingMaxTemp) {
|
|
||||||
if (settings.heating.target < heatingMinTemp || settings.heating.target > heatingMaxTemp) {
|
|
||||||
settings.heating.target = constrain(settings.heating.target, heatingMinTemp, heatingMaxTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
_heatingMinTemp = heatingMinTemp;
|
|
||||||
_heatingMaxTemp = heatingMaxTemp;
|
|
||||||
_isStupidMode = isStupidMode;
|
|
||||||
|
|
||||||
this->haHelper->publishNumberHeatingTarget(heatingMinTemp, heatingMaxTemp, false);
|
|
||||||
this->haHelper->publishClimateHeating(
|
|
||||||
heatingMinTemp,
|
|
||||||
heatingMaxTemp,
|
|
||||||
isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR
|
|
||||||
);
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
|
|
||||||
} else if (_isStupidMode != isStupidMode) {
|
|
||||||
_isStupidMode = isStupidMode;
|
|
||||||
this->haHelper->publishClimateHeating(
|
|
||||||
heatingMinTemp,
|
|
||||||
heatingMaxTemp,
|
|
||||||
isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR
|
|
||||||
);
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_dhwPresent && (force || _dhwMinTemp != settings.dhw.minTemp || _dhwMaxTemp != settings.dhw.maxTemp)) {
|
|
||||||
_dhwMinTemp = settings.dhw.minTemp;
|
|
||||||
_dhwMaxTemp = settings.dhw.maxTemp;
|
|
||||||
|
|
||||||
this->haHelper->publishNumberDhwTarget(settings.dhw.minTemp, settings.dhw.maxTemp, false);
|
|
||||||
this->haHelper->publishClimateDhw(settings.dhw.minTemp, settings.dhw.maxTemp);
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force || _editableOutdoorTemp != editableOutdoorTemp) {
|
|
||||||
_editableOutdoorTemp = editableOutdoorTemp;
|
|
||||||
|
|
||||||
if (editableOutdoorTemp) {
|
|
||||||
this->haHelper->deleteSensorOutdoorTemp();
|
|
||||||
this->haHelper->publishNumberOutdoorTemp();
|
|
||||||
} else {
|
|
||||||
this->haHelper->deleteNumberOutdoorTemp();
|
|
||||||
this->haHelper->publishSensorOutdoorTemp();
|
|
||||||
}
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force || _editableIndoorTemp != editableIndoorTemp) {
|
|
||||||
_editableIndoorTemp = editableIndoorTemp;
|
|
||||||
|
|
||||||
if (editableIndoorTemp) {
|
|
||||||
this->haHelper->deleteSensorIndoorTemp();
|
|
||||||
this->haHelper->publishNumberIndoorTemp();
|
|
||||||
} else {
|
|
||||||
this->haHelper->deleteNumberIndoorTemp();
|
|
||||||
this->haHelper->publishSensorIndoorTemp();
|
|
||||||
}
|
|
||||||
|
|
||||||
published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return published;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publishSettings(const char* topic) {
|
|
||||||
JsonDocument doc;
|
|
||||||
safeSettingsToJson(settings, doc);
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
return this->writer->publish(topic, doc, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publishVariables(const char* topic) {
|
|
||||||
JsonDocument doc;
|
|
||||||
varsToJson(vars, doc);
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
return this->writer->publish(topic, doc, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,774 +0,0 @@
|
|||||||
#include <CustomOpenTherm.h>
|
|
||||||
extern FileData fsSettings;
|
|
||||||
|
|
||||||
class OpenThermTask : public Task {
|
|
||||||
public:
|
|
||||||
OpenThermTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) {}
|
|
||||||
|
|
||||||
~OpenThermTask() {
|
|
||||||
delete this->instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const unsigned short readyTime = 60000;
|
|
||||||
const unsigned short dhwSetTempInterval = 60000;
|
|
||||||
const unsigned short heatingSetTempInterval = 60000;
|
|
||||||
const unsigned int initializingInterval = 3600000;
|
|
||||||
|
|
||||||
CustomOpenTherm* instance = nullptr;
|
|
||||||
unsigned long instanceCreatedTime = 0;
|
|
||||||
byte instanceInGpio = 0;
|
|
||||||
byte instanceOutGpio = 0;
|
|
||||||
bool isInitialized = false;
|
|
||||||
unsigned long initializedTime = 0;
|
|
||||||
unsigned int initializedMemberIdCode = 0;
|
|
||||||
byte dhwFlowRateMultiplier = 1;
|
|
||||||
byte pressureMultiplier = 1;
|
|
||||||
bool pump = true;
|
|
||||||
unsigned long lastSuccessResponse = 0;
|
|
||||||
unsigned long prevUpdateNonEssentialVars = 0;
|
|
||||||
unsigned long dhwSetTempTime = 0;
|
|
||||||
unsigned long heatingSetTempTime = 0;
|
|
||||||
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "OpenTherm";
|
|
||||||
}
|
|
||||||
|
|
||||||
int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
#ifdef LED_OT_RX_GPIO
|
|
||||||
pinMode(LED_OT_RX_GPIO, OUTPUT);
|
|
||||||
digitalWrite(LED_OT_RX_GPIO, LOW);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// delete instance
|
|
||||||
if (this->instance != nullptr) {
|
|
||||||
delete this->instance;
|
|
||||||
this->instance = nullptr;
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Stopped"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GPIO_IS_VALID(settings.opentherm.inGpio) || !GPIO_IS_VALID(settings.opentherm.outGpio)) {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Not started. GPIO IN: %hhu or GPIO OUT: %hhu is not valid"), settings.opentherm.inGpio, settings.opentherm.outGpio);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create instance
|
|
||||||
this->instance = new CustomOpenTherm(settings.opentherm.inGpio, settings.opentherm.outGpio);
|
|
||||||
|
|
||||||
// flags
|
|
||||||
this->instanceCreatedTime = millis();
|
|
||||||
this->instanceInGpio = settings.opentherm.inGpio;
|
|
||||||
this->instanceOutGpio = settings.opentherm.outGpio;
|
|
||||||
this->isInitialized = false;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Started. GPIO IN: %hhu, GPIO OUT: %hhu"), settings.opentherm.inGpio, settings.opentherm.outGpio);
|
|
||||||
|
|
||||||
this->instance->setAfterSendRequestCallback([this](unsigned long request, unsigned long response, OpenThermResponseStatus status, byte attempt) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_OT),
|
|
||||||
F("ID: %4d Request: %8lx Response: %8lx Attempt: %2d Status: %s"),
|
|
||||||
CustomOpenTherm::getDataID(request), request, response, attempt, CustomOpenTherm::statusToString(status)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (status == OpenThermResponseStatus::SUCCESS) {
|
|
||||||
this->lastSuccessResponse = millis();
|
|
||||||
|
|
||||||
#ifdef LED_OT_RX_GPIO
|
|
||||||
{
|
|
||||||
digitalWrite(LED_OT_RX_GPIO, HIGH);
|
|
||||||
delayMicroseconds(2000);
|
|
||||||
digitalWrite(LED_OT_RX_GPIO, LOW);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this->instance->setYieldCallback([this]() {
|
|
||||||
this->delay(25);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->instance->begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
static byte currentHeatingTemp, currentDhwTemp = 0;
|
|
||||||
|
|
||||||
if (this->instanceInGpio != settings.opentherm.inGpio || this->instanceOutGpio != settings.opentherm.outGpio) {
|
|
||||||
this->setup();
|
|
||||||
|
|
||||||
} else if (this->initializedMemberIdCode != settings.opentherm.memberIdCode || millis() - this->initializedTime > this->initializingInterval) {
|
|
||||||
this->isInitialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->instance == nullptr) {
|
|
||||||
this->delay(5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool heatingEnabled = (vars.states.emergency || settings.heating.enable) && this->pump && this->isReady();
|
|
||||||
bool heatingCh2Enabled = settings.opentherm.heatingCh2Enabled;
|
|
||||||
if (settings.opentherm.heatingCh1ToCh2) {
|
|
||||||
heatingCh2Enabled = heatingEnabled;
|
|
||||||
|
|
||||||
} else if (settings.opentherm.dhwToCh2) {
|
|
||||||
heatingCh2Enabled = settings.opentherm.dhwPresent && settings.dhw.enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long response = this->instance->setBoilerStatus(
|
|
||||||
heatingEnabled,
|
|
||||||
settings.opentherm.dhwPresent && settings.dhw.enable,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
heatingCh2Enabled,
|
|
||||||
settings.opentherm.summerWinterMode,
|
|
||||||
settings.opentherm.dhwBlocking
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Invalid response after setBoilerStatus: %s"), CustomOpenTherm::statusToString(this->instance->getLastResponseStatus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vars.states.otStatus && millis() - this->lastSuccessResponse < 1150) {
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Connected"));
|
|
||||||
|
|
||||||
vars.states.otStatus = true;
|
|
||||||
|
|
||||||
} else if (vars.states.otStatus && millis() - this->lastSuccessResponse > 1150) {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Disconnected"));
|
|
||||||
|
|
||||||
vars.states.otStatus = false;
|
|
||||||
this->isInitialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If boiler is disconnected, no need try setting other OT stuff
|
|
||||||
if (!vars.states.otStatus) {
|
|
||||||
vars.states.heating = false;
|
|
||||||
vars.states.dhw = false;
|
|
||||||
vars.states.flame = false;
|
|
||||||
vars.states.fault = false;
|
|
||||||
vars.states.diagnostic = false;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->isInitialized) {
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Initializing..."));
|
|
||||||
this->isInitialized = true;
|
|
||||||
this->initializedTime = millis();
|
|
||||||
this->initializedMemberIdCode = settings.opentherm.memberIdCode;
|
|
||||||
this->dhwFlowRateMultiplier = 1;
|
|
||||||
this->pressureMultiplier = 1;
|
|
||||||
this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vars.parameters.heatingEnabled != heatingEnabled) {
|
|
||||||
this->prevUpdateNonEssentialVars = 0;
|
|
||||||
vars.parameters.heatingEnabled = heatingEnabled;
|
|
||||||
Log.sinfoln(FPSTR(L_OT_HEATING), "%s", heatingEnabled ? F("Enabled") : F("Disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.states.heating = CustomOpenTherm::isCentralHeatingActive(response);
|
|
||||||
vars.states.dhw = settings.opentherm.dhwPresent ? CustomOpenTherm::isHotWaterActive(response) : false;
|
|
||||||
vars.states.flame = CustomOpenTherm::isFlameOn(response);
|
|
||||||
vars.states.fault = CustomOpenTherm::isFault(response);
|
|
||||||
vars.states.diagnostic = CustomOpenTherm::isDiagnostic(response);
|
|
||||||
|
|
||||||
// These parameters will be updated every minute
|
|
||||||
if (millis() - this->prevUpdateNonEssentialVars > 60000) {
|
|
||||||
if (!heatingEnabled && settings.opentherm.modulationSyncWithHeating) {
|
|
||||||
if (setMaxModulationLevel(0)) {
|
|
||||||
Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation 0% (off)"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set max modulation 0% (off)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (setMaxModulationLevel(settings.heating.maxModulation)) {
|
|
||||||
Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation %hhu%%"), settings.heating.maxModulation);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set max modulation %hhu%%"), settings.heating.maxModulation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get DHW min/max temp (if necessary)
|
|
||||||
if (settings.opentherm.dhwPresent) {
|
|
||||||
if (updateMinMaxDhwTemp()) {
|
|
||||||
if (settings.dhw.minTemp < vars.parameters.dhwMinTemp) {
|
|
||||||
settings.dhw.minTemp = vars.parameters.dhwMinTemp;
|
|
||||||
fsSettings.update();
|
|
||||||
Log.snoticeln(FPSTR(L_OT_DHW), F("Updated min temp: %hhu"), settings.dhw.minTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.dhw.maxTemp > vars.parameters.dhwMaxTemp) {
|
|
||||||
settings.dhw.maxTemp = vars.parameters.dhwMaxTemp;
|
|
||||||
fsSettings.update();
|
|
||||||
Log.snoticeln(FPSTR(L_OT_DHW), F("Updated max temp: %hhu"), settings.dhw.maxTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_DHW), F("Failed get min/max temp"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.dhw.minTemp >= settings.dhw.maxTemp) {
|
|
||||||
settings.dhw.minTemp = 30;
|
|
||||||
settings.dhw.maxTemp = 60;
|
|
||||||
fsSettings.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get heating min/max temp
|
|
||||||
if (updateMinMaxHeatingTemp()) {
|
|
||||||
if (settings.heating.minTemp < vars.parameters.heatingMinTemp) {
|
|
||||||
settings.heating.minTemp = vars.parameters.heatingMinTemp;
|
|
||||||
fsSettings.update();
|
|
||||||
Log.snoticeln(FPSTR(L_OT_HEATING), F("Updated min temp: %hhu"), settings.heating.minTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.heating.maxTemp > vars.parameters.heatingMaxTemp) {
|
|
||||||
settings.heating.maxTemp = vars.parameters.heatingMaxTemp;
|
|
||||||
fsSettings.update();
|
|
||||||
Log.snoticeln(FPSTR(L_OT_HEATING), F("Updated max temp: %hhu"), settings.heating.maxTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed get min/max temp"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.heating.minTemp >= settings.heating.maxTemp) {
|
|
||||||
settings.heating.minTemp = 20;
|
|
||||||
settings.heating.maxTemp = 90;
|
|
||||||
fsSettings.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force set max heating temp
|
|
||||||
setMaxHeatingTemp(settings.heating.maxTemp);
|
|
||||||
|
|
||||||
// Get outdoor temp (if necessary)
|
|
||||||
if (settings.sensors.outdoor.type == SensorType::BOILER) {
|
|
||||||
updateOutsideTemp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get fault code (if necessary)
|
|
||||||
if (vars.states.fault) {
|
|
||||||
updateFaultCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePressure();
|
|
||||||
|
|
||||||
this->prevUpdateNonEssentialVars = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get current modulation level (if necessary)
|
|
||||||
if ((settings.opentherm.dhwPresent && settings.dhw.enable) || settings.heating.enable || heatingEnabled) {
|
|
||||||
updateModulationLevel();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
vars.sensors.modulation = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update DHW sensors (if necessary)
|
|
||||||
if (settings.opentherm.dhwPresent) {
|
|
||||||
updateDhwTemp();
|
|
||||||
updateDhwFlowRate();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
vars.temperatures.dhw = 0.0f;
|
|
||||||
vars.sensors.dhwFlowRate = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current heating temp
|
|
||||||
updateHeatingTemp();
|
|
||||||
|
|
||||||
|
|
||||||
// Fault reset action
|
|
||||||
if (vars.actions.resetFault) {
|
|
||||||
if (vars.states.fault) {
|
|
||||||
if (this->instance->sendBoilerReset()) {
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Boiler fault reset successfully"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.serrorln(FPSTR(L_OT), F("Boiler fault reset failed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.actions.resetFault = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Diag reset action
|
|
||||||
if (vars.actions.resetDiagnostic) {
|
|
||||||
if (vars.states.diagnostic) {
|
|
||||||
if (this->instance->sendServiceReset()) {
|
|
||||||
Log.sinfoln(FPSTR(L_OT), F("Boiler diagnostic reset successfully"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.serrorln(FPSTR(L_OT), F("Boiler diagnostic reset failed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.actions.resetDiagnostic = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Update DHW temp
|
|
||||||
byte newDhwTemp = settings.dhw.target;
|
|
||||||
if (settings.opentherm.dhwPresent && settings.dhw.enable && (needSetDhwTemp() || newDhwTemp != currentDhwTemp)) {
|
|
||||||
if (newDhwTemp < settings.dhw.minTemp || newDhwTemp > settings.dhw.maxTemp) {
|
|
||||||
newDhwTemp = constrain(newDhwTemp, settings.dhw.minTemp, settings.dhw.maxTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_OT_DHW), F("Set temp = %u"), newDhwTemp);
|
|
||||||
|
|
||||||
// Set DHW temp
|
|
||||||
if (this->instance->setDhwTemp(newDhwTemp)) {
|
|
||||||
currentDhwTemp = newDhwTemp;
|
|
||||||
this->dhwSetTempTime = millis();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_DHW), F("Failed set temp"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set DHW temp to CH2
|
|
||||||
if (settings.opentherm.dhwToCh2) {
|
|
||||||
if (!this->instance->setHeatingCh2Temp(newDhwTemp)) {
|
|
||||||
Log.swarningln(FPSTR(L_OT_DHW), F("Failed set ch2 temp"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Update heating temp
|
|
||||||
if (heatingEnabled && (needSetHeatingTemp() || fabs(vars.parameters.heatingSetpoint - currentHeatingTemp) > 0.0001)) {
|
|
||||||
Log.sinfoln(FPSTR(L_OT_HEATING), F("Set temp = %u"), vars.parameters.heatingSetpoint);
|
|
||||||
|
|
||||||
// Set heating temp
|
|
||||||
if (this->instance->setHeatingCh1Temp(vars.parameters.heatingSetpoint)) {
|
|
||||||
currentHeatingTemp = vars.parameters.heatingSetpoint;
|
|
||||||
this->heatingSetTempTime = millis();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set temp"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set heating temp to CH2
|
|
||||||
if (settings.opentherm.heatingCh1ToCh2) {
|
|
||||||
if (!this->instance->setHeatingCh2Temp(vars.parameters.heatingSetpoint)) {
|
|
||||||
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set ch2 temp"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Hysteresis
|
|
||||||
// Only if enabled PID or/and Equitherm
|
|
||||||
if (settings.heating.hysteresis > 0 && (!vars.states.emergency || settings.emergency.usePid) && (settings.equitherm.enable || settings.pid.enable)) {
|
|
||||||
float halfHyst = settings.heating.hysteresis / 2;
|
|
||||||
if (this->pump && vars.temperatures.indoor - settings.heating.target + 0.0001 >= halfHyst) {
|
|
||||||
this->pump = false;
|
|
||||||
|
|
||||||
} else if (!this->pump && vars.temperatures.indoor - settings.heating.target - 0.0001 <= -(halfHyst)) {
|
|
||||||
this->pump = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!this->pump) {
|
|
||||||
this->pump = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void initialize() {
|
|
||||||
// Not all boilers support these, only try once when the boiler becomes connected
|
|
||||||
if (updateSlaveVersion()) {
|
|
||||||
Log.straceln(FPSTR(L_OT), F("Slave version: %u, type: %u"), vars.parameters.slaveVersion, vars.parameters.slaveType);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Get slave version failed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0x013F
|
|
||||||
if (setMasterVersion(0x3F, 0x01)) {
|
|
||||||
Log.straceln(FPSTR(L_OT), F("Master version: %u, type: %u"), vars.parameters.masterVersion, vars.parameters.masterType);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Set master version failed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateSlaveConfig()) {
|
|
||||||
Log.straceln(FPSTR(L_OT), F("Slave member id: %u, flags: %u"), vars.parameters.slaveMemberId, vars.parameters.slaveFlags);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Get slave config failed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setMasterConfig(settings.opentherm.memberIdCode & 0xFF, (settings.opentherm.memberIdCode & 0xFFFF) >> 8)) {
|
|
||||||
Log.straceln(FPSTR(L_OT), F("Master member id: %u, flags: %u"), vars.parameters.masterMemberId, vars.parameters.masterFlags);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_OT), F("Set master config failed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isReady() {
|
|
||||||
return millis() - this->instanceCreatedTime > this->readyTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needSetDhwTemp() {
|
|
||||||
return millis() - this->dhwSetTempTime > this->dhwSetTempInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needSetHeatingTemp() {
|
|
||||||
return millis() - this->heatingSetTempTime > this->heatingSetTempInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateSlaveConfig() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::SConfigSMemberIDcode,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.slaveMemberId = response & 0xFF;
|
|
||||||
vars.parameters.slaveFlags = (response & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
/*uint8_t flags = (response & 0xFFFF) >> 8;
|
|
||||||
Log.straceln(
|
|
||||||
"OT",
|
|
||||||
F("MasterMemberIdCode:\r\n DHW present: %u\r\n Control type: %u\r\n Cooling configuration: %u\r\n DHW configuration: %u\r\n Pump control: %u\r\n CH2 present: %u\r\n Remote water filling function: %u\r\n Heat/cool mode control: %u\r\n Slave MemberID Code: %u\r\n Raw: %u"),
|
|
||||||
(bool) (flags & 0x01),
|
|
||||||
(bool) (flags & 0x02),
|
|
||||||
(bool) (flags & 0x04),
|
|
||||||
(bool) (flags & 0x08),
|
|
||||||
(bool) (flags & 0x10),
|
|
||||||
(bool) (flags & 0x20),
|
|
||||||
(bool) (flags & 0x40),
|
|
||||||
(bool) (flags & 0x80),
|
|
||||||
response & 0xFF,
|
|
||||||
response
|
|
||||||
);*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the Master Config
|
|
||||||
* From slave member id code:
|
|
||||||
* id: slave.memberIdCode & 0xFF,
|
|
||||||
* flags: (slave.memberIdCode & 0xFFFF) >> 8
|
|
||||||
* @param id
|
|
||||||
* @param flags
|
|
||||||
* @param force
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool setMasterConfig(uint8_t id, uint8_t flags, bool force = false) {
|
|
||||||
//uint8_t configId = settings.opentherm.memberIdCode & 0xFF;
|
|
||||||
//uint8_t configFlags = (settings.opentherm.memberIdCode & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
vars.parameters.masterMemberId = (force || id || settings.opentherm.memberIdCode > 65535)
|
|
||||||
? id
|
|
||||||
: vars.parameters.slaveMemberId;
|
|
||||||
|
|
||||||
vars.parameters.masterFlags = (force || flags || settings.opentherm.memberIdCode > 65535)
|
|
||||||
? flags
|
|
||||||
: vars.parameters.slaveFlags;
|
|
||||||
|
|
||||||
unsigned int request = (unsigned int) vars.parameters.masterMemberId | (unsigned int) vars.parameters.masterFlags << 8;
|
|
||||||
// if empty request
|
|
||||||
if (!request) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::MConfigMMemberIDcode,
|
|
||||||
request
|
|
||||||
));
|
|
||||||
|
|
||||||
return CustomOpenTherm::isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setMaxModulationLevel(byte value) {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::MaxRelModLevelSetting,
|
|
||||||
this->instance->toF88(value)
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.maxModulation = this->instance->fromF88(response);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateSlaveOtVersion() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::OpenThermVersionSlave,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.slaveOtVersion = CustomOpenTherm::getFloat(response);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setMasterOtVersion(float version) {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::OpenThermVersionMaster,
|
|
||||||
this->instance->toF88(version)
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.masterOtVersion = this->instance->fromF88(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateSlaveVersion() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::SlaveVersion,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.slaveVersion = response & 0xFF;
|
|
||||||
vars.parameters.slaveType = (response & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setMasterVersion(uint8_t version, uint8_t type) {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::MasterVersion,
|
|
||||||
(unsigned int) version | (unsigned int) type << 8
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.parameters.masterVersion = response & 0xFF;
|
|
||||||
vars.parameters.masterType = (response & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateMinMaxDhwTemp() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::TdhwSetUBTdhwSetLB,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte minTemp = response & 0xFF;
|
|
||||||
byte maxTemp = (response & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
if (minTemp >= 0 && maxTemp > 0 && maxTemp > minTemp) {
|
|
||||||
vars.parameters.dhwMinTemp = minTemp;
|
|
||||||
vars.parameters.dhwMaxTemp = maxTemp;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateMinMaxHeatingTemp() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::MaxTSetUBMaxTSetLB,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte minTemp = response & 0xFF;
|
|
||||||
byte maxTemp = (response & 0xFFFF) >> 8;
|
|
||||||
|
|
||||||
if (minTemp >= 0 && maxTemp > 0 && maxTemp > minTemp) {
|
|
||||||
vars.parameters.heatingMinTemp = minTemp;
|
|
||||||
vars.parameters.heatingMaxTemp = maxTemp;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setMaxHeatingTemp(byte value) {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::MaxTSet,
|
|
||||||
CustomOpenTherm::temperatureToData(value)
|
|
||||||
));
|
|
||||||
|
|
||||||
return CustomOpenTherm::isValidResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateOutsideTemp() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::Toutside,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.temperatures.outdoor = CustomOpenTherm::getFloat(response) + settings.sensors.outdoor.offset;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateHeatingTemp() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermMessageType::READ_DATA,
|
|
||||||
OpenThermMessageID::Tboiler,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
|
||||||
if (value <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.temperatures.heating = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool updateDhwTemp() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermMessageType::READ_DATA,
|
|
||||||
OpenThermMessageID::Tdhw,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
|
||||||
if (value <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.temperatures.dhw = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateDhwFlowRate() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermMessageType::READ_DATA,
|
|
||||||
OpenThermMessageID::DHWFlowRate,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
|
||||||
if (value > 16 && this->dhwFlowRateMultiplier != 10) {
|
|
||||||
this->dhwFlowRateMultiplier = 10;
|
|
||||||
}
|
|
||||||
vars.sensors.dhwFlowRate = this->dhwFlowRateMultiplier == 1 ? value : value / this->dhwFlowRateMultiplier;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateFaultCode() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::ASFflags,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.sensors.faultCode = response & 0xFF;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updateModulationLevel() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::RelModLevel,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float modulation = this->instance->fromF88(response);
|
|
||||||
if (!vars.states.flame) {
|
|
||||||
vars.sensors.modulation = 0;
|
|
||||||
} else {
|
|
||||||
vars.sensors.modulation = modulation;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updatePressure() {
|
|
||||||
unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
|
||||||
OpenThermRequestType::READ_DATA,
|
|
||||||
OpenThermMessageID::CHPressure,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!CustomOpenTherm::isValidResponse(response)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
|
||||||
if (value > 5 && this->pressureMultiplier != 10) {
|
|
||||||
this->pressureMultiplier = 10;
|
|
||||||
}
|
|
||||||
vars.sensors.pressure = this->pressureMultiplier == 1 ? value : value / this->pressureMultiplier;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,647 +0,0 @@
|
|||||||
#define PORTAL_CACHE_TIME "max-age=86400"
|
|
||||||
#define PORTAL_CACHE settings.system.debug ? nullptr : PORTAL_CACHE_TIME
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <Updater.h>
|
|
||||||
using WebServer = ESP8266WebServer;
|
|
||||||
#else
|
|
||||||
#include <WebServer.h>
|
|
||||||
#include <Update.h>
|
|
||||||
#endif
|
|
||||||
#include <BufferedWebServer.h>
|
|
||||||
#include <StaticPage.h>
|
|
||||||
#include <DynamicPage.h>
|
|
||||||
#include <UpgradeHandler.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
|
|
||||||
extern Network::Manager* network;
|
|
||||||
extern FileData fsSettings, fsNetworkSettings;
|
|
||||||
extern MqttTask* tMqtt;
|
|
||||||
|
|
||||||
|
|
||||||
class PortalTask : public LeanTask {
|
|
||||||
public:
|
|
||||||
PortalTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {
|
|
||||||
this->webServer = new WebServer(80);
|
|
||||||
this->bufferedWebServer = new BufferedWebServer(this->webServer, 32u);
|
|
||||||
this->dnsServer = new DNSServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
~PortalTask() {
|
|
||||||
delete this->bufferedWebServer;
|
|
||||||
|
|
||||||
if (this->webServer != nullptr) {
|
|
||||||
this->stopWebServer();
|
|
||||||
delete this->webServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->dnsServer != nullptr) {
|
|
||||||
this->stopDnsServer();
|
|
||||||
delete this->dnsServer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const unsigned int changeStateInterval = 5000;
|
|
||||||
|
|
||||||
WebServer* webServer = nullptr;
|
|
||||||
BufferedWebServer* bufferedWebServer = nullptr;
|
|
||||||
DNSServer* dnsServer = nullptr;
|
|
||||||
|
|
||||||
bool webServerEnabled = false;
|
|
||||||
bool dnsServerEnabled = false;
|
|
||||||
unsigned long webServerChangeState = 0;
|
|
||||||
unsigned long dnsServerChangeState = 0;
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "Portal";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
this->dnsServer->setTTL(0);
|
|
||||||
this->dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->webServer->enableETag(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// index page
|
|
||||||
/*auto indexPage = (new DynamicPage("/", &LittleFS, "/index.html"))
|
|
||||||
->setTemplateCallback([](const char* var) -> String {
|
|
||||||
String result;
|
|
||||||
|
|
||||||
if (strcmp(var, "ver") == 0) {
|
|
||||||
result = PROJECT_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
this->webServer->addHandler(indexPage);*/
|
|
||||||
this->webServer->addHandler(new StaticPage("/", &LittleFS, "/index.html", PORTAL_CACHE));
|
|
||||||
|
|
||||||
// restart
|
|
||||||
this->webServer->on("/restart.html", HTTP_GET, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->send(401);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.actions.restart = true;
|
|
||||||
this->webServer->sendHeader("Location", "/");
|
|
||||||
this->webServer->send(302);
|
|
||||||
});
|
|
||||||
|
|
||||||
// network settings page
|
|
||||||
auto networkPage = (new StaticPage("/network.html", &LittleFS, "/network.html", PORTAL_CACHE))
|
|
||||||
->setBeforeSendCallback([this]() {
|
|
||||||
if (this->isNeedAuth() && !this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->requestAuthentication(DIGEST_AUTH);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
this->webServer->addHandler(networkPage);
|
|
||||||
|
|
||||||
// settings page
|
|
||||||
auto settingsPage = (new StaticPage("/settings.html", &LittleFS, "/settings.html", PORTAL_CACHE))
|
|
||||||
->setBeforeSendCallback([this]() {
|
|
||||||
if (this->isNeedAuth() && !this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->requestAuthentication(DIGEST_AUTH);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
this->webServer->addHandler(settingsPage);
|
|
||||||
|
|
||||||
// upgrade page
|
|
||||||
auto upgradePage = (new StaticPage("/upgrade.html", &LittleFS, "/upgrade.html", PORTAL_CACHE))
|
|
||||||
->setBeforeSendCallback([this]() {
|
|
||||||
if (this->isNeedAuth() && !this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->requestAuthentication(DIGEST_AUTH);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
this->webServer->addHandler(upgradePage);
|
|
||||||
|
|
||||||
// OTA
|
|
||||||
auto upgradeHandler = (new UpgradeHandler("/api/upgrade"))->setCanUploadCallback([this](const String& uri) {
|
|
||||||
if (this->isNeedAuth() && !this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->sendHeader("Connection", "close");
|
|
||||||
this->webServer->send(401);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
})->setBeforeUpgradeCallback([](UpgradeHandler::UpgradeType type) -> bool {
|
|
||||||
return true;
|
|
||||||
})->setAfterUpgradeCallback([this](const UpgradeHandler::UpgradeResult& fwResult, const UpgradeHandler::UpgradeResult& fsResult) {
|
|
||||||
unsigned short status = 200;
|
|
||||||
if (fwResult.status == UpgradeHandler::UpgradeStatus::SUCCESS || fsResult.status == UpgradeHandler::UpgradeStatus::SUCCESS) {
|
|
||||||
vars.actions.restart = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
status = 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
String response = "{\"firmware\": {\"status\": ";
|
|
||||||
response.concat((short int) fwResult.status);
|
|
||||||
response.concat(", \"error\": \"");
|
|
||||||
response.concat(fwResult.error);
|
|
||||||
response.concat("\"}, \"filesystem\": {\"status\": ");
|
|
||||||
response.concat((short int) fsResult.status);
|
|
||||||
response.concat(", \"error\": \"");
|
|
||||||
response.concat(fsResult.error);
|
|
||||||
response.concat("\"}}");
|
|
||||||
this->webServer->send(status, "application/json", response);
|
|
||||||
});
|
|
||||||
this->webServer->addHandler(upgradeHandler);
|
|
||||||
|
|
||||||
|
|
||||||
// backup
|
|
||||||
this->webServer->on("/api/backup/save", HTTP_GET, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument networkSettingsDoc;
|
|
||||||
networkSettingsToJson(networkSettings, networkSettingsDoc);
|
|
||||||
networkSettingsDoc.shrinkToFit();
|
|
||||||
|
|
||||||
JsonDocument settingsDoc;
|
|
||||||
settingsToJson(settings, settingsDoc);
|
|
||||||
settingsDoc.shrinkToFit();
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
doc["network"] = networkSettingsDoc;
|
|
||||||
doc["settings"] = settingsDoc;
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->webServer->sendHeader(F("Content-Disposition"), F("attachment; filename=\"backup.json\""));
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/backup/restore", HTTP_POST, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String plain = this->webServer->arg(0);
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Request /api/backup/restore %d bytes: %s"), plain.length(), plain.c_str());
|
|
||||||
|
|
||||||
if (plain.length() < 5) {
|
|
||||||
this->webServer->send(406);
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (plain.length() > 2048) {
|
|
||||||
this->webServer->send(413);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
DeserializationError dErr = deserializeJson(doc, plain);
|
|
||||||
plain.clear();
|
|
||||||
|
|
||||||
if (dErr != DeserializationError::Ok || doc.isNull() || !doc.size()) {
|
|
||||||
this->webServer->send(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changed = false;
|
|
||||||
if (doc["settings"] && jsonToSettings(doc["settings"], settings)) {
|
|
||||||
vars.actions.restart = true;
|
|
||||||
fsSettings.update();
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doc["network"] && jsonToNetworkSettings(doc["network"], networkSettings)) {
|
|
||||||
fsNetworkSettings.update();
|
|
||||||
network->setHostname(networkSettings.hostname)
|
|
||||||
->setStaCredentials(networkSettings.sta.ssid, networkSettings.sta.password, networkSettings.sta.channel)
|
|
||||||
->setUseDhcp(networkSettings.useDhcp)
|
|
||||||
->setStaticConfig(
|
|
||||||
networkSettings.staticConfig.ip,
|
|
||||||
networkSettings.staticConfig.gateway,
|
|
||||||
networkSettings.staticConfig.subnet,
|
|
||||||
networkSettings.staticConfig.dns
|
|
||||||
)
|
|
||||||
->reconnect();
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->webServer->send(changed ? 201 : 200);
|
|
||||||
});
|
|
||||||
|
|
||||||
// network
|
|
||||||
this->webServer->on("/api/network/settings", HTTP_GET, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
networkSettingsToJson(networkSettings, doc);
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/network/settings", HTTP_POST, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String plain = this->webServer->arg(0);
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Request /api/network/settings %d bytes: %s"), plain.length(), plain.c_str());
|
|
||||||
|
|
||||||
if (plain.length() < 5) {
|
|
||||||
this->webServer->send(406);
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (plain.length() > 512) {
|
|
||||||
this->webServer->send(413);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
DeserializationError dErr = deserializeJson(doc, plain);
|
|
||||||
plain.clear();
|
|
||||||
|
|
||||||
if (dErr != DeserializationError::Ok || doc.isNull() || !doc.size()) {
|
|
||||||
this->webServer->send(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changed = jsonToNetworkSettings(doc, networkSettings);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
this->webServer->send(201);
|
|
||||||
|
|
||||||
fsNetworkSettings.update();
|
|
||||||
network->setHostname(networkSettings.hostname)
|
|
||||||
->setStaCredentials(networkSettings.sta.ssid, networkSettings.sta.password, networkSettings.sta.channel)
|
|
||||||
->setUseDhcp(networkSettings.useDhcp)
|
|
||||||
->setStaticConfig(
|
|
||||||
networkSettings.staticConfig.ip,
|
|
||||||
networkSettings.staticConfig.gateway,
|
|
||||||
networkSettings.staticConfig.subnet,
|
|
||||||
networkSettings.staticConfig.dns
|
|
||||||
)
|
|
||||||
->reconnect();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->webServer->send(200);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/network/status", HTTP_GET, [this]() {
|
|
||||||
bool isConnected = network->isConnected();
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
doc["hostname"] = networkSettings.hostname;
|
|
||||||
doc["mac"] = network->getStaMac();
|
|
||||||
doc["isConnected"] = isConnected;
|
|
||||||
doc["ssid"] = network->getStaSsid();
|
|
||||||
doc["signalQuality"] = isConnected ? Network::Manager::rssiToSignalQuality(network->getRssi()) : 0;
|
|
||||||
doc["channel"] = isConnected ? network->getStaChannel() : 0;
|
|
||||||
doc["ip"] = isConnected ? network->getStaIp().toString() : "";
|
|
||||||
doc["subnet"] = isConnected ? network->getStaSubnet().toString() : "";
|
|
||||||
doc["gateway"] = isConnected ? network->getStaGateway().toString() : "";
|
|
||||||
doc["dns"] = isConnected ? network->getStaDns().toString() : "";
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/network/scan", HTTP_GET, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
this->webServer->send(401);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto apCount = WiFi.scanComplete();
|
|
||||||
if (apCount <= 0) {
|
|
||||||
if (apCount != WIFI_SCAN_RUNNING) {
|
|
||||||
WiFi.scanNetworks(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->webServer->send(404);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
for (short int i = 0; i < apCount; i++) {
|
|
||||||
String ssid = WiFi.SSID(i);
|
|
||||||
doc[i]["ssid"] = ssid;
|
|
||||||
doc[i]["signalQuality"] = Network::Manager::rssiToSignalQuality(WiFi.RSSI(i));
|
|
||||||
doc[i]["channel"] = WiFi.channel(i);
|
|
||||||
doc[i]["hidden"] = !ssid.length();
|
|
||||||
doc[i]["encryptionType"] = WiFi.encryptionType(i);
|
|
||||||
}
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
|
|
||||||
WiFi.scanDelete();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// settings
|
|
||||||
this->webServer->on("/api/settings", HTTP_GET, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
settingsToJson(settings, doc);
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/settings", HTTP_POST, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String plain = this->webServer->arg(0);
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Request /api/settings %d bytes: %s"), plain.length(), plain.c_str());
|
|
||||||
|
|
||||||
if (plain.length() < 5) {
|
|
||||||
this->webServer->send(406);
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (plain.length() > 2048) {
|
|
||||||
this->webServer->send(413);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
DeserializationError dErr = deserializeJson(doc, plain);
|
|
||||||
plain.clear();
|
|
||||||
|
|
||||||
if (dErr != DeserializationError::Ok || doc.isNull() || !doc.size()) {
|
|
||||||
this->webServer->send(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changed = jsonToSettings(doc, settings);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
fsSettings.update();
|
|
||||||
this->webServer->send(201);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->webServer->send(200);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
this->webServer->on("/api/vars", HTTP_GET, [this]() {
|
|
||||||
JsonDocument doc;
|
|
||||||
varsToJson(vars, doc);
|
|
||||||
|
|
||||||
doc["system"]["version"] = PROJECT_VERSION;
|
|
||||||
doc["system"]["buildDate"] = __DATE__ " " __TIME__;
|
|
||||||
doc["system"]["uptime"] = millis() / 1000ul;
|
|
||||||
doc["system"]["totalHeap"] = getTotalHeap();
|
|
||||||
doc["system"]["freeHeap"] = getFreeHeap();
|
|
||||||
doc["system"]["minFreeHeap"] = getFreeHeap(true);
|
|
||||||
doc["system"]["maxFreeBlockHeap"] = getMaxFreeBlockHeap();
|
|
||||||
doc["system"]["minMaxFreeBlockHeap"] = getMaxFreeBlockHeap(true);
|
|
||||||
doc["system"]["resetReason"] = getResetReason();
|
|
||||||
doc["system"]["mqttConnected"] = tMqtt->isConnected();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->on("/api/vars", HTTP_POST, [this]() {
|
|
||||||
if (this->isNeedAuth()) {
|
|
||||||
if (!this->webServer->authenticate(settings.portal.login, settings.portal.password)) {
|
|
||||||
return this->webServer->send(401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String plain = this->webServer->arg(0);
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Request /api/vars %d bytes: %s"), plain.length(), plain.c_str());
|
|
||||||
|
|
||||||
if (plain.length() < 5) {
|
|
||||||
this->webServer->send(406);
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (plain.length() > 1024) {
|
|
||||||
this->webServer->send(413);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonDocument doc;
|
|
||||||
DeserializationError dErr = deserializeJson(doc, plain);
|
|
||||||
plain.clear();
|
|
||||||
|
|
||||||
if (dErr != DeserializationError::Ok || doc.isNull() || !doc.size()) {
|
|
||||||
this->webServer->send(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changed = jsonToVars(doc, vars);
|
|
||||||
doc.clear();
|
|
||||||
doc.shrinkToFit();
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
this->webServer->send(201);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->webServer->send(200);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// not found
|
|
||||||
this->webServer->onNotFound([this]() {
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Page not found, uri: %s"), this->webServer->uri().c_str());
|
|
||||||
|
|
||||||
const String uri = this->webServer->uri();
|
|
||||||
if (uri.equals("/")) {
|
|
||||||
this->webServer->send(200, "text/plain", F("The file system is not flashed!"));
|
|
||||||
|
|
||||||
} else if (network->isApEnabled()) {
|
|
||||||
this->onCaptivePortal();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->webServer->send(404, "text/plain", F("Page not found"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this->webServer->serveStatic("/favicon.ico", LittleFS, "/static/favicon.ico", PORTAL_CACHE);
|
|
||||||
this->webServer->serveStatic("/static", LittleFS, "/static", PORTAL_CACHE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// web server
|
|
||||||
if (!this->stateWebServer() && (network->isApEnabled() || network->isConnected()) && millis() - this->webServerChangeState >= this->changeStateInterval) {
|
|
||||||
this->startWebServer();
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started: AP up or STA connected"));
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else if (this->stateWebServer() && !network->isApEnabled() && !network->isStaEnabled()) {
|
|
||||||
this->stopWebServer();
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Stopped: AP and STA down"));
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// dns server
|
|
||||||
if (!this->stateDnsServer() && this->stateWebServer() && network->isApEnabled() && network->hasApClients() && millis() - this->dnsServerChangeState >= this->changeStateInterval) {
|
|
||||||
this->startDnsServer();
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Started: AP up"));
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else if (this->stateDnsServer() && (!network->isApEnabled() || !this->stateWebServer())) {
|
|
||||||
this->stopDnsServer();
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Stopped: AP down"));
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->stateDnsServer()) {
|
|
||||||
this->dnsServer->processNextRequest();
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
::delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->stateWebServer()) {
|
|
||||||
this->webServer->handleClient();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNeedAuth() {
|
|
||||||
return !network->isApEnabled() && settings.portal.useAuth && strlen(settings.portal.password);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onCaptivePortal() {
|
|
||||||
const String uri = this->webServer->uri();
|
|
||||||
|
|
||||||
if (uri.equals("/connecttest.txt")) {
|
|
||||||
this->webServer->sendHeader(F("Location"), F("http://logout.net"));
|
|
||||||
this->webServer->send(302);
|
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_CAPTIVE), F("Redirect to http://logout.net with 302 code"));
|
|
||||||
|
|
||||||
} else if (uri.equals("/wpad.dat")) {
|
|
||||||
this->webServer->send(404);
|
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_CAPTIVE), F("Send empty page with 404 code"));
|
|
||||||
|
|
||||||
} else if (uri.equals("/success.txt")) {
|
|
||||||
this->webServer->send(200);
|
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_CAPTIVE), F("Send empty page with 200 code"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String portalUrl = "http://" + network->getApIp().toString() + '/';
|
|
||||||
|
|
||||||
this->webServer->sendHeader("Location", portalUrl.c_str());
|
|
||||||
this->webServer->send(302);
|
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_PORTAL_CAPTIVE), F("Redirect to portal page with 302 code"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool stateWebServer() {
|
|
||||||
return this->webServerEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startWebServer() {
|
|
||||||
if (this->stateWebServer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->webServer->begin();
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
this->webServer->getServer().setNoDelay(true);
|
|
||||||
#endif
|
|
||||||
this->webServerEnabled = true;
|
|
||||||
this->webServerChangeState = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopWebServer() {
|
|
||||||
if (!this->stateWebServer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->webServer->handleClient();
|
|
||||||
this->webServer->stop();
|
|
||||||
this->webServerEnabled = false;
|
|
||||||
this->webServerChangeState = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool stateDnsServer() {
|
|
||||||
return this->dnsServerEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startDnsServer() {
|
|
||||||
if (this->stateDnsServer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->dnsServer->start(53, "*", network->getApIp());
|
|
||||||
this->dnsServerEnabled = true;
|
|
||||||
this->dnsServerChangeState = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopDnsServer() {
|
|
||||||
if (!this->stateDnsServer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->dnsServer->processNextRequest();
|
|
||||||
this->dnsServer->stop();
|
|
||||||
this->dnsServerEnabled = false;
|
|
||||||
this->dnsServerChangeState = millis();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,346 +0,0 @@
|
|||||||
#include <Equitherm.h>
|
|
||||||
#include <GyverPID.h>
|
|
||||||
#include <PIDtuner.h>
|
|
||||||
|
|
||||||
Equitherm etRegulator;
|
|
||||||
GyverPID pidRegulator(0, 0, 0);
|
|
||||||
PIDtuner pidTuner;
|
|
||||||
|
|
||||||
|
|
||||||
class RegulatorTask : public LeanTask {
|
|
||||||
public:
|
|
||||||
RegulatorTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool tunerInit = false;
|
|
||||||
byte tunerState = 0;
|
|
||||||
byte tunerRegulator = 0;
|
|
||||||
float prevHeatingTarget = 0;
|
|
||||||
float prevEtResult = 0;
|
|
||||||
float prevPidResult = 0;
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "Regulator";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
byte newTemp = vars.parameters.heatingSetpoint;
|
|
||||||
|
|
||||||
if (vars.states.emergency) {
|
|
||||||
if (settings.heating.turbo) {
|
|
||||||
settings.heating.turbo = false;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
newTemp = getEmergencyModeTemp();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (vars.tuning.enable || tunerInit) {
|
|
||||||
if (settings.heating.turbo) {
|
|
||||||
settings.heating.turbo = false;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
newTemp = getTuningModeTemp();
|
|
||||||
|
|
||||||
if (newTemp == 0) {
|
|
||||||
vars.tuning.enable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vars.tuning.enable) {
|
|
||||||
if (settings.heating.turbo && (fabs(settings.heating.target - vars.temperatures.indoor) < 1 || !settings.heating.enable || (settings.equitherm.enable && settings.pid.enable))) {
|
|
||||||
settings.heating.turbo = false;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
newTemp = getNormalModeTemp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ограничиваем, если до этого не ограничило
|
|
||||||
if (newTemp < settings.heating.minTemp || newTemp > settings.heating.maxTemp) {
|
|
||||||
newTemp = constrain(newTemp, settings.heating.minTemp, settings.heating.maxTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (abs(vars.parameters.heatingSetpoint - newTemp) + 0.0001 >= 1) {
|
|
||||||
vars.parameters.heatingSetpoint = newTemp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
byte getEmergencyModeTemp() {
|
|
||||||
float newTemp = 0;
|
|
||||||
|
|
||||||
// if use equitherm
|
|
||||||
if (settings.emergency.useEquitherm && settings.sensors.outdoor.type != SensorType::MANUAL) {
|
|
||||||
float etResult = getEquithermTemp(settings.heating.minTemp, settings.heating.maxTemp);
|
|
||||||
|
|
||||||
if (fabs(prevEtResult - etResult) + 0.0001 >= 0.5) {
|
|
||||||
prevEtResult = etResult;
|
|
||||||
newTemp += etResult;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR_EQUITHERM), F("New emergency result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
newTemp += prevEtResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(settings.emergency.usePid && settings.sensors.indoor.type != SensorType::MANUAL) {
|
|
||||||
if (vars.parameters.heatingEnabled) {
|
|
||||||
float pidResult = getPidTemp(
|
|
||||||
settings.heating.minTemp,
|
|
||||||
settings.heating.maxTemp
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fabs(prevPidResult - pidResult) + 0.0001 >= 0.5) {
|
|
||||||
prevPidResult = pidResult;
|
|
||||||
newTemp += pidResult;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("New emergency result: %hhu (%.2f)"), (uint8_t) round(pidResult), pidResult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
newTemp += prevPidResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!vars.parameters.heatingEnabled && prevPidResult != 0) {
|
|
||||||
newTemp += prevPidResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// default temp, manual mode
|
|
||||||
newTemp = settings.emergency.target;
|
|
||||||
}
|
|
||||||
|
|
||||||
return round(newTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte getNormalModeTemp() {
|
|
||||||
float newTemp = 0;
|
|
||||||
|
|
||||||
if (fabs(prevHeatingTarget - settings.heating.target) > 0.0001) {
|
|
||||||
prevHeatingTarget = settings.heating.target;
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR), F("New target: %.2f"), settings.heating.target);
|
|
||||||
|
|
||||||
if (settings.equitherm.enable && settings.pid.enable) {
|
|
||||||
pidRegulator.integral = 0;
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if use equitherm
|
|
||||||
if (settings.equitherm.enable) {
|
|
||||||
float etResult = getEquithermTemp(settings.heating.minTemp, settings.heating.maxTemp);
|
|
||||||
|
|
||||||
if (fabs(prevEtResult - etResult) + 0.0001 >= 0.5) {
|
|
||||||
prevEtResult = etResult;
|
|
||||||
newTemp += etResult;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR_EQUITHERM), F("New result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
newTemp += prevEtResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if use pid
|
|
||||||
if (settings.pid.enable) {
|
|
||||||
if (vars.parameters.heatingEnabled) {
|
|
||||||
float pidResult = getPidTemp(
|
|
||||||
settings.equitherm.enable ? (settings.pid.maxTemp * -1) : settings.pid.minTemp,
|
|
||||||
settings.pid.maxTemp
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fabs(prevPidResult - pidResult) + 0.0001 >= 0.5) {
|
|
||||||
prevPidResult = pidResult;
|
|
||||||
newTemp += pidResult;
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("New result: %hhd (%.2f)"), (int8_t) round(pidResult), pidResult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
newTemp += prevPidResult;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newTemp += prevPidResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// default temp, manual mode
|
|
||||||
if (!settings.equitherm.enable && !settings.pid.enable) {
|
|
||||||
newTemp = settings.heating.target;
|
|
||||||
}
|
|
||||||
|
|
||||||
newTemp = round(newTemp);
|
|
||||||
newTemp = constrain(newTemp, 0, 100);
|
|
||||||
return newTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte getTuningModeTemp() {
|
|
||||||
if (tunerInit && (!vars.tuning.enable || vars.tuning.regulator != tunerRegulator)) {
|
|
||||||
if (tunerRegulator == 0) {
|
|
||||||
pidTuner.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
tunerInit = false;
|
|
||||||
tunerRegulator = 0;
|
|
||||||
tunerState = 0;
|
|
||||||
Log.sinfoln("REGULATOR.TUNING", F("Stopped"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vars.tuning.enable) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (vars.tuning.regulator == 0) {
|
|
||||||
// @TODO дописать
|
|
||||||
Log.sinfoln("REGULATOR.TUNING.EQUITHERM", F("Not implemented"));
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} else if (vars.tuning.regulator == 1) {
|
|
||||||
// PID tuner
|
|
||||||
float defaultTemp = settings.equitherm.enable
|
|
||||||
? getEquithermTemp(settings.heating.minTemp, settings.heating.maxTemp)
|
|
||||||
: settings.heating.target;
|
|
||||||
|
|
||||||
if (tunerInit && pidTuner.getState() == 3) {
|
|
||||||
Log.sinfoln("REGULATOR.TUNING.PID", F("Finished"));
|
|
||||||
for (Stream* stream : Log.getStreams()) {
|
|
||||||
pidTuner.debugText(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
pidTuner.reset();
|
|
||||||
tunerInit = false;
|
|
||||||
tunerRegulator = 0;
|
|
||||||
tunerState = 0;
|
|
||||||
|
|
||||||
if (pidTuner.getAccuracy() < 90) {
|
|
||||||
Log.swarningln("REGULATOR.TUNING.PID", F("Bad result, try again..."));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
settings.pid.p_factor = pidTuner.getPID_p();
|
|
||||||
settings.pid.i_factor = pidTuner.getPID_i();
|
|
||||||
settings.pid.d_factor = pidTuner.getPID_d();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tunerInit) {
|
|
||||||
Log.sinfoln("REGULATOR.TUNING.PID", F("Start..."));
|
|
||||||
|
|
||||||
float step;
|
|
||||||
if (vars.temperatures.indoor - vars.temperatures.outdoor > 10) {
|
|
||||||
step = ceil(vars.parameters.heatingSetpoint / vars.temperatures.indoor * 2);
|
|
||||||
} else {
|
|
||||||
step = 5.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float startTemp = step;
|
|
||||||
Log.sinfoln("REGULATOR.TUNING.PID", F("Started. Start value: %f, step: %f"), startTemp, step);
|
|
||||||
pidTuner.setParameters(NORMAL, startTemp, step, 20 * 60 * 1000, 0.15, 60 * 1000, 10000);
|
|
||||||
tunerInit = true;
|
|
||||||
tunerRegulator = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pidTuner.setInput(vars.temperatures.indoor);
|
|
||||||
pidTuner.compute();
|
|
||||||
|
|
||||||
if (tunerState > 0 && pidTuner.getState() != tunerState) {
|
|
||||||
Log.sinfoln("REGULATOR.TUNING.PID", F("Log:"));
|
|
||||||
for (Stream* stream : Log.getStreams()) {
|
|
||||||
pidTuner.debugText(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
tunerState = pidTuner.getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
return round(defaultTemp + pidTuner.getOutput());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float getEquithermTemp(int minTemp, int maxTemp) {
|
|
||||||
if (vars.states.emergency) {
|
|
||||||
etRegulator.Kt = 0;
|
|
||||||
etRegulator.indoorTemp = 0;
|
|
||||||
etRegulator.outdoorTemp = vars.temperatures.outdoor;
|
|
||||||
|
|
||||||
} else if (settings.pid.enable) {
|
|
||||||
etRegulator.Kt = 0;
|
|
||||||
etRegulator.indoorTemp = round(vars.temperatures.indoor);
|
|
||||||
etRegulator.outdoorTemp = round(vars.temperatures.outdoor);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (settings.heating.turbo) {
|
|
||||||
etRegulator.Kt = 10;
|
|
||||||
} else {
|
|
||||||
etRegulator.Kt = settings.equitherm.t_factor;
|
|
||||||
}
|
|
||||||
etRegulator.indoorTemp = vars.temperatures.indoor;
|
|
||||||
etRegulator.outdoorTemp = vars.temperatures.outdoor;
|
|
||||||
}
|
|
||||||
|
|
||||||
etRegulator.setLimits(minTemp, maxTemp);
|
|
||||||
etRegulator.Kn = settings.equitherm.n_factor;
|
|
||||||
// etRegulator.Kn = tuneEquithermN(etRegulator.Kn, vars.temperatures.indoor, settings.heating.target, 300, 1800, 0.01, 1);
|
|
||||||
etRegulator.Kk = settings.equitherm.k_factor;
|
|
||||||
etRegulator.targetTemp = vars.states.emergency ? settings.emergency.target : settings.heating.target;
|
|
||||||
|
|
||||||
return etRegulator.getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
float getPidTemp(int minTemp, int maxTemp) {
|
|
||||||
pidRegulator.Kp = settings.pid.p_factor;
|
|
||||||
pidRegulator.Ki = settings.pid.i_factor;
|
|
||||||
pidRegulator.Kd = settings.pid.d_factor;
|
|
||||||
|
|
||||||
pidRegulator.setLimits(minTemp, maxTemp);
|
|
||||||
pidRegulator.setDt(settings.pid.dt * 1000u);
|
|
||||||
pidRegulator.input = vars.temperatures.indoor;
|
|
||||||
pidRegulator.setpoint = settings.heating.target;
|
|
||||||
|
|
||||||
return pidRegulator.getResultTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
float tuneEquithermN(float ratio, float currentTemp, float setTemp, unsigned int dirtyInterval = 60, unsigned int accurateInterval = 1800, float accurateStep = 0.01, float accurateStepAfter = 1) {
|
|
||||||
static uint32_t _prevIteration = millis();
|
|
||||||
|
|
||||||
if (abs(currentTemp - setTemp) < accurateStepAfter) {
|
|
||||||
if (millis() - _prevIteration < (accurateInterval * 1000)) {
|
|
||||||
return ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentTemp - setTemp > 0.1f) {
|
|
||||||
ratio -= accurateStep;
|
|
||||||
|
|
||||||
} else if (currentTemp - setTemp < -0.1f) {
|
|
||||||
ratio += accurateStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (millis() - _prevIteration < (dirtyInterval * 1000)) {
|
|
||||||
return ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
ratio = ratio * (setTemp / currentTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
_prevIteration = millis();
|
|
||||||
return ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,341 +0,0 @@
|
|||||||
#include <OneWire.h>
|
|
||||||
#include <DallasTemperature.h>
|
|
||||||
|
|
||||||
#if USE_BLE
|
|
||||||
#include <NimBLEDevice.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class SensorsTask : public LeanTask {
|
|
||||||
public:
|
|
||||||
SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {
|
|
||||||
this->oneWireOutdoorSensor = new OneWire();
|
|
||||||
this->outdoorSensor = new DallasTemperature(this->oneWireOutdoorSensor);
|
|
||||||
this->outdoorSensor->setWaitForConversion(false);
|
|
||||||
|
|
||||||
this->oneWireIndoorSensor = new OneWire();
|
|
||||||
this->indoorSensor = new DallasTemperature(this->oneWireIndoorSensor);
|
|
||||||
this->indoorSensor->setWaitForConversion(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
~SensorsTask() {
|
|
||||||
delete this->outdoorSensor;
|
|
||||||
delete this->oneWireOutdoorSensor;
|
|
||||||
delete this->indoorSensor;
|
|
||||||
delete this->oneWireIndoorSensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
OneWire* oneWireOutdoorSensor = nullptr;
|
|
||||||
OneWire* oneWireIndoorSensor = nullptr;
|
|
||||||
|
|
||||||
DallasTemperature* outdoorSensor = nullptr;
|
|
||||||
DallasTemperature* indoorSensor = nullptr;
|
|
||||||
|
|
||||||
bool initOutdoorSensor = false;
|
|
||||||
unsigned long startOutdoorConversionTime = 0;
|
|
||||||
float filteredOutdoorTemp = 0;
|
|
||||||
bool emptyOutdoorTemp = true;
|
|
||||||
|
|
||||||
bool initIndoorSensor = false;
|
|
||||||
unsigned long startIndoorConversionTime = 0;
|
|
||||||
float filteredIndoorTemp = 0;
|
|
||||||
bool emptyIndoorTemp = true;
|
|
||||||
|
|
||||||
#if USE_BLE
|
|
||||||
BLEClient* pBleClient = nullptr;
|
|
||||||
bool initBleSensor = false;
|
|
||||||
bool initBleNotify = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char* getTaskName() {
|
|
||||||
return "Sensors";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int getTaskCore() {
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int getTaskPriority() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
bool indoorTempUpdated = false;
|
|
||||||
bool outdoorTempUpdated = false;
|
|
||||||
|
|
||||||
if (settings.sensors.outdoor.type == SensorType::DS18B20 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
|
|
||||||
outdoorTemperatureSensor();
|
|
||||||
outdoorTempUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.sensors.indoor.type == SensorType::DS18B20 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
|
|
||||||
indoorTemperatureSensor();
|
|
||||||
indoorTempUpdated = true;
|
|
||||||
}
|
|
||||||
#if USE_BLE
|
|
||||||
else if (settings.sensors.indoor.type == SensorType::BLUETOOTH) {
|
|
||||||
indoorTemperatureBluetoothSensor();
|
|
||||||
indoorTempUpdated = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (outdoorTempUpdated && fabs(vars.temperatures.outdoor - this->filteredOutdoorTemp) > 0.099) {
|
|
||||||
vars.temperatures.outdoor = this->filteredOutdoorTemp + settings.sensors.outdoor.offset;
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_OUTDOOR), F("New temp: %f"), vars.temperatures.outdoor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indoorTempUpdated && fabs(vars.temperatures.indoor - this->filteredIndoorTemp) > 0.099) {
|
|
||||||
vars.temperatures.indoor = this->filteredIndoorTemp + settings.sensors.indoor.offset;
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_INDOOR), F("New temp: %f"), vars.temperatures.indoor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if USE_BLE
|
|
||||||
void indoorTemperatureBluetoothSensor() {
|
|
||||||
static bool initBleNotify = false;
|
|
||||||
if (!initBleSensor && millis() > 5000) {
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Init BLE"));
|
|
||||||
BLEDevice::init("");
|
|
||||||
|
|
||||||
pBleClient = BLEDevice::createClient();
|
|
||||||
pBleClient->setConnectTimeout(5);
|
|
||||||
|
|
||||||
initBleSensor = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!initBleSensor || pBleClient->isConnected()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset init notify flag
|
|
||||||
this->initBleNotify = false;
|
|
||||||
|
|
||||||
// Connect to the remote BLE Server.
|
|
||||||
BLEAddress bleServerAddress(settings.sensors.indoor.bleAddresss);
|
|
||||||
if (!pBleClient->connect(bleServerAddress)) {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), "Failed connecting to device at %s", bleServerAddress.toString().c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), "Connected to device at %s", bleServerAddress.toString().c_str());
|
|
||||||
|
|
||||||
NimBLEUUID serviceUUID((uint16_t) 0x181AU);
|
|
||||||
BLERemoteService* pRemoteService = pBleClient->getService(serviceUUID);
|
|
||||||
if (!pRemoteService) {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Failed to find service UUID: %s"), serviceUUID.toString().c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Found service UUID: %s"), serviceUUID.toString().c_str());
|
|
||||||
|
|
||||||
// 0x2A6E - Notify temperature x0.01C (pvvx)
|
|
||||||
if (!this->initBleNotify) {
|
|
||||||
NimBLEUUID charUUID((uint16_t) 0x2A6E);
|
|
||||||
BLERemoteCharacteristic* pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
|
|
||||||
if (pRemoteCharacteristic && pRemoteCharacteristic->canNotify()) {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Found characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
|
|
||||||
this->initBleNotify = pRemoteCharacteristic->subscribe(true, [this](NimBLERemoteCharacteristic*, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (length != 2) {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Invalid notification data"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = ((pData[0] | (pData[1] << 8)) * 0.01);
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_INDOOR), F("Raw temp: %f"), rawTemp);
|
|
||||||
|
|
||||||
if (this->emptyIndoorTemp) {
|
|
||||||
this->filteredIndoorTemp = rawTemp;
|
|
||||||
this->emptyIndoorTemp = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->filteredIndoorTemp += (rawTemp - this->filteredIndoorTemp) * EXT_SENSORS_FILTER_K;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->filteredIndoorTemp = floor(this->filteredIndoorTemp * 100) / 100;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this->initBleNotify) {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Subscribed to characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Failed to subscribe to characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0x2A1F - Notify temperature x0.1C (atc1441/pvvx)
|
|
||||||
if (!this->initBleNotify) {
|
|
||||||
NimBLEUUID charUUID((uint16_t) 0x2A1F);
|
|
||||||
BLERemoteCharacteristic* pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
|
|
||||||
if (pRemoteCharacteristic && pRemoteCharacteristic->canNotify()) {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Found characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
|
|
||||||
this->initBleNotify = pRemoteCharacteristic->subscribe(true, [this](NimBLERemoteCharacteristic*, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (length != 2) {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Invalid notification data"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = ((pData[0] | (pData[1] << 8)) * 0.1);
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_INDOOR), F("Raw temp: %f"), rawTemp);
|
|
||||||
|
|
||||||
if (this->emptyIndoorTemp) {
|
|
||||||
this->filteredIndoorTemp = rawTemp;
|
|
||||||
this->emptyIndoorTemp = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->filteredIndoorTemp += (rawTemp - this->filteredIndoorTemp) * EXT_SENSORS_FILTER_K;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->filteredIndoorTemp = floor(this->filteredIndoorTemp * 100) / 100;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this->initBleNotify) {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_BLE), F("Subscribed to characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Failed to subscribe to characteristic UUID: %s"), charUUID.toString().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->initBleNotify) {
|
|
||||||
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Not found supported characteristics"));
|
|
||||||
pBleClient->disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void outdoorTemperatureSensor() {
|
|
||||||
if (!this->initOutdoorSensor) {
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_OUTDOOR), F("Starting on gpio %hhu..."), settings.sensors.outdoor.gpio);
|
|
||||||
|
|
||||||
this->oneWireOutdoorSensor->begin(settings.sensors.outdoor.gpio);
|
|
||||||
this->outdoorSensor->begin();
|
|
||||||
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_OUTDOOR),
|
|
||||||
F("Devices on bus: %hhu, DS18* devices: %hhu"),
|
|
||||||
this->outdoorSensor->getDeviceCount(),
|
|
||||||
this->outdoorSensor->getDS18Count()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this->outdoorSensor->getDeviceCount() > 0) {
|
|
||||||
this->initOutdoorSensor = true;
|
|
||||||
this->outdoorSensor->setResolution(12);
|
|
||||||
this->outdoorSensor->requestTemperatures();
|
|
||||||
this->startOutdoorConversionTime = millis();
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_OUTDOOR), F("Started"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long estimateConversionTime = millis() - this->startOutdoorConversionTime;
|
|
||||||
if (estimateConversionTime < this->outdoorSensor->millisToWaitForConversion()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool completed = this->outdoorSensor->isConversionComplete();
|
|
||||||
if (!completed && estimateConversionTime >= 1000) {
|
|
||||||
this->initOutdoorSensor = false;
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_SENSORS_OUTDOOR), F("Could not read temperature data (no response)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!completed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = this->outdoorSensor->getTempCByIndex(0);
|
|
||||||
if (rawTemp == DEVICE_DISCONNECTED_C) {
|
|
||||||
this->initOutdoorSensor = false;
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_SENSORS_OUTDOOR), F("Could not read temperature data (not connected)"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_OUTDOOR), F("Raw temp: %f"), rawTemp);
|
|
||||||
|
|
||||||
if (this->emptyOutdoorTemp) {
|
|
||||||
this->filteredOutdoorTemp = rawTemp;
|
|
||||||
this->emptyOutdoorTemp = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->filteredOutdoorTemp += (rawTemp - this->filteredOutdoorTemp) * EXT_SENSORS_FILTER_K;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->filteredOutdoorTemp = floor(this->filteredOutdoorTemp * 100) / 100;
|
|
||||||
this->outdoorSensor->requestTemperatures();
|
|
||||||
this->startOutdoorConversionTime = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void indoorTemperatureSensor() {
|
|
||||||
if (!this->initIndoorSensor) {
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_INDOOR), F("Starting on gpio %hhu..."), settings.sensors.indoor.gpio);
|
|
||||||
|
|
||||||
this->oneWireIndoorSensor->begin(settings.sensors.indoor.gpio);
|
|
||||||
this->indoorSensor->begin();
|
|
||||||
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_INDOOR),
|
|
||||||
F("Devices on bus: %hhu, DS18* devices: %hhu"),
|
|
||||||
this->indoorSensor->getDeviceCount(),
|
|
||||||
this->indoorSensor->getDS18Count()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this->indoorSensor->getDeviceCount() > 0) {
|
|
||||||
this->initIndoorSensor = true;
|
|
||||||
this->indoorSensor->setResolution(12);
|
|
||||||
this->indoorSensor->requestTemperatures();
|
|
||||||
this->startIndoorConversionTime = millis();
|
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_INDOOR), F("Started"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long estimateConversionTime = millis() - this->startIndoorConversionTime;
|
|
||||||
if (estimateConversionTime < this->indoorSensor->millisToWaitForConversion()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool completed = this->indoorSensor->isConversionComplete();
|
|
||||||
if (!completed && estimateConversionTime >= 1000) {
|
|
||||||
this->initIndoorSensor = false;
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_SENSORS_INDOOR), F("Could not read temperature data (no response)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!completed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = this->indoorSensor->getTempCByIndex(0);
|
|
||||||
if (rawTemp == DEVICE_DISCONNECTED_C) {
|
|
||||||
this->initIndoorSensor = false;
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_SENSORS_INDOOR), F("Could not read temperature data (not connected)"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_INDOOR), F("Raw temp: %f"), rawTemp);
|
|
||||||
|
|
||||||
if (this->emptyIndoorTemp) {
|
|
||||||
this->filteredIndoorTemp = rawTemp;
|
|
||||||
this->emptyIndoorTemp = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->filteredIndoorTemp += (rawTemp - this->filteredIndoorTemp) * EXT_SENSORS_FILTER_K;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->filteredIndoorTemp = floor(this->filteredIndoorTemp * 100) / 100;
|
|
||||||
this->indoorSensor->requestTemperatures();
|
|
||||||
this->startIndoorConversionTime = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
struct NetworkSettings {
|
|
||||||
char hostname[25] = DEFAULT_HOSTNAME;
|
|
||||||
bool useDhcp = true;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
char ip[16] = "192.168.0.100";
|
|
||||||
char gateway[16] = "192.168.0.1";
|
|
||||||
char subnet[16] = "255.255.255.0";
|
|
||||||
char dns[16] = "192.168.0.1";
|
|
||||||
} staticConfig;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
char ssid[33] = DEFAULT_AP_SSID;
|
|
||||||
char password[65] = DEFAULT_AP_PASSWORD;
|
|
||||||
byte channel = 6;
|
|
||||||
} ap;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
char ssid[33] = DEFAULT_STA_SSID;
|
|
||||||
char password[65] = DEFAULT_STA_PASSWORD;
|
|
||||||
byte channel = 0;
|
|
||||||
} sta;
|
|
||||||
} networkSettings;
|
|
||||||
|
|
||||||
struct Settings {
|
|
||||||
struct {
|
|
||||||
bool debug = DEBUG_BY_DEFAULT;
|
|
||||||
bool useSerial = USE_SERIAL;
|
|
||||||
bool useTelnet = USE_TELNET;
|
|
||||||
} system;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool useAuth = false;
|
|
||||||
char login[13] = DEFAULT_PORTAL_LOGIN;
|
|
||||||
char password[33] = DEFAULT_PORTAL_PASSWORD;
|
|
||||||
} portal;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
byte inGpio = DEFAULT_OT_IN_GPIO;
|
|
||||||
byte outGpio = DEFAULT_OT_OUT_GPIO;
|
|
||||||
unsigned int memberIdCode = 0;
|
|
||||||
bool dhwPresent = true;
|
|
||||||
bool summerWinterMode = false;
|
|
||||||
bool heatingCh2Enabled = true;
|
|
||||||
bool heatingCh1ToCh2 = false;
|
|
||||||
bool dhwToCh2 = false;
|
|
||||||
bool dhwBlocking = false;
|
|
||||||
bool modulationSyncWithHeating = false;
|
|
||||||
} opentherm;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
char server[81] = DEFAULT_MQTT_SERVER;
|
|
||||||
unsigned short port = DEFAULT_MQTT_PORT;
|
|
||||||
char user[33] = DEFAULT_MQTT_USER;
|
|
||||||
char password[33] = DEFAULT_MQTT_PASSWORD;
|
|
||||||
char prefix[33] = DEFAULT_MQTT_PREFIX;
|
|
||||||
unsigned short interval = 5;
|
|
||||||
} mqtt;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enable = true;
|
|
||||||
float target = 40.0f;
|
|
||||||
bool useEquitherm = false;
|
|
||||||
bool usePid = false;
|
|
||||||
} emergency;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enable = true;
|
|
||||||
bool turbo = false;
|
|
||||||
float target = 40.0f;
|
|
||||||
float hysteresis = 0.5f;
|
|
||||||
byte minTemp = DEFAULT_HEATING_MIN_TEMP;
|
|
||||||
byte maxTemp = DEFAULT_HEATING_MAX_TEMP;
|
|
||||||
byte maxModulation = 100;
|
|
||||||
} heating;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enable = true;
|
|
||||||
byte target = 40;
|
|
||||||
byte minTemp = DEFAULT_DHW_MIN_TEMP;
|
|
||||||
byte maxTemp = DEFAULT_DHW_MAX_TEMP;
|
|
||||||
} dhw;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enable = false;
|
|
||||||
float p_factor = 50;
|
|
||||||
float i_factor = 0.006f;
|
|
||||||
float d_factor = 10000;
|
|
||||||
unsigned short dt = 180;
|
|
||||||
byte minTemp = 0;
|
|
||||||
byte maxTemp = DEFAULT_HEATING_MAX_TEMP;
|
|
||||||
} pid;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enable = false;
|
|
||||||
float n_factor = 0.7f;
|
|
||||||
float k_factor = 3.0f;
|
|
||||||
float t_factor = 2.0f;
|
|
||||||
} equitherm;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
struct {
|
|
||||||
SensorType type = SensorType::BOILER;
|
|
||||||
byte gpio = DEFAULT_SENSOR_OUTDOOR_GPIO;
|
|
||||||
float offset = 0.0f;
|
|
||||||
} outdoor;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
SensorType type = SensorType::MANUAL;
|
|
||||||
byte gpio = DEFAULT_SENSOR_INDOOR_GPIO;
|
|
||||||
uint8_t bleAddresss[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
||||||
float offset = 0.0f;
|
|
||||||
} indoor;
|
|
||||||
} sensors;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool use = false;
|
|
||||||
byte gpio = DEFAULT_EXT_PUMP_GPIO;
|
|
||||||
unsigned short postCirculationTime = 600;
|
|
||||||
unsigned int antiStuckInterval = 2592000;
|
|
||||||
unsigned short antiStuckTime = 300;
|
|
||||||
} externalPump;
|
|
||||||
|
|
||||||
char validationValue[8] = SETTINGS_VALID_VALUE;
|
|
||||||
} settings;
|
|
||||||
|
|
||||||
struct Variables {
|
|
||||||
struct {
|
|
||||||
bool enable = false;
|
|
||||||
byte regulator = 0;
|
|
||||||
} tuning;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool otStatus = false;
|
|
||||||
bool emergency = false;
|
|
||||||
bool heating = false;
|
|
||||||
bool dhw = false;
|
|
||||||
bool flame = false;
|
|
||||||
bool fault = false;
|
|
||||||
bool diagnostic = false;
|
|
||||||
bool externalPump = false;
|
|
||||||
} states;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
float modulation = 0.0f;
|
|
||||||
float pressure = 0.0f;
|
|
||||||
float dhwFlowRate = 0.0f;
|
|
||||||
byte faultCode = 0;
|
|
||||||
int8_t rssi = 0;
|
|
||||||
} sensors;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
float indoor = 0.0f;
|
|
||||||
float outdoor = 0.0f;
|
|
||||||
float heating = 0.0f;
|
|
||||||
float dhw = 0.0f;
|
|
||||||
} temperatures;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool heatingEnabled = false;
|
|
||||||
byte heatingMinTemp = DEFAULT_HEATING_MIN_TEMP;
|
|
||||||
byte heatingMaxTemp = DEFAULT_HEATING_MAX_TEMP;
|
|
||||||
byte heatingSetpoint = 0;
|
|
||||||
unsigned long extPumpLastEnableTime = 0;
|
|
||||||
byte dhwMinTemp = DEFAULT_DHW_MIN_TEMP;
|
|
||||||
byte dhwMaxTemp = DEFAULT_DHW_MAX_TEMP;
|
|
||||||
byte maxModulation = 0;
|
|
||||||
uint8_t slaveMemberId = 0;
|
|
||||||
uint8_t slaveFlags = 0;
|
|
||||||
uint8_t slaveType = 0;
|
|
||||||
uint8_t slaveVersion = 0;
|
|
||||||
float slaveOtVersion = 0.0f;
|
|
||||||
uint8_t masterMemberId = 0;
|
|
||||||
uint8_t masterFlags = 0;
|
|
||||||
uint8_t masterType = 0;
|
|
||||||
uint8_t masterVersion = 0;
|
|
||||||
float masterOtVersion = 0;
|
|
||||||
} parameters;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
bool restart = false;
|
|
||||||
bool resetFault = false;
|
|
||||||
bool resetDiagnostic = false;
|
|
||||||
} actions;
|
|
||||||
} vars;
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
#define PROJECT_NAME "OpenTherm Gateway"
|
|
||||||
#define PROJECT_VERSION "1.4.0-rc.17"
|
|
||||||
#define PROJECT_REPO "https://github.com/Laxilef/OTGateway"
|
|
||||||
|
|
||||||
#define EMERGENCY_TIME_TRESHOLD 120000
|
|
||||||
#define MQTT_RECONNECT_INTERVAL 15000
|
|
||||||
|
|
||||||
#define EXT_SENSORS_INTERVAL 5000
|
|
||||||
#define EXT_SENSORS_FILTER_K 0.15
|
|
||||||
|
|
||||||
#define CONFIG_URL "http://%s/"
|
|
||||||
#define SETTINGS_VALID_VALUE "stvalid" // only 8 chars!
|
|
||||||
|
|
||||||
#define GPIO_IS_NOT_CONFIGURED 0xff
|
|
||||||
#define DEFAULT_HEATING_MIN_TEMP 20
|
|
||||||
#define DEFAULT_HEATING_MAX_TEMP 90
|
|
||||||
#define DEFAULT_DHW_MIN_TEMP 30
|
|
||||||
#define DEFAULT_DHW_MAX_TEMP 60
|
|
||||||
|
|
||||||
#ifndef USE_SERIAL
|
|
||||||
#define USE_SERIAL true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef USE_TELNET
|
|
||||||
#define USE_TELNET true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef USE_BLE
|
|
||||||
#define USE_BLE false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_HOSTNAME
|
|
||||||
#define DEFAULT_HOSTNAME "opentherm"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_AP_SSID
|
|
||||||
#define DEFAULT_AP_SSID "OpenTherm Gateway"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_AP_PASSWORD
|
|
||||||
#define DEFAULT_AP_PASSWORD "otgateway123456"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_STA_SSID
|
|
||||||
#define DEFAULT_STA_SSID ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_STA_PASSWORD
|
|
||||||
#define DEFAULT_STA_PASSWORD ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEBUG_BY_DEFAULT
|
|
||||||
#define DEBUG_BY_DEFAULT false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_PORTAL_LOGIN
|
|
||||||
#define DEFAULT_PORTAL_LOGIN ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_PORTAL_PASSWORD
|
|
||||||
#define DEFAULT_PORTAL_PASSWORD ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_SERVER
|
|
||||||
#define DEFAULT_MQTT_SERVER ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_PORT
|
|
||||||
#define DEFAULT_MQTT_PORT 1883
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_USER
|
|
||||||
#define DEFAULT_MQTT_USER ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_PASSWORD
|
|
||||||
#define DEFAULT_MQTT_PASSWORD ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_PREFIX
|
|
||||||
#define DEFAULT_MQTT_PREFIX "opentherm"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_OT_IN_GPIO
|
|
||||||
#define DEFAULT_OT_IN_GPIO GPIO_IS_NOT_CONFIGURED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_OT_OUT_GPIO
|
|
||||||
#define DEFAULT_OT_OUT_GPIO GPIO_IS_NOT_CONFIGURED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_SENSOR_OUTDOOR_GPIO
|
|
||||||
#define DEFAULT_SENSOR_OUTDOOR_GPIO GPIO_IS_NOT_CONFIGURED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_SENSOR_INDOOR_GPIO
|
|
||||||
#define DEFAULT_SENSOR_INDOOR_GPIO GPIO_IS_NOT_CONFIGURED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_EXT_PUMP_GPIO
|
|
||||||
#define DEFAULT_EXT_PUMP_GPIO GPIO_IS_NOT_CONFIGURED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PROGMEM
|
|
||||||
#define PROGMEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GPIO_IS_VALID_GPIO
|
|
||||||
#define GPIO_IS_VALID_GPIO(gpioNum) (gpioNum >= 0 && gpioNum <= 16)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GPIO_IS_VALID(gpioNum) (gpioNum != GPIO_IS_NOT_CONFIGURED && GPIO_IS_VALID_GPIO(gpioNum))
|
|
||||||
|
|
||||||
enum class SensorType : byte {
|
|
||||||
BOILER,
|
|
||||||
MANUAL,
|
|
||||||
DS18B20,
|
|
||||||
BLUETOOTH
|
|
||||||
};
|
|
||||||
|
|
||||||
char buffer[255];
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include "defines.h"
|
|
||||||
#include "strings.h"
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include <FileData.h>
|
|
||||||
#include <LittleFS.h>
|
|
||||||
#include "ESPTelnetStream.h"
|
|
||||||
#include <TinyLogger.h>
|
|
||||||
#include <NetworkManager.h>
|
|
||||||
#include "Settings.h"
|
|
||||||
#include <utils.h>
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include <ESP32Scheduler.h>
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#include <Scheduler.h>
|
|
||||||
#else
|
|
||||||
#error Wrong board. Supported boards: esp8266, esp32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <Task.h>
|
|
||||||
#include <LeanTask.h>
|
|
||||||
#include "MqttTask.h"
|
|
||||||
#include "OpenThermTask.h"
|
|
||||||
#include "SensorsTask.h"
|
|
||||||
#include "RegulatorTask.h"
|
|
||||||
#include "PortalTask.h"
|
|
||||||
#include "MainTask.h"
|
|
||||||
|
|
||||||
// Vars
|
|
||||||
FileData fsNetworkSettings(&LittleFS, "/network.conf", 'n', &networkSettings, sizeof(networkSettings), 1000);
|
|
||||||
FileData fsSettings(&LittleFS, "/settings.conf", 's', &settings, sizeof(settings), 60000);
|
|
||||||
ESPTelnetStream* telnetStream = nullptr;
|
|
||||||
Network::Manager* network = nullptr;
|
|
||||||
|
|
||||||
// Tasks
|
|
||||||
MqttTask* tMqtt;
|
|
||||||
OpenThermTask* tOt;
|
|
||||||
SensorsTask* tSensors;
|
|
||||||
RegulatorTask* tRegulator;
|
|
||||||
PortalTask* tPortal;
|
|
||||||
MainTask* tMain;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
LittleFS.begin();
|
|
||||||
|
|
||||||
Log.setLevel(TinyLogger::Level::VERBOSE);
|
|
||||||
Log.setServiceTemplate("\033[1m[%s]\033[22m");
|
|
||||||
Log.setLevelTemplate("\033[1m[%s]\033[22m");
|
|
||||||
Log.setMsgPrefix("\033[m ");
|
|
||||||
Log.setDateTemplate("\033[1m[%H:%M:%S]\033[22m");
|
|
||||||
Log.setDateCallback([] {
|
|
||||||
unsigned int time = millis() / 1000;
|
|
||||||
int sec = time % 60;
|
|
||||||
int min = time % 3600 / 60;
|
|
||||||
int hour = time / 3600;
|
|
||||||
|
|
||||||
return tm{sec, min, hour};
|
|
||||||
});
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
Log.addStream(&Serial);
|
|
||||||
Log.print("\n\n\r");
|
|
||||||
|
|
||||||
// network settings
|
|
||||||
switch (fsNetworkSettings.read()) {
|
|
||||||
case FD_FS_ERR:
|
|
||||||
Log.swarningln(FPSTR(L_NETWORK_SETTINGS), F("Filesystem error, load default"));
|
|
||||||
break;
|
|
||||||
case FD_FILE_ERR:
|
|
||||||
Log.swarningln(FPSTR(L_NETWORK_SETTINGS), F("Bad data, load default"));
|
|
||||||
break;
|
|
||||||
case FD_WRITE:
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK_SETTINGS), F("Not found, load default"));
|
|
||||||
break;
|
|
||||||
case FD_ADD:
|
|
||||||
case FD_READ:
|
|
||||||
Log.sinfoln(FPSTR(L_NETWORK_SETTINGS), F("Loaded"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// settings
|
|
||||||
switch (fsSettings.read()) {
|
|
||||||
case FD_FS_ERR:
|
|
||||||
Log.swarningln(FPSTR(L_SETTINGS), F("Filesystem error, load default"));
|
|
||||||
break;
|
|
||||||
case FD_FILE_ERR:
|
|
||||||
Log.swarningln(FPSTR(L_SETTINGS), F("Bad data, load default"));
|
|
||||||
break;
|
|
||||||
case FD_WRITE:
|
|
||||||
Log.sinfoln(FPSTR(L_SETTINGS), F("Not found, load default"));
|
|
||||||
break;
|
|
||||||
case FD_ADD:
|
|
||||||
case FD_READ:
|
|
||||||
Log.sinfoln(FPSTR(L_SETTINGS), F("Loaded"));
|
|
||||||
|
|
||||||
if (strcmp(SETTINGS_VALID_VALUE, settings.validationValue) != 0) {
|
|
||||||
Log.swarningln(FPSTR(L_SETTINGS), F("Not valid, set default and restart..."));
|
|
||||||
fsSettings.reset();
|
|
||||||
::delay(5000);
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logs
|
|
||||||
if (!settings.system.useSerial) {
|
|
||||||
Log.clearStreams();
|
|
||||||
Serial.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.system.useTelnet) {
|
|
||||||
telnetStream = new ESPTelnetStream;
|
|
||||||
telnetStream->setKeepAliveInterval(500);
|
|
||||||
Log.addStream(telnetStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.setLevel(settings.system.debug ? TinyLogger::Level::VERBOSE : TinyLogger::Level::INFO);
|
|
||||||
|
|
||||||
// network
|
|
||||||
network = (new Network::Manager)
|
|
||||||
->setHostname(networkSettings.hostname)
|
|
||||||
->setStaCredentials(
|
|
||||||
#ifdef WOKWI
|
|
||||||
"Wokwi-GUEST", nullptr, 6
|
|
||||||
#else
|
|
||||||
strlen(networkSettings.sta.ssid) ? networkSettings.sta.ssid : nullptr,
|
|
||||||
strlen(networkSettings.sta.password) ? networkSettings.sta.password : nullptr,
|
|
||||||
networkSettings.sta.channel
|
|
||||||
#endif
|
|
||||||
)->setApCredentials(
|
|
||||||
strlen(networkSettings.ap.ssid) ? networkSettings.ap.ssid : nullptr,
|
|
||||||
strlen(networkSettings.ap.password) ? networkSettings.ap.password : nullptr,
|
|
||||||
networkSettings.ap.channel
|
|
||||||
);
|
|
||||||
|
|
||||||
// tasks
|
|
||||||
tMqtt = new MqttTask(false, 500);
|
|
||||||
Scheduler.start(tMqtt);
|
|
||||||
|
|
||||||
tOt = new OpenThermTask(true, 750);
|
|
||||||
Scheduler.start(tOt);
|
|
||||||
|
|
||||||
tSensors = new SensorsTask(true, EXT_SENSORS_INTERVAL);
|
|
||||||
Scheduler.start(tSensors);
|
|
||||||
|
|
||||||
tRegulator = new RegulatorTask(true, 10000);
|
|
||||||
Scheduler.start(tRegulator);
|
|
||||||
|
|
||||||
tPortal = new PortalTask(true, 0);
|
|
||||||
Scheduler.start(tPortal);
|
|
||||||
|
|
||||||
tMain = new MainTask(true, 100);
|
|
||||||
Scheduler.start(tMain);
|
|
||||||
|
|
||||||
Scheduler.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef PROGMEM
|
|
||||||
#define PROGMEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char L_SETTINGS[] PROGMEM = "SETTINGS";
|
|
||||||
const char L_NETWORK[] PROGMEM = "NETWORK";
|
|
||||||
const char L_NETWORK_SETTINGS[] PROGMEM = "NETWORK.SETTINGS";
|
|
||||||
const char L_PORTAL_WEBSERVER[] PROGMEM = "PORTAL.WEBSERVER";
|
|
||||||
const char L_PORTAL_DNSSERVER[] PROGMEM = "PORTAL.DNSSERVER";
|
|
||||||
const char L_PORTAL_CAPTIVE[] PROGMEM = "PORTAL.CAPTIVE";
|
|
||||||
const char L_PORTAL_OTA[] PROGMEM = "PORTAL.OTA";
|
|
||||||
const char L_MAIN[] PROGMEM = "MAIN";
|
|
||||||
const char L_MQTT[] PROGMEM = "MQTT";
|
|
||||||
const char L_MQTT_MSG[] PROGMEM = "MQTT.MSG";
|
|
||||||
const char L_OT[] PROGMEM = "OT";
|
|
||||||
const char L_OT_DHW[] PROGMEM = "OT.DHW";
|
|
||||||
const char L_OT_HEATING[] PROGMEM = "OT.HEATING";
|
|
||||||
const char L_SENSORS_OUTDOOR[] PROGMEM = "SENSORS.OUTDOOR";
|
|
||||||
const char L_SENSORS_INDOOR[] PROGMEM = "SENSORS.INDOOR";
|
|
||||||
const char L_SENSORS_BLE[] PROGMEM = "SENSORS.BLE";
|
|
||||||
const char L_REGULATOR[] PROGMEM = "REGULATOR";
|
|
||||||
const char L_REGULATOR_PID[] PROGMEM = "REGULATOR.PID";
|
|
||||||
const char L_REGULATOR_EQUITHERM[] PROGMEM = "REGULATOR.EQUITHERM";
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
@media (min-width: 1280px) {
|
|
||||||
.container {
|
|
||||||
max-width: 1000px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 1536px) {
|
|
||||||
.container {
|
|
||||||
max-width: 1000px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
header,
|
|
||||||
main,
|
|
||||||
footer {
|
|
||||||
padding-top: 1rem !important;
|
|
||||||
padding-bottom: 1rem !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
article {
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.success {
|
|
||||||
background-color: var(--pico-form-element-valid-border-color);
|
|
||||||
border-color: var(--pico-form-element-valid-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
button.failed {
|
|
||||||
background-color: var(--pico-form-element-invalid-border-color);
|
|
||||||
border-color: var(--pico-form-element-invalid-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
tr.network:hover {
|
|
||||||
--pico-background-color: var(--pico-primary-focus);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.greatSignal {
|
|
||||||
background-color: var(--pico-form-element-valid-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.normalSignal {
|
|
||||||
background-color: #e48500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.badSignal {
|
|
||||||
background-color: var(--pico-form-element-invalid-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.primary {
|
|
||||||
border: 0.25rem solid var(--pico-form-element-invalid-border-color);
|
|
||||||
padding: 1rem;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
display: inline-block;
|
|
||||||
padding: calc(var(--pico-nav-link-spacing-vertical) - var(--pico-border-width) * 2) var(--pico-nav-link-spacing-horizontal);
|
|
||||||
vertical-align: baseline;
|
|
||||||
line-height: var(--pico-line-height);
|
|
||||||
background-color: var(--pico-code-kbd-background-color);
|
|
||||||
border-radius: var(--pico-border-radius);
|
|
||||||
color: var(--pico-code-kbd-color);
|
|
||||||
font-weight: bolder;
|
|
||||||
font-size: 1.3rem;
|
|
||||||
font-family: var(--pico-font-family-monospace);
|
|
||||||
}
|
|
||||||
|
|
||||||
nav li a:has(> div.logo) {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
@@ -1,680 +0,0 @@
|
|||||||
function setupForm(formSelector) {
|
|
||||||
const form = document.querySelector(formSelector);
|
|
||||||
if (!form) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
form.querySelectorAll('input').forEach(item => {
|
|
||||||
item.addEventListener('change', (e) => {
|
|
||||||
e.target.setAttribute('aria-invalid', !e.target.checkValidity());
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const url = form.action;
|
|
||||||
let button = form.querySelector('button[type="submit"]');
|
|
||||||
let defaultText;
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
defaultText = button.textContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
form.addEventListener('submit', async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Please wait...';
|
|
||||||
button.setAttribute('disabled', true);
|
|
||||||
button.setAttribute('aria-busy', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onSuccess = (response) => {
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Saved';
|
|
||||||
button.classList.add('success');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFailed = (response) => {
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Error';
|
|
||||||
button.classList.add('failed');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
let fd = new FormData(form);
|
|
||||||
let checkboxes = form.querySelectorAll('input[type="checkbox"]');
|
|
||||||
for (let checkbox of checkboxes) {
|
|
||||||
fd.append(checkbox.getAttribute('name'), checkbox.checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
let response = await fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
cache: 'no-cache',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: form2json(fd)
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
onSuccess(response);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
onFailed(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
onFailed(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupNetworkScanForm(formSelector, tableSelector) {
|
|
||||||
const form = document.querySelector(formSelector);
|
|
||||||
if (!form) {
|
|
||||||
console.error("form not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = form.action;
|
|
||||||
let button = form.querySelector('button[type="submit"]');
|
|
||||||
let defaultText;
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
defaultText = button.innerHTML;
|
|
||||||
}
|
|
||||||
|
|
||||||
const onSubmitFn = async (event) => {
|
|
||||||
if (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.innerHTML = 'Please wait...';
|
|
||||||
button.setAttribute('disabled', true);
|
|
||||||
button.setAttribute('aria-busy', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
let table = document.querySelector(tableSelector);
|
|
||||||
if (!table) {
|
|
||||||
console.error("table not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const onSuccess = async (response) => {
|
|
||||||
let result = await response.json();
|
|
||||||
console.log('networks: ', result);
|
|
||||||
|
|
||||||
let tbody = table.querySelector('tbody');
|
|
||||||
if (!tbody) {
|
|
||||||
tbody = table.createTBody();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (tbody.rows.length > 0) {
|
|
||||||
tbody.rows[0].remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < result.length; i++) {
|
|
||||||
let row = tbody.insertRow(-1);
|
|
||||||
row.classList.add("network");
|
|
||||||
row.setAttribute('data-ssid', result[i].hidden ? '' : result[i].ssid);
|
|
||||||
row.onclick = function () {
|
|
||||||
const input = document.querySelector('input.sta-ssid');
|
|
||||||
const ssid = this.getAttribute('data-ssid');
|
|
||||||
if (!input || !ssid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
input.value = ssid;
|
|
||||||
input.focus();
|
|
||||||
};
|
|
||||||
|
|
||||||
row.insertCell().textContent = "#" + (i + 1);
|
|
||||||
row.insertCell().innerHTML = result[i].hidden ? '<i>Hidden</i>' : result[i].ssid;
|
|
||||||
|
|
||||||
const signalCell = row.insertCell();
|
|
||||||
const signalElement = document.createElement("kbd");
|
|
||||||
signalElement.textContent = result[i].signalQuality + "%";
|
|
||||||
if (result[i].signalQuality > 60) {
|
|
||||||
signalElement.classList.add('greatSignal');
|
|
||||||
} else if (result[i].signalQuality > 40) {
|
|
||||||
signalElement.classList.add('normalSignal');
|
|
||||||
} else {
|
|
||||||
signalElement.classList.add('badSignal');
|
|
||||||
}
|
|
||||||
signalCell.appendChild(signalElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.innerHTML = defaultText;
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFailed = async (response) => {
|
|
||||||
table.classList.remove('hidden');
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.innerHTML = defaultText;
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let attempts = 6;
|
|
||||||
let attemptFn = async () => {
|
|
||||||
attempts--;
|
|
||||||
|
|
||||||
try {
|
|
||||||
let response = await fetch(url, { cache: 'no-cache' });
|
|
||||||
|
|
||||||
if (response.status == 200) {
|
|
||||||
await onSuccess(response);
|
|
||||||
|
|
||||||
} else if (attempts <= 0) {
|
|
||||||
await onFailed(response);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
setTimeout(attemptFn, 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
if (attempts <= 0) {
|
|
||||||
onFailed(err);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
setTimeout(attemptFn, 10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
attemptFn();
|
|
||||||
};
|
|
||||||
|
|
||||||
form.addEventListener('submit', onSubmitFn);
|
|
||||||
onSubmitFn();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupRestoreBackupForm(formSelector) {
|
|
||||||
const form = document.querySelector(formSelector);
|
|
||||||
if (!form) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = form.action;
|
|
||||||
let button = form.querySelector('button[type="submit"]');
|
|
||||||
let defaultText;
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
defaultText = button.textContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
form.addEventListener('submit', async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Please wait...';
|
|
||||||
button.setAttribute('disabled', true);
|
|
||||||
button.setAttribute('aria-busy', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onSuccess = (response) => {
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Restored';
|
|
||||||
button.classList.add('success');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFailed = (response) => {
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Error';
|
|
||||||
button.classList.add('failed');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const files = form.querySelector('#restore-file').files;
|
|
||||||
if (files.length <= 0) {
|
|
||||||
onFailed(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.readAsText(files[0]);
|
|
||||||
reader.onload = async function () {
|
|
||||||
try {
|
|
||||||
let response = await fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
cache: 'no-cache',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: reader.result
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
onSuccess(response);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
onFailed(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
onFailed(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
reader.onerror = function () {
|
|
||||||
console.log(reader.error);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupUpgradeForm(formSelector) {
|
|
||||||
const form = document.querySelector(formSelector);
|
|
||||||
if (!form) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = form.action;
|
|
||||||
let button = form.querySelector('button[type="submit"]');
|
|
||||||
let defaultText;
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
defaultText = button.textContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusToText = (status) => {
|
|
||||||
switch (status) {
|
|
||||||
case 0:
|
|
||||||
return "None";
|
|
||||||
case 1:
|
|
||||||
return "No file";
|
|
||||||
case 2:
|
|
||||||
return "Success";
|
|
||||||
case 3:
|
|
||||||
return "Prohibited";
|
|
||||||
case 4:
|
|
||||||
return "Aborted";
|
|
||||||
case 5:
|
|
||||||
return "Error on start";
|
|
||||||
case 6:
|
|
||||||
return "Error on write";
|
|
||||||
case 7:
|
|
||||||
return "Error on finish";
|
|
||||||
default:
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onResult = async (response) => {
|
|
||||||
if (!response) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
let resItem = form.querySelector('.upgrade-firmware-result');
|
|
||||||
if (resItem && result.firmware.status > 1) {
|
|
||||||
resItem.textContent = statusToText(result.firmware.status);
|
|
||||||
resItem.classList.remove('hidden');
|
|
||||||
|
|
||||||
if (result.firmware.status == 2) {
|
|
||||||
resItem.classList.remove('failed');
|
|
||||||
resItem.classList.add('success');
|
|
||||||
} else {
|
|
||||||
resItem.classList.remove('success');
|
|
||||||
resItem.classList.add('failed');
|
|
||||||
|
|
||||||
if (result.firmware.error != "") {
|
|
||||||
resItem.textContent += ": " + result.firmware.error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resItem = form.querySelector('.upgrade-filesystem-result');
|
|
||||||
if (resItem && result.filesystem.status > 1) {
|
|
||||||
resItem.textContent = statusToText(result.filesystem.status);
|
|
||||||
resItem.classList.remove('hidden');
|
|
||||||
|
|
||||||
if (result.filesystem.status == 2) {
|
|
||||||
resItem.classList.remove('failed');
|
|
||||||
resItem.classList.add('success');
|
|
||||||
} else {
|
|
||||||
resItem.classList.remove('success');
|
|
||||||
resItem.classList.add('failed');
|
|
||||||
|
|
||||||
if (result.filesystem.error != "") {
|
|
||||||
resItem.textContent += ": " + result.filesystem.error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSuccess = (response) => {
|
|
||||||
onResult(response);
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.textContent = defaultText;
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFailed = (response) => {
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Error';
|
|
||||||
button.classList.add('failed');
|
|
||||||
button.removeAttribute('aria-busy');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
button.removeAttribute('disabled');
|
|
||||||
button.classList.remove('success', 'failed');
|
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
form.addEventListener('submit', async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
button.textContent = 'Uploading...';
|
|
||||||
button.setAttribute('disabled', true);
|
|
||||||
button.setAttribute('aria-busy', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let fd = new FormData(form);
|
|
||||||
let response = await fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
cache: 'no-cache',
|
|
||||||
body: fd
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status >= 200 && response.status < 500) {
|
|
||||||
onSuccess(response);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
onFailed(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
onFailed(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadNetworkStatus() {
|
|
||||||
let response = await fetch('/api/network/status', { cache: 'no-cache' });
|
|
||||||
let result = await response.json();
|
|
||||||
|
|
||||||
setValue('.network-hostname', result.hostname);
|
|
||||||
setValue('.network-mac', result.mac);
|
|
||||||
setState('.network-connected', result.isConnected);
|
|
||||||
setValue('.network-ssid', result.ssid);
|
|
||||||
setValue('.network-signal', result.signalQuality);
|
|
||||||
setValue('.network-ip', result.ip);
|
|
||||||
setValue('.network-subnet', result.subnet);
|
|
||||||
setValue('.network-gateway', result.gateway);
|
|
||||||
setValue('.network-dns', result.dns);
|
|
||||||
|
|
||||||
setBusy('.main-busy', '.main-table', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadNetworkSettings() {
|
|
||||||
let response = await fetch('/api/network/settings', { cache: 'no-cache' });
|
|
||||||
let result = await response.json();
|
|
||||||
|
|
||||||
setInputValue('.network-hostname', result.hostname);
|
|
||||||
setCheckboxValue('.network-use-dhcp', result.useDhcp);
|
|
||||||
setInputValue('.network-static-ip', result.staticConfig.ip);
|
|
||||||
setInputValue('.network-static-gateway', result.staticConfig.gateway);
|
|
||||||
setInputValue('.network-static-subnet', result.staticConfig.subnet);
|
|
||||||
setInputValue('.network-static-dns', result.staticConfig.dns);
|
|
||||||
setBusy('#network-settings-busy', '#network-settings', false);
|
|
||||||
|
|
||||||
setInputValue('.sta-ssid', result.sta.ssid);
|
|
||||||
setInputValue('.sta-password', result.sta.password);
|
|
||||||
setInputValue('.sta-channel', result.sta.channel);
|
|
||||||
setBusy('#sta-settings-busy', '#sta-settings', false);
|
|
||||||
|
|
||||||
setInputValue('.ap-ssid', result.ap.ssid);
|
|
||||||
setInputValue('.ap-password', result.ap.password);
|
|
||||||
setInputValue('.ap-channel', result.ap.channel);
|
|
||||||
setBusy('#ap-settings-busy', '#ap-settings', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadSettings() {
|
|
||||||
let response = await fetch('/api/settings', { cache: 'no-cache' });
|
|
||||||
let result = await response.json();
|
|
||||||
|
|
||||||
setCheckboxValue('.system-debug', result.system.debug);
|
|
||||||
setCheckboxValue('.system-use-serial', result.system.useSerial);
|
|
||||||
setCheckboxValue('.system-use-telnet', result.system.useTelnet);
|
|
||||||
setBusy('#system-settings-busy', '#system-settings', false);
|
|
||||||
|
|
||||||
setCheckboxValue('.portal-use-auth', result.portal.useAuth);
|
|
||||||
setInputValue('.portal-login', result.portal.login);
|
|
||||||
setInputValue('.portal-password', result.portal.password);
|
|
||||||
setBusy('#portal-settings-busy', '#portal-settings', false);
|
|
||||||
|
|
||||||
setInputValue('.opentherm-in-gpio', result.opentherm.inGpio < 255 ? result.opentherm.inGpio : '');
|
|
||||||
setInputValue('.opentherm-out-gpio', result.opentherm.outGpio < 255 ? result.opentherm.outGpio : '');
|
|
||||||
setInputValue('.opentherm-member-id-code', result.opentherm.memberIdCode);
|
|
||||||
setCheckboxValue('.opentherm-dhw-present', result.opentherm.dhwPresent);
|
|
||||||
setCheckboxValue('.opentherm-sw-mode', result.opentherm.summerWinterMode);
|
|
||||||
setCheckboxValue('.opentherm-heating-ch2-enabled', result.opentherm.heatingCh2Enabled);
|
|
||||||
setCheckboxValue('.opentherm-heating-ch1-to-ch2', result.opentherm.heatingCh1ToCh2);
|
|
||||||
setCheckboxValue('.opentherm-dhw-to-ch2', result.opentherm.dhwToCh2);
|
|
||||||
setCheckboxValue('.opentherm-dhw-blocking', result.opentherm.dhwBlocking);
|
|
||||||
setCheckboxValue('.opentherm-sync-modulation-with-heating', result.opentherm.modulationSyncWithHeating);
|
|
||||||
setBusy('#opentherm-settings-busy', '#opentherm-settings', false);
|
|
||||||
|
|
||||||
setInputValue('.mqtt-server', result.mqtt.server);
|
|
||||||
setInputValue('.mqtt-port', result.mqtt.port);
|
|
||||||
setInputValue('.mqtt-user', result.mqtt.user);
|
|
||||||
setInputValue('.mqtt-password', result.mqtt.password);
|
|
||||||
setInputValue('.mqtt-prefix', result.mqtt.prefix);
|
|
||||||
setInputValue('.mqtt-interval', result.mqtt.interval);
|
|
||||||
setBusy('#mqtt-settings-busy', '#mqtt-settings', false);
|
|
||||||
|
|
||||||
setRadioValue('.outdoor-sensor-type', result.sensors.outdoor.type);
|
|
||||||
setInputValue('.outdoor-sensor-gpio', result.sensors.outdoor.gpio < 255 ? result.sensors.outdoor.gpio : '');
|
|
||||||
setInputValue('.outdoor-sensor-offset', result.sensors.outdoor.offset);
|
|
||||||
setBusy('#outdoor-sensor-settings-busy', '#outdoor-sensor-settings', false);
|
|
||||||
|
|
||||||
setRadioValue('.indoor-sensor-type', result.sensors.indoor.type);
|
|
||||||
setInputValue('.indoor-sensor-gpio', result.sensors.indoor.gpio < 255 ? result.sensors.indoor.gpio : '');
|
|
||||||
setInputValue('.indoor-sensor-offset', result.sensors.indoor.offset);
|
|
||||||
setInputValue('.indoor-sensor-ble-addresss', result.sensors.indoor.bleAddresss);
|
|
||||||
setBusy('#indoor-sensor-settings-busy', '#indoor-sensor-settings', false);
|
|
||||||
|
|
||||||
setCheckboxValue('.extpump-use', result.externalPump.use);
|
|
||||||
setInputValue('.extpump-gpio', result.externalPump.gpio < 255 ? result.externalPump.gpio : '');
|
|
||||||
setInputValue('.extpump-pc-time', result.externalPump.postCirculationTime);
|
|
||||||
setInputValue('.extpump-as-interval', result.externalPump.antiStuckInterval);
|
|
||||||
setInputValue('.extpump-as-time', result.externalPump.antiStuckTime);
|
|
||||||
setBusy('#extpump-settings-busy', '#extpump-settings', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadVars() {
|
|
||||||
let response = await fetch('/api/vars');
|
|
||||||
let result = await response.json();
|
|
||||||
|
|
||||||
setState('.ot-connected', result.states.otStatus);
|
|
||||||
setState('.ot-emergency', result.states.emergency);
|
|
||||||
setState('.ot-heating', result.states.heating);
|
|
||||||
setState('.ot-dhw', result.states.dhw);
|
|
||||||
setState('.ot-flame', result.states.flame);
|
|
||||||
setState('.ot-fault', result.states.fault);
|
|
||||||
setState('.ot-diagnostic', result.states.diagnostic);
|
|
||||||
setState('.ot-external-pump', result.states.externalPump);
|
|
||||||
|
|
||||||
setValue('.ot-modulation', result.sensors.modulation);
|
|
||||||
setValue('.ot-pressure', result.sensors.pressure);
|
|
||||||
setValue('.ot-dhw-flow-rate', result.sensors.dhwFlowRate);
|
|
||||||
setValue('.ot-fault-code', result.sensors.faultCode ? ("E" + result.sensors.faultCode) : "-");
|
|
||||||
|
|
||||||
setValue('.indoor-temp', result.temperatures.indoor);
|
|
||||||
setValue('.outdoor-temp', result.temperatures.outdoor);
|
|
||||||
setValue('.heating-temp', result.temperatures.heating);
|
|
||||||
setValue('.heating-setpoint-temp', result.parameters.heatingSetpoint);
|
|
||||||
setValue('.dhw-temp', result.temperatures.dhw);
|
|
||||||
|
|
||||||
setBusy('.ot-busy', '.ot-table', false);
|
|
||||||
|
|
||||||
setValue('.version', result.system.version);
|
|
||||||
setValue('.build-date', result.system.buildDate);
|
|
||||||
setValue('.uptime', result.system.uptime);
|
|
||||||
setValue('.uptime-days', Math.floor(result.system.uptime / 86400));
|
|
||||||
setValue('.uptime-hours', Math.floor(result.system.uptime % 86400 / 3600));
|
|
||||||
setValue('.uptime-min', Math.floor(result.system.uptime % 3600 / 60));
|
|
||||||
setValue('.uptime-sec', Math.floor(result.system.uptime % 60));
|
|
||||||
setValue('.total-heap', result.system.totalHeap);
|
|
||||||
setValue('.free-heap', result.system.freeHeap);
|
|
||||||
setValue('.min-free-heap', result.system.minFreeHeap);
|
|
||||||
setValue('.max-free-block-heap', result.system.maxFreeBlockHeap);
|
|
||||||
setValue('.min-max-free-block-heap', result.system.minMaxFreeBlockHeap);
|
|
||||||
setValue('.reset-reason', result.system.resetReason);
|
|
||||||
setState('.mqtt-connected', result.system.mqttConnected);
|
|
||||||
|
|
||||||
setBusy('.system-busy', '.system-table', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBusy(busySelector, contentSelector, value) {
|
|
||||||
let busy = document.querySelector(busySelector);
|
|
||||||
let content = document.querySelector(contentSelector);
|
|
||||||
if (!busy || !content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
busy.classList.add('hidden');
|
|
||||||
content.classList.remove('hidden');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
busy.classList.remove('hidden');
|
|
||||||
content.classList.add('hidden');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setState(selector, value) {
|
|
||||||
let item = document.querySelector(selector);
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setAttribute('aria-invalid', !value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setValue(selector, value) {
|
|
||||||
let item = document.querySelector(selector);
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.innerHTML = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCheckboxValue(selector, value) {
|
|
||||||
let item = document.querySelector(selector);
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.checked = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setRadioValue(selector, value) {
|
|
||||||
let items = document.querySelectorAll(selector);
|
|
||||||
if (!items.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let item of items) {
|
|
||||||
item.checked = item.value == value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setInputValue(selector, value) {
|
|
||||||
let item = document.querySelector(selector);
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function form2json(data) {
|
|
||||||
let method = function (object, pair) {
|
|
||||||
let keys = pair[0].replace(/\]/g, '').split('[');
|
|
||||||
let key = keys[0];
|
|
||||||
let value = pair[1];
|
|
||||||
if (value === 'true' || value === 'false') {
|
|
||||||
value = value === 'true';
|
|
||||||
} else if (typeof (value) === 'string' && value.trim() !== '' && !isNaN(value)) {
|
|
||||||
value = parseFloat(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keys.length > 1) {
|
|
||||||
let i, x, segment;
|
|
||||||
let last = value;
|
|
||||||
let type = isNaN(keys[1]) ? {} : [];
|
|
||||||
value = segment = object[key] || type;
|
|
||||||
|
|
||||||
for (i = 1; i < keys.length; i++) {
|
|
||||||
x = keys[i];
|
|
||||||
if (i == keys.length - 1) {
|
|
||||||
if (Array.isArray(segment)) {
|
|
||||||
segment.push(last);
|
|
||||||
} else {
|
|
||||||
segment[x] = last;
|
|
||||||
}
|
|
||||||
} else if (segment[x] == undefined) {
|
|
||||||
segment[x] = isNaN(keys[i + 1]) ? {} : [];
|
|
||||||
}
|
|
||||||
segment = segment[x];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object[key] = value;
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
let object = Array.from(data).reduce(method, {});
|
|
||||||
return JSON.stringify(object);
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,117 @@
|
|||||||
|
@media (min-width: 576px) {
|
||||||
|
article {
|
||||||
|
--pico-block-spacing-vertical: calc(var(--pico-spacing) * 0.75);
|
||||||
|
--pico-block-spacing-horizontal: calc(var(--pico-spacing) * 0.75);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
article {
|
||||||
|
--pico-block-spacing-vertical: var(--pico-spacing);
|
||||||
|
--pico-block-spacing-horizontal: var(--pico-spacing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1024px) {
|
||||||
|
article {
|
||||||
|
--pico-block-spacing-vertical: calc(var(--pico-spacing) * 1.25);
|
||||||
|
--pico-block-spacing-horizontal: calc(var(--pico-spacing) * 1.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1280px) {
|
||||||
|
article {
|
||||||
|
--pico-block-spacing-vertical: calc(var(--pico-spacing) * 1.5);
|
||||||
|
--pico-block-spacing-horizontal: calc(var(--pico-spacing) * 1.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1000px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1536px) {
|
||||||
|
article {
|
||||||
|
--pico-block-spacing-vertical: calc(var(--pico-spacing) * 1.75);
|
||||||
|
--pico-block-spacing-horizontal: calc(var(--pico-spacing) * 1.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1000px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header,
|
||||||
|
main,
|
||||||
|
footer {
|
||||||
|
padding-top: 1rem !important;
|
||||||
|
padding-bottom: 1rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
article {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*nav li a:has(> div.logo) {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}*/
|
||||||
|
nav li :where(a, [role=link]) {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
details>div {
|
||||||
|
padding: 0 var(--pico-form-element-spacing-horizontal);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:nth-last-child(1 of table tr:not(.hidden)) th,
|
||||||
|
:nth-last-child(1 of table tr:not(.hidden)) td {
|
||||||
|
border-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.success {
|
||||||
|
background-color: var(--pico-form-element-valid-border-color);
|
||||||
|
border-color: var(--pico-form-element-valid-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
button.failed {
|
||||||
|
background-color: var(--pico-form-element-invalid-border-color);
|
||||||
|
border-color: var(--pico-form-element-invalid-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary {
|
||||||
|
border: 0.25rem solid var(--pico-form-element-invalid-border-color);
|
||||||
|
padding: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
display: inline-block;
|
||||||
|
padding: calc(var(--pico-nav-link-spacing-vertical) - var(--pico-border-width) * 2) var(--pico-nav-link-spacing-horizontal);
|
||||||
|
vertical-align: baseline;
|
||||||
|
line-height: var(--pico-line-height);
|
||||||
|
background-color: var(--pico-code-kbd-background-color);
|
||||||
|
border-radius: var(--pico-border-radius);
|
||||||
|
color: var(--pico-code-kbd-color);
|
||||||
|
font-weight: bolder;
|
||||||
|
font-size: 1.3rem;
|
||||||
|
font-family: var(--pico-font-family-monospace);
|
||||||
|
}
|
||||||
|
|
||||||
|
.powered-by {
|
||||||
|
margin: 2rem 0 0 0;
|
||||||
|
text-align: center;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import shutil
|
|
||||||
import os
|
|
||||||
Import("env")
|
|
||||||
|
|
||||||
|
|
||||||
def post_build(source, target, env):
|
|
||||||
copy_to_build_dir({
|
|
||||||
source[0].get_abspath(): "firmware_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")),
|
|
||||||
env.subst("$BUILD_DIR/${PROGNAME}.factory.bin"): "firmware_%s_%s.factory.bin" % (env["PIOENV"], env.GetProjectOption("version")),
|
|
||||||
}, os.path.join(env["PROJECT_DIR"], "build"));
|
|
||||||
|
|
||||||
env.Execute("pio run --target buildfs --environment %s" % env["PIOENV"]);
|
|
||||||
|
|
||||||
|
|
||||||
def after_buildfs(source, target, env):
|
|
||||||
copy_to_build_dir({
|
|
||||||
source[0].get_abspath(): "filesystem_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")),
|
|
||||||
}, os.path.join(env["PROJECT_DIR"], "build"));
|
|
||||||
|
|
||||||
|
|
||||||
def copy_to_build_dir(files, build_dir):
|
|
||||||
if os.path.exists(build_dir) == False:
|
|
||||||
return
|
|
||||||
|
|
||||||
for src in files:
|
|
||||||
if os.path.exists(src):
|
|
||||||
dst = os.path.join(build_dir, files[src])
|
|
||||||
|
|
||||||
print("Copying '%s' to '%s'" % (src, dst))
|
|
||||||
shutil.copy(src, dst)
|
|
||||||
|
|
||||||
|
|
||||||
env.AddPostAction("buildprog", post_build)
|
|
||||||
env.AddPostAction("buildfs", after_buildfs)
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
# Source: https://raw.githubusercontent.com/letscontrolit/ESPEasy/mega/tools/pio/post_esp32.py
|
|
||||||
|
|
||||||
# Part of ESPEasy build toolchain.
|
|
||||||
#
|
|
||||||
# Combines separate bin files with their respective offsets into a single file
|
|
||||||
# This single file must then be flashed to an ESP32 node with 0 offset.
|
|
||||||
#
|
|
||||||
# Original implementation: Bartłomiej Zimoń (@uzi18)
|
|
||||||
# Maintainer: Gijs Noorlander (@TD-er)
|
|
||||||
#
|
|
||||||
# Special thanks to @Jason2866 (Tasmota) for helping debug flashing to >4MB flash
|
|
||||||
# Thanks @jesserockz (esphome) for adapting to use esptool.py with merge_bin
|
|
||||||
#
|
|
||||||
# Typical layout of the generated file:
|
|
||||||
# Offset | File
|
|
||||||
# - 0x1000 | ~\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader_dout_40m.bin
|
|
||||||
# - 0x8000 | ~\ESPEasy\.pio\build\<env name>\partitions.bin
|
|
||||||
# - 0xe000 | ~\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin
|
|
||||||
# - 0x10000 | ~\ESPEasy\.pio\build\<env name>/<built binary>.bin
|
|
||||||
|
|
||||||
Import("env")
|
|
||||||
|
|
||||||
platform = env.PioPlatform()
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from os.path import join
|
|
||||||
|
|
||||||
sys.path.append(join(platform.get_package_dir("tool-esptoolpy")))
|
|
||||||
import esptool
|
|
||||||
|
|
||||||
def esp32_create_combined_bin(source, target, env):
|
|
||||||
print("Generating combined binary for serial flashing")
|
|
||||||
|
|
||||||
# The offset from begin of the file where the app0 partition starts
|
|
||||||
# This is defined in the partition .csv file
|
|
||||||
app_offset = 0x10000
|
|
||||||
|
|
||||||
new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin")
|
|
||||||
sections = env.subst(env.get("FLASH_EXTRA_IMAGES"))
|
|
||||||
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
|
|
||||||
chip = env.get("BOARD_MCU")
|
|
||||||
flash_size = env.BoardConfig().get("upload.flash_size")
|
|
||||||
flash_freq = env.BoardConfig().get("build.f_flash", '40m')
|
|
||||||
flash_freq = flash_freq.replace('000000L', 'm')
|
|
||||||
flash_mode = env.BoardConfig().get("build.flash_mode", "dio")
|
|
||||||
memory_type = env.BoardConfig().get("build.arduino.memory_type", "qio_qspi")
|
|
||||||
if flash_mode == "qio" or flash_mode == "qout":
|
|
||||||
flash_mode = "dio"
|
|
||||||
if memory_type == "opi_opi" or memory_type == "opi_qspi":
|
|
||||||
flash_mode = "dout"
|
|
||||||
cmd = [
|
|
||||||
"--chip",
|
|
||||||
chip,
|
|
||||||
"merge_bin",
|
|
||||||
"-o",
|
|
||||||
new_file_name,
|
|
||||||
"--flash_mode",
|
|
||||||
flash_mode,
|
|
||||||
"--flash_freq",
|
|
||||||
flash_freq,
|
|
||||||
"--flash_size",
|
|
||||||
flash_size,
|
|
||||||
]
|
|
||||||
|
|
||||||
print(" Offset | File")
|
|
||||||
for section in sections:
|
|
||||||
sect_adr, sect_file = section.split(" ", 1)
|
|
||||||
print(f" - {sect_adr} | {sect_file}")
|
|
||||||
cmd += [sect_adr, sect_file]
|
|
||||||
|
|
||||||
print(f" - {hex(app_offset)} | {firmware_name}")
|
|
||||||
cmd += [hex(app_offset), firmware_name]
|
|
||||||
|
|
||||||
print('Using esptool.py arguments: %s' % ' '.join(cmd))
|
|
||||||
|
|
||||||
esptool.main(cmd)
|
|
||||||
|
|
||||||
|
|
||||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 1,
|
|
||||||
"editor": "wokwi",
|
|
||||||
"parts": [
|
|
||||||
{ "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": 0, "left": 0, "attrs": {} }
|
|
||||||
],
|
|
||||||
"connections": [
|
|
||||||
[ "esp:TX0", "$serialMonitor:RX", "", [] ],
|
|
||||||
[ "esp:RX0", "$serialMonitor:TX", "", [] ]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
[wokwi]
|
|
||||||
version = 1
|
|
||||||
elf = "../../.pio/build/nodemcu_32s/firmware.elf"
|
|
||||||
firmware = "../../.pio/build/nodemcu_32s/firmware.bin"
|
|
||||||
|
|
||||||
[[net.forward]]
|
|
||||||
from = "localhost:9080"
|
|
||||||
to = "target:80"
|
|
||||||