mirror of
https://github.com/arendst/Tasmota.git
synced 2026-07-28 04:15:53 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d96191888d | ||
|
|
fa0b7d7784 | ||
|
|
06d0c62dfa | ||
|
|
e0f759a318 | ||
|
|
963476e688 | ||
|
|
e9f4ca930a | ||
|
|
e1895cbeba | ||
|
|
ebee148be8 | ||
|
|
99c9b1671c | ||
|
|
5fdc5e890a | ||
|
|
700e51b091 | ||
|
|
1377b4b171 | ||
|
|
941deba815 | ||
|
|
7825bc0f0a | ||
|
|
13ed472eb9 | ||
|
|
2efb5cd1cd | ||
|
|
c0b1ceba8b | ||
|
|
1e78eae300 | ||
|
|
d28aaf0625 | ||
|
|
3fea292e16 | ||
|
|
05073b7ab7 | ||
|
|
5334b0393e | ||
|
|
5d2d248fce | ||
|
|
01830dd38a | ||
|
|
eed7d75291 | ||
|
|
42183e3bbc | ||
|
|
eab7250102 | ||
|
|
c88080b2bd | ||
|
|
48635f0906 | ||
|
|
a93cde09a6 | ||
|
|
25632ff7f8 | ||
|
|
24520bfcfa | ||
|
|
934d6e3f15 | ||
|
|
0a9ec10b0a | ||
|
|
22ef93a2c4 | ||
|
|
7e6b3a2bb1 | ||
|
|
88ec2c6a94 | ||
|
|
3a4210e0e2 | ||
|
|
dd44bdb471 | ||
|
|
2d8947d1c7 | ||
|
|
39a65e230b | ||
|
|
c768f7d610 | ||
|
|
ee883bdcb8 | ||
|
|
e914053041 | ||
|
|
2195ddd496 | ||
|
|
92958f4bdd | ||
|
|
b88ec7f5a9 | ||
|
|
d763fd52eb | ||
|
|
98d06e8809 | ||
|
|
0f103db4c6 | ||
|
|
9e2159c1c6 | ||
|
|
d8eda2ff13 | ||
|
|
e2468b58bc | ||
|
|
5aa8457a85 | ||
|
|
44b69bfd97 | ||
|
|
70ccdfe9b9 | ||
|
|
26d3a8c191 | ||
|
|
88648a8099 | ||
|
|
afc7b96b7c | ||
|
|
ec8b41903b | ||
|
|
ceb6fab51d | ||
|
|
f6f6616c9d | ||
|
|
3143b6e65e | ||
|
|
103c5606ac | ||
|
|
32c3a66ead | ||
|
|
bc9d44d74a | ||
|
|
09acb77277 | ||
|
|
7ce5b4cba5 | ||
|
|
77da1dfdc1 |
+5
-2
@@ -10,11 +10,14 @@ install:
|
||||
|
||||
script:
|
||||
- platformio run
|
||||
before_deploy:
|
||||
- for file in .pioenvs/*/firmware.bin; do cp $file ${file%/*}.bin; done
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: I5x8qJ5+229qJv5jSnNPGERQHl0NSKvrVHdpVzr/HOo2zeZ/Q5sMhHWo3IBD3AKjGdSlpyNApDwYTaGvenMe+xtUWSSxYIy2ptWAWfkpOtUMx3lI3brZJRt8s98xS5m972SC9mlNT2ZU+i6hZ6srYv2w4nDuyX+j7Q6IGqvYtabxUWzza/Zg0yNpPScvvzscW1CVhdEd5qYH6OKfBfuVOj3ZG4pCycvbejhkUJwbCQ5m8+DEXUol8BKeh92+TPC3jDHXWIStdgLIrmkZ3YWxMQBgQ41QIkaf6X1/0WYEcY0DFW6hlDzg2GbJ8tPRRPC9dfgMs3ZMKJkc7e4x7wMvG2QXQ0aO6e7xTMw41JZ/OrIit0JDHB1M8bWDPUhHwjiCht4W77n7KWFk9sIUDzOdMdd69BIMt5IohtkjnIT2dXekB4xiNvfPLYUa70aOuSHWi3HXVSE1R7RX0brmNf/mH1Pm91uun3UqtIwhrpD0gteQnc0EAlHoOJOazdn3cohrtmECZJo+f+EiqFfEHT2hBrHPEvWknNfxAyPS7jYWKQ7pTMk+y/BUkLyIQkimvNz41azA6sA75nnQrZ+ZJQa+KP2cEObMBs/ekzA45nds1UXpolI1W8QIOxJ/Y10C1yxr6V5a3WWg1H8EbF0HaqiyIeQx/UCz7gl62CbLEDui9PA=
|
||||
file: ".pioenvs/sonoff/firmware.bin"
|
||||
file_glob: true
|
||||
file: ".pioenvs/*.bin"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
tags: true
|
||||
+674
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -1,9 +1,15 @@
|
||||
## Sonoff-Tasmota
|
||||
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
|
||||
|
||||
Current version is **5.0.2** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
|
||||
Current version is **5.6.1** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
|
||||
|
||||
### **** ATTENTION Version 5.0.x specific information ****
|
||||
### ATTENTION All versions
|
||||
|
||||
Only Flash Mode DOUT is supported. Do not use Flash Mode DIO / QIO / QOUT as it might seem to brick your device.
|
||||
|
||||
See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips) for background information.
|
||||
|
||||
### ATTENTION Version 5 specific information
|
||||
|
||||
This version uses a new linker script to free flash memory for future code additions. It moves the settings from Spiffs to Eeprom. If you compile your own firmware download the new linker to your IDE or Platformio base folder. See [Wiki > Prerequisite](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite).
|
||||
|
||||
@@ -15,7 +21,7 @@ Best practice to implement is:
|
||||
|
||||
You should now have a device with 32k more code memory to play with.
|
||||
|
||||
### *********************************************************
|
||||
### Version Information
|
||||
|
||||
- This version provides all (Sonoff) modules in one file and starts up with Sonoff Basic.
|
||||
- Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```.
|
||||
@@ -34,11 +40,16 @@ The following devices are supported:
|
||||
- [iTead Sonoff Dual](http://sonoff.itead.cc/en/products/sonoff/sonoff-dual)
|
||||
- [iTead Sonoff Pow](http://sonoff.itead.cc/en/products/sonoff/sonoff-pow)
|
||||
- [iTead Sonoff 4CH](http://sonoff.itead.cc/en/products/sonoff/sonoff-4ch)
|
||||
- [iTead Sonoff 4CH Pro](http://sonoff.itead.cc/en/products/sonoff/sonoff-4ch-pro)
|
||||
- [iTead S20 Smart Socket](http://sonoff.itead.cc/en/products/residential/s20-socket)
|
||||
- [iTead Slampher](http://sonoff.itead.cc/en/products/residential/slampher-rf)
|
||||
- [iTead Sonoff Touch](http://sonoff.itead.cc/en/products/residential/sonoff-touch)
|
||||
- [iTead Sonoff T1](http://sonoff.itead.cc/en/products/residential/sonoff-t1)
|
||||
- [iTead Sonoff SC](http://sonoff.itead.cc/en/products/residential/sonoff-sc)
|
||||
- [iTead Sonoff Led](http://sonoff.itead.cc/en/products/appliances/sonoff-led)
|
||||
- [iTead Sonoff BN-SZ01 Ceiling Led](http://sonoff.itead.cc/en/products/appliances/bn-sz01)
|
||||
- [iTead Sonoff B1](http://sonoff.itead.cc/en/products/residential/sonoff-b1)
|
||||
- [iTead Sonoff RF Bridge 433](http://sonoff.itead.cc/en/products/appliances/sonoff-rf-bridge-433)
|
||||
- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html)
|
||||
- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html)
|
||||
- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -156,9 +156,6 @@ generic.menu.FlashSize.1M64.upload.maximum_size=958448
|
||||
generic.menu.FlashSize.1M0=1M (no SPIFFS)
|
||||
generic.menu.FlashSize.1M0.build.flash_size=1M
|
||||
generic.menu.FlashSize.1M0.build.flash_ld=eagle.flash.1m0.ld
|
||||
generic.menu.FlashSize.1M0.build.spiffs_start=0xFB000
|
||||
generic.menu.FlashSize.1M0.build.spiffs_end=0xFB000
|
||||
generic.menu.FlashSize.1M0.build.spiffs_blocksize=4096
|
||||
generic.menu.FlashSize.1M0.upload.maximum_size=1023984
|
||||
|
||||
generic.menu.FlashSize.2M=2M (1M SPIFFS)
|
||||
@@ -359,9 +356,6 @@ esp8285.menu.FlashSize.1M64.upload.maximum_size=958448
|
||||
esp8285.menu.FlashSize.1M0=1M (no SPIFFS)
|
||||
esp8285.menu.FlashSize.1M0.build.flash_size=1M
|
||||
esp8285.menu.FlashSize.1M0.build.flash_ld=eagle.flash.1m0.ld
|
||||
esp8285.menu.FlashSize.1M0.build.spiffs_start=0xFB000
|
||||
esp8285.menu.FlashSize.1M0.build.spiffs_end=0xFB000
|
||||
esp8285.menu.FlashSize.1M0.build.spiffs_blocksize=4096
|
||||
esp8285.menu.FlashSize.1M0.upload.maximum_size=1023984
|
||||
|
||||
##############################################################
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Flash Split for 1M chips */
|
||||
/* Flash Split for 1M chips, no SPIFFS */
|
||||
/* sketch 999KB */
|
||||
/* eeprom 20KB */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,131 @@
|
||||
|
||||
# ESP8266 platform
|
||||
# ------------------------------
|
||||
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=ESP8266 Modules
|
||||
version=2.4.0
|
||||
|
||||
|
||||
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
build.lwip_lib=-llwip_gcc
|
||||
build.lwip_flags=-DLWIP_OPEN_SRC
|
||||
|
||||
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
|
||||
compiler.sdk.path={runtime.platform.path}/tools/sdk
|
||||
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
|
||||
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/lwip/include" "-I{compiler.libc.path}/include" "-I{build.path}/core"
|
||||
|
||||
compiler.c.cmd=xtensa-lx106-elf-gcc
|
||||
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
|
||||
|
||||
compiler.S.cmd=xtensa-lx106-elf-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
|
||||
|
||||
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u call_user_start -u _printf_float -u _scanf_float -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
|
||||
|
||||
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
|
||||
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -laxtls -lespnow -lsmartconfig -lmesh -lwpa2 -lstdc++ -lm -lc -lgcc
|
||||
|
||||
compiler.cpp.cmd=xtensa-lx106-elf-g++
|
||||
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections
|
||||
|
||||
compiler.as.cmd=xtensa-lx106-elf-as
|
||||
|
||||
compiler.ar.cmd=xtensa-lx106-elf-ar
|
||||
compiler.ar.flags=cru
|
||||
|
||||
compiler.elf2hex.cmd=esptool
|
||||
compiler.elf2hex.flags=
|
||||
|
||||
compiler.size.cmd=xtensa-lx106-elf-size
|
||||
|
||||
compiler.esptool.cmd=esptool
|
||||
compiler.esptool.cmd.windows=esptool.exe
|
||||
|
||||
# This can be overriden in boards.txt
|
||||
build.extra_flags=-DESP8266
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.objcopy.eep.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
## generate file with git version number
|
||||
## needs bash, git, and echo
|
||||
|
||||
## windows-compatible version may be added later
|
||||
|
||||
|
||||
## Compile c files
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
|
||||
|
||||
## Create eeprom
|
||||
recipe.objcopy.eep.pattern=
|
||||
|
||||
## Create hex
|
||||
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
recipe.objcopy.hex.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.bin
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.bin
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
|
||||
#recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
|
||||
|
||||
# ------------------------------
|
||||
|
||||
tools.esptool.cmd=esptool
|
||||
tools.esptool.cmd.windows=esptool.exe
|
||||
tools.esptool.path={runtime.tools.esptool.path}
|
||||
tools.esptool.network_cmd=python
|
||||
tools.esptool.network_cmd.windows=python.exe
|
||||
|
||||
tools.esptool.upload.protocol=esp
|
||||
tools.esptool.upload.params.verbose=-vv
|
||||
tools.esptool.upload.params.quiet=
|
||||
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
|
||||
tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
|
||||
|
||||
tools.mkspiffs.cmd=mkspiffs
|
||||
tools.mkspiffs.cmd.windows=mkspiffs.exe
|
||||
tools.mkspiffs.path={runtime.tools.mkspiffs.path}
|
||||
|
||||
tools.espupload.cmd=python
|
||||
tools.espupload.cmd.windows=python.exe
|
||||
tools.espupload.path={runtime.platform.path}/tools
|
||||
|
||||
tools.espupload.upload.protocol=espupload
|
||||
tools.espupload.upload.params.verbose=
|
||||
tools.espupload.upload.params.quiet=
|
||||
tools.espupload.upload.pattern="{cmd}" "{path}/espupload.py" -f "{build.path}/{build.project_name}.bin"
|
||||
+26
-8
@@ -10,16 +10,34 @@
|
||||
[platformio]
|
||||
src_dir = sonoff
|
||||
|
||||
; Uncomment one of the lines below to build/upload only one environment
|
||||
;env_default = sonoff
|
||||
;env_default = sonoff-minimal
|
||||
;env_default = sonoff-ds18x20
|
||||
|
||||
; Sonoff et al
|
||||
[env:sonoff]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = esp01_1m
|
||||
|
||||
; Select one of two board_flash_mode options below
|
||||
; Sonoff Basic et al. (ESP8266 uses dio or qio)
|
||||
board_flash_mode = qio
|
||||
; Sonoff Touch and Sonoff 4CH (ESP8285 uses dout)
|
||||
; board_flash_mode = dout
|
||||
|
||||
board_flash_mode = dout
|
||||
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=512
|
||||
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON
|
||||
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON
|
||||
|
||||
; Sonoff minimal
|
||||
[env:sonoff-minimal] ; Placeholder to be configured
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = esp01_1m
|
||||
board_flash_mode = dout
|
||||
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=512 -DBE_MINIMAL
|
||||
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON
|
||||
|
||||
; Sonoff multiple DS18x20
|
||||
[env:sonoff-ds18x20]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = esp01_1m
|
||||
board_flash_mode = dout
|
||||
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=758 -DUSE_DS18x20 -DMESSZ=600
|
||||
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON, OneWire
|
||||
|
||||
+172
-1
@@ -1,4 +1,175 @@
|
||||
/* 5.0.2 20170503
|
||||
/* 5.6.1 20170818
|
||||
* Change module list order in webpage
|
||||
* Fix Sonoff T1 1CH and 2CH configuration (#751)
|
||||
*
|
||||
* 5.6.0 20170818
|
||||
* Fix Sonoff Pow intermittent exception 0
|
||||
* Change Sonoff Pow sending Domoticz telemetry data only
|
||||
* Add Ai-Thinker RGBW led (AiLight) (experimental)
|
||||
* Add NeoPixelBus library to Sonoff Led for Hue support
|
||||
* Add user configurable GPIO4 and GPIO5 to module Sonoff Bridge
|
||||
* Add Sonoff B1 RGBCW led support with command Color RRGGBBCCWW (#676)
|
||||
* Add command CT 152..500 to Sonoff Led and Sonoff B1 to control Color Temperature
|
||||
* Add Cold-Warm slider to web page for Sonoff Led and Sonoff B1
|
||||
* Add CT parameter to Hue
|
||||
* Add Sonoff T1 support (#582)
|
||||
* Add AnalogInput0 if configured as Analog Input to webpage (#697, #746)
|
||||
* Add command SetOption14 0|1 to enable interlock mode (#719, #721)
|
||||
* Fix Mitsubishi HVAC IR power controll (#740)
|
||||
*
|
||||
* 5.5.2 20170808
|
||||
* Extent max number of WS2812 pixels from 256 to 512 (#667)
|
||||
* Add OTA handling if server responds with no update available (#695)
|
||||
* Removed undocumented command FlashMode (#696)
|
||||
* Fix compile time error message due to increased message buffer size (#703)
|
||||
*
|
||||
* 5.5.1 20170805
|
||||
* Fix Sonoff Rf Bridge issues
|
||||
* Add Sonoff RF Bridge MQTT messages on received and learned RF signal
|
||||
* Add command VoltRes 0|1 to select voltage resolution to 0.1 V (#654)
|
||||
* Add averaging to Analog input (#686)
|
||||
* Add Energy tele data on Sonoff Pow Threshold change (#688)
|
||||
* Fix inconsistent property names in Messages (#690)
|
||||
*
|
||||
* 5.5.0 20170730
|
||||
* Reduce code space by removing the following commands as they are replaced by SetOption alternatives:
|
||||
* SaveState = SetOption0
|
||||
* ButtonRestrict = SetOption1
|
||||
* Units = SetOption2
|
||||
* MQTT = SetOption3
|
||||
* MQTTResponse = SetOption4
|
||||
* TempUnit = SetOption8
|
||||
* Smoothing WS2812 animation poll, invert fade speed and max allowed wakeup time down to 3000 seconds
|
||||
* Fix initial button press detection
|
||||
* Add support for Sonoff RF Bridge 433 using command RfKey
|
||||
* Fix regression from 5.0.7 by increasing message buffer size from 360 to 368 to accomodate 4 x DS18x20 sensors (#637)
|
||||
* Add GroupTopic to Topic test when using ButtonTopic/SwitchTopic to send either ON/OFF or TOGGLE (#642)
|
||||
* Adjust HLW calibration limits to accomodate HuaFan device and add commands HlwPSet, HlwUSet and HlwISet (#654)
|
||||
*
|
||||
* 5.4.0 20170725
|
||||
* Fix command reset regression introduced in 5.2.0
|
||||
* Increase polling from 0.1 second to 0.05 second
|
||||
* Add multipress to all buttons
|
||||
* Fix button 1 double press behaviour on multi relay devices
|
||||
* Add support for Hua Fan Smart Socket (#479)
|
||||
* Add support for Sonoff 4ch Pro (#565)
|
||||
* Add command SetOption13 1 to allow immediate action on single button press
|
||||
* (disables multipress, hold and unrestricted commands) (#587)
|
||||
*
|
||||
* 5.3.0 20170715
|
||||
* Major Hue rewrite which might introduce Alexa problems. If so, initiate an issue
|
||||
* Add support for Sonoff Led and BN-SZ01 Ceiling Led brightness control to Hue
|
||||
* Fix Sonoff Led Power, Dimmer and Color MQTT response (#176)
|
||||
* Add commands Delay and Backlog to allow multiple commands at once separated by ";" (#593)
|
||||
* Use default flashmode DOUT to solve restart hangs on esp8285 chips (#453, #598)
|
||||
* Change Web console column width from 99 to 300 (#599)
|
||||
*
|
||||
* 5.2.4 20170703
|
||||
* Removed flash mode update after selecting different module solving esp8285 related problems
|
||||
* Add device type flag to sonoff_template.ino
|
||||
* Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led (#567)
|
||||
*
|
||||
* 5.2.3 20170630
|
||||
* Change Sonoff Led color conversion code
|
||||
* Fix SetOption12 handling
|
||||
* Simplify auto configuration upgrade
|
||||
* Add option Upgrade <version_number> to only upgrade to any higher version (Old PR #213)
|
||||
* Change FallbackTopic to cmnd/<MQTTClient>/<command> <parameter> bypassing FullTopic and Prefix (#538)
|
||||
*
|
||||
* 5.2.2 20170625
|
||||
* Add configuration SaveAddress to Status 1 and Information Page
|
||||
* Change Sonoff Led Color conversion from AtoH to strtol
|
||||
* Fix possible wrong uploads due to configuration overwrites (#542)
|
||||
* Fix payload negative numbers (#547)
|
||||
*
|
||||
* 5.2.1 20170622
|
||||
* Fix Restore Configuration in case of lower version
|
||||
* Revert auto configuration upgrade allowing easy upgrade which was removed in version 5.2.0
|
||||
* Fix config auto upgrade from versions below version 4.1.1 (#530)
|
||||
*
|
||||
* 5.2.0 20170619
|
||||
* Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear
|
||||
* Fix command CounterDebounce by removing test for active GPIO (#524)
|
||||
* Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525)
|
||||
*
|
||||
* 5.1.7 20170616
|
||||
* Prep removal of SetOptions alternatives
|
||||
* Restore webpage upgrade error messages removed in 5.1.5
|
||||
* Add hold button functionality to buttons 2 to 4
|
||||
* Add command SetOption32 1..100 to set Key Hold Time from 0.1 seconds to 10 seconds (#200)
|
||||
* Allow slashes in Topic, GroupTopic, ButtonTopic and SwitchTopic (#507)
|
||||
* Changed webpage form actions from post to get and use relative path url (#434, #522)
|
||||
*
|
||||
* 5.1.6 20170606
|
||||
* Shrink code
|
||||
* Removed online configuration of Domoticz In and Domoticz Out MQTT strings
|
||||
* Removed commands DomoticzInTopic and DomoticzOutTopic
|
||||
* Add define KEY_HOLD_TIME to configure button hold threshold before sending MQTT Hold message
|
||||
* Add command StateText4 to configure button MQTT Hold text (= MQTT_CMND_HOLD)
|
||||
* Add command SetOption11 0|1 to swap pushbutton single and double press functionality (#200)
|
||||
* Add command SwitchMode<x> 5 (PUSHBUTTONHOLD) and 6 (PUSHBUTTONHOLD_INV) (#489)
|
||||
*
|
||||
* 5.1.5 20170604
|
||||
* Shrink code in preparation to ESP8266-Arduino 2.4.0-rc1
|
||||
* Add effect parameter to HUE Device (#464)
|
||||
*
|
||||
* 5.1.4 20170601
|
||||
* Removed pre-compiled versions from repository as they are available within the release
|
||||
* Changed HUE Device type to color supporting version (#464)
|
||||
* Fix compile error when BE_MINIMAL is selected (#467, #476)
|
||||
* Add multiple compiled versions to release using updated Travis script and platformio.ini (#467)
|
||||
*
|
||||
* 5.1.3 20170520
|
||||
* Add Domoticz Counter
|
||||
*
|
||||
* 5.1.2 20170519
|
||||
* Fix Counter/Timer JSON message and update Counter/Timer on webpage
|
||||
* Fix WS2812 Domoticz related regression issues
|
||||
*
|
||||
* 5.1.1 20170517
|
||||
* Allow command FullTopic in group mode
|
||||
* Prepare for more use of RTC memory
|
||||
* Add independant WS2812 led string power control (#386, #390)
|
||||
* Add command Counter<x> to control up to four GPIO falling edge interrupt counters or timers (#459)
|
||||
* Add command CounterType<x> to select between pulse counting or pulse timing
|
||||
* Add command CounterDebounce to select global counter debounce time in mSec
|
||||
*
|
||||
* 5.1.0 20170513
|
||||
* Fix Offline/Removal of retained topic when FullTopic is changed
|
||||
* Add FullTopic to MQTT Configuration and Information web pages
|
||||
* Add license model GPLv3 (#188)
|
||||
*
|
||||
* 5.0.7 20170511
|
||||
* Fix possible exception 28 on empty command
|
||||
* Add command SetOption0 as replacement for SaveState
|
||||
* Add command SetOption1 as replacement for ButtonRestrict
|
||||
* Add command SetOption2 as replacement for Units
|
||||
* Add command SetOption4 as replacement for MqttResponse
|
||||
* Add command SetOption8 as replacement for TempUnit
|
||||
* Add command SetOption10 On|Off to select between Offline or Removing previous retained topic (#417, #436)
|
||||
*
|
||||
* 5.0.6 20170510
|
||||
* Remove hyphen in case of a single DHT sensor connected (#427)
|
||||
* Add command MqttRetry <seconds> to change default MQTT reconnect retry timer from minimal 10 seconds (#429)
|
||||
*
|
||||
* 5.0.5 20170508
|
||||
* Add command FullTopic with tokens %topic% (replaced by command Topic value) and
|
||||
* %prefix% (replaced by command Prefix<x> values) for more flexible topic definitions (#244)
|
||||
* See wiki > MQTT Features https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features for more information
|
||||
*
|
||||
* 5.0.4 20170505
|
||||
* Add Sonoff Pow Energy Total up to 40 MWh
|
||||
* Add command EnergyReset 1|2|3 to reset Energy counters (#406)
|
||||
* Fix Domoticz Energy logging (#411)
|
||||
* Add command PowerOnState 4 to keep relay always on and disabling all power control (#418)
|
||||
*
|
||||
* 5.0.3 20170504
|
||||
* Add command SensorRetain on|off to enable retaining of mqtt message tele/sonoff/SENSOR (#74)
|
||||
* Change WifiConfig timeout from 60 seconds to 180 seconds (#212)
|
||||
* Change Sonoff Touch command Ledstate functionality by turning led on if power is off (#214)
|
||||
* Add 4 seconds delay after power on before enabling button to workaround Wemos D1 mini RTS circuit (#380)
|
||||
*
|
||||
* 5.0.2 20170503
|
||||
* Reset SaveData, SaveState and MqttResponse to default values due to rearranging settings
|
||||
* Moved some settings to flag area
|
||||
* Add command TempUnit Celsius|Fahrenheit for selecting Celsius or Fahrenheit (#347)
|
||||
|
||||
+82
-46
@@ -1,34 +1,54 @@
|
||||
/*********************************************************************************************\
|
||||
* Config settings
|
||||
\*********************************************************************************************/
|
||||
/*
|
||||
settings.h - setting variables for Sonoff-Tasmota
|
||||
|
||||
typedef struct {
|
||||
uint32_t savestate : 1;
|
||||
uint32_t button_restrict : 1;
|
||||
uint32_t value_units : 1;
|
||||
uint32_t mqtt_enabled : 1;
|
||||
uint32_t mqtt_response : 1;
|
||||
uint32_t mqtt_power_retain : 1;
|
||||
uint32_t mqtt_button_retain : 1;
|
||||
uint32_t mqtt_switch_retain : 1;
|
||||
uint32_t temperature_conversion : 1;
|
||||
uint32_t spare23 : 1;
|
||||
uint32_t spare22 : 1;
|
||||
uint32_t spare21 : 1;
|
||||
uint32_t spare20 : 1;
|
||||
uint32_t spare19 : 1;
|
||||
uint32_t spare18 : 1;
|
||||
uint32_t spare17 : 1;
|
||||
uint32_t spare16 : 1;
|
||||
uint32_t spare15 : 1;
|
||||
uint32_t spare14 : 1;
|
||||
uint32_t spare13 : 1;
|
||||
uint32_t spare12 : 1;
|
||||
uint32_t emulation : 2;
|
||||
uint32_t energy_resolution : 3;
|
||||
uint32_t pressure_resolution : 2;
|
||||
uint32_t humidity_resolution : 2;
|
||||
uint32_t temperature_resolution : 2;
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define PARAM8_SIZE 23 // Number of param bytes
|
||||
|
||||
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
||||
uint32_t data; // Allow bit manipulation using SetOption
|
||||
struct {
|
||||
uint32_t savestate : 1; // bit 0
|
||||
uint32_t button_restrict : 1; // bit 1
|
||||
uint32_t value_units : 1; // bit 2
|
||||
uint32_t mqtt_enabled : 1; // bit 3
|
||||
uint32_t mqtt_response : 1; // bit 4
|
||||
uint32_t mqtt_power_retain : 1;
|
||||
uint32_t mqtt_button_retain : 1;
|
||||
uint32_t mqtt_switch_retain : 1;
|
||||
uint32_t temperature_conversion : 1; // bit 8
|
||||
uint32_t mqtt_sensor_retain : 1;
|
||||
uint32_t mqtt_offline : 1; // bit 10
|
||||
uint32_t button_swap : 1; // bit 11 (v5.1.6)
|
||||
uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0)
|
||||
uint32_t button_single : 1; // bit 13 (v5.4.0)
|
||||
uint32_t interlock : 1; // bit 14 (v5.6.0)
|
||||
uint32_t spare15 : 1;
|
||||
uint32_t spare16 : 1;
|
||||
uint32_t spare17 : 1;
|
||||
uint32_t spare18 : 1;
|
||||
uint32_t spare19 : 1;
|
||||
uint32_t voltage_resolution : 1;
|
||||
uint32_t emulation : 2;
|
||||
uint32_t energy_resolution : 3;
|
||||
uint32_t pressure_resolution : 2;
|
||||
uint32_t humidity_resolution : 2;
|
||||
uint32_t temperature_resolution : 2;
|
||||
};
|
||||
} sysBitfield;
|
||||
|
||||
struct SYSCFG {
|
||||
@@ -36,15 +56,15 @@ struct SYSCFG {
|
||||
unsigned long saveFlag;
|
||||
unsigned long version;
|
||||
unsigned long bootcount;
|
||||
sysBitfield flag; // Add flag since 5.0.2
|
||||
sysBitfield flag; // Add flag since 5.0.2
|
||||
int16_t savedata;
|
||||
|
||||
int8_t timezone;
|
||||
char otaUrl[101];
|
||||
|
||||
char mqtt_prefix[3][11]; // was ex_friendlyname[33] until 3.2.5
|
||||
char mqtt_prefix[3][11]; // was ex_friendlyname[33] until 3.2.5
|
||||
|
||||
byte serial_enable; // Not used (ever)
|
||||
byte serial_enable; // Not used (ever)
|
||||
byte seriallog_level;
|
||||
uint8_t sta_config;
|
||||
byte sta_active;
|
||||
@@ -66,19 +86,19 @@ struct SYSCFG {
|
||||
char mqtt_topic[33];
|
||||
char button_topic[33];
|
||||
char mqtt_grptopic[33];
|
||||
char state_text[3][11]; // was ex_mqtt_subtopic[33] until 4.1.1
|
||||
byte ex_mqtt_button_retain; // Not used since 5.0.2
|
||||
byte ex_mqtt_power_retain; // Not used since 5.0.2
|
||||
byte ex_value_units; // Not used since 5.0.2
|
||||
byte ex_button_restrict; // Not used since 5.0.2
|
||||
char ex_state_text[3][11]; // was state_text until 5.1.6, was ex_mqtt_subtopic[33] until 4.1.1
|
||||
byte ex_mqtt_button_retain; // Not used since 5.0.2
|
||||
byte ex_mqtt_power_retain; // Not used since 5.0.2
|
||||
byte ex_value_units; // Not used since 5.0.2
|
||||
byte ex_button_restrict; // Not used since 5.0.2
|
||||
uint16_t tele_period;
|
||||
|
||||
uint8_t power;
|
||||
uint8_t ledstate;
|
||||
uint8_t ex_switchmode; // Not used since 3.9.21
|
||||
|
||||
char domoticz_in_topic[33];
|
||||
char domoticz_out_topic[33];
|
||||
uint8_t param[PARAM8_SIZE]; // was domoticz_in_topic until 5.1.6
|
||||
char state_text[4][11]; // was domoticz_out_topic until 5.1.6
|
||||
|
||||
uint16_t domoticz_update_timer;
|
||||
unsigned long domoticz_relay_idx[4];
|
||||
unsigned long domoticz_key_idx[4];
|
||||
@@ -105,7 +125,7 @@ struct SYSCFG {
|
||||
uint16_t hlw_mkwhs; // MaxEnergyStart
|
||||
|
||||
// 3.0.6
|
||||
uint16_t ex_pulsetime; // Not used since 4.0.4
|
||||
uint16_t mqtt_retry; // was ex_pulsetime until 4.0.4
|
||||
|
||||
// 3.1.1
|
||||
uint8_t poweronstate;
|
||||
@@ -132,8 +152,8 @@ struct SYSCFG {
|
||||
|
||||
// 3.2.8
|
||||
char switch_topic[33];
|
||||
byte ex_mqtt_switch_retain; // Not used since 5.0.2
|
||||
uint8_t ex_mqtt_enabled; // Not used since 5.0.2
|
||||
byte ex_mqtt_switch_retain; // Not used since 5.0.2
|
||||
uint8_t ex_mqtt_enabled; // Not used since 5.0.2
|
||||
|
||||
// 3.2.12
|
||||
uint8_t sleep;
|
||||
@@ -154,7 +174,7 @@ struct SYSCFG {
|
||||
uint16_t led_wakeup;
|
||||
|
||||
// 3.9.7
|
||||
uint8_t ex_emulation; // Not used since 5.0.2
|
||||
uint8_t ex_emulation; // Not used since 5.0.2
|
||||
|
||||
// 3.9.20
|
||||
char web_password[33];
|
||||
@@ -172,13 +192,29 @@ struct SYSCFG {
|
||||
// 4.0.9
|
||||
uint32_t ip_address[4];
|
||||
|
||||
// 5.0.4
|
||||
unsigned long hlw_kWhtotal;
|
||||
|
||||
// 5.0.4a
|
||||
char mqtt_fulltopic[101];
|
||||
|
||||
// 5.1.1
|
||||
unsigned long pCounter[MAX_COUNTERS];
|
||||
uint16_t pCounterType;
|
||||
uint16_t pCounterDebounce;
|
||||
|
||||
// 5.4.1
|
||||
uint8_t sfb_code[17][9];
|
||||
|
||||
} sysCfg;
|
||||
|
||||
struct RTCMEM {
|
||||
uint16_t valid;
|
||||
byte osw_flag;
|
||||
byte nu1;
|
||||
uint8_t power;
|
||||
unsigned long hlw_kWhtoday;
|
||||
unsigned long hlw_kWhtotal;
|
||||
unsigned long pCounter[MAX_COUNTERS];
|
||||
} rtcMem;
|
||||
|
||||
// See issue https://github.com/esp8266/Arduino/issues/2913
|
||||
|
||||
+180
-88
@@ -1,28 +1,24 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
settings.ino - user settings for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const uint8_t sfb_codeDefault[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
|
||||
|
||||
/*********************************************************************************************\
|
||||
* RTC memory
|
||||
\*********************************************************************************************/
|
||||
@@ -65,6 +61,12 @@ void RTC_Load()
|
||||
if (rtcMem.valid != RTC_MEM_VALID) {
|
||||
memset(&rtcMem, 0x00, sizeof(RTCMEM));
|
||||
rtcMem.valid = RTC_MEM_VALID;
|
||||
rtcMem.power = sysCfg.power;
|
||||
rtcMem.hlw_kWhtoday = sysCfg.hlw_kWhtoday;
|
||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
||||
for (byte i = 0; i < 4; i++) {
|
||||
rtcMem.pCounter[i] = sysCfg.pCounter[i];
|
||||
}
|
||||
RTC_Save();
|
||||
}
|
||||
_rtcHash = getRtcHash();
|
||||
@@ -129,54 +131,38 @@ extern "C" uint32_t _SPIFFS_end;
|
||||
|
||||
// Version 4.2 config = eeprom area
|
||||
#define CFG_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
|
||||
// Version 5.2 allow for more flash space
|
||||
#define CFG_ROTATES 8 // Number of flash sectors used (handles uploads)
|
||||
|
||||
uint32_t _cfgHash = 0;
|
||||
uint32_t _cfgLocation = CFG_LOCATION;
|
||||
|
||||
/********************************************************************************************/
|
||||
/*
|
||||
* Based on cores/esp8266/Updater.cpp
|
||||
*/
|
||||
void setFlashMode(byte option, byte mode)
|
||||
void setFlashModeDout()
|
||||
{
|
||||
char log[LOGSZ];
|
||||
uint8_t *_buffer;
|
||||
uint32_t address;
|
||||
|
||||
// option 0 - Use absolute address 0
|
||||
// option 1 - Use OTA/Upgrade relative address
|
||||
|
||||
if (option) {
|
||||
eboot_command ebcmd;
|
||||
eboot_command_read(&ebcmd);
|
||||
address = ebcmd.args[0];
|
||||
} else {
|
||||
address = 0;
|
||||
}
|
||||
eboot_command ebcmd;
|
||||
eboot_command_read(&ebcmd);
|
||||
address = ebcmd.args[0];
|
||||
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
|
||||
if (SPI_FLASH_RESULT_OK == spi_flash_read(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE)) {
|
||||
if (_buffer[2] != mode) {
|
||||
_buffer[2] = mode &3;
|
||||
if (_buffer[2] != 3) { // DOUT
|
||||
_buffer[2] = 3;
|
||||
noInterrupts();
|
||||
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(address / FLASH_SECTOR_SIZE)) {
|
||||
spi_flash_write(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE);
|
||||
}
|
||||
interrupts();
|
||||
snprintf_P(log, sizeof(log), PSTR("FLSH: Set Flash Mode to %d"), (option) ? mode : ESP.getFlashChipMode());
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
}
|
||||
delete[] _buffer;
|
||||
}
|
||||
|
||||
void setModuleFlashMode(byte option)
|
||||
{
|
||||
uint8_t mode = 0; // QIO - ESP8266
|
||||
if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
|
||||
mode = 3; // DOUT - ESP8285
|
||||
}
|
||||
setFlashMode(option, mode);
|
||||
}
|
||||
|
||||
uint32_t getHash()
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
@@ -192,18 +178,53 @@ uint32_t getHash()
|
||||
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
||||
\*********************************************************************************************/
|
||||
|
||||
void CFG_Save()
|
||||
uint32_t CFG_Address()
|
||||
{
|
||||
return _cfgLocation * SPI_FLASH_SEC_SIZE;
|
||||
}
|
||||
|
||||
void CFG_Save(byte rotate)
|
||||
{
|
||||
/* Save configuration in eeprom or one of 7 slots below
|
||||
*
|
||||
* rotate 0 = Save in next flash slot
|
||||
* rotate 1 = Save only in eeprom flash slot until SetOption12 0 or restart
|
||||
* rotate 2 = Save in eeprom flash slot, erase next flash slots and continue depending on stop_flash_rotate
|
||||
* stop_flash_rotate 0 = Allow flash slot rotation (SetOption12 0)
|
||||
* stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1)
|
||||
*/
|
||||
char log[LOGSZ];
|
||||
|
||||
#ifndef BE_MINIMAL
|
||||
if (getHash() != _cfgHash) {
|
||||
noInterrupts();
|
||||
if ((getHash() != _cfgHash) || rotate) {
|
||||
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
|
||||
stop_flash_rotate = 1;
|
||||
}
|
||||
if (2 == rotate) { // Use eeprom flash slot and erase next flash slots if stop_flash_rotate is off (default)
|
||||
_cfgLocation = CFG_LOCATION +1;
|
||||
}
|
||||
if (stop_flash_rotate) {
|
||||
_cfgLocation = CFG_LOCATION;
|
||||
} else {
|
||||
_cfgLocation--;
|
||||
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
|
||||
_cfgLocation = CFG_LOCATION;
|
||||
}
|
||||
}
|
||||
sysCfg.saveFlag++;
|
||||
spi_flash_erase_sector(CFG_LOCATION);
|
||||
spi_flash_write(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
noInterrupts();
|
||||
spi_flash_erase_sector(_cfgLocation);
|
||||
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
snprintf_P(log, sizeof(log), PSTR("Config: Saved configuration (%d bytes) to flash at %X and count %d"), sizeof(SYSCFG), CFG_LOCATION, sysCfg.saveFlag);
|
||||
if (!stop_flash_rotate && rotate) {
|
||||
for (byte i = 1; i < CFG_ROTATES; i++) {
|
||||
noInterrupts();
|
||||
spi_flash_erase_sector(_cfgLocation -i); // Delete previous configurations by resetting to 0xFF
|
||||
interrupts();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
snprintf_P(log, sizeof(log), PSTR("Cnfg: Save (%d bytes) to flash at %X and count %d"), sizeof(SYSCFG), _cfgLocation, sysCfg.saveFlag);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
_cfgHash = getHash();
|
||||
}
|
||||
@@ -213,6 +234,8 @@ void CFG_Save()
|
||||
|
||||
void CFG_Load()
|
||||
{
|
||||
/* Load configuration from eeprom or one of 7 slots below if first load does not stop_flash_rotate
|
||||
*/
|
||||
char log[LOGSZ];
|
||||
|
||||
struct SYSCFGH {
|
||||
@@ -220,29 +243,37 @@ void CFG_Load()
|
||||
unsigned long saveFlag;
|
||||
} _sysCfgH;
|
||||
|
||||
noInterrupts();
|
||||
spi_flash_read(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
snprintf_P(log, sizeof(log), PSTR("Config: Loaded configuration from flash at %X and count %d"), CFG_LOCATION, sysCfg.saveFlag);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
_cfgLocation = CFG_LOCATION +1;
|
||||
for (byte i = 0; i < CFG_ROTATES; i++) {
|
||||
_cfgLocation--;
|
||||
noInterrupts();
|
||||
spi_flash_read(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||
interrupts();
|
||||
|
||||
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
|
||||
// addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
if (((sysCfg.version > 0x05000200) && sysCfg.flag.stop_flash_rotate) || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
|
||||
break;
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
snprintf_P(log, sizeof(log), PSTR("Cnfg: Load from flash at %X and count %d"), _cfgLocation, sysCfg.saveFlag);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
||||
if ((sysCfg.version < 0x04020000) || (sysCfg.version > 0x06000000)) {
|
||||
noInterrupts();
|
||||
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
||||
CFG_Default();
|
||||
} else {
|
||||
sysCfg.saveFlag = 0;
|
||||
}
|
||||
} else {
|
||||
// Auto upgrade
|
||||
noInterrupts();
|
||||
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
if ((sysCfg.cfg_holder != CFG_HOLDER) || (sysCfg.version >= 0x04020000)) {
|
||||
CFG_Default();
|
||||
}
|
||||
}
|
||||
|
||||
_cfgHash = getHash();
|
||||
|
||||
RTC_Load();
|
||||
@@ -257,7 +288,7 @@ void CFG_Erase()
|
||||
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
|
||||
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
||||
|
||||
snprintf_P(log, sizeof(log), PSTR("Config: Erasing %d flash sectors"), _sectorEnd - _sectorStart);
|
||||
snprintf_P(log, sizeof(log), PSTR("Cnfg: Erase %d flash sectors"), _sectorEnd - _sectorStart);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
||||
@@ -277,7 +308,7 @@ void CFG_Erase()
|
||||
}
|
||||
}
|
||||
|
||||
void CFG_Dump(uint16_t srow, uint16_t mrow)
|
||||
void CFG_Dump(char* parms)
|
||||
{
|
||||
#define CFG_COLS 16
|
||||
|
||||
@@ -286,18 +317,25 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
|
||||
uint16_t maxrow;
|
||||
uint16_t row;
|
||||
uint16_t col;
|
||||
char *p;
|
||||
|
||||
uint8_t *buffer = (uint8_t *) &sysCfg;
|
||||
row = 0;
|
||||
maxrow = ((sizeof(SYSCFG)+CFG_COLS)/CFG_COLS);
|
||||
if ((srow > 0) && (srow < maxrow)) {
|
||||
row = srow;
|
||||
|
||||
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
||||
uint16_t mrow = strtol(p, &p, 10);
|
||||
|
||||
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
|
||||
// addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
if (0 == mrow) { // Default only 8 lines
|
||||
mrow = 8;
|
||||
}
|
||||
if (0 == mrow) { // Default only four lines
|
||||
mrow = 4;
|
||||
if (srow > maxrow) {
|
||||
srow = maxrow - mrow;
|
||||
}
|
||||
if ((mrow > 0) && (mrow < (maxrow - row))) {
|
||||
maxrow = row + mrow;
|
||||
if (mrow < (maxrow - srow)) {
|
||||
maxrow = srow + mrow;
|
||||
}
|
||||
|
||||
for (row = srow; row < maxrow; row++) {
|
||||
@@ -318,6 +356,7 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
|
||||
}
|
||||
snprintf_P(log, sizeof(log), PSTR("%s|"), log);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,10 +364,10 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
|
||||
|
||||
void CFG_Default()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_NONE, PSTR("Config: Use default configuration"));
|
||||
addLog_P(LOG_LEVEL_NONE, PSTR("Cnfg: Use defaults"));
|
||||
CFG_DefaultSet1();
|
||||
CFG_DefaultSet2();
|
||||
CFG_Save();
|
||||
CFG_Save(2);
|
||||
}
|
||||
|
||||
void CFG_DefaultSet1()
|
||||
@@ -386,8 +425,6 @@ void CFG_DefaultSet2()
|
||||
sysCfg.blinkcount = APP_BLINKCOUNT;
|
||||
sysCfg.sleep = APP_SLEEP;
|
||||
|
||||
strlcpy(sysCfg.domoticz_in_topic, DOMOTICZ_IN_TOPIC, sizeof(sysCfg.domoticz_in_topic));
|
||||
strlcpy(sysCfg.domoticz_out_topic, DOMOTICZ_OUT_TOPIC, sizeof(sysCfg.domoticz_out_topic));
|
||||
sysCfg.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
|
||||
for (byte i = 0; i < 4; i++) {
|
||||
sysCfg.switchmode[i] = SWITCH_MODE;
|
||||
@@ -443,11 +480,31 @@ void CFG_DefaultSet2()
|
||||
// 4.0.9
|
||||
CFG_DefaultSet_4_0_9();
|
||||
|
||||
// 4.1.1
|
||||
// 4.1.1 + 5.1.6
|
||||
CFG_DefaultSet_4_1_1();
|
||||
|
||||
// 5.0.2
|
||||
CFG_DefaultSet_5_0_2();
|
||||
|
||||
// 5.0.4
|
||||
// sysCfg.hlw_kWhtotal = 0;
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
|
||||
// 5.0.5
|
||||
strlcpy(sysCfg.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(sysCfg.mqtt_fulltopic));
|
||||
|
||||
// 5.0.6
|
||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
||||
|
||||
// 5.1.7
|
||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
|
||||
// 5.2.0
|
||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
|
||||
// 5.4.1
|
||||
memcpy_P(sysCfg.sfb_code[0], sfb_codeDefault, 9);
|
||||
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
@@ -508,7 +565,7 @@ void CFG_DefaultSet_4_0_4()
|
||||
}
|
||||
}
|
||||
}
|
||||
sysCfg.pulsetime[0] = sysCfg.ex_pulsetime;
|
||||
sysCfg.pulsetime[0] = APP_PULSETIME;
|
||||
for (byte i = 1; i < MAX_PULSETIMERS; i++) {
|
||||
sysCfg.pulsetime[i] = 0;
|
||||
}
|
||||
@@ -530,6 +587,7 @@ void CFG_DefaultSet_4_1_1()
|
||||
strlcpy(sysCfg.state_text[0], MQTT_STATUS_OFF, sizeof(sysCfg.state_text[0]));
|
||||
strlcpy(sysCfg.state_text[1], MQTT_STATUS_ON, sizeof(sysCfg.state_text[1]));
|
||||
strlcpy(sysCfg.state_text[2], MQTT_CMND_TOGGLE, sizeof(sysCfg.state_text[2]));
|
||||
strlcpy(sysCfg.state_text[3], MQTT_CMND_HOLD, sizeof(sysCfg.state_text[3])); // v5.1.6
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_5_0_2()
|
||||
@@ -546,9 +604,6 @@ void CFG_DefaultSet_5_0_2()
|
||||
void CFG_Delta()
|
||||
{
|
||||
if (sysCfg.version != VERSION) { // Fix version dependent changes
|
||||
if (sysCfg.version < 0x03000600) { // 3.0.6 - Add parameter
|
||||
sysCfg.ex_pulsetime = APP_PULSETIME;
|
||||
}
|
||||
if (sysCfg.version < 0x03010200) { // 3.1.2 - Add parameter
|
||||
sysCfg.poweronstate = APP_POWERON_STATE;
|
||||
}
|
||||
@@ -583,7 +638,7 @@ void CFG_Delta()
|
||||
strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password));
|
||||
}
|
||||
if (sysCfg.version < 0x03091500) {
|
||||
for (byte i = 0; i < 4; i++) sysCfg.switchmode[i] = sysCfg.ex_switchmode;
|
||||
for (byte i = 0; i < 4; i++) sysCfg.switchmode[i] = SWITCH_MODE;
|
||||
}
|
||||
if (sysCfg.version < 0x04000200) {
|
||||
sysCfg.ex_button_restrict = 0;
|
||||
@@ -622,8 +677,45 @@ void CFG_Delta()
|
||||
|
||||
sysCfg.savedata = SAVE_DATA;
|
||||
}
|
||||
|
||||
if (sysCfg.version < 0x05000400) {
|
||||
sysCfg.hlw_kWhtotal = 0;
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
}
|
||||
if (sysCfg.version < 0x05000500) {
|
||||
strlcpy(sysCfg.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(sysCfg.mqtt_fulltopic));
|
||||
}
|
||||
if (sysCfg.version < 0x05000600) {
|
||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
||||
}
|
||||
if (sysCfg.version < 0x05010100) {
|
||||
sysCfg.pCounterType = 0;
|
||||
sysCfg.pCounterDebounce = 0;
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
sysCfg.pCounter[i] = 0;
|
||||
rtcMem.pCounter[i] = 0;
|
||||
}
|
||||
}
|
||||
if (sysCfg.version < 0x05010600) {
|
||||
if (sysCfg.version > 0x04010100) {
|
||||
memcpy(sysCfg.state_text, sysCfg.ex_state_text, 33);
|
||||
}
|
||||
strlcpy(sysCfg.state_text[3], MQTT_CMND_HOLD, sizeof(sysCfg.state_text[3]));
|
||||
}
|
||||
if (sysCfg.version < 0x05010700) {
|
||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
}
|
||||
if (sysCfg.version < 0x05020000) {
|
||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
}
|
||||
if (sysCfg.version < 0x05050000) {
|
||||
for (byte i = 0; i < 17; i++) {
|
||||
sysCfg.sfb_code[i][0] = 0;
|
||||
}
|
||||
memcpy_P(sysCfg.sfb_code[0], sfb_codeDefault, 9);
|
||||
}
|
||||
|
||||
sysCfg.version = VERSION;
|
||||
CFG_Save(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+864
-504
File diff suppressed because it is too large
Load Diff
+202
-9
@@ -1,6 +1,21 @@
|
||||
/*********************************************************************************************\
|
||||
* Template parameters
|
||||
\*********************************************************************************************/
|
||||
/*
|
||||
sonoff_template.h - template settings for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// User selectable GPIO functionality
|
||||
enum upins_t {
|
||||
@@ -42,6 +57,10 @@ enum upins_t {
|
||||
GPIO_PWM3, // Red (swapped with Blue from original)
|
||||
GPIO_PWM4, // Green
|
||||
GPIO_PWM5, // Blue (swapped with Red from original)
|
||||
GPIO_CNTR1,
|
||||
GPIO_CNTR2,
|
||||
GPIO_CNTR3,
|
||||
GPIO_CNTR4,
|
||||
GPIO_SENSOR_END };
|
||||
|
||||
// Text in webpage Module Parameters and commands GPIOS and GPIO
|
||||
@@ -83,7 +102,11 @@ const char sensors[GPIO_SENSOR_END][9] PROGMEM = {
|
||||
"PWM2",
|
||||
"PWM3",
|
||||
"PWM4",
|
||||
"PWM5"
|
||||
"PWM5",
|
||||
"Counter1",
|
||||
"Counter2",
|
||||
"Counter3",
|
||||
"Counter4"
|
||||
};
|
||||
|
||||
// Programmer selectable GPIO functionality offset by user selectable GPIOs
|
||||
@@ -94,6 +117,8 @@ enum fpins_t {
|
||||
GPIO_HLW_CF1, // HLW8012 CF1 voltage / current (Sonoff Pow)
|
||||
GPIO_HLW_CF, // HLW8012 CF power (Sonoff Pow)
|
||||
GPIO_ADC0, // ADC
|
||||
GPIO_DI, // my92x1 PWM input
|
||||
GPIO_DCKI, // my92x1 CLK input
|
||||
GPIO_USER, // User configurable
|
||||
GPIO_MAX };
|
||||
|
||||
@@ -122,6 +147,15 @@ enum module_t {
|
||||
SONOFF_DEV,
|
||||
H801,
|
||||
SONOFF_SC,
|
||||
SONOFF_BN,
|
||||
SONOFF_4CHPRO,
|
||||
HUAFAN_SS,
|
||||
SONOFF_BRIDGE,
|
||||
SONOFF_B1,
|
||||
AILIGHT,
|
||||
SONOFF_T11,
|
||||
SONOFF_T12,
|
||||
SONOFF_T13,
|
||||
MAXMODULE };
|
||||
|
||||
/********************************************************************************************/
|
||||
@@ -137,6 +171,39 @@ typedef struct MYTMPLT {
|
||||
myio gp;
|
||||
} mytmplt;
|
||||
|
||||
const uint8_t nicelist[MAXMODULE] PROGMEM = {
|
||||
SONOFF_BASIC,
|
||||
SONOFF_RF,
|
||||
SONOFF_TH,
|
||||
SONOFF_DUAL,
|
||||
SONOFF_POW,
|
||||
SONOFF_4CH,
|
||||
SONOFF_4CHPRO,
|
||||
SONOFF_SV,
|
||||
SONOFF_DEV,
|
||||
S20,
|
||||
SLAMPHER,
|
||||
SONOFF_TOUCH,
|
||||
SONOFF_T11,
|
||||
SONOFF_T12,
|
||||
SONOFF_T13,
|
||||
SONOFF_SC,
|
||||
SONOFF_B1,
|
||||
SONOFF_LED,
|
||||
SONOFF_BN,
|
||||
SONOFF_BRIDGE,
|
||||
CH1,
|
||||
CH4,
|
||||
MOTOR,
|
||||
ELECTRODRAGON,
|
||||
EXS_RELAY,
|
||||
WION,
|
||||
H801,
|
||||
HUAFAN_SS,
|
||||
AILIGHT,
|
||||
WEMOS
|
||||
};
|
||||
|
||||
// Default module settings
|
||||
const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
|
||||
@@ -148,7 +215,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
0, // GPIO05
|
||||
0, // GPIO06 (SD_CLK Flash)
|
||||
0, // GPIO07 (SD_DATA0 Flash QIO/DIO/DOUT)
|
||||
0, // GPIO08 (SD_DATA1 Flash QIO/DIO)
|
||||
0, // GPIO08 (SD_DATA1 Flash QIO/DIO/DOUT)
|
||||
0, // GPIO09 (SD_DATA2 Flash QIO)
|
||||
0, // GPIO10 (SD_DATA3 Flash QIO)
|
||||
0, // GPIO11 (SD_CMD Flash)
|
||||
@@ -232,7 +299,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
0, 0, 0, // Flash connection
|
||||
GPIO_KEY2, // GPIO09 Button 2
|
||||
GPIO_KEY3, // GPIO10 Button 3
|
||||
0,
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Red Led and Relay 1 (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
GPIO_KEY4, // GPIO14 Button 4
|
||||
@@ -268,7 +335,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
0, 0,
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0, 0,
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
@@ -285,7 +353,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
GPIO_USER, // GPIO15 Optional sensor (PWM4 Blue)
|
||||
0, 0
|
||||
},
|
||||
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
|
||||
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266 and PSF-B01 - ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, // Flash connection
|
||||
@@ -293,7 +361,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{ "4 Channel", // 4 Channel Inching/Latching Relays
|
||||
{ "4 Channel", // 4 Channel Inching/Latching Relays (ESP8266)
|
||||
0,
|
||||
GPIO_TXD, // GPIO01 Relay control
|
||||
0,
|
||||
@@ -409,6 +477,131 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
0,
|
||||
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{ "Sonoff BN-SZ", // Sonoff BN-SZ01 Ceiling led (ESP8285)
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
GPIO_PWM1, // GPIO12 Light
|
||||
GPIO_LED1_INV, // GPIO13 Red Led (0 = On, 1 = Off)
|
||||
0, 0,
|
||||
0, 0
|
||||
},
|
||||
{ "Sonoff 4CH Pro", // Sonoff 4CH Pro (ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button 1
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
GPIO_USER, // GPIO02 Optional sensor
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
GPIO_REL3, // GPIO04 Sonoff 4CH Red Led and Relay 3 (0 = Off, 1 = On)
|
||||
GPIO_REL2, // GPIO05 Sonoff 4CH Red Led and Relay 2 (0 = Off, 1 = On)
|
||||
0, 0, 0, // Flash connection
|
||||
GPIO_KEY2, // GPIO09 Button 2
|
||||
GPIO_KEY3, // GPIO10 Button 3
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Red Led and Relay 1 (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
GPIO_KEY4, // GPIO14 Button 4
|
||||
GPIO_REL4, // GPIO15 Red Led and Relay 4 (0 = Off, 1 = On)
|
||||
0, 0
|
||||
},
|
||||
{ "Huafan SS", // Hua Fan Smart Socket (ESP8266) - like Sonoff Pow
|
||||
GPIO_LED1_INV, // GPIO0 Blue Led (0 = On, 1 = Off)
|
||||
0, 0,
|
||||
GPIO_LED2_INV, // GPIO3 Red Led (0 = On, 1 = Off)
|
||||
GPIO_KEY1, // GPIO4 Button
|
||||
GPIO_REL1_INV, // GPIO5 Relay (0 = On, 1 = Off)
|
||||
0, 0, 0, 0, 0, 0, // Flash connection
|
||||
GPIO_HLW_CF1, // GPIO12 HLW8012 CF1 voltage / current
|
||||
GPIO_HLW_SEL, // GPIO13 HLW8012 Sel output
|
||||
GPIO_HLW_CF, // GPIO14 HLW8012 CF power
|
||||
0, 0, 0
|
||||
},
|
||||
{ "Sonoff Bridge", // Sonoff RF Bridge 433 (ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button
|
||||
GPIO_TXD, // GPIO01 RF bridge control
|
||||
GPIO_USER, // GPIO02 Optional sensor
|
||||
GPIO_RXD, // GPIO03 RF bridge control
|
||||
GPIO_USER, // GPIO04 Optional sensor
|
||||
GPIO_USER, // GPIO05 Optional sensor
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
0,
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{ "Sonoff B1", // Sonoff B1 (ESP8285 - my9231)
|
||||
GPIO_KEY1, // GPIO00 Pad
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor pad
|
||||
GPIO_USER, // GPIO02 Optional sensor SDA pad
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor pad
|
||||
0, 0,
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
GPIO_DI, // GPIO12 my9231 DI
|
||||
0,
|
||||
GPIO_DCKI, // GPIO14 my9231 DCKI
|
||||
0, 0, 0
|
||||
},
|
||||
{ "AiLight", // Ai-Thinker RGBW led (ESP8266 - my9291)
|
||||
GPIO_KEY1, // GPIO00 Pad
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor pad
|
||||
GPIO_USER, // GPIO02 Optional sensor SDA pad
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor pad
|
||||
0, 0,
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
0,
|
||||
GPIO_DI, // GPIO13 my9291 DI
|
||||
0,
|
||||
GPIO_DCKI, // GPIO15 my9291 DCKI
|
||||
0, 0
|
||||
},
|
||||
{ "Sonoff T1 1CH", // Sonoff T1 1CH (ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button 1
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
0,
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
0, 0,
|
||||
0, 0, 0, // Flash connection
|
||||
0, 0,
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Blue Led and Relay 1 (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{ "Sonoff T1 2CH", // Sonoff T1 2CH (ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button 1
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
0,
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
0,
|
||||
GPIO_REL2, // GPIO05 Blue Led and Relay 2 (0 = Off, 1 = On)
|
||||
0, 0, 0, // Flash connection
|
||||
GPIO_KEY2, // GPIO09 Button 2
|
||||
0,
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Blue Led and Relay 1 (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
},
|
||||
{ "Sonoff T1 3CH", // Sonoff T1 3CH (ESP8285)
|
||||
GPIO_KEY1, // GPIO00 Button 1
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
0,
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
GPIO_REL3, // GPIO04 Blue Led and Relay 3 (0 = Off, 1 = On)
|
||||
GPIO_REL2, // GPIO05 Blue Led and Relay 2 (0 = Off, 1 = On)
|
||||
0, 0, 0, // Flash connection
|
||||
GPIO_KEY2, // GPIO09 Button 2
|
||||
GPIO_KEY3, // GPIO10 Button 3
|
||||
0, // Flash connection
|
||||
GPIO_REL1, // GPIO12 Blue Led and Relay 1 (0 = Off, 1 = On)
|
||||
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
|
||||
0, 0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
support.h - parameters used by platformio for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+121
-25
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
support.ino - support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const char JSON_SNS_TEMPHUM[] PROGMEM =
|
||||
@@ -172,12 +166,79 @@ boolean parseIP(uint32_t* addr, const char* str)
|
||||
return (3 == i);
|
||||
}
|
||||
|
||||
void mqttfy(byte option, char* str)
|
||||
{
|
||||
// option 0 = replace by underscore
|
||||
// option 1 = delete character
|
||||
uint16_t i = 0;
|
||||
while (str[i] > 0) {
|
||||
// if ((str[i] == '/') || (str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
||||
if ((str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
||||
if (option) {
|
||||
uint16_t j = i;
|
||||
while (str[j] > 0) {
|
||||
str[j] = str[j +1];
|
||||
j++;
|
||||
}
|
||||
i--;
|
||||
} else {
|
||||
str[i] = '_';
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to parse & check if version_str is newer than our currently installed version.
|
||||
bool newerVersion(char* version_str)
|
||||
{
|
||||
uint32_t version = 0;
|
||||
uint8_t i = 0;
|
||||
char *str_ptr;
|
||||
char* version_dup = strdup(version_str); // Duplicate the version_str as strtok_r will modify it.
|
||||
|
||||
if (!version_dup) {
|
||||
return false; // Bail if we can't duplicate. Assume bad.
|
||||
}
|
||||
// Loop through the version string, splitting on '.' seperators.
|
||||
for (char *str = strtok_r(version_dup, ".", &str_ptr); str && i < sizeof(VERSION); str = strtok_r(NULL, ".", &str_ptr), i++) {
|
||||
int field = atoi(str);
|
||||
// The fields in a version string can only range from 0-255.
|
||||
if ((field < 0) || (field > 255)) {
|
||||
free(version_dup);
|
||||
return false;
|
||||
}
|
||||
// Shuffle the accumulated bytes across, and add the new byte.
|
||||
version = (version << 8) + field;
|
||||
// Check alpha delimiter after 1.2.3 only
|
||||
if ((2 == i) && isalpha(str[strlen(str)-1])) {
|
||||
field = str[strlen(str)-1] & 0x1f;
|
||||
version = (version << 8) + field;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
free(version_dup); // We no longer need this.
|
||||
// A version string should have 2-4 fields. e.g. 1.2, 1.2.3, or 1.2.3a (= 1.2.3.1).
|
||||
// If not, then don't consider it a valid version string.
|
||||
if ((i < 2) || (i > sizeof(VERSION))) {
|
||||
return false;
|
||||
}
|
||||
// Keep shifting the parsed version until we hit the maximum number of tokens.
|
||||
// VERSION stores the major number of the version in the most significant byte of the uint32_t.
|
||||
while (i < sizeof(VERSION)) {
|
||||
version <<= 8;
|
||||
i++;
|
||||
}
|
||||
// Now we should have a fully constructed version number in uint32_t form.
|
||||
return (version > VERSION);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Wifi
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define WIFI_CONFIG_SEC 60 // seconds before restart
|
||||
#define WIFI_MANAGER_SEC 120 // seconds before restart
|
||||
#define WIFI_CONFIG_SEC 180 // seconds before restart
|
||||
#define WIFI_MANAGER_SEC 180 // seconds before restart
|
||||
#define WIFI_CHECK_SEC 20 // seconds
|
||||
#define WIFI_RETRY_SEC 30 // seconds
|
||||
|
||||
@@ -309,8 +370,8 @@ void WIFI_begin(uint8_t flag)
|
||||
#ifdef USE_EMULATION
|
||||
UDP_Disconnect();
|
||||
#endif // USE_EMULATION
|
||||
if (!strncmp(ESP.getSdkVersion(),"1.5.3",5)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, "Wifi: Patch issue 2186");
|
||||
if (!strncmp_P(ESP.getSdkVersion(),PSTR("1.5.3"),5)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("Wifi: Patch issue 2186"));
|
||||
WiFi.mode(WIFI_OFF); // See https://github.com/esp8266/Arduino/issues/2186
|
||||
}
|
||||
WiFi.disconnect();
|
||||
@@ -688,10 +749,11 @@ uint32_t dsttime = 0;
|
||||
uint32_t stdtime = 0;
|
||||
uint32_t ntptime = 0;
|
||||
uint32_t midnight = 1451602800;
|
||||
uint8_t midnightnow = 0;
|
||||
|
||||
String getBuildDateTime()
|
||||
{
|
||||
// "2017-03-07T11:08:02"
|
||||
// "2017-03-07T11:08:02" - ISO8601:2004
|
||||
char bdt[21];
|
||||
char *str;
|
||||
char *p;
|
||||
@@ -722,7 +784,7 @@ String getBuildDateTime()
|
||||
|
||||
String getDateTime()
|
||||
{
|
||||
// "2017-03-07T11:08:02"
|
||||
// "2017-03-07T11:08:02" - ISO8601:2004
|
||||
char dt[21];
|
||||
|
||||
snprintf_P(dt, sizeof(dt), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"),
|
||||
@@ -730,6 +792,20 @@ String getDateTime()
|
||||
return String(dt);
|
||||
}
|
||||
|
||||
String getUTCDateTime()
|
||||
{
|
||||
// "2017-03-07T11:08:02" - ISO8601:2004
|
||||
char dt[21];
|
||||
|
||||
TIME_T tmpTime;
|
||||
breakTime(utctime, tmpTime);
|
||||
tmpTime.Year += 1970;
|
||||
|
||||
snprintf_P(dt, sizeof(dt), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"),
|
||||
tmpTime.Year, tmpTime.Month, tmpTime.Day, tmpTime.Hour, tmpTime.Minute, tmpTime.Second);
|
||||
return String(dt);
|
||||
}
|
||||
|
||||
void breakTime(uint32_t timeInput, TIME_T &tm)
|
||||
{
|
||||
// break the given timeInput into time components
|
||||
@@ -873,6 +949,15 @@ uint32_t rtc_midnight()
|
||||
return midnight;
|
||||
}
|
||||
|
||||
boolean rtc_midnight_now()
|
||||
{
|
||||
boolean mnflg = midnightnow;
|
||||
if (mnflg) {
|
||||
midnightnow = 0;
|
||||
}
|
||||
return mnflg;
|
||||
}
|
||||
|
||||
void rtc_second()
|
||||
{
|
||||
char log[LOGSZ];
|
||||
@@ -925,6 +1010,7 @@ void rtc_second()
|
||||
breakTime(loctime, rtcTime);
|
||||
if (!rtcTime.Hour && !rtcTime.Minute && !rtcTime.Second && rtcTime.Valid) {
|
||||
midnight = loctime;
|
||||
midnightnow = 1;
|
||||
}
|
||||
rtcTime.Year += 1970;
|
||||
}
|
||||
@@ -961,6 +1047,16 @@ char tempUnit()
|
||||
return (sysCfg.flag.temperature_conversion) ? 'F' : 'C';
|
||||
}
|
||||
|
||||
uint16_t getAdc0()
|
||||
{
|
||||
uint16_t alr = 0;
|
||||
for (byte i = 0; i < 32; i++) {
|
||||
alr += analogRead(A0);
|
||||
delay(1);
|
||||
}
|
||||
return alr >> 5;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Syslog
|
||||
\*********************************************************************************************/
|
||||
|
||||
+43
-18
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
user_config.h - user specific configuration for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* User specific configuration parameters
|
||||
*
|
||||
* ATTENTION: Changes to most PARAMETER defines will only override flash settings if you change
|
||||
* define CFG_HOLDER.
|
||||
* Most parameters can be changed online using commands via MQTT, WebConsole or serial
|
||||
@@ -14,7 +31,7 @@
|
||||
|
||||
#define CFG_HOLDER 0x20161209 // [Reset 1] Change this value to load following default configuration parameters
|
||||
#define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds)
|
||||
#define SAVE_STATE 1 // [SaveState] Save changed power state to Flash (0 = disable, 1 = enable)
|
||||
#define SAVE_STATE 1 // [SetOption0] Save changed power state to Flash (0 = disable, 1 = enable)
|
||||
|
||||
// -- Wifi ----------------------------------------
|
||||
#define WIFI_IP_ADDRESS "0.0.0.0" // [IpAddress1] Set to 0.0.0.0 for using DHCP or IP address
|
||||
@@ -40,7 +57,7 @@
|
||||
#define OTA_URL "http://domus1:80/api/arduino/" PROJECT ".ino.bin" // [OtaUrl]
|
||||
|
||||
// -- MQTT ----------------------------------------
|
||||
#define MQTT_USE 1 // [Mqtt] Select default MQTT use (0 = Off, 1 = On)
|
||||
#define MQTT_USE 1 // [SetOption3] Select default MQTT use (0 = Off, 1 = On)
|
||||
// !!! TLS uses a LOT OF MEMORY (20k) so be careful to enable other options at the same time !!!
|
||||
//#define USE_MQTT_TLS // EXPERIMENTAL Use TLS for MQTT connection (+53k code, +20k mem) - Disable by //
|
||||
// Needs Fingerprint, TLS Port, UserId and Password
|
||||
@@ -57,14 +74,6 @@
|
||||
#define MQTT_PASS "DVES_PASS" // [MqttPassword] Optional password
|
||||
#endif
|
||||
|
||||
#define MQTT_CLIENT_ID "DVES_%06X" // [MqttClient] Also fall back topic using Chip Id = last 6 characters of MAC address
|
||||
|
||||
#define SUB_PREFIX "cmnd" // [Prefix1] Sonoff devices subscribe to:- SUB_PREFIX/MQTT_TOPIC and SUB_PREFIX/MQTT_GRPTOPIC
|
||||
#define PUB_PREFIX "stat" // [Prefix2] Sonoff devices publish to:- PUB_PREFIX/MQTT_TOPIC
|
||||
#define PUB_PREFIX2 "tele" // [Prefix3] Sonoff devices publish telemetry data to:- PUB_PREFIX2/MQTT_TOPIC/UPTIME, POWER/LIGHT and TIME
|
||||
// May be named the same as PUB_PREFIX
|
||||
#define MQTT_TOPIC PROJECT // [Topic] (unique) MQTT device topic
|
||||
#define MQTT_GRPTOPIC "sonoffs" // [GroupTopic] MQTT Group topic
|
||||
#define MQTT_BUTTON_RETAIN 0 // [ButtonRetain] Button may send retain flag (0 = off, 1 = on)
|
||||
#define MQTT_POWER_RETAIN 0 // [PowerRetain] Power status message may send retain flag (0 = off, 1 = on)
|
||||
#define MQTT_SWITCH_RETAIN 0 // [SwitchRetain] Switch may send retain flag (0 = off, 1 = on)
|
||||
@@ -72,14 +81,29 @@
|
||||
#define MQTT_STATUS_OFF "OFF" // [StateText1] Command or Status result when turned off (needs to be a string like "0" or "Off")
|
||||
#define MQTT_STATUS_ON "ON" // [StateText2] Command or Status result when turned on (needs to be a string like "1" or "On")
|
||||
#define MQTT_CMND_TOGGLE "TOGGLE" // [StateText3] Command to send when toggling (needs to be a string like "2" or "Toggle")
|
||||
#define MQTT_CMND_HOLD "HOLD" // [StateText4] Command to send when button is kept down for over KEY_HOLD_TIME * 0.1 seconds (needs to be a string like "HOLD")
|
||||
|
||||
// -- MQTT topics ---------------------------------
|
||||
//#define MQTT_FULLTOPIC "tasmota/bedroom/%topic%/%prefix%/" // Up to max 80 characers
|
||||
#define MQTT_FULLTOPIC "%prefix%/%topic%/" // [FullTopic] Subscribe and Publish full topic name - Legacy topic
|
||||
|
||||
// %prefix% token options
|
||||
#define SUB_PREFIX "cmnd" // [Prefix1] Sonoff devices subscribe to %prefix%/%topic% being SUB_PREFIX/MQTT_TOPIC and SUB_PREFIX/MQTT_GRPTOPIC
|
||||
#define PUB_PREFIX "stat" // [Prefix2] Sonoff devices publish to %prefix%/%topic% being PUB_PREFIX/MQTT_TOPIC
|
||||
#define PUB_PREFIX2 "tele" // [Prefix3] Sonoff devices publish telemetry data to %prefix%/%topic% being PUB_PREFIX2/MQTT_TOPIC/UPTIME, POWER and TIME
|
||||
// May be named the same as PUB_PREFIX
|
||||
// %topic% token options (also ButtonTopic and SwitchTopic)
|
||||
#define MQTT_TOPIC PROJECT // [Topic] (unique) MQTT device topic
|
||||
#define MQTT_GRPTOPIC "sonoffs" // [GroupTopic] MQTT Group topic
|
||||
#define MQTT_CLIENT_ID "DVES_%06X" // [MqttClient] Also fall back topic using Chip Id = last 6 characters of MAC address
|
||||
|
||||
// -- MQTT - Telemetry ----------------------------
|
||||
#define TELE_PERIOD 300 // [TelePeriod] Telemetry (0 = disable, 10 - 3600 seconds)
|
||||
|
||||
// -- MQTT - Domoticz -----------------------------
|
||||
#define USE_DOMOTICZ // Enable Domoticz (+7k code, +0.3k mem) - Disable by //
|
||||
#define DOMOTICZ_IN_TOPIC "domoticz/in" // [DomoticzInTopic]
|
||||
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // [DomoticzOutTopic]
|
||||
#define DOMOTICZ_IN_TOPIC "domoticz/in" // Domoticz Input Topic
|
||||
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // Domoticz Output Topic
|
||||
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional)
|
||||
|
||||
// -- HTTP ----------------------------------------
|
||||
@@ -117,10 +141,11 @@
|
||||
#define APP_BLINKCOUNT 10 // [BlinkCount] Number of blinks (0 = 32000)
|
||||
#define APP_SLEEP 0 // [Sleep] Sleep time to lower energy consumption (0 = Off, 1 - 250 mSec)
|
||||
|
||||
#define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON or PUSHBUTTON_INV (the wall switch state)
|
||||
#define KEY_HOLD_TIME 40 // [SetOption32] Number of 0.1 seconds to hold Button or external Pushbutton before sending HOLD message
|
||||
#define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD or PUSHBUTTONHOLD_INV (the wall switch state)
|
||||
#define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with
|
||||
|
||||
#define TEMP_CONVERSION 0 // [TempUnit] Return temperature in (0 = Celsius or 1 = Fahrenheit)
|
||||
#define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit)
|
||||
#define TEMP_RESOLUTION 1 // [TempRes] Maximum number of decimals (0 - 3) showing sensor Temperature
|
||||
#define HUMIDITY_RESOLUTION 1 // [HumRes] Maximum number of decimals (0 - 3) showing sensor Humidity
|
||||
#define PRESSURE_RESOLUTION 1 // [PressRes] Maximum number of decimals (0 - 3) showing sensor Pressure
|
||||
@@ -140,9 +165,9 @@
|
||||
#define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+3k code, 0.3k mem)
|
||||
// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code)
|
||||
|
||||
#define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+8k code, +1k mem) - Disable by //
|
||||
#define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+11k code, +1k mem) - Disable by //
|
||||
#define USE_WS2812_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB)
|
||||
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial TXD) (+1k mem)
|
||||
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem)
|
||||
// When USE_WS2812_DMA is enabled expect Exceptions on Pow
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
user_config_override.h - user configuration overrides user_config.h for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*****************************************************************************************************\
|
||||
* User specific configuration parameters to override user_config.h
|
||||
*
|
||||
* ATTENTION: - Changes to most PARAMETER defines will only override flash settings if you change
|
||||
* define CFG_HOLDER.
|
||||
* - Expect compiler warnings when no ifdef/undef/endif sequence is used.
|
||||
|
||||
+263
-231
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
webserver.ino - webserver for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
@@ -28,7 +22,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
* Web server and WiFi Manager
|
||||
*
|
||||
* Enables configuration and reconfiguration of WiFi credentials using a Captive Portal
|
||||
* Source by AlexT (https://github.com/tzapu)
|
||||
* Based on source by AlexT (https://github.com/tzapu)
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
@@ -76,6 +70,9 @@ const char HTTP_HEAD[] PROGMEM =
|
||||
"function lb(p){"
|
||||
"la('?d='+p);"
|
||||
"}"
|
||||
"function lc(p){"
|
||||
"la('?t='+p);"
|
||||
"}"
|
||||
"</script>"
|
||||
|
||||
"<style>"
|
||||
@@ -87,11 +84,13 @@ const char HTTP_HEAD[] PROGMEM =
|
||||
"td{padding:0px;}"
|
||||
"button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;-webkit-transition-duration:0.4s;transition-duration:0.4s;}"
|
||||
"button:hover{background-color:#006cba;}"
|
||||
".p{float:left;text-align:left;}"
|
||||
".q{float:right;text-align:right;}"
|
||||
"</style>"
|
||||
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<div style='text-align:left;display:inline-block;min-width:320px;'>"
|
||||
"<div style='text-align:left;display:inline-block;min-width:340px;'>"
|
||||
"<div style='text-align:center;'><h3>{ha} Module</h3><h2>{h}</h2></div>";
|
||||
const char HTTP_SCRIPT_CONSOL[] PROGMEM =
|
||||
"var sn=0;" // Scroll position
|
||||
@@ -137,50 +136,44 @@ const char HTTP_SCRIPT_MODULE[] PROGMEM =
|
||||
"}"
|
||||
"function sl(){"
|
||||
"var o0=\"";
|
||||
const char HTTP_LNK_STYLE[] PROGMEM =
|
||||
".q{float:right;width:64px;text-align:right;}"
|
||||
".l{background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6O"
|
||||
"Sk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eA"
|
||||
"XvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==') no-repeat left center;background-size:1em;}"
|
||||
"</style>";
|
||||
const char HTTP_MSG_RSTRT[] PROGMEM =
|
||||
"<br/><div style='text-align:center;'>Device will restart in a few seconds</div><br/>";
|
||||
const char HTTP_BTN_MENU1[] PROGMEM =
|
||||
"<br/><form action='/cn' method='post'><button>Configuration</button></form>"
|
||||
"<br/><form action='/in' method='post'><button>Information</button></form>"
|
||||
"<br/><form action='/up' method='post'><button>Firmware upgrade</button></form>"
|
||||
"<br/><form action='/cs' method='post'><button>Console</button></form>";
|
||||
"<br/><form action='cn' method='get'><button>Configuration</button></form>"
|
||||
"<br/><form action='in' method='get'><button>Information</button></form>"
|
||||
"<br/><form action='up' method='get'><button>Firmware upgrade</button></form>"
|
||||
"<br/><form action='cs' method='get'><button>Console</button></form>";
|
||||
const char HTTP_BTN_RSTRT[] PROGMEM =
|
||||
"<br/><form action='/rb' method='post' onsubmit='return confirm(\"Confirm Restart\");'><button>Restart</button></form>";
|
||||
"<br/><form action='rb' method='get' onsubmit='return confirm(\"Confirm Restart\");'><button>Restart</button></form>";
|
||||
const char HTTP_BTN_MENU2[] PROGMEM =
|
||||
"<br/><form action='/md' method='post'><button>Configure Module</button></form>"
|
||||
"<br/><form action='/w0' method='post'><button>Configure WiFi</button></form>";
|
||||
"<br/><form action='md' method='get'><button>Configure Module</button></form>"
|
||||
"<br/><form action='w0' method='get'><button>Configure WiFi</button></form>";
|
||||
const char HTTP_BTN_MENU3[] PROGMEM =
|
||||
"<br/><form action='/mq' method='post'><button>Configure MQTT</button></form>"
|
||||
"<br/><form action='mq' method='get'><button>Configure MQTT</button></form>"
|
||||
#ifdef USE_DOMOTICZ
|
||||
"<br/><form action='/dm' method='post'><button>Configure Domoticz</button></form>"
|
||||
"<br/><form action='dm' method='get'><button>Configure Domoticz</button></form>"
|
||||
#endif // USE_DOMOTICZ
|
||||
"";
|
||||
const char HTTP_BTN_MENU4[] PROGMEM =
|
||||
"<br/><form action='/lg' method='post'><button>Configure Logging</button></form>"
|
||||
"<br/><form action='/co' method='post'><button>Configure Other</button></form>"
|
||||
"<br/><form action='/rt' method='post' onsubmit='return confirm(\"Confirm Reset Configuration\");'><button>Reset Configuration</button></form>"
|
||||
"<br/><form action='/dl' method='post'><button>Backup Configuration</button></form>"
|
||||
"<br/><form action='/rs' method='post'><button>Restore Configuration</button></form>";
|
||||
"<br/><form action='lg' method='get'><button>Configure Logging</button></form>"
|
||||
"<br/><form action='co' method='get'><button>Configure Other</button></form>"
|
||||
"<br/><form action='rt' method='get' onsubmit='return confirm(\"Confirm Reset Configuration\");'><button>Reset Configuration</button></form>"
|
||||
"<br/><form action='dl' method='get'><button>Backup Configuration</button></form>"
|
||||
"<br/><form action='rs' method='get'><button>Restore Configuration</button></form>";
|
||||
const char HTTP_BTN_MAIN[] PROGMEM =
|
||||
"<br/><br/><form action='/' method='post'><button>Main menu</button></form>";
|
||||
"<br/><br/><form action='.' method='get'><button>Main menu</button></form>";
|
||||
const char HTTP_BTN_CONF[] PROGMEM =
|
||||
"<br/><br/><form action='/cn' method='post'><button>Configuration menu</button></form>";
|
||||
"<br/><br/><form action='cn' method='get'><button>Configuration menu</button></form>";
|
||||
const char HTTP_FORM_MODULE[] PROGMEM =
|
||||
"<fieldset><legend><b> Module parameters </b></legend><form method='post' action='sv'>"
|
||||
"<fieldset><legend><b> Module parameters </b></legend><form method='get' action='sv'>"
|
||||
"<input id='w' name='w' value='6' hidden><input id='r' name='r' value='1' hidden>"
|
||||
"<br/><b>Module type</b> ({mt})<br/><select id='mt' name='mt'>";
|
||||
const char HTTP_LNK_ITEM[] PROGMEM =
|
||||
"<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
||||
"<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q'>{i} {r}%</span></div>";
|
||||
const char HTTP_LNK_SCAN[] PROGMEM =
|
||||
"<div><a href='/w1'>Scan for wifi networks</a></div><br/>";
|
||||
const char HTTP_FORM_WIFI[] PROGMEM =
|
||||
"<fieldset><legend><b> Wifi parameters </b></legend><form method='post' action='sv'>"
|
||||
"<fieldset><legend><b> Wifi parameters </b></legend><form method='get' action='sv'>"
|
||||
"<input id='w' name='w' value='1' hidden><input id='r' name='r' value='1' hidden>"
|
||||
"<br/><b>AP1 SSId</b> (" STA_SSID1 ")<br/><input id='s1' name='s1' length=32 placeholder='" STA_SSID1 "' value='{s1}'><br/>"
|
||||
"<br/><b>AP1 Password</b></br><input id='p1' name='p1' length=64 type='password' placeholder='" STA_PASS1 "' value='{p1}'><br/>"
|
||||
@@ -188,16 +181,17 @@ const char HTTP_FORM_WIFI[] PROGMEM =
|
||||
"<br/><b>AP2 Password</b></br><input id='p2' name='p2' length=64 type='password' placeholder='" STA_PASS2 "' value='{p2}'><br/>"
|
||||
"<br/><b>Hostname</b> (" WIFI_HOSTNAME ")<br/><input id='h' name='h' length=32 placeholder='" WIFI_HOSTNAME" ' value='{h1}'><br/>";
|
||||
const char HTTP_FORM_MQTT[] PROGMEM =
|
||||
"<fieldset><legend><b> MQTT parameters </b></legend><form method='post' action='sv'>"
|
||||
"<fieldset><legend><b> MQTT parameters </b></legend><form method='get' action='sv'>"
|
||||
"<input id='w' name='w' value='2' hidden><input id='r' name='r' value='1' hidden>"
|
||||
"<br/><b>Host</b> (" MQTT_HOST ")<br/><input id='mh' name='mh' length=32 placeholder='" MQTT_HOST" ' value='{m1}'><br/>"
|
||||
"<br/><b>Port</b> (" STR(MQTT_PORT) ")<br/><input id='ml' name='ml' length=5 placeholder='" STR(MQTT_PORT) "' value='{m2}'><br/>"
|
||||
"<br/><b>Client Id</b> ({m0})<br/><input id='mc' name='mc' length=32 placeholder='" MQTT_CLIENT_ID "' value='{m3}'><br/>"
|
||||
"<br/><b>User</b> (" MQTT_USER ")<br/><input id='mu' name='mu' length=32 placeholder='" MQTT_USER "' value='{m4}'><br/>"
|
||||
"<br/><b>Password</b><br/><input id='mp' name='mp' length=32 type='password' placeholder='" MQTT_PASS "' value='{m5}'><br/>"
|
||||
"<br/><b>Topic</b> (" MQTT_TOPIC ")<br/><input id='mt' name='mt' length=32 placeholder='" MQTT_TOPIC" ' value='{m6}'><br/>";
|
||||
"<br/><b>Topic</b> = %topic% (" MQTT_TOPIC ")<br/><input id='mt' name='mt' length=32 placeholder='" MQTT_TOPIC" ' value='{m6}'><br/>"
|
||||
"<br/><b>Full Topic</b> (" MQTT_FULLTOPIC ")<br/><input id='mf' name='mf' length=80 placeholder='" MQTT_FULLTOPIC" ' value='{m7}'><br/>";
|
||||
const char HTTP_FORM_LOG1[] PROGMEM =
|
||||
"<fieldset><legend><b> Logging parameters </b></legend><form method='post' action='sv'>"
|
||||
"<fieldset><legend><b> Logging parameters </b></legend><form method='get' action='sv'>"
|
||||
"<input id='w' name='w' value='3' hidden><input id='r' name='r' value='0' hidden>";
|
||||
const char HTTP_FORM_LOG2[] PROGMEM =
|
||||
"<br/><b>{b0}log level</b> ({b1})<br/><select id='{b2}' name='{b2}'>"
|
||||
@@ -212,47 +206,40 @@ const char HTTP_FORM_LOG3[] PROGMEM =
|
||||
"<br/><b>Syslog port</b> (" STR(SYS_LOG_PORT) ")<br/><input id='lp' name='lp' length=5 placeholder='" STR(SYS_LOG_PORT) "' value='{l3}'><br/>"
|
||||
"<br/><b>Telemetric period</b> (" STR(TELE_PERIOD) ")<br/><input id='lt' name='lt' length=4 placeholder='" STR(TELE_PERIOD) "' value='{l4}'><br/>";
|
||||
const char HTTP_FORM_OTHER[] PROGMEM =
|
||||
"<fieldset><legend><b> Other parameters </b></legend><form method='post' action='sv'>"
|
||||
"<fieldset><legend><b> Other parameters </b></legend><form method='get' action='sv'>"
|
||||
"<input id='w' name='w' value='5' hidden><input id='r' name='r' value='1' hidden>"
|
||||
"<br/><b>Web Admin Password</b><br/><input id='p1' name='p1' length=32 type='password' placeholder='" WEB_PASSWORD "' value='{p1}'><br/>"
|
||||
"<br/><input style='width:10%;float:left' id='b1' name='b1' type='checkbox'{r1}><b>MQTT enable</b><br/>";
|
||||
const char HTTP_FORM_OTHER2[] PROGMEM =
|
||||
"<br/><b>Friendly Name {1</b> ({2)<br/><input id='a{1' name='a{1' length=32 placeholder='{2' value='{3'><br/>";
|
||||
#ifdef USE_EMULATION
|
||||
const char HTTP_FORM_OTHER3[] PROGMEM =
|
||||
"<br/><fieldset><legend><b> Emulation </b></legend>"
|
||||
"<br/><input style='width:10%;float:left' id='b2' name='b2' type='radio' value='0'{r2}><b>None</b>"
|
||||
"<br/><input style='width:10%;float:left' id='b2' name='b2' type='radio' value='1'{r3}><b>Belkin WeMo</b> single device"
|
||||
"<br/><input style='width:10%;float:left' id='b2' name='b2' type='radio' value='2'{r4}><b>Hue Bridge</b> multi devices<br/>";
|
||||
const char HTTP_FORM_OTHER3a[] PROGMEM =
|
||||
"<br/><fieldset><legend><b> Emulation </b></legend>";
|
||||
const char HTTP_FORM_OTHER3b[] PROGMEM =
|
||||
"<br/><input style='width:10%;float:left' id='b2' name='b2' type='radio' value='{1'{2><b>{3</b>{4";
|
||||
#endif // USE_EMULATION
|
||||
const char HTTP_FORM_END[] PROGMEM =
|
||||
"<br/><button type='submit'>Save</button></form></fieldset>";
|
||||
const char HTTP_FORM_RST[] PROGMEM =
|
||||
"<div id='f1' name='f1' style='display:block;'>"
|
||||
"<fieldset><legend><b> Restore configuration </b></legend>"
|
||||
"<form method='post' action='u2' enctype='multipart/form-data'>"
|
||||
"<br/><input type='file' name='u2'><br/>"
|
||||
"<br/><button type='submit' onclick='document.getElementById(\"f1\").style.display=\"none\";document.getElementById(\"f2\").style.display=\"block\";this.form.submit();'>Start restore</button></form>"
|
||||
"</fieldset>"
|
||||
"</div>"
|
||||
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>Restore started ...</b></div>";
|
||||
"<fieldset><legend><b> Restore configuration </b></legend>";
|
||||
const char HTTP_FORM_UPG[] PROGMEM =
|
||||
"<div id='f1' name='f1' style='display:block;'>"
|
||||
"<fieldset><legend><b> Upgrade by web server </b></legend>"
|
||||
"<form method='post' action='u1'>"
|
||||
"<form method='get' action='u1'>"
|
||||
"<br/>OTA Url<br/><input id='o' name='o' length=80 placeholder='OTA_URL' value='{o1}'><br/>"
|
||||
"<br/><button type='submit'>Start upgrade</button></form>"
|
||||
"</fieldset><br/><br/>"
|
||||
"<fieldset><legend><b> Upgrade by file upload </b></legend>"
|
||||
"<fieldset><legend><b> Upgrade by file upload </b></legend>";
|
||||
const char HTTP_FORM_RST_UPG[] PROGMEM =
|
||||
"<form method='post' action='u2' enctype='multipart/form-data'>"
|
||||
"<br/><input type='file' name='u2'><br/>"
|
||||
// "<br/><button type='submit' onclick='this.disabled=true;this.form.submit();'>Start upgrade</button></form></fieldset>"
|
||||
"<br/><button type='submit' onclick='document.getElementById(\"f1\").style.display=\"none\";document.getElementById(\"f2\").style.display=\"block\";this.form.submit();'>Start upgrade</button></form>"
|
||||
"<br/><button type='submit' onclick='document.getElementById(\"f1\").style.display=\"none\";document.getElementById(\"f2\").style.display=\"block\";this.form.submit();'>Start {r1}</button></form>"
|
||||
"</fieldset>"
|
||||
"</div>"
|
||||
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>Upload started ...</b></div>";
|
||||
const char HTTP_FORM_CMND[] PROGMEM =
|
||||
"<br/><textarea readonly id='t1' name='t1' cols='99' wrap='off'></textarea><br/><br/>"
|
||||
"<br/><textarea readonly id='t1' name='t1' cols='" STR(MESSZ) "' wrap='off'></textarea><br/><br/>"
|
||||
"<form method='get' onsubmit='return l(1);'>"
|
||||
"<input style='width:98%' id='c1' name='c1' length='99' placeholder='Enter command' autofocus><br/>"
|
||||
// "<br/><button type='submit'>Send command</button>"
|
||||
@@ -278,6 +265,12 @@ const char HTTP_END[] PROGMEM =
|
||||
"</body>"
|
||||
"</html>";
|
||||
|
||||
const char HDR_CTYPE_PLAIN[] PROGMEM = "text/plain";
|
||||
const char HDR_CTYPE_HTML[] PROGMEM = "text/html";
|
||||
const char HDR_CTYPE_XML[] PROGMEM = "text/xml";
|
||||
const char HDR_CTYPE_JSON[] PROGMEM = "application/json";
|
||||
const char HDR_CTYPE_STREAM[] PROGMEM = "application/octet-stream";
|
||||
|
||||
#define DNS_PORT 53
|
||||
enum http_t {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER};
|
||||
|
||||
@@ -390,30 +383,34 @@ void pollDnsWeb()
|
||||
}
|
||||
}
|
||||
|
||||
void setHeader()
|
||||
{
|
||||
webServer->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
webServer->sendHeader(F("Pragma"), F("no-cache"));
|
||||
webServer->sendHeader(F("Expires"), F("-1"));
|
||||
}
|
||||
|
||||
void showPage(String &page)
|
||||
{
|
||||
if((HTTP_ADMIN == _httpflag) && (sysCfg.web_password[0] != 0) && !webServer->authenticate(WEB_USERNAME, sysCfg.web_password)) {
|
||||
return webServer->requestAuthentication();
|
||||
}
|
||||
page.replace("{ha}", my_module.name);
|
||||
page.replace("{h}", sysCfg.friendlyname[0]);
|
||||
page.replace(F("{ha}"), my_module.name);
|
||||
page.replace(F("{h}"), sysCfg.friendlyname[0]);
|
||||
if (HTTP_MANAGER == _httpflag) {
|
||||
if (WIFI_configCounter()) {
|
||||
page.replace("<body>", "<body onload='u()'>");
|
||||
page.replace(F("<body>"), F("<body onload='u()'>"));
|
||||
page += FPSTR(HTTP_COUNTER);
|
||||
}
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
webServer->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
webServer->sendHeader("Pragma", "no-cache");
|
||||
webServer->sendHeader("Expires", "-1");
|
||||
webServer->send(200, "text/html", page);
|
||||
setHeader();
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_HTML), page);
|
||||
}
|
||||
|
||||
void handleRoot()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle root"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Root"));
|
||||
|
||||
if (captivePortal()) { // If captive portal redirect instead of displaying the page.
|
||||
return;
|
||||
@@ -422,15 +419,20 @@ void handleRoot()
|
||||
if (HTTP_MANAGER == _httpflag) {
|
||||
handleWifi0();
|
||||
} else {
|
||||
char stemp[10], line[100];
|
||||
char stemp[10], line[160];
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Main menu");
|
||||
page.replace("<body>", "<body onload='la()'>");
|
||||
page.replace(F("{v}"), F("Main menu"));
|
||||
page.replace(F("<body>"), F("<body onload='la()'>"));
|
||||
|
||||
page += F("<div id='l1' name='l1'></div>");
|
||||
if (Maxdevice) {
|
||||
if (SONOFF_LED == sysCfg.module) {
|
||||
snprintf_P(line, sizeof(line), PSTR("<input type='range' min='1' max='100' value='%d' onchange='lb(value)'>"),
|
||||
if (sfl_flg) {
|
||||
if ((2 == sfl_flg) || (5 == sfl_flg)) {
|
||||
snprintf_P(line, sizeof(line), PSTR("<div><span class='p'>Cold</span><span class='q'>Warm</span></div><div><input type='range' min='153' max='500' value='%d' onchange='lc(value)'></div>"),
|
||||
sl_getColorTemp());
|
||||
page += line;
|
||||
}
|
||||
snprintf_P(line, sizeof(line), PSTR("<div><span class='p'>Dark</span><span class='q'>Bright</span></div><div><input type='range' min='1' max='100' value='%d' onchange='lb(value)'></div>"),
|
||||
sysCfg.led_dimmer[0]);
|
||||
page += line;
|
||||
}
|
||||
@@ -444,6 +446,23 @@ void handleRoot()
|
||||
}
|
||||
page += F("</tr></table>");
|
||||
}
|
||||
if (SONOFF_BRIDGE == sysCfg.module) {
|
||||
page += FPSTR(HTTP_TABLE100);
|
||||
page += F("<tr>");
|
||||
byte idx = 0;
|
||||
for (byte i = 0; i < 4; i++) {
|
||||
if (idx > 0) {
|
||||
page += F("</tr><tr>");
|
||||
}
|
||||
for (byte j = 0; j < 4; j++) {
|
||||
idx++;
|
||||
snprintf_P(line, sizeof(line), PSTR("<td style='width:25%'><button onclick='la(\"?k=%d\");'>%d</button></td>"),
|
||||
idx, idx);
|
||||
page += line;
|
||||
}
|
||||
}
|
||||
page += F("</tr></table>");
|
||||
}
|
||||
|
||||
if (HTTP_ADMIN == _httpflag) {
|
||||
page += FPSTR(HTTP_BTN_MENU1);
|
||||
@@ -455,7 +474,7 @@ void handleRoot()
|
||||
|
||||
void handleAjax2()
|
||||
{
|
||||
char svalue[16];
|
||||
char svalue[50];
|
||||
|
||||
if (strlen(webServer->arg("o").c_str())) {
|
||||
do_cmnd_power(atoi(webServer->arg("o").c_str()), 2);
|
||||
@@ -464,8 +483,23 @@ void handleAjax2()
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("dimmer %s"), webServer->arg("d").c_str());
|
||||
do_cmnd(svalue);
|
||||
}
|
||||
if (strlen(webServer->arg("t").c_str())) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("ct %s"), webServer->arg("t").c_str());
|
||||
do_cmnd(svalue);
|
||||
}
|
||||
if (strlen(webServer->arg("k").c_str())) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("rfkey%s"), webServer->arg("k").c_str());
|
||||
do_cmnd(svalue);
|
||||
}
|
||||
|
||||
String tpage = "";
|
||||
tpage += counter_webPresent();
|
||||
#ifndef USE_ADC_VCC
|
||||
if (pin[GPIO_ADC0] < 99) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("<tr><th>AnalogInput0</th><td>%d</td></tr>"), getAdc0());
|
||||
tpage += svalue;
|
||||
}
|
||||
#endif
|
||||
if (hlw_flg) {
|
||||
tpage += hlw_webPresent();
|
||||
}
|
||||
@@ -515,7 +549,6 @@ void handleAjax2()
|
||||
page += F("<tr>");
|
||||
for (byte idx = 1; idx <= Maxdevice; idx++) {
|
||||
snprintf_P(line, sizeof(line), PSTR("<td style='width:%d%'><div style='text-align:center;font-weight:bold;font-size:%dpx'>%s</div></td>"),
|
||||
// 100 / Maxdevice, 70 - (Maxdevice * 8), (power & (0x01 << (idx -1))) ? "ON" : "OFF");
|
||||
100 / Maxdevice, 70 - (Maxdevice * 8), getStateText(bitRead(power, idx -1)));
|
||||
page += line;
|
||||
}
|
||||
@@ -523,16 +556,13 @@ void handleAjax2()
|
||||
}
|
||||
/*
|
||||
* Will interrupt user action when selected
|
||||
if (SONOFF_LED == sysCfg.module) {
|
||||
if (sfl_flg) {
|
||||
snprintf_P(line, sizeof(line), PSTR("<input type='range' min='1' max='100' value='%d' onchange='lb(value)'>"),
|
||||
sysCfg.led_dimmer[0]);
|
||||
page += line;
|
||||
}
|
||||
*/
|
||||
webServer->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
webServer->sendHeader("Pragma", "no-cache");
|
||||
webServer->sendHeader("Expires", "-1");
|
||||
webServer->send(200, "text/plain", page);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_HTML), page);
|
||||
}
|
||||
|
||||
boolean httpUser()
|
||||
@@ -549,10 +579,10 @@ void handleConfig()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Config"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Configuration");
|
||||
page.replace(F("{v}"), F("Configuration"));
|
||||
page += FPSTR(HTTP_BTN_MENU2);
|
||||
if (sysCfg.flag.mqtt_enabled) {
|
||||
page += FPSTR(HTTP_BTN_MENU3);
|
||||
@@ -609,21 +639,24 @@ void handleModule()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
char stemp[20], line[128];
|
||||
char stemp[20];
|
||||
char line[128];
|
||||
uint8_t midx;
|
||||
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle Module config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Module config"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Config module");
|
||||
page.replace(F("{v}"), F("Config module"));
|
||||
page += FPSTR(HTTP_FORM_MODULE);
|
||||
|
||||
snprintf_P(stemp, sizeof(stemp), modules[MODULE].name);
|
||||
page.replace("{mt}", stemp);
|
||||
page.replace(F("{mt}"), stemp);
|
||||
|
||||
for (byte i = 0; i < MAXMODULE; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), modules[i].name);
|
||||
for (byte i = 0; i < MAXMODULE; i++) {
|
||||
midx = pgm_read_byte(nicelist + i);
|
||||
snprintf_P(stemp, sizeof(stemp), modules[midx].name);
|
||||
snprintf_P(line, sizeof(line), PSTR("<option%s value='%d'>%02d %s</option>"),
|
||||
(i == sysCfg.module) ? " selected" : "", i, i +1, stemp);
|
||||
(midx == sysCfg.module) ? " selected" : "", midx, midx +1, stemp);
|
||||
page += line;
|
||||
}
|
||||
page += F("</select></br>");
|
||||
@@ -650,8 +683,8 @@ void handleModule()
|
||||
}
|
||||
}
|
||||
func += F("}</script>");
|
||||
page.replace("</script>", func);
|
||||
page.replace("<body>", "<body onload='sl()'>");
|
||||
page.replace(F("</script>"), func);
|
||||
page.replace(F("<body>"), F("<body onload='sl()'>"));
|
||||
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
@@ -675,11 +708,10 @@ void handleWifi(boolean scan)
|
||||
}
|
||||
char log[LOGSZ];
|
||||
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle Wifi config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Wifi config"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Configure Wifi");
|
||||
page.replace("</style>", FPSTR(HTTP_LNK_STYLE));
|
||||
page.replace(F("{v}"), F("Configure Wifi"));
|
||||
|
||||
if (scan) {
|
||||
#ifdef USE_EMULATION
|
||||
@@ -738,13 +770,10 @@ void handleWifi(boolean scan)
|
||||
String item = FPSTR(HTTP_LNK_ITEM);
|
||||
String rssiQ;
|
||||
rssiQ += quality;
|
||||
item.replace("{v}", WiFi.SSID(indices[i]));
|
||||
item.replace("{r}", rssiQ);
|
||||
if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) {
|
||||
item.replace("{i}", "l");
|
||||
} else {
|
||||
item.replace("{i}", "");
|
||||
}
|
||||
item.replace(F("{v}"), WiFi.SSID(indices[i]));
|
||||
item.replace(F("{r}"), rssiQ);
|
||||
uint8_t auth = WiFi.encryptionType(indices[i]);
|
||||
item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F("WEP") : (ENC_TYPE_TKIP == auth) ? F("WPA PSK") : (ENC_TYPE_CCMP == auth) ? F("WPA2 PSK") : (ENC_TYPE_AUTO == auth) ? F("AUTO") : F(""));
|
||||
page += item;
|
||||
delay(0);
|
||||
} else {
|
||||
@@ -759,11 +788,11 @@ void handleWifi(boolean scan)
|
||||
}
|
||||
|
||||
page += FPSTR(HTTP_FORM_WIFI);
|
||||
page.replace("{h1}", sysCfg.hostname);
|
||||
page.replace("{s1}", sysCfg.sta_ssid[0]);
|
||||
page.replace("{p1}", sysCfg.sta_pwd[0]);
|
||||
page.replace("{s2}", sysCfg.sta_ssid[1]);
|
||||
page.replace("{p2}", sysCfg.sta_pwd[1]);
|
||||
page.replace(F("{h1}"), sysCfg.hostname);
|
||||
page.replace(F("{s1}"), sysCfg.sta_ssid[0]);
|
||||
page.replace(F("{p1}"), sysCfg.sta_pwd[0]);
|
||||
page.replace(F("{s2}"), sysCfg.sta_ssid[1]);
|
||||
page.replace(F("{p2}"), sysCfg.sta_pwd[1]);
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
if (HTTP_MANAGER == _httpflag) {
|
||||
page += FPSTR(HTTP_BTN_RSTRT);
|
||||
@@ -778,20 +807,21 @@ void handleMqtt()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle MQTT config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: MQTT config"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Configure MQTT");
|
||||
page.replace(F("{v}"), F("Configure MQTT"));
|
||||
page += FPSTR(HTTP_FORM_MQTT);
|
||||
char str[sizeof(sysCfg.mqtt_client)];
|
||||
getClient(str, MQTT_CLIENT_ID, sizeof(sysCfg.mqtt_client));
|
||||
page.replace("{m0}", str);
|
||||
page.replace("{m1}", sysCfg.mqtt_host);
|
||||
page.replace("{m2}", String(sysCfg.mqtt_port));
|
||||
page.replace("{m3}", sysCfg.mqtt_client);
|
||||
page.replace("{m4}", (sysCfg.mqtt_user[0] == '\0')?"0":sysCfg.mqtt_user);
|
||||
page.replace("{m5}", (sysCfg.mqtt_pwd[0] == '\0')?"0":sysCfg.mqtt_pwd);
|
||||
page.replace("{m6}", sysCfg.mqtt_topic);
|
||||
page.replace(F("{m0}"), str);
|
||||
page.replace(F("{m1}"), sysCfg.mqtt_host);
|
||||
page.replace(F("{m2}"), String(sysCfg.mqtt_port));
|
||||
page.replace(F("{m3}"), sysCfg.mqtt_client);
|
||||
page.replace(F("{m4}"), (sysCfg.mqtt_user[0] == '\0')?"0":sysCfg.mqtt_user);
|
||||
page.replace(F("{m5}"), (sysCfg.mqtt_pwd[0] == '\0')?"0":sysCfg.mqtt_pwd);
|
||||
page.replace(F("{m6}"), sysCfg.mqtt_topic);
|
||||
page.replace(F("{m7}"), sysCfg.mqtt_fulltopic);
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
showPage(page);
|
||||
@@ -802,44 +832,44 @@ void handleLog()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle Log config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Log config"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Config logging");
|
||||
page.replace(F("{v}"), F("Config logging"));
|
||||
page += FPSTR(HTTP_FORM_LOG1);
|
||||
for (byte idx = 0; idx < 3; idx++) {
|
||||
page += FPSTR(HTTP_FORM_LOG2);
|
||||
switch (idx) {
|
||||
case 0:
|
||||
page.replace("{b0}", F("Serial "));
|
||||
page.replace("{b1}", STR(SERIAL_LOG_LEVEL));
|
||||
page.replace("{b2}", "ls");
|
||||
page.replace(F("{b0}"), F("Serial "));
|
||||
page.replace(F("{b1}"), STR(SERIAL_LOG_LEVEL));
|
||||
page.replace(F("{b2}"), F("ls"));
|
||||
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
|
||||
page.replace("{a" + String(i), (i == sysCfg.seriallog_level) ? " selected " : " ");
|
||||
page.replace("{a" + String(i), (i == sysCfg.seriallog_level) ? F(" selected ") : F(" "));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
page.replace("{b0}", F("Web "));
|
||||
page.replace("{b1}", STR(WEB_LOG_LEVEL));
|
||||
page.replace("{b2}", "lw");
|
||||
page.replace(F("{b0}"), F("Web "));
|
||||
page.replace(F("{b1}"), STR(WEB_LOG_LEVEL));
|
||||
page.replace(F("{b2}"), F("lw"));
|
||||
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
|
||||
page.replace("{a" + String(i), (i == sysCfg.weblog_level) ? " selected " : " ");
|
||||
page.replace("{a" + String(i), (i == sysCfg.weblog_level) ? F(" selected ") : F(" "));
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
page.replace("{b0}", F("Sys"));
|
||||
page.replace("{b1}", STR(SYS_LOG_LEVEL));
|
||||
page.replace("{b2}", "ll");
|
||||
page.replace(F("{b0}"), F("Sys"));
|
||||
page.replace(F("{b1}"), STR(SYS_LOG_LEVEL));
|
||||
page.replace(F("{b2}"), F("ll"));
|
||||
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
|
||||
page.replace("{a" + String(i), (i == sysCfg.syslog_level) ? " selected " : " ");
|
||||
page.replace("{a" + String(i), (i == sysCfg.syslog_level) ? F(" selected ") : F(" "));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
page += FPSTR(HTTP_FORM_LOG3);
|
||||
page.replace("{l2}", sysCfg.syslog_host);
|
||||
page.replace("{l3}", String(sysCfg.syslog_port));
|
||||
page.replace("{l4}", String(sysCfg.tele_period));
|
||||
page.replace(F("{l2}"), sysCfg.syslog_host);
|
||||
page.replace(F("{l3}"), String(sysCfg.syslog_port));
|
||||
page.replace(F("{l4}"), String(sysCfg.tele_period));
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
showPage(page);
|
||||
@@ -850,29 +880,34 @@ void handleOther()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle other config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Other config"));
|
||||
char stemp[40];
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Configure Other");
|
||||
page.replace(F("{v}"), F("Configure Other"));
|
||||
page += FPSTR(HTTP_FORM_OTHER);
|
||||
page.replace("{p1}", sysCfg.web_password);
|
||||
page.replace("{r1}", (sysCfg.flag.mqtt_enabled) ? " checked" : "");
|
||||
page.replace(F("{p1}"), sysCfg.web_password);
|
||||
page.replace(F("{r1}"), (sysCfg.flag.mqtt_enabled) ? F(" checked") : F(""));
|
||||
page += FPSTR(HTTP_FORM_OTHER2);
|
||||
page.replace("{1", "1");
|
||||
page.replace("{2", FRIENDLY_NAME);
|
||||
page.replace("{3", sysCfg.friendlyname[0]);
|
||||
page.replace(F("{1"), F("1"));
|
||||
page.replace(F("{2"), FRIENDLY_NAME);
|
||||
page.replace(F("{3"), sysCfg.friendlyname[0]);
|
||||
#ifdef USE_EMULATION
|
||||
page += FPSTR(HTTP_FORM_OTHER3);
|
||||
page.replace("{r2}", (EMUL_NONE == sysCfg.flag.emulation) ? " checked" : "");
|
||||
page.replace("{r3}", (EMUL_WEMO == sysCfg.flag.emulation) ? " checked" : "");
|
||||
page.replace("{r4}", (EMUL_HUE == sysCfg.flag.emulation) ? " checked" : "");
|
||||
page += FPSTR(HTTP_FORM_OTHER3a);
|
||||
for (byte i = 0; i < EMUL_MAX; i++) {
|
||||
page += FPSTR(HTTP_FORM_OTHER3b);
|
||||
page.replace(F("{1"), String(i));
|
||||
page.replace(F("{2"), (i == sysCfg.flag.emulation) ? F(" checked") : F(""));
|
||||
page.replace(F("{3"), (i == EMUL_NONE) ? F("None") : (i == EMUL_WEMO) ? F("Belkin WeMo") : F("Hue Bridge"));
|
||||
page.replace(F("{4"), (i == EMUL_NONE) ? F("") : (i == EMUL_WEMO) ? F(" single device") : F(" multi devices"));
|
||||
}
|
||||
page += F("<br/>");
|
||||
for (int i = 1; i < Maxdevice; i++) {
|
||||
page += FPSTR(HTTP_FORM_OTHER2);
|
||||
page.replace("{1", String(i +1));
|
||||
page.replace(F("{1"), String(i +1));
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR(FRIENDLY_NAME"%d"), i +1);
|
||||
page.replace("{2", stemp);
|
||||
page.replace("{3", sysCfg.friendlyname[i]);
|
||||
page.replace(F("{2"), stemp);
|
||||
page.replace(F("{3"), sysCfg.friendlyname[i]);
|
||||
}
|
||||
page += F("<br/></fieldset>");
|
||||
#endif // USE_EMULATION
|
||||
@@ -886,7 +921,7 @@ void handleDownload()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle download config"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Download config"));
|
||||
|
||||
uint8_t buffer[sizeof(sysCfg)];
|
||||
|
||||
@@ -896,8 +931,8 @@ void handleDownload()
|
||||
char attachment[100];
|
||||
snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"),
|
||||
sysCfg.friendlyname[0], Version);
|
||||
webServer->sendHeader("Content-Disposition", attachment);
|
||||
webServer->send(200, "application/octet-stream", "");
|
||||
webServer->sendHeader(F("Content-Disposition"), attachment);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
|
||||
memcpy(buffer, &sysCfg, sizeof(sysCfg));
|
||||
buffer[0] = CONFIG_FILE_SIGN;
|
||||
buffer[1] = (!CONFIG_FILE_XOR)?0:1;
|
||||
@@ -916,7 +951,8 @@ void handleSave()
|
||||
}
|
||||
|
||||
char log[LOGSZ +20];
|
||||
char stemp[20];
|
||||
char stemp[TOPSZ];
|
||||
char stemp2[TOPSZ];
|
||||
byte what = 0;
|
||||
byte restart;
|
||||
String result = "";
|
||||
@@ -942,14 +978,22 @@ void handleSave()
|
||||
result += F("<br/>Trying to connect device to network<br/>If it fails reconnect to try again");
|
||||
break;
|
||||
case 2:
|
||||
strlcpy(stemp, (!strlen(webServer->arg("mt").c_str())) ? MQTT_TOPIC : webServer->arg("mt").c_str(), sizeof(stemp));
|
||||
mqttfy(0, stemp);
|
||||
strlcpy(stemp2, (!strlen(webServer->arg("mf").c_str())) ? MQTT_FULLTOPIC : webServer->arg("mf").c_str(), sizeof(stemp2));
|
||||
mqttfy(1,stemp2);
|
||||
if ((strcmp(stemp, sysCfg.mqtt_topic)) || (strcmp(stemp2, sysCfg.mqtt_fulltopic))) {
|
||||
mqtt_publish_topic_P(2, PSTR("LWT"), (sysCfg.flag.mqtt_offline) ? "Offline" : "", true); // Offline or remove previous retained topic
|
||||
}
|
||||
strlcpy(sysCfg.mqtt_topic, stemp, sizeof(sysCfg.mqtt_topic));
|
||||
strlcpy(sysCfg.mqtt_fulltopic, stemp2, sizeof(sysCfg.mqtt_fulltopic));
|
||||
strlcpy(sysCfg.mqtt_host, (!strlen(webServer->arg("mh").c_str())) ? MQTT_HOST : webServer->arg("mh").c_str(), sizeof(sysCfg.mqtt_host));
|
||||
sysCfg.mqtt_port = (!strlen(webServer->arg("ml").c_str())) ? MQTT_PORT : atoi(webServer->arg("ml").c_str());
|
||||
strlcpy(sysCfg.mqtt_client, (!strlen(webServer->arg("mc").c_str())) ? MQTT_CLIENT_ID : webServer->arg("mc").c_str(), sizeof(sysCfg.mqtt_client));
|
||||
strlcpy(sysCfg.mqtt_user, (!strlen(webServer->arg("mu").c_str())) ? MQTT_USER : (!strcmp(webServer->arg("mu").c_str(),"0")) ? "" : webServer->arg("mu").c_str(), sizeof(sysCfg.mqtt_user));
|
||||
strlcpy(sysCfg.mqtt_pwd, (!strlen(webServer->arg("mp").c_str())) ? MQTT_PASS : (!strcmp(webServer->arg("mp").c_str(),"0")) ? "" : webServer->arg("mp").c_str(), sizeof(sysCfg.mqtt_pwd));
|
||||
strlcpy(sysCfg.mqtt_topic, (!strlen(webServer->arg("mt").c_str())) ? MQTT_TOPIC : webServer->arg("mt").c_str(), sizeof(sysCfg.mqtt_topic));
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: MQTT Host %s, Port %d, Client %s, User %s, Password %s, Topic %s"),
|
||||
sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_client, sysCfg.mqtt_user, sysCfg.mqtt_pwd, sysCfg.mqtt_topic);
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: MQTT Host %s, Port %d, Client %s, User %s, Password %s, Topic %s, FullTopic %s"),
|
||||
sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_client, sysCfg.mqtt_user, sysCfg.mqtt_pwd, sysCfg.mqtt_topic, sysCfg.mqtt_fulltopic);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
break;
|
||||
case 3:
|
||||
@@ -1001,7 +1045,6 @@ void handleSave()
|
||||
gpios += F(", GPIO"); gpios += String(i); gpios += F(" "); gpios += String(sysCfg.my_module.gp.io[i]);
|
||||
}
|
||||
}
|
||||
setModuleFlashMode(0);
|
||||
snprintf_P(stemp, sizeof(stemp), modules[sysCfg.module].name);
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: %s Module%s"), stemp, gpios.c_str());
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
@@ -1011,7 +1054,7 @@ void handleSave()
|
||||
restart = (!strlen(webServer->arg("r").c_str())) ? 1 : atoi(webServer->arg("r").c_str());
|
||||
if (restart) {
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Save parameters");
|
||||
page.replace(F("{v}"), F("Save parameters"));
|
||||
page += F("<div style='text-align:center;'><b>Parameters saved</b><br/>");
|
||||
page += result;
|
||||
page += F("</div>");
|
||||
@@ -1040,7 +1083,7 @@ void handleReset()
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Reset parameters"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Default parameters");
|
||||
page.replace(F("{v}"), F("Default parameters"));
|
||||
page += F("<div style='text-align:center;'>Parameters reset to default</div>");
|
||||
page += FPSTR(HTTP_MSG_RSTRT);
|
||||
page += FPSTR(HTTP_BTN_MAIN);
|
||||
@@ -1055,11 +1098,13 @@ void handleRestore()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle restore"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Restore"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Restore Configuration");
|
||||
page.replace(F("{v}"), F("Restore Configuration"));
|
||||
page += FPSTR(HTTP_FORM_RST);
|
||||
page += FPSTR(HTTP_FORM_RST_UPG);
|
||||
page.replace(F("{r1}"), F("restore"));
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
showPage(page);
|
||||
|
||||
@@ -1072,12 +1117,14 @@ void handleUpgrade()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle upgrade"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Upgrade"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Firmware upgrade");
|
||||
page.replace(F("{v}"), F("Firmware upgrade"));
|
||||
page += FPSTR(HTTP_FORM_UPG);
|
||||
page.replace("{o1}", sysCfg.otaUrl);
|
||||
page.replace(F("{o1}"), sysCfg.otaUrl);
|
||||
page += FPSTR(HTTP_FORM_RST_UPG);
|
||||
page.replace(F("{r1}"), F("upgrade"));
|
||||
page += FPSTR(HTTP_BTN_MAIN);
|
||||
showPage(page);
|
||||
|
||||
@@ -1101,7 +1148,7 @@ void handleUpgradeStart()
|
||||
}
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Info");
|
||||
page.replace(F("{v}"), F("Info"));
|
||||
page += F("<div style='text-align:center;'><b>Upgrade started ...</b></div>");
|
||||
page += FPSTR(HTTP_MSG_RSTRT);
|
||||
page += FPSTR(HTTP_BTN_MAIN);
|
||||
@@ -1126,30 +1173,27 @@ void handleUploadDone()
|
||||
mqttcounter = 0;
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Info");
|
||||
page.replace(F("{v}"), F("Info"));
|
||||
page += F("<div style='text-align:center;'><b>Upload ");
|
||||
if (_uploaderror) {
|
||||
page += F("<font color='red'>failed</font></b><br/><br/>");
|
||||
switch (_uploaderror) {
|
||||
case 1: strcpy_P(error, PSTR("No file selected")); break;
|
||||
case 2: strcpy_P(error, PSTR("File size is larger than available free space")); break;
|
||||
case 3: strcpy_P(error, PSTR("File magic header does not start with 0xE9")); break;
|
||||
case 4: strcpy_P(error, PSTR("File flash size is larger than device flash size")); break;
|
||||
case 5: strcpy_P(error, PSTR("File upload buffer miscompare")); break;
|
||||
case 6: strcpy_P(error, PSTR("Upload failed. Enable logging option 3 for more information")); break;
|
||||
case 2: strcpy_P(error, PSTR("Not enough space")); break;
|
||||
case 3: strcpy_P(error, PSTR("Magic byte is not 0xE9")); break;
|
||||
case 4: strcpy_P(error, PSTR("IDE flash size larger than device flash size")); break;
|
||||
case 5: strcpy_P(error, PSTR("Upload buffer miscompare")); break;
|
||||
case 6: strcpy_P(error, PSTR("Upload failed. Enable logging 3")); break;
|
||||
case 7: strcpy_P(error, PSTR("Upload aborted")); break;
|
||||
case 8: strcpy_P(error, PSTR("Invalid configuration file")); break;
|
||||
case 9: strcpy_P(error, PSTR("Configuration file too large")); break;
|
||||
case 8: strcpy_P(error, PSTR("File invalid")); break;
|
||||
case 9: strcpy_P(error, PSTR("File too large")); break;
|
||||
default:
|
||||
snprintf_P(error, sizeof(error), PSTR("Upload error code %d"), _uploaderror);
|
||||
}
|
||||
page += error;
|
||||
if (!_uploadfiletype && Update.hasError()) {
|
||||
page += F("<br/><br/>Update error code (see Updater.cpp) ");
|
||||
page += String(Update.getError());
|
||||
}
|
||||
snprintf_P(log, sizeof(log), PSTR("Upload: Error - %s"), error);
|
||||
snprintf_P(log, sizeof(log), PSTR("Upload: %s"), error);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
stop_flash_rotate = sysCfg.flag.stop_flash_rotate;
|
||||
} else {
|
||||
page += F("<font color='green'>successful</font></b><br/><br/>Device will restart in a few seconds");
|
||||
restartflag = 2;
|
||||
@@ -1183,6 +1227,7 @@ void handleUploadLoop()
|
||||
_uploaderror = 1;
|
||||
return;
|
||||
}
|
||||
CFG_Save(1); // Free flash for upload
|
||||
snprintf_P(log, sizeof(log), PSTR("Upload: File %s ..."), upload.filename.c_str());
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
if (!_uploadfiletype) {
|
||||
@@ -1195,9 +1240,6 @@ void handleUploadLoop()
|
||||
}
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
if (!Update.begin(maxSketchSpace)) { //start with max available size
|
||||
if (_serialoutput) {
|
||||
Update.printError(Serial);
|
||||
}
|
||||
_uploaderror = 2;
|
||||
return;
|
||||
}
|
||||
@@ -1225,10 +1267,7 @@ void handleUploadLoop()
|
||||
_uploaderror = 4;
|
||||
return;
|
||||
}
|
||||
if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
|
||||
upload.buf[2] = 3; // DOUT - ESP8285
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("FLSH: Set Flash Mode to 3"));
|
||||
}
|
||||
upload.buf[2] = 3; // Force DOUT - ESP8285
|
||||
}
|
||||
}
|
||||
if (_uploadfiletype) { // config
|
||||
@@ -1240,12 +1279,10 @@ void handleUploadLoop()
|
||||
}
|
||||
CFG_DefaultSet2();
|
||||
memcpy((char*)&sysCfg +16, upload.buf +16, upload.currentSize -16);
|
||||
memcpy((char*)&sysCfg +8, upload.buf +8, 4); // Restore version and auto upgrade
|
||||
}
|
||||
} else { // firmware
|
||||
if (!_uploaderror && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) {
|
||||
if (_serialoutput) {
|
||||
Update.printError(Serial);
|
||||
}
|
||||
_uploaderror = 5;
|
||||
return;
|
||||
}
|
||||
@@ -1290,9 +1327,9 @@ void handleCmnd()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
char svalue[128]; // was MESSZ
|
||||
char svalue[INPUT_BUFFER_SIZE]; // big to serve Backlog
|
||||
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle cmnd"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Command"));
|
||||
|
||||
uint8_t valid = 1;
|
||||
if (sysCfg.web_password[0] != 0) {
|
||||
@@ -1340,11 +1377,7 @@ void handleCmnd()
|
||||
} else {
|
||||
message = F("Need user=<username>&password=<password>\n");
|
||||
}
|
||||
|
||||
webServer->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
webServer->sendHeader("Pragma", "no-cache");
|
||||
webServer->sendHeader("Expires", "-1");
|
||||
webServer->send(200, "text/plain", message);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), message);
|
||||
}
|
||||
|
||||
void handleConsole()
|
||||
@@ -1353,12 +1386,12 @@ void handleConsole()
|
||||
return;
|
||||
}
|
||||
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle console"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Console"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Console");
|
||||
page.replace("</script>", FPSTR(HTTP_SCRIPT_CONSOL));
|
||||
page.replace("<body>", "<body onload='l()'>");
|
||||
page.replace(F("{v}"), F("Console"));
|
||||
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_CONSOL));
|
||||
page.replace(F("<body>"), F("<body onload='l()'>"));
|
||||
page += FPSTR(HTTP_FORM_CMND);
|
||||
page += FPSTR(HTTP_BTN_MAIN);
|
||||
showPage(page);
|
||||
@@ -1370,7 +1403,7 @@ void handleAjax()
|
||||
return;
|
||||
}
|
||||
char log[LOGSZ];
|
||||
char svalue[128]; // was MESSZ
|
||||
char svalue[INPUT_BUFFER_SIZE]; // big to serve Backlog
|
||||
byte cflg = 1;
|
||||
byte counter = 99;
|
||||
|
||||
@@ -1418,11 +1451,7 @@ void handleAjax()
|
||||
} while (counter != logidx);
|
||||
}
|
||||
message += F("</l></r>");
|
||||
|
||||
webServer->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
webServer->sendHeader("Pragma", "no-cache");
|
||||
webServer->sendHeader("Expires", "-1");
|
||||
webServer->send(200, "text/xml", message);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), message);
|
||||
}
|
||||
|
||||
void handleInfo()
|
||||
@@ -1430,12 +1459,14 @@ void handleInfo()
|
||||
if (httpUser()) {
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle info"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Info"));
|
||||
|
||||
char stopic[TOPSZ];
|
||||
|
||||
int freeMem = ESP.getFreeHeap();
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Information");
|
||||
page.replace(F("{v}"), F("Information"));
|
||||
// page += F("<fieldset><legend><b> Information </b></legend>");
|
||||
page += F("<style>td{padding:0px 5px;}</style>");
|
||||
page += F("<table style'width:100%;'>");
|
||||
@@ -1444,7 +1475,8 @@ void handleInfo()
|
||||
page += F("<tr><th>Core/SDK version</th><td>"); page += ESP.getCoreVersion(); page += F("/"); page += String(ESP.getSdkVersion()); page += F("</td></tr>");
|
||||
// page += F("<tr><th>Boot version</th><td>"); page += String(ESP.getBootVersion()); page += F("</td></tr>");
|
||||
page += F("<tr><th>Uptime</th><td>"); page += String(uptime); page += F(" Hours</td></tr>");
|
||||
page += F("<tr><th>Flash write count</th><td>"); page += String(sysCfg.saveFlag); page += F("</td></tr>");
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), CFG_Address());
|
||||
page += F("<tr><th>Flash write count</th><td>"); page += String(sysCfg.saveFlag); page += stopic; page += F("</td></tr>");
|
||||
page += F("<tr><th>Boot count</th><td>"); page += String(sysCfg.bootcount); page += F("</td></tr>");
|
||||
page += F("<tr><th>Reset reason</th><td>"); page += getResetReason(); page += F("</td></tr>");
|
||||
for (byte i = 0; i < Maxdevice; i++) {
|
||||
@@ -1453,8 +1485,8 @@ void handleInfo()
|
||||
page += F("</th><td>"); page += sysCfg.friendlyname[i]; page += F("</td></tr>");
|
||||
}
|
||||
page += F("<tr><td> </td></tr>");
|
||||
// page += F("<tr><th>SSId (RSSI)</th><td>"); page += (sysCfg.sta_active)? sysCfg.sta_ssid2 : sysCfg.sta_ssid1; page += F(" ("); page += WIFI_getRSSIasQuality(WiFi.RSSI()); page += F("%)</td></tr>");
|
||||
page += F("<tr><th>AP"); page += String(sysCfg.sta_active +1); page += F(" SSId (RSSI)</th><td>"); page += sysCfg.sta_ssid[sysCfg.sta_active]; page += F(" ("); page += WIFI_getRSSIasQuality(WiFi.RSSI()); page += F("%)</td></tr>");
|
||||
page += F("<tr><th>AP"); page += String(sysCfg.sta_active +1);
|
||||
page += F(" SSId (RSSI)</th><td>"); page += sysCfg.sta_ssid[sysCfg.sta_active]; page += F(" ("); page += WIFI_getRSSIasQuality(WiFi.RSSI()); page += F("%)</td></tr>");
|
||||
page += F("<tr><th>Hostname</th><td>"); page += Hostname; page += F("</td></tr>");
|
||||
if (static_cast<uint32_t>(WiFi.localIP()) != 0) {
|
||||
page += F("<tr><th>IP address</th><td>"); page += WiFi.localIP().toString(); page += F("</td></tr>");
|
||||
@@ -1477,10 +1509,14 @@ void handleInfo()
|
||||
// page += F("<tr><th>MQTT Password</th><td>"); page += sysCfg.mqtt_pwd; page += F("</td></tr>");
|
||||
page += F("<tr><th>MQTT Topic</th><td>"); page += sysCfg.mqtt_topic; page += F("</td></tr>");
|
||||
page += F("<tr><th>MQTT Group Topic</th><td>"); page += sysCfg.mqtt_grptopic; page += F("</td></tr>");
|
||||
|
||||
getTopic_P(stopic, 0, sysCfg.mqtt_topic, "");
|
||||
page += F("<tr><th>MQTT Full Topic</th><td>"); page += stopic; page += F("</td></tr>");
|
||||
|
||||
} else {
|
||||
page += F("<tr><th>MQTT</th><td>Disabled</td></tr>");
|
||||
}
|
||||
|
||||
page += F("<tr><td> </td></tr>");
|
||||
page += F("<tr><th>Emulation</th><td>");
|
||||
#ifdef USE_EMULATION
|
||||
if (EMUL_WEMO == sysCfg.flag.emulation) {
|
||||
@@ -1534,7 +1570,7 @@ void handleRestart()
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Restarting"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Info");
|
||||
page.replace(F("{v}"), F("Info"));
|
||||
page += FPSTR(HTTP_MSG_RSTRT);
|
||||
if (HTTP_MANAGER == _httpflag) {
|
||||
_httpflag = HTTP_ADMIN;
|
||||
@@ -1561,22 +1597,18 @@ void handleNotFound()
|
||||
} else
|
||||
#endif // USE_EMULATION
|
||||
{
|
||||
String message = "File Not Found\n\n";
|
||||
message += "URI: ";
|
||||
String message = F("File Not Found\n\nURI: ");
|
||||
message += webServer->uri();
|
||||
message += "\nMethod: ";
|
||||
message += ( webServer->method() == HTTP_GET ) ? "GET" : "POST";
|
||||
message += "\nArguments: ";
|
||||
message += F("\nMethod: ");
|
||||
message += (webServer->method() == HTTP_GET) ? F("GET") : F("POST");
|
||||
message += F("\nArguments: ");
|
||||
message += webServer->args();
|
||||
message += "\n";
|
||||
message += F("\n");
|
||||
for ( uint8_t i = 0; i < webServer->args(); i++ ) {
|
||||
message += " " + webServer->argName ( i ) + ": " + webServer->arg ( i ) + "\n";
|
||||
message += " " + webServer->argName(i) + ": " + webServer->arg(i) + "\n";
|
||||
}
|
||||
|
||||
webServer->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
webServer->sendHeader("Pragma", "no-cache");
|
||||
webServer->sendHeader("Expires", "-1");
|
||||
webServer->send(404, "text/plain", message);
|
||||
setHeader();
|
||||
webServer->send(404, FPSTR(HDR_CTYPE_PLAIN), message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1586,8 +1618,8 @@ boolean captivePortal()
|
||||
if ((HTTP_MANAGER == _httpflag) && !isIp(webServer->hostHeader())) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Request redirected to captive portal"));
|
||||
|
||||
webServer->sendHeader("Location", String("http://") + webServer->client().localIP().toString(), true);
|
||||
webServer->send(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||
webServer->sendHeader(F("Location"), String("http://") + webServer->client().localIP().toString(), true);
|
||||
webServer->send(302, FPSTR(HDR_CTYPE_PLAIN), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||
webServer->client().stop(); // Stop is needed because we sent no content length
|
||||
return true;
|
||||
}
|
||||
|
||||
+65
-77
@@ -1,53 +1,49 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xdrv_domoticz.ino - domoticz support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_DOMOTICZ
|
||||
|
||||
#define DOMOTICZ_MAX_SENSORS 5
|
||||
#define DOMOTICZ_MAX_SENSORS 6
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_FORM_DOMOTICZ[] PROGMEM =
|
||||
"<fieldset><legend><b> Domoticz parameters </b></legend><form method='post' action='sv'>"
|
||||
"<input id='w' name='w' value='4' hidden><input id='r' name='r' value='1' hidden>"
|
||||
"<br/><table style='width:97%'>"
|
||||
"<tr><td><b>In topic</b> (" DOMOTICZ_IN_TOPIC ")</td><td style='width:30%'><input id='it' name='it' length=32 placeholder='" DOMOTICZ_IN_TOPIC "' value='{d1}'></td></tr>"
|
||||
"<tr><td><b>Out topic</b> (" DOMOTICZ_OUT_TOPIC ")</td><td><input id='ot' name='ot' length=32 placeholder='" DOMOTICZ_OUT_TOPIC "' value='{d2}'></td></tr>";
|
||||
"<br/><table style='width:97%'>";
|
||||
const char HTTP_FORM_DOMOTICZ_RELAY[] PROGMEM =
|
||||
"<tr><td><b>Idx {1</b></td></td><td><input id='r{1' name='r{1' length=8 placeholder='0' value='{2'></td></tr>"
|
||||
"<tr><td><b>Idx {1</b></td></td><td width='20%'><input id='r{1' name='r{1' length=8 placeholder='0' value='{2'></td></tr>"
|
||||
"<tr><td><b>Key idx {1</b></td><td><input id='k{1' name='k{1' length=8 placeholder='0' value='{3'></td></tr>";
|
||||
const char HTTP_FORM_DOMOTICZ_SWITCH[] PROGMEM =
|
||||
"<tr><td><b>Switch idx {1</b></td><td><input id='s{1' name='s{1' length=8 placeholder='0' value='{4'></td></tr>";
|
||||
"<tr><td><b>Switch idx {1</b></td><td width='20%'><input id='s{1' name='s{1' length=8 placeholder='0' value='{4'></td></tr>";
|
||||
const char HTTP_FORM_DOMOTICZ_SENSOR[] PROGMEM =
|
||||
"<tr><td><b>Sensor idx {1</b> - {2</td><td><input id='l{1' name='l{1' length=8 placeholder='0' value='{5'></td></tr>";
|
||||
"<tr><td><b>Sensor idx {1</b> - {2</td><td width='20%'><input id='l{1' name='l{1' length=8 placeholder='0' value='{5'></td></tr>";
|
||||
const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM =
|
||||
"<tr><td><b>Update timer</b> (" STR(DOMOTICZ_UPDATE_TIMER) ")</td><td><input id='ut' name='ut' length=32 placeholder='" STR(DOMOTICZ_UPDATE_TIMER) "' value='{6'</td></tr>";
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
const char domoticz_sensors[DOMOTICZ_MAX_SENSORS][14] PROGMEM =
|
||||
{ "Temp", "Temp,Hum", "Temp,Hum,Baro", "Power,Energy", "Illuminance" };
|
||||
{ "Temp", "Temp,Hum", "Temp,Hum,Baro", "Power,Energy", "Illuminance", "Count" };
|
||||
|
||||
char domoticz_in_topic[] = DOMOTICZ_IN_TOPIC;
|
||||
char domoticz_out_topic[] = DOMOTICZ_OUT_TOPIC;
|
||||
|
||||
boolean domoticz_subscribe = false;
|
||||
int domoticz_update_timer = 0;
|
||||
byte domoticz_update_flag = 1;
|
||||
|
||||
@@ -55,38 +51,37 @@ void mqtt_publishDomoticzPowerState(byte device)
|
||||
{
|
||||
char svalue[64]; // was MESSZ
|
||||
|
||||
if (sysCfg.domoticz_relay_idx[device -1] && (strlen(sysCfg.domoticz_in_topic) != 0)) {
|
||||
if (sysCfg.flag.mqtt_enabled && sysCfg.domoticz_relay_idx[device -1]) {
|
||||
if ((device < 1) || (device > Maxdevice)) {
|
||||
device = 1;
|
||||
}
|
||||
|
||||
if (SONOFF_LED == sysCfg.module) {
|
||||
if (sfl_flg) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
|
||||
sysCfg.domoticz_relay_idx[device -1], sysCfg.led_dimmer[device -1]);
|
||||
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
|
||||
mqtt_publish(domoticz_in_topic, svalue);
|
||||
}
|
||||
else if ((1 == device) && (pin[GPIO_WS2812] < 99)) {
|
||||
else if ((Maxdevice == device) && (pin[GPIO_WS2812] < 99)) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
|
||||
sysCfg.domoticz_relay_idx[device -1], sysCfg.ws_dimmer);
|
||||
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
|
||||
mqtt_publish(domoticz_in_topic, svalue);
|
||||
}
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"\"}"),
|
||||
sysCfg.domoticz_relay_idx[device -1], (power & (0x01 << (device -1))) ? 1 : 0);
|
||||
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
|
||||
mqtt_publish(domoticz_in_topic, svalue);
|
||||
}
|
||||
}
|
||||
|
||||
void domoticz_updatePowerState(byte device)
|
||||
{
|
||||
if (domoticz_update_flag) {
|
||||
if (domoticz_update_flag) {
|
||||
mqtt_publishDomoticzPowerState(device);
|
||||
}
|
||||
domoticz_update_flag = 1;
|
||||
}
|
||||
domoticz_update_flag = 1;
|
||||
}
|
||||
|
||||
void domoticz_mqttUpdate()
|
||||
{
|
||||
if ((sysCfg.domoticz_update_timer || domoticz_update_timer) && sysCfg.domoticz_relay_idx[0]) {
|
||||
if (domoticz_subscribe && (sysCfg.domoticz_update_timer || domoticz_update_timer)) {
|
||||
domoticz_update_timer--;
|
||||
if (domoticz_update_timer <= 0) {
|
||||
domoticz_update_timer = sysCfg.domoticz_update_timer;
|
||||
@@ -104,9 +99,14 @@ void domoticz_setUpdateTimer(uint16_t value)
|
||||
|
||||
void domoticz_mqttSubscribe()
|
||||
{
|
||||
if (sysCfg.domoticz_relay_idx[0] && (strlen(sysCfg.domoticz_out_topic) != 0)) {
|
||||
for (byte i = 0; i < Maxdevice; i++) {
|
||||
if (sysCfg.domoticz_relay_idx[i]) {
|
||||
domoticz_subscribe = true;
|
||||
}
|
||||
}
|
||||
if (domoticz_subscribe) {
|
||||
char stopic[TOPSZ];
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), sysCfg.domoticz_out_topic); // domoticz topic
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), domoticz_out_topic); // domoticz topic
|
||||
mqttClient.subscribe(stopic);
|
||||
mqttClient.loop(); // Solve LmacRxBlk:1 messages
|
||||
}
|
||||
@@ -138,12 +138,13 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
||||
{
|
||||
char log[LOGSZ];
|
||||
char stemp1[10];
|
||||
char scommand[10];
|
||||
unsigned long idx = 0;
|
||||
int16_t nvalue;
|
||||
int16_t found = 0;
|
||||
|
||||
domoticz_update_flag = 1;
|
||||
if (!strncmp(topicBuf, sysCfg.domoticz_out_topic, strlen(sysCfg.domoticz_out_topic)) != 0) {
|
||||
if (!strncmp(topicBuf, domoticz_out_topic, strlen(domoticz_out_topic)) != 0) {
|
||||
if (sdataBuf < 20) {
|
||||
return 1;
|
||||
}
|
||||
@@ -170,19 +171,17 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
||||
if ((pin[GPIO_WS2812] < 99) && (sysCfg.ws_dimmer == nvalue)) {
|
||||
return 1;
|
||||
}
|
||||
if ((SONOFF_LED == sysCfg.module) && (sysCfg.led_dimmer[i] == nvalue)) {
|
||||
if (sfl_flg && (sysCfg.led_dimmer[i] == nvalue)) {
|
||||
return 1;
|
||||
}
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("%s/%s/DIMMER%s"),
|
||||
sysCfg.mqtt_prefix[0], sysCfg.mqtt_topic, (Maxdevice > 1) ? stemp1 : "");
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("/DIMMER%s"), (Maxdevice > 1) ? stemp1 : "");
|
||||
snprintf_P(dataBuf, sdataBuf, PSTR("%d"), nvalue);
|
||||
found = 1;
|
||||
} else {
|
||||
if (((power >> i) &1) == nvalue) {
|
||||
return 1;
|
||||
}
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("%s/%s/POWER%s"),
|
||||
sysCfg.mqtt_prefix[0], sysCfg.mqtt_topic, (Maxdevice > 1) ? stemp1 : "");
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("/POWER%s"), (Maxdevice > 1) ? stemp1 : "");
|
||||
snprintf_P(dataBuf, sdataBuf, PSTR("%d"), nvalue);
|
||||
found = 1;
|
||||
}
|
||||
@@ -211,47 +210,33 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
|
||||
boolean serviced = true;
|
||||
|
||||
if (!strncmp_P(type,PSTR("DOMOTICZ"),8)) {
|
||||
if (!strcmp_P(type +8,PSTR("INTOPIC"))) {
|
||||
if ((data_len > 0) && (data_len < sizeof(sysCfg.domoticz_in_topic))) {
|
||||
strlcpy(sysCfg.domoticz_in_topic, (1 == payload) ? DOMOTICZ_IN_TOPIC : dataBuf, sizeof(sysCfg.domoticz_in_topic));
|
||||
restartflag = 2;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzInTopic\":\"%s\"}"), sysCfg.domoticz_in_topic);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("OUTTOPIC"))) {
|
||||
if ((data_len > 0) && (data_len < sizeof(sysCfg.domoticz_out_topic))) {
|
||||
strlcpy(sysCfg.domoticz_out_topic, (1 == payload) ? DOMOTICZ_OUT_TOPIC : dataBuf, sizeof(sysCfg.domoticz_out_topic));
|
||||
restartflag = 2;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzOutTopic\":\"%s\"}"), sysCfg.domoticz_out_topic);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("IDX")) && (index > 0) && (index <= Maxdevice)) {
|
||||
if ((data_len > 0) && (payload >= 0)) {
|
||||
if (!strcmp_P(type +8,PSTR("IDX")) && (index > 0) && (index <= Maxdevice)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_relay_idx[index -1] = payload;
|
||||
restartflag = 2;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzIdx%d\":%d}"), index, sysCfg.domoticz_relay_idx[index -1]);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("KEYIDX")) && (index > 0) && (index <= Maxdevice)) {
|
||||
if ((data_len > 0) && (payload >= 0)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_key_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzKeyIdx%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("SWITCHIDX")) && (index > 0) && (index <= Maxdevice)) {
|
||||
if ((data_len > 0) && (payload >= 0)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_switch_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzSwitchIdx%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("SENSORIDX")) && (index > 0) && (index <= DOMOTICZ_MAX_SENSORS)) {
|
||||
if ((data_len > 0) && (payload >= 0)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_sensor_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzSensorIdx%d\":%d}"), index, sysCfg.domoticz_sensor_idx[index -1]);
|
||||
}
|
||||
else if (!strcmp_P(type +8,PSTR("UPDATETIMER"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.domoticz_update_timer = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"DomoticzUpdateTimer\":%d}"), sysCfg.domoticz_update_timer);
|
||||
@@ -269,7 +254,7 @@ boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
|
||||
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"),
|
||||
(key) ? sysCfg.domoticz_switch_idx[device -1] : sysCfg.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off");
|
||||
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
|
||||
mqtt_publish(domoticz_in_topic, svalue);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -290,10 +275,10 @@ void dom_sensor(byte idx, char *data)
|
||||
{
|
||||
char dmess[64];
|
||||
|
||||
if (sysCfg.domoticz_sensor_idx[idx] && (strlen(sysCfg.domoticz_in_topic) != 0)) {
|
||||
if (sysCfg.domoticz_sensor_idx[idx]) {
|
||||
snprintf_P(dmess, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
|
||||
sysCfg.domoticz_sensor_idx[idx], data);
|
||||
mqtt_publish(sysCfg.domoticz_in_topic, dmess);
|
||||
mqtt_publish(domoticz_in_topic, dmess);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +315,13 @@ void domoticz_sensor5(uint16_t lux)
|
||||
dom_sensor(4, data);
|
||||
}
|
||||
|
||||
void domoticz_sensor6(uint32_t count)
|
||||
{
|
||||
char data[16];
|
||||
snprintf_P(data, sizeof(data), PSTR("%d"), count);
|
||||
dom_sensor(5, data);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
@@ -348,8 +340,6 @@ void handleDomoticz()
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Configure Domoticz");
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ);
|
||||
page.replace("{d1}", String(sysCfg.domoticz_in_topic));
|
||||
page.replace("{d2}", String(sysCfg.domoticz_out_topic));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < Maxdevice) {
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ_RELAY);
|
||||
@@ -381,8 +371,6 @@ void domoticz_saveSettings()
|
||||
{
|
||||
char log[LOGSZ], stemp[20];
|
||||
|
||||
strlcpy(sysCfg.domoticz_in_topic, (!strlen(webServer->arg("it").c_str())) ? DOMOTICZ_IN_TOPIC : webServer->arg("it").c_str(), sizeof(sysCfg.domoticz_in_topic));
|
||||
strlcpy(sysCfg.domoticz_out_topic, (!strlen(webServer->arg("ot").c_str())) ? DOMOTICZ_OUT_TOPIC : webServer->arg("ot").c_str(), sizeof(sysCfg.domoticz_out_topic));
|
||||
for (byte i = 0; i < 4; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
|
||||
sysCfg.domoticz_relay_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
@@ -396,15 +384,15 @@ void domoticz_saveSettings()
|
||||
sysCfg.domoticz_sensor_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
}
|
||||
sysCfg.domoticz_update_timer = (!strlen(webServer->arg("ut").c_str())) ? DOMOTICZ_UPDATE_TIMER : atoi(webServer->arg("ut").c_str());
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: Domoticz in %s, out %s, idx %d, %d, %d, %d, update timer %d"),
|
||||
sysCfg.domoticz_in_topic, sysCfg.domoticz_out_topic,
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: Domoticz idx %d, %d, %d, %d, update timer %d"),
|
||||
sysCfg.domoticz_relay_idx[0], sysCfg.domoticz_relay_idx[1], sysCfg.domoticz_relay_idx[2], sysCfg.domoticz_relay_idx[3],
|
||||
sysCfg.domoticz_update_timer);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: key %d, %d, %d, %d, switch %d, %d, %d, %d, sensor %d, %d, %d, %d, %d"),
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: key %d, %d, %d, %d, switch %d, %d, %d, %d, sensor %d, %d, %d, %d, %d, %d"),
|
||||
sysCfg.domoticz_key_idx[0], sysCfg.domoticz_key_idx[1], sysCfg.domoticz_key_idx[2], sysCfg.domoticz_key_idx[3],
|
||||
sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3],
|
||||
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3], sysCfg.domoticz_sensor_idx[4]);
|
||||
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3],
|
||||
sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5]);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
+14
-20
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Heiko Krupp and Theo Arends. All rights reserved.
|
||||
xdrv_ir_send.ino - infra red support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_IR_REMOTE
|
||||
@@ -267,7 +261,7 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
|
||||
mode = (p - HVACMODE +1) << 3; // HOT = 0x08, DRY = 0x10, COOL = 0x18, AUTO = 0x20
|
||||
mitsubir->setMode(mode);
|
||||
|
||||
mitsubir->setPower(~HVAC_Power);
|
||||
mitsubir->setPower(HVAC_Power);
|
||||
|
||||
if (HVAC_FanMode == NULL) {
|
||||
p = (char*)FANSPEED; // default FAN_SPEED_AUTO
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
xdrv_snfbridge.ino - sonoff RF bridge 433 support for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
Sonoff RF Bridge 433
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint8_t sfb_rcvflg = 0;
|
||||
uint8_t sfb_learnKey = 1;
|
||||
uint8_t sfb_learnFlg = 0;
|
||||
|
||||
void sb_received()
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint32_t sid = 0;
|
||||
uint32_t rid = 0;
|
||||
uint16_t rsy = 0;
|
||||
uint16_t rlo = 0;
|
||||
uint16_t rhi = 0;
|
||||
char svalue[90];
|
||||
char rfkey[8];
|
||||
char log[LOGSZ];
|
||||
|
||||
svalue[0] = '\0';
|
||||
for (i = 0; i < SerialInByteCounter; i++) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%02X "), svalue, serialInBuf[i]);
|
||||
}
|
||||
snprintf_P(log, sizeof(log), PSTR("BRDG: Received %s"), svalue);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
if (0xA2 == serialInBuf[0]) { // Learn timeout
|
||||
sfb_learnFlg = 0;
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfKey%d\":\"Learn failed\"}"), sfb_learnKey);
|
||||
mqtt_publish_topic_P(5, PSTR("RFKEY"), svalue);
|
||||
}
|
||||
else if (0xA3 == serialInBuf[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||
sfb_learnFlg = 0;
|
||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
||||
if (rlo && rhi) {
|
||||
for (i = 0; i < 9; i++) {
|
||||
sysCfg.sfb_code[sfb_learnKey][i] = serialInBuf[i +1];
|
||||
}
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfKey%d\":\"Learned\"}"), sfb_learnKey);
|
||||
} else {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfKey%d\":\"Learn failed\"}"), sfb_learnKey);
|
||||
}
|
||||
mqtt_publish_topic_P(5, PSTR("RFKEY"), svalue);
|
||||
}
|
||||
else if (0xA4 == serialInBuf[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
|
||||
rsy = serialInBuf[1] << 8 | serialInBuf[2]; // Sync time in uSec
|
||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
||||
rid = serialInBuf[7] << 16 | serialInBuf[8] << 8 | serialInBuf[9];
|
||||
strcpy_P(rfkey, PSTR("\"None\""));
|
||||
for (i = 1; i <= 16; i++) {
|
||||
if (sysCfg.sfb_code[i][0]) {
|
||||
sid = sysCfg.sfb_code[i][6] << 16 | sysCfg.sfb_code[i][7] << 8 | sysCfg.sfb_code[i][8];
|
||||
if (sid == rid) {
|
||||
snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfReceived\":{\"Sync\":%d, \"Low\":%d, \"High\":%d, \"Data\":\"%06X\", \"RfKey\":%s}}"),
|
||||
rsy, rlo, rhi, rid, rfkey);
|
||||
mqtt_publish_topic_P(6, PSTR("RFRECEIVED"), svalue);
|
||||
}
|
||||
}
|
||||
|
||||
boolean sb_serial()
|
||||
{
|
||||
if (sfb_rcvflg) {
|
||||
if (!((SerialInByteCounter == 0) && (SerialInByte == 0))) { // Skip leading 0
|
||||
serialInBuf[SerialInByteCounter++] = SerialInByte;
|
||||
if (0x55 == SerialInByte) { // 0x55 - End of text
|
||||
sb_received();
|
||||
sfb_rcvflg = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
SerialInByte = 0;
|
||||
}
|
||||
if (0xAA == SerialInByte) { // 0xAA - Start of text
|
||||
SerialInByteCounter = 0;
|
||||
SerialInByte = 0;
|
||||
sfb_rcvflg = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sb_sendAck()
|
||||
{
|
||||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA0); // Acknowledge
|
||||
Serial.write(0x55); // End of Text
|
||||
}
|
||||
|
||||
void sb_send(uint8_t idx, uint8_t key)
|
||||
{
|
||||
uint8_t code;
|
||||
|
||||
key--; // Support 1 to 16
|
||||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA5); // Send following code
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
Serial.write(sysCfg.sfb_code[idx][i]);
|
||||
}
|
||||
if (0 == idx) {
|
||||
code = (0x10 << (key >> 2)) | (0x01 << (key & 3)); // 11,12,14,18,21,22,24,28,41,42,44,48,81,82,84,88
|
||||
} else {
|
||||
code = sysCfg.sfb_code[idx][8];
|
||||
}
|
||||
Serial.write(code);
|
||||
Serial.write(0x55); // End of Text
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void sb_learn(uint8_t key)
|
||||
{
|
||||
sfb_learnKey = key;
|
||||
sfb_learnFlg = 1;
|
||||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA1); // Start learning
|
||||
Serial.write(0x55); // End of Text
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
|
||||
{
|
||||
boolean serviced = true;
|
||||
char *p;
|
||||
|
||||
if (!strcmp_P(type, PSTR("RFDEFAULT"))) {
|
||||
if (4 == data_len) {
|
||||
uint16_t hexcode = strtol(dataBuf, &p, 16);
|
||||
uint8_t msb = hexcode >> 8;
|
||||
uint8_t lsb = hexcode & 0xFF;
|
||||
if ((hexcode > 0) && (hexcode < 0x7FFF) && (msb != 0x55) && (lsb != 0x55)) {
|
||||
sysCfg.sfb_code[0][6] = msb;
|
||||
sysCfg.sfb_code[0][7] = lsb;
|
||||
}
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfDefault\":\"%0X%0X\"}"), sysCfg.sfb_code[0][6], sysCfg.sfb_code[0][7]);
|
||||
}
|
||||
else if (!strcmp_P(type, PSTR("RFKEY")) && (index > 0) && (index <= 16)) {
|
||||
if (!sfb_learnFlg) {
|
||||
if (2 == payload) {
|
||||
sb_learn(index);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfKey%d\":\"Start learning\"}"), index);
|
||||
}
|
||||
else if (3 == payload) {
|
||||
sysCfg.sfb_code[index][0] = 0;
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfKey%d\":\"Set to default\"}"), index);
|
||||
} else {
|
||||
if ((1 == payload) || (0 == sysCfg.sfb_code[index][0])) {
|
||||
sb_send(0, index);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfKey%d\":\"Default sent\"}"), index);
|
||||
} else {
|
||||
sb_send(index, 0);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfKey%d\":\"Learned sent\"}"), index);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"RfKey%d\":\"Learning active\"}"), sfb_learnKey);
|
||||
}
|
||||
}
|
||||
else {
|
||||
serviced = false; // Unknown command
|
||||
}
|
||||
return serviced;
|
||||
}
|
||||
+408
-138
@@ -1,30 +1,31 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xdrv_snfled.ino - sonoff led support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Sonoff Led
|
||||
* Sonoff B1, AiLight, Sonoff Led and BN-SZ01
|
||||
*
|
||||
* sfl_flg Module Color ColorTemp
|
||||
* 1 Sonoff BN-SZ W no
|
||||
* 2 Sonoff Led CW yes
|
||||
* 3 not used
|
||||
* 4 AiLight RGBW no
|
||||
* 5 Sonoff B1 RGBCW yes
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint8_t ledTable[] = {
|
||||
@@ -45,9 +46,9 @@ uint8_t ledTable[] = {
|
||||
184,186,189,191,193,195,197,199,201,204,206,208,210,212,215,217,
|
||||
219,221,224,226,228,231,233,235,238,240,243,245,248,250,253,255 };
|
||||
|
||||
uint8_t sl_dcolor[2];
|
||||
uint8_t sl_tcolor[2];
|
||||
uint8_t sl_lcolor[2];
|
||||
uint8_t sl_dcolor[5];
|
||||
uint8_t sl_tcolor[5];
|
||||
uint8_t sl_lcolor[5];
|
||||
|
||||
uint8_t sl_power;
|
||||
uint8_t sl_any;
|
||||
@@ -55,54 +56,236 @@ uint8_t sl_wakeupActive = 0;
|
||||
uint8_t sl_wakeupDimmer = 0;
|
||||
uint16_t sl_wakeupCntr = 0;
|
||||
|
||||
uint32_t Atoh(char *s)
|
||||
{
|
||||
uint32_t value = 0;
|
||||
uint32_t digit;
|
||||
int8_t c;
|
||||
|
||||
while((c = *s++)) {
|
||||
if ('0' <= c && c <= '9') {
|
||||
digit = c - '0';
|
||||
}
|
||||
else if ('A' <= c && c <= 'F') {
|
||||
digit = c - 'A' + 10;
|
||||
}
|
||||
else if ('a' <= c && c <= 'f') {
|
||||
digit = c - 'a' + 10;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
value = (value << 4) | digit;
|
||||
}
|
||||
return value;
|
||||
/*********************************************************************************************\
|
||||
* Sonoff B1 and AiLight inspired by OpenLight https://github.com/icamgo/noduino-sdk
|
||||
\*********************************************************************************************/
|
||||
|
||||
extern "C" {
|
||||
void os_delay_us(unsigned int);
|
||||
}
|
||||
|
||||
void sl_setDim(uint8_t myDimmer)
|
||||
uint8_t sl_pdi;
|
||||
uint8_t sl_pdcki;
|
||||
|
||||
void sl_di_pulse(uint8_t times)
|
||||
{
|
||||
float newDim = 100 / (float)myDimmer;
|
||||
float fmyCld = (float)sysCfg.led_color[0] / newDim;
|
||||
float fmyWrm = (float)sysCfg.led_color[1] / newDim;
|
||||
sl_dcolor[0] = (uint8_t)fmyCld;
|
||||
sl_dcolor[1] = (uint8_t)fmyWrm;
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(sl_pdi, HIGH);
|
||||
digitalWrite(sl_pdi, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_dcki_pulse(uint8_t times)
|
||||
{
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(sl_pdcki, HIGH);
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_my92x1_write(uint8_t data)
|
||||
{
|
||||
for (uint8_t i = 0; i < 4; i++) { // Send 8bit Data
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
digitalWrite(sl_pdi, (data & 0x80));
|
||||
digitalWrite(sl_pdcki, HIGH);
|
||||
data = data << 1;
|
||||
digitalWrite(sl_pdi, (data & 0x80));
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
digitalWrite(sl_pdi, LOW);
|
||||
data = data << 1;
|
||||
}
|
||||
}
|
||||
|
||||
void sl_my92x1_init()
|
||||
{
|
||||
uint8_t chips = sfl_flg -3; // 1 (AiLight) or 2 (Sonoff B1)
|
||||
|
||||
sl_dcki_pulse(chips * 32); // Clear all duty register
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
// Send 12 DI pulse, after 6 pulse's falling edge store duty data, and 12
|
||||
// pulse's rising edge convert to command mode.
|
||||
sl_di_pulse(12);
|
||||
os_delay_us(12); // Delay >12us, begin send CMD data
|
||||
for (uint8_t n = 0; n < chips; n++) { // Send CMD data
|
||||
sl_my92x1_write(0x18); // ONE_SHOT_DISABLE, REACTION_FAST, BIT_WIDTH_8, FREQUENCY_DIVIDE_1, SCATTER_APDM
|
||||
}
|
||||
os_delay_us(12); // TStart > 12us. Delay 12 us.
|
||||
// Send 16 DI pulse, at 14 pulse's falling edge store CMD data, and
|
||||
// at 16 pulse's falling edge convert to duty mode.
|
||||
sl_di_pulse(16);
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
}
|
||||
|
||||
void sl_my92x1_duty(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b, uint8_t duty_w, uint8_t duty_c)
|
||||
{
|
||||
uint8_t channels[2] = { 4, 6 };
|
||||
|
||||
uint8_t didx = sfl_flg -4; // 0 or 1
|
||||
|
||||
uint8_t duty[2][6] = {{ duty_r, duty_g, duty_b, duty_w, 0, 0 }, // Definition for RGBW channels
|
||||
{ duty_w, duty_c, 0, duty_g, duty_r, duty_b }}; // Definition for RGBWC channels
|
||||
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
for (uint8_t channel = 0; channel < channels[didx]; channel++) {
|
||||
sl_my92x1_write(duty[didx][channel]); // Send 8bit Data
|
||||
}
|
||||
os_delay_us(12); // TStart > 12us. Ready for send DI pulse.
|
||||
sl_di_pulse(8); // Send 8 DI pulse. After 8 pulse falling edge, store old data.
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void sl_init(void)
|
||||
{
|
||||
sysCfg.pwmvalue[0] = 0; // We use led_color
|
||||
sysCfg.pwmvalue[1] = 0; // We use led_color
|
||||
pin[GPIO_WS2812] = 99; // I do not allow both Sonoff Led AND WS2812 led
|
||||
if (sfl_flg < 4) {
|
||||
if (!my_module.gp.io[4]) {
|
||||
pinMode(4, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(4, LOW);
|
||||
}
|
||||
if (!my_module.gp.io[5]) {
|
||||
pinMode(5, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(5, LOW);
|
||||
}
|
||||
if (!my_module.gp.io[14]) {
|
||||
pinMode(14, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(14, LOW);
|
||||
}
|
||||
sysCfg.pwmvalue[0] = 0; // We use dimmer / led_color
|
||||
if (2 == sfl_flg) {
|
||||
sysCfg.pwmvalue[1] = 0; // We use led_color
|
||||
}
|
||||
} else {
|
||||
sl_pdi = pin[GPIO_DI];
|
||||
sl_pdcki = pin[GPIO_DCKI];
|
||||
|
||||
pinMode(sl_pdi, OUTPUT);
|
||||
pinMode(sl_pdcki, OUTPUT);
|
||||
digitalWrite(sl_pdi, LOW);
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
|
||||
sl_my92x1_init();
|
||||
}
|
||||
|
||||
sl_power = 0;
|
||||
sl_any = 0;
|
||||
sl_wakeupActive = 0;
|
||||
}
|
||||
|
||||
void sl_setColorTemp(uint16_t ct)
|
||||
{
|
||||
/* Color Temperature (https://developers.meethue.com/documentation/core-concepts)
|
||||
*
|
||||
* ct = 153 = 2000K = Warm = CCWW = 00FF
|
||||
* ct = 500 = 6500K = Cold = CCWW = FF00
|
||||
*/
|
||||
uint16_t my_ct = ct - 153;
|
||||
if (my_ct > 347) {
|
||||
my_ct = 347;
|
||||
}
|
||||
uint16_t icold = (100 * (347 - my_ct)) / 136;
|
||||
uint16_t iwarm = (100 * my_ct) / 136;
|
||||
if (5 == sfl_flg) {
|
||||
sysCfg.led_color[0] = 0;
|
||||
sysCfg.led_color[1] = 0;
|
||||
sysCfg.led_color[2] = 0;
|
||||
sysCfg.led_color[3] = (uint8_t)icold;
|
||||
sysCfg.led_color[4] = (uint8_t)iwarm;
|
||||
} else {
|
||||
sysCfg.led_color[0] = (uint8_t)icold;
|
||||
sysCfg.led_color[1] = (uint8_t)iwarm;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t sl_getColorTemp()
|
||||
{
|
||||
uint8_t ct_idx = 0;
|
||||
if (5 == sfl_flg) {
|
||||
ct_idx = 3;
|
||||
}
|
||||
uint16_t my_ct = sysCfg.led_color[ct_idx +1];
|
||||
if (my_ct > 0) {
|
||||
return ((my_ct * 136) / 100) + 154;
|
||||
} else {
|
||||
my_ct = sysCfg.led_color[ct_idx];
|
||||
return 499 - ((my_ct * 136) / 100);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setDim(uint8_t myDimmer)
|
||||
{
|
||||
float temp;
|
||||
|
||||
if ((1 == sfl_flg) && (100 == myDimmer)) {
|
||||
myDimmer = 99; // BN-SZ01 starts flickering at dimmer = 100
|
||||
}
|
||||
float newDim = 100 / (float)myDimmer;
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
temp = (float)sysCfg.led_color[i] / newDim;
|
||||
sl_dcolor[i] = (uint8_t)temp;
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setColor()
|
||||
{
|
||||
uint8_t highest = 0;
|
||||
float temp;
|
||||
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
if (highest < sl_dcolor[i]) {
|
||||
highest = sl_dcolor[i];
|
||||
}
|
||||
}
|
||||
float mDim = (float)highest / 2.55;
|
||||
sysCfg.led_dimmer[0] = (uint8_t)mDim;
|
||||
float newDim = 100 / mDim;
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
temp = (float)sl_dcolor[i] * newDim;
|
||||
sysCfg.led_color[i] = (uint8_t)temp;
|
||||
}
|
||||
}
|
||||
|
||||
char* sl_getColor(char* scolor)
|
||||
{
|
||||
sl_setDim(sysCfg.led_dimmer[0]);
|
||||
scolor[0] = '\0';
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
snprintf_P(scolor, 11, PSTR("%s%02X"), scolor, sl_dcolor[i]);
|
||||
}
|
||||
return scolor;
|
||||
}
|
||||
|
||||
void sl_prepPower(char *svalue, uint16_t ssvalue)
|
||||
{
|
||||
char scolor[11];
|
||||
|
||||
// do_cmnd_power(index, (sysCfg.led_dimmer[0]>0));
|
||||
if (sysCfg.led_dimmer[0] && !(power&1)) {
|
||||
do_cmnd_power(1, 7); // No publishPowerState
|
||||
}
|
||||
else if (!sysCfg.led_dimmer[0] && (power&1)) {
|
||||
do_cmnd_power(1, 6); // No publishPowerState
|
||||
}
|
||||
#ifdef USE_DOMOTICZ
|
||||
mqtt_publishDomoticzPowerState(1);
|
||||
#endif // USE_DOMOTICZ
|
||||
if (sfl_flg > 1) {
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"POWER\":\"%s\", \"Dimmer\":%d, \"Color\":\"%s\"}"),
|
||||
getStateText(power &1), sysCfg.led_dimmer[0], sl_getColor(scolor));
|
||||
} else {
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"POWER\":\"%s\", \"Dimmer\":%d}"),
|
||||
getStateText(power &1), sysCfg.led_dimmer[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setPower(uint8_t power)
|
||||
{
|
||||
sl_power = power &1;
|
||||
sl_wakeupActive = 0;
|
||||
if (sl_wakeupActive) {
|
||||
sl_wakeupActive--;
|
||||
}
|
||||
sl_animate();
|
||||
}
|
||||
|
||||
@@ -111,38 +294,38 @@ void sl_animate()
|
||||
// {"Wakeup":"Done"}
|
||||
char svalue[32]; // was MESSZ
|
||||
uint8_t fadeValue;
|
||||
uint8_t cur_col[5];
|
||||
|
||||
if (0 == sl_power) { // Power Off
|
||||
sl_tcolor[0] = 0;
|
||||
sl_tcolor[1] = 0;
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sl_tcolor[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!sl_wakeupActive) { // Power On
|
||||
sl_setDim(sysCfg.led_dimmer[0]);
|
||||
if (0 == sysCfg.led_fade) {
|
||||
sl_tcolor[0] = sl_dcolor[0];
|
||||
sl_tcolor[1] = sl_dcolor[1];
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sl_tcolor[i] = sl_dcolor[i];
|
||||
}
|
||||
} else {
|
||||
if ((sl_tcolor[0] != sl_dcolor[0]) || (sl_tcolor[1] != sl_dcolor[1])) {
|
||||
if (sl_tcolor[0] < sl_dcolor[0]) {
|
||||
sl_tcolor[0] += ((sl_dcolor[0] - sl_tcolor[0]) >> sysCfg.led_speed) +1;
|
||||
}
|
||||
if (sl_tcolor[1] < sl_dcolor[1]) {
|
||||
sl_tcolor[1] += ((sl_dcolor[1] - sl_tcolor[1]) >> sysCfg.led_speed) +1;
|
||||
}
|
||||
if (sl_tcolor[0] > sl_dcolor[0]) {
|
||||
sl_tcolor[0] -= ((sl_tcolor[0] - sl_dcolor[0]) >> sysCfg.led_speed) +1;
|
||||
}
|
||||
if (sl_tcolor[1] > sl_dcolor[1]) {
|
||||
sl_tcolor[1] -= ((sl_tcolor[1] - sl_dcolor[1]) >> sysCfg.led_speed) +1;
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
if (sl_tcolor[i] != sl_dcolor[i]) {
|
||||
if (sl_tcolor[i] < sl_dcolor[i]) {
|
||||
sl_tcolor[i] += ((sl_dcolor[i] - sl_tcolor[i]) >> sysCfg.led_speed) +1;
|
||||
}
|
||||
if (sl_tcolor[i] > sl_dcolor[i]) {
|
||||
sl_tcolor[i] -= ((sl_tcolor[i] - sl_dcolor[i]) >> sysCfg.led_speed) +1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // Power On using wake up duration
|
||||
if (1 == sl_wakeupActive) {
|
||||
sl_wakeupActive = 2;
|
||||
sl_tcolor[0] = 0;
|
||||
sl_tcolor[1] = 0;
|
||||
if (2 == sl_wakeupActive) {
|
||||
sl_wakeupActive = 1;
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sl_tcolor[i] = 0;
|
||||
}
|
||||
sl_wakeupCntr = 0;
|
||||
sl_wakeupDimmer = 0;
|
||||
}
|
||||
@@ -152,25 +335,135 @@ void sl_animate()
|
||||
sl_wakeupDimmer++;
|
||||
if (sl_wakeupDimmer <= sysCfg.led_dimmer[0]) {
|
||||
sl_setDim(sl_wakeupDimmer);
|
||||
sl_tcolor[0] = sl_dcolor[0];
|
||||
sl_tcolor[1] = sl_dcolor[1];
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sl_tcolor[i] = sl_dcolor[i];
|
||||
}
|
||||
} else {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Wakeup\":\"Done\"}"));
|
||||
mqtt_publish_topic_P(1, PSTR("WAKEUP"), svalue);
|
||||
mqtt_publish_topic_P(2, PSTR("WAKEUP"), svalue);
|
||||
sl_wakeupActive = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((sl_lcolor[0] != sl_tcolor[0]) || (sl_lcolor[1] != sl_tcolor[1]) || sl_any) {
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
if (sl_lcolor[i] != sl_tcolor[i]) {
|
||||
sl_any = 1;
|
||||
}
|
||||
}
|
||||
if (sl_any) {
|
||||
sl_any = 0;
|
||||
sl_lcolor[0] = sl_tcolor[0];
|
||||
sl_lcolor[1] = sl_tcolor[1];
|
||||
for (byte i = 0; i < 2; i++) {
|
||||
if (pin[GPIO_PWM1 +i] < 99) {
|
||||
analogWrite(pin[GPIO_PWM1 +i], ((sysCfg.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i]) * (PWM_RANGE / 255));
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sl_lcolor[i] = sl_tcolor[i];
|
||||
cur_col[i] = (sysCfg.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i];
|
||||
if (sfl_flg < 4) {
|
||||
if (pin[GPIO_PWM1 +i] < 99) {
|
||||
analogWrite(pin[GPIO_PWM1 +i], cur_col[i] * (PWM_RANGE / 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sfl_flg > 3) {
|
||||
sl_my92x1_duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Hue support
|
||||
\*********************************************************************************************/
|
||||
|
||||
void sl_rgb2hsb(float *hue, float *sat, float *bri)
|
||||
{
|
||||
RgbColor dcolor;
|
||||
|
||||
sl_setDim(sysCfg.led_dimmer[0]);
|
||||
dcolor.R = sl_dcolor[0];
|
||||
dcolor.G = sl_dcolor[1];
|
||||
dcolor.B = sl_dcolor[2];
|
||||
HsbColor hsb = HsbColor(dcolor);
|
||||
*hue = hsb.H;
|
||||
*sat = hsb.S;
|
||||
*bri = hsb.B;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void sl_replaceHSB(String *response)
|
||||
{
|
||||
float hue;
|
||||
float sat;
|
||||
float bri;
|
||||
|
||||
if (sfl_flg > 2) {
|
||||
sl_rgb2hsb(&hue, &sat, &bri);
|
||||
response->replace("{h}", String((uint16_t)(65535.0f * hue)));
|
||||
response->replace("{s}", String((uint8_t)(254.0f * sat)));
|
||||
response->replace("{b}", String((uint8_t)(254.0f * bri)));
|
||||
} else {
|
||||
response->replace("{h}", "0");
|
||||
response->replace("{s}", "0");
|
||||
// response->replace("{b}", String((uint8_t)(2.54f * (float)sysCfg.led_dimmer[0])));
|
||||
response->replace("{b}", String((uint8_t)(0.01f * (float)sysCfg.led_dimmer[0])));
|
||||
}
|
||||
}
|
||||
|
||||
void sl_getHSB(float *hue, float *sat, float *bri)
|
||||
{
|
||||
if (sfl_flg > 2) {
|
||||
sl_rgb2hsb(hue, sat, bri);
|
||||
} else {
|
||||
*hue = 0;
|
||||
*sat = 0;
|
||||
// *bri = (2.54f * (float)sysCfg.led_dimmer[0]);
|
||||
*bri = (0.01f * (float)sysCfg.led_dimmer[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
||||
{
|
||||
char svalue[MESSZ];
|
||||
HsbColor hsb;
|
||||
|
||||
/*
|
||||
char log[LOGSZ];
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
char stemp3[10];
|
||||
dtostrf(hue, 1, 3, stemp1);
|
||||
dtostrf(sat, 1, 3, stemp2);
|
||||
dtostrf(bri, 1, 3, stemp3);
|
||||
snprintf_P(log, sizeof(log), PSTR("HUE: Set Hue %s, Sat %s, Bri %s, Ct %d"), stemp1, stemp2, stemp3, ct);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
*/
|
||||
|
||||
if (sfl_flg > 2) {
|
||||
if ((5 == sfl_flg) && (ct > 0)) {
|
||||
sl_setColorTemp(ct);
|
||||
} else {
|
||||
hsb.H = hue;
|
||||
hsb.S = sat;
|
||||
hsb.B = bri;
|
||||
RgbColor tmp = RgbColor(hsb);
|
||||
sl_dcolor[0] = tmp.R;
|
||||
sl_dcolor[1] = tmp.G;
|
||||
sl_dcolor[2] = tmp.B;
|
||||
sl_setColor();
|
||||
}
|
||||
sl_prepPower(svalue, sizeof(svalue));
|
||||
mqtt_publish_topic_P(5, "COLOR", svalue);
|
||||
} else {
|
||||
uint8_t tmp = (uint8_t)(bri * 100);
|
||||
sysCfg.led_dimmer[0] = tmp;
|
||||
if (2 == sfl_flg) {
|
||||
if (ct > 0) {
|
||||
sl_setColorTemp(ct);
|
||||
}
|
||||
sl_prepPower(svalue, sizeof(svalue));
|
||||
mqtt_publish_topic_P(5, "COLOR", svalue);
|
||||
} else {
|
||||
sl_prepPower(svalue, sizeof(svalue));
|
||||
mqtt_publish_topic_P(5, "DIMMER", svalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,38 +475,31 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
|
||||
{
|
||||
boolean serviced = true;
|
||||
boolean coldim = false;
|
||||
char scolor[11];
|
||||
char *p;
|
||||
|
||||
if (!strcmp_P(type,PSTR("COLOR"))) {
|
||||
uint8_t my_color[5];
|
||||
if (4 == data_len) {
|
||||
char ccold[3], cwarm[3];
|
||||
memcpy(ccold, dataBufUc, 2);
|
||||
ccold[2] = '\0';
|
||||
memcpy(cwarm, dataBufUc + 2, 2);
|
||||
cwarm[2] = '\0';
|
||||
my_color[0] = Atoh(ccold);
|
||||
my_color[1] = Atoh(cwarm);
|
||||
uint16_t temp = my_color[0];
|
||||
if (temp < my_color[1]) {
|
||||
temp = my_color[1];
|
||||
if ((sfl_flg > 1) && !strcmp_P(type,PSTR("COLOR"))) {
|
||||
if ((2 * sfl_flg) == data_len) {
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
strlcpy(scolor, dataBufUc + (i *2), 3);
|
||||
sl_dcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
||||
}
|
||||
float mDim = (float)temp / 2.55;
|
||||
sysCfg.led_dimmer[0] = (uint8_t)mDim;
|
||||
float newDim = 100 / mDim;
|
||||
float fmyCold = (float)my_color[0] * newDim;
|
||||
float fmyWarm = (float)my_color[1] * newDim;
|
||||
sysCfg.led_color[0] = (uint8_t)fmyCold;
|
||||
sysCfg.led_color[1] = (uint8_t)fmyWarm;
|
||||
sl_setColor();
|
||||
coldim = true;
|
||||
} else {
|
||||
sl_setDim(sysCfg.led_dimmer[0]);
|
||||
uint16_t color = (uint16_t)sl_dcolor[0] << 8;
|
||||
color += (uint16_t)sl_dcolor[1];
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Color\":\"%04X\"}"), color);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Color\":\"%s\"}"), sl_getColor(scolor));
|
||||
}
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("CT")) && ((2 == sfl_flg) || (5 == sfl_flg))) { // ColorTemp
|
||||
if ((payload >= 153) && (payload <= 500)) { // https://developers.meethue.com/documentation/core-concepts
|
||||
sl_setColorTemp(payload);
|
||||
coldim = true;
|
||||
} else {
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"CT\":%d}"), sl_getColorTemp());
|
||||
}
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("DIMMER"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 100)) {
|
||||
if ((payload >= 0) && (payload <= 100)) {
|
||||
sysCfg.led_dimmer[0] = payload;
|
||||
coldim = true;
|
||||
} else {
|
||||
@@ -221,7 +507,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
|
||||
}
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("LEDTABLE"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 2)) {
|
||||
if ((payload >= 0) && (payload <= 2)) {
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
@@ -236,56 +522,40 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"LedTable\":\"%s\"}"), getStateText(sysCfg.led_table));
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("FADE"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 2)) {
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.led_fade = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.led_fade ^= 1;
|
||||
break;
|
||||
}
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.led_fade = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.led_fade ^= 1;
|
||||
break;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Fade\":\"%s\"}"), getStateText(sysCfg.led_fade));
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SPEED"))) { // 1 - fast, 8 - slow
|
||||
if ((data_len > 0) && (payload > 0) && (payload <= 8)) {
|
||||
if ((payload > 0) && (payload <= 8)) {
|
||||
sysCfg.led_speed = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Speed\":%d}"), sysCfg.led_speed);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("WAKEUPDURATION"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload < 3601)) {
|
||||
if ((payload > 0) && (payload < 3001)) {
|
||||
sysCfg.led_wakeup = payload;
|
||||
sl_wakeupActive = 0;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"WakeUpDuration\":%d}"), sysCfg.led_wakeup);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("WAKEUP"))) {
|
||||
do_cmnd_power(index, 1);
|
||||
sl_wakeupActive = 1;
|
||||
sl_wakeupActive = 3;
|
||||
do_cmnd_power(1, 1);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Wakeup\":\"Started\"}"));
|
||||
}
|
||||
else {
|
||||
serviced = false; // Unknown command
|
||||
}
|
||||
if (coldim) {
|
||||
// do_cmnd_power(index, (sysCfg.led_dimmer[0]>0));
|
||||
if (sysCfg.led_dimmer[0] && !(power&1)) {
|
||||
do_cmnd_power(1, 1);
|
||||
}
|
||||
else if (!sysCfg.led_dimmer[0] && (power&1)) {
|
||||
do_cmnd_power(1, 0);
|
||||
}
|
||||
#ifdef USE_DOMOTICZ
|
||||
mqtt_publishDomoticzPowerState(1);
|
||||
#endif // USE_DOMOTICZ
|
||||
sl_setDim(sysCfg.led_dimmer[0]);
|
||||
uint16_t color = (uint16_t)sl_dcolor[0] << 8;
|
||||
color += (uint16_t)sl_dcolor[1];
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"POWER\":\"%s\", \"Dimmer\":%d, \"Color\":\"%04X\"}"),
|
||||
getStateText(power &1), sysCfg.led_dimmer[0], color);
|
||||
sl_prepPower(svalue, ssvalue);
|
||||
}
|
||||
return serviced;
|
||||
}
|
||||
|
||||
+46
-52
@@ -1,62 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xdrv_snfsc.ino - sonoff SC support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Sonoff Sc
|
||||
*
|
||||
* sc_value[0] DHT11 Humidity
|
||||
* sc_value[1] DHT11 Temperature in Celsius
|
||||
* sc_value[2] Light level from 1 (Dark) to 10 (Bright) - inverted from original
|
||||
* sc_value[3] Noise level from 1 (Quiet) to 10 (Loud)
|
||||
* sc_value[4] Air Quality level from 1 (Bad) to 10 (Good) - inverted from original
|
||||
*
|
||||
* To ATMEGA328P:
|
||||
* AT+DEVCONFIG="uploadFreq":1800,"humiThreshold":2,"tempThreshold":1[1B]
|
||||
* AT+NOTIFY="uploadFreq":1800,"humiThreshold":2,"tempThreshold":1[1B]
|
||||
* response: AT+NOTIFY=ok[1B]
|
||||
* AT+SEND=fail[1B]
|
||||
* AT+SEND=ok[1B]
|
||||
* AT+STATUS=4[1B]
|
||||
* AT+STATUS[1B]
|
||||
* AT+START[1B]
|
||||
*
|
||||
* From ATMEGA328P:
|
||||
* AT+UPDATE="humidity":42,"temperature":20,"light":7,"noise":3,"dusty":1[1B]
|
||||
* response: AT+SEND=ok[1B] or AT+SEND=fail[1B]
|
||||
* AT+STATUS?[1B]
|
||||
* response: AT+STATUS=4[1B]
|
||||
*
|
||||
* Sequence:
|
||||
* SC sends: ATMEGA328P sends:
|
||||
* AT+START[1B]
|
||||
* AT+UPDATE="humidity":42,"temperature":20,"light":7,"noise":3,"dusty":1[1B]
|
||||
* AT+SEND=ok[1B]
|
||||
*
|
||||
* AT+STATUS?[1B]
|
||||
* AT+STATUS=4[1B]
|
||||
*
|
||||
Sonoff Sc
|
||||
|
||||
sc_value[0] DHT11 Humidity
|
||||
sc_value[1] DHT11 Temperature in Celsius
|
||||
sc_value[2] Light level from 1 (Dark) to 10 (Bright) - inverted from original
|
||||
sc_value[3] Noise level from 1 (Quiet) to 10 (Loud)
|
||||
sc_value[4] Air Quality level from 1 (Bad) to 10 (Good) - inverted from original
|
||||
|
||||
To ATMEGA328P:
|
||||
AT+DEVCONFIG="uploadFreq":1800,"humiThreshold":2,"tempThreshold":1[1B]
|
||||
AT+NOTIFY="uploadFreq":1800,"humiThreshold":2,"tempThreshold":1[1B]
|
||||
response: AT+NOTIFY=ok[1B]
|
||||
AT+SEND=fail[1B]
|
||||
AT+SEND=ok[1B]
|
||||
AT+STATUS=4[1B]
|
||||
AT+STATUS[1B]
|
||||
AT+START[1B]
|
||||
|
||||
From ATMEGA328P:
|
||||
AT+UPDATE="humidity":42,"temperature":20,"light":7,"noise":3,"dusty":1[1B]
|
||||
response: AT+SEND=ok[1B] or AT+SEND=fail[1B]
|
||||
AT+STATUS?[1B]
|
||||
response: AT+STATUS=4[1B]
|
||||
|
||||
Sequence:
|
||||
SC sends: ATMEGA328P sends:
|
||||
AT+START[1B]
|
||||
AT+UPDATE="humidity":42,"temperature":20,"light":7,"noise":3,"dusty":1[1B]
|
||||
AT+SEND=ok[1B]
|
||||
|
||||
AT+STATUS?[1B]
|
||||
AT+STATUS=4[1B]
|
||||
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint16_t sc_value[5] = { 0 };
|
||||
|
||||
+336
-231
@@ -1,28 +1,26 @@
|
||||
/*
|
||||
Copyright (c) 2017 Heiko Krupp and Theo Arends. All rights reserved.
|
||||
xdrv_wemohue.ino - wemo and hue support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Belkin WeMo and Philips Hue bridge emulation
|
||||
\*********************************************************************************************/
|
||||
|
||||
#ifdef USE_EMULATION
|
||||
|
||||
#define UDP_BUFFER_SIZE 200 // Max UDP buffer size needed for M-SEARCH message
|
||||
@@ -36,6 +34,7 @@ uint32_t portMulticast = 1900; // Multicast address and port
|
||||
/*********************************************************************************************\
|
||||
* WeMo UPNP support routines
|
||||
\*********************************************************************************************/
|
||||
|
||||
const char WEMO_MSEARCH[] PROGMEM =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"CACHE-CONTROL: max-age=86400\r\n"
|
||||
@@ -89,44 +88,53 @@ void wemo_respondToMSearch()
|
||||
/*********************************************************************************************\
|
||||
* Hue Bridge UPNP support routines
|
||||
* Need to send 3 response packets with varying ST and USN
|
||||
*
|
||||
* Using Espressif Inc Mac Address of 5C:CF:7F:00:00:00
|
||||
* Philips Lighting is 00:17:88:00:00:00
|
||||
\*********************************************************************************************/
|
||||
|
||||
const char HUE_RESPONSE[] PROGMEM =
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"HOST: 239.255.255.250:1900\r\n"
|
||||
"CACHE-CONTROL: max-age=100\r\n"
|
||||
"EXT:\r\n"
|
||||
"LOCATION: http://{r1}:80/description.xml\r\n"
|
||||
"SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.15.0\r\n"
|
||||
"SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.16.0\r\n"
|
||||
"hue-bridgeid: {r2}\r\n";
|
||||
const char HUE_ST1[] PROGMEM =
|
||||
"ST: upnp:rootdevice\r\n";
|
||||
const char HUE_USN1[] PROGMEM =
|
||||
"ST: upnp:rootdevice\r\n"
|
||||
"USN: uuid:{r3}::upnp:rootdevice\r\n"
|
||||
"\r\n";
|
||||
|
||||
const char HUE_ST2[] PROGMEM =
|
||||
"ST: uuid:{r3}\r\n";
|
||||
const char HUE_USN2[] PROGMEM =
|
||||
"ST: uuid:{r3}\r\n"
|
||||
"USN: uuid:{r3}\r\n"
|
||||
"\r\n";
|
||||
|
||||
const char HUE_ST3[] PROGMEM =
|
||||
"ST: urn:schemas-upnp-org:device:basic:1\r\n";
|
||||
"ST: urn:schemas-upnp-org:device:Basic:1\r\n"
|
||||
"USN: uuid:{r3}\r\n"
|
||||
"\r\n";
|
||||
|
||||
String hue_bridgeid()
|
||||
{
|
||||
char bridgeid[16];
|
||||
|
||||
snprintf_P(bridgeid, sizeof(bridgeid), PSTR("5CCF7FFFFE%03X"), ESP.getChipId());
|
||||
return String(bridgeid);
|
||||
String temp = WiFi.macAddress();
|
||||
temp.replace(":", "");
|
||||
String bridgeid = temp.substring(0, 6) + "FFFE" + temp.substring(6);
|
||||
return bridgeid; // 5CCF7FFFFE139F3D
|
||||
}
|
||||
|
||||
String hue_serial()
|
||||
{
|
||||
String serial = WiFi.macAddress();
|
||||
serial.replace(":", "");
|
||||
serial.toLowerCase();
|
||||
return serial; // 5ccf7f139f3d
|
||||
}
|
||||
|
||||
String hue_UUID()
|
||||
{
|
||||
char serial[36];
|
||||
|
||||
snprintf_P(serial, sizeof(serial), PSTR("f6543a06-da50-11ba-8d8f-5ccf7f%03x"), ESP.getChipId());
|
||||
return String(serial);
|
||||
String uuid = F("f6543a06-da50-11ba-8d8f-");
|
||||
uuid += hue_serial();
|
||||
return uuid; // f6543a06-da50-11ba-8d8f-5ccf7f139f3d
|
||||
}
|
||||
|
||||
void hue_respondToMSearch()
|
||||
@@ -135,40 +143,35 @@ void hue_respondToMSearch()
|
||||
char log[LOGSZ];
|
||||
|
||||
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
|
||||
String response = FPSTR(HUE_RESPONSE);
|
||||
String response_st = FPSTR(HUE_ST1);
|
||||
String response_usn = FPSTR(HUE_USN1);
|
||||
response += response_st + response_usn;
|
||||
response.replace("{r1}", WiFi.localIP().toString());
|
||||
response.replace("{r2}", hue_bridgeid());
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
response = FPSTR(HUE_RESPONSE);
|
||||
response_st = FPSTR(HUE_ST2);
|
||||
response_usn = FPSTR(HUE_USN2);
|
||||
response += response_st + response_usn;
|
||||
response.replace("{r1}", WiFi.localIP().toString());
|
||||
response.replace("{r2}", hue_bridgeid());
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
response = FPSTR(HUE_RESPONSE);
|
||||
response_st = FPSTR(HUE_ST3);
|
||||
response += response_st + response_usn;
|
||||
response.replace("{r1}", WiFi.localIP().toString());
|
||||
response.replace("{r2}", hue_bridgeid());
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
|
||||
snprintf_P(message, sizeof(message), PSTR("3 response packets sent"));
|
||||
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
String response1 = FPSTR(HUE_RESPONSE);
|
||||
response1.replace("{r1}", WiFi.localIP().toString());
|
||||
response1.replace("{r2}", hue_bridgeid());
|
||||
|
||||
String response = response1;
|
||||
response += FPSTR(HUE_ST1);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
|
||||
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
response = response1;
|
||||
response += FPSTR(HUE_ST2);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
|
||||
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
response = response1;
|
||||
response += FPSTR(HUE_ST3);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
|
||||
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
snprintf_P(message, sizeof(message), PSTR("3 response packets sent"));
|
||||
} else {
|
||||
snprintf_P(message, sizeof(message), PSTR("Failed to send response"));
|
||||
}
|
||||
@@ -177,7 +180,9 @@ void hue_respondToMSearch()
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************************************************************************\
|
||||
* Belkin WeMo and Philips Hue bridge UDP multicast support
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean UDP_Disconnect()
|
||||
{
|
||||
@@ -212,12 +217,25 @@ void pollUDP()
|
||||
packetBuffer[len] = 0;
|
||||
}
|
||||
String request = packetBuffer;
|
||||
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet received"));
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, packetBuffer);
|
||||
|
||||
if (request.indexOf("M-SEARCH") >= 0) {
|
||||
if ((EMUL_WEMO == sysCfg.flag.emulation) &&(request.indexOf("urn:Belkin:device:**") > 0)) {
|
||||
request.toLowerCase();
|
||||
request.replace(" ", "");
|
||||
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, request.c_str());
|
||||
|
||||
if ((EMUL_WEMO == sysCfg.flag.emulation) && (request.indexOf(F("urn:belkin:device:**")) > 0)) {
|
||||
wemo_respondToMSearch();
|
||||
}
|
||||
else if ((EMUL_HUE == sysCfg.flag.emulation) && ((request.indexOf("ST: urn:schemas-upnp-org:device:basic:1") > 0) || (request.indexOf("ST: upnp:rootdevice") > 0) || (request.indexOf("ST: ssdp:all") > 0))) {
|
||||
else if ((EMUL_HUE == sysCfg.flag.emulation) &&
|
||||
((request.indexOf(F("st:urn:schemas-upnp-org:device:basic:1")) > 0) ||
|
||||
(request.indexOf(F("st:upnp:rootdevice")) > 0) ||
|
||||
(request.indexOf(F("st:ssdpsearch:all")) > 0) ||
|
||||
(request.indexOf(F("st:ssdp:all")) > 0))) {
|
||||
hue_respondToMSearch();
|
||||
}
|
||||
}
|
||||
@@ -227,8 +245,9 @@ void pollUDP()
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
/*********************************************************************************************\
|
||||
* Web server additions
|
||||
* Wemo web server additions
|
||||
\*********************************************************************************************/
|
||||
|
||||
const char WEMO_EVENTSERVICE_XML[] PROGMEM =
|
||||
"<?scpd xmlns=\"urn:Belkin:service-1-0\"?>"
|
||||
"<actionList>"
|
||||
@@ -281,45 +300,93 @@ const char WEMO_SETUP_XML[] PROGMEM =
|
||||
"</device>"
|
||||
"</root>\r\n"
|
||||
"\r\n";
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void handleUPnPevent()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: WeMo basic event"));
|
||||
|
||||
String request = webServer->arg(0);
|
||||
if (request.indexOf(F("State>1</Binary")) > 0) {
|
||||
// do_cmnd_power(1, 1);
|
||||
do_cmnd_power(Maxdevice, 1);
|
||||
}
|
||||
if (request.indexOf(F("State>0</Binary")) > 0) {
|
||||
// do_cmnd_power(1, 0);
|
||||
do_cmnd_power(Maxdevice, 0);
|
||||
}
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), "");
|
||||
}
|
||||
|
||||
void handleUPnPservice()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: WeMo event service"));
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_EVENTSERVICE_XML));
|
||||
}
|
||||
|
||||
void handleUPnPsetupWemo()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: WeMo setup"));
|
||||
|
||||
String setup_xml = FPSTR(WEMO_SETUP_XML);
|
||||
setup_xml.replace("{x1}", sysCfg.friendlyname[0]);
|
||||
setup_xml.replace("{x2}", wemo_UUID());
|
||||
setup_xml.replace("{x3}", wemo_serial());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), setup_xml);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Hue web server additions
|
||||
\*********************************************************************************************/
|
||||
|
||||
const char HUE_DESCRIPTION_XML[] PROGMEM =
|
||||
"<?xml version=\"1.0\"?>"
|
||||
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
|
||||
"<specVersion>"
|
||||
"<major>1</major>"
|
||||
"<minor>0</minor>"
|
||||
"<major>1</major>"
|
||||
"<minor>0</minor>"
|
||||
"</specVersion>"
|
||||
"<URLBase>http://{x1}/</URLBase>"
|
||||
// "<URLBase>http://{x1}/</URLBase>"
|
||||
"<URLBase>http://{x1}:80/</URLBase>"
|
||||
"<device>"
|
||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||
"<friendlyName>Amazon-Echo-HA-Bridge ({x1})</friendlyName>"
|
||||
"<manufacturer>Royal Philips Electronics</manufacturer>"
|
||||
"<modelName>Philips hue bridge 2012</modelName>"
|
||||
"<modelNumber>929000226503</modelNumber>"
|
||||
"<UDN>uuid:{x2}</UDN>"
|
||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||
"<friendlyName>Amazon-Echo-HA-Bridge ({x1})</friendlyName>"
|
||||
// "<friendlyName>Philips hue ({x1})</friendlyName>"
|
||||
"<manufacturer>Royal Philips Electronics</manufacturer>"
|
||||
"<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>"
|
||||
"<modelName>Philips hue bridge 2012</modelName>"
|
||||
"<modelNumber>929000226503</modelNumber>"
|
||||
"<serialNumber>{x3}</serialNumber>"
|
||||
"<UDN>uuid:{x2}</UDN>"
|
||||
"</device>"
|
||||
"</root>\r\n"
|
||||
"\r\n";
|
||||
const char HUE_LIGHT_STATUS_JSON[] PROGMEM =
|
||||
"{\"state\":"
|
||||
"{\"on\":{state},"
|
||||
"\"bri\":{b},"
|
||||
"\"hue\":{h},"
|
||||
"\"sat\":{s},"
|
||||
"\"effect\":\"none\","
|
||||
"\"ct\":0,"
|
||||
"\"alert\":\"none\","
|
||||
"\"colormode\":\"hs\","
|
||||
"\"reachable\":true"
|
||||
"},"
|
||||
"\"type\":\"Dimmable light\","
|
||||
"\"on\":{state},"
|
||||
"\"bri\":{b},"
|
||||
"\"hue\":{h},"
|
||||
"\"sat\":{s},"
|
||||
"\"xy\":[0.5, 0.5],"
|
||||
"\"ct\":500,"
|
||||
"\"alert\":\"none\","
|
||||
"\"effect\":\"none\","
|
||||
"\"colormode\":\"hs\","
|
||||
"\"reachable\":true";
|
||||
const char HUE_LIGHTS_STATUS_JSON[] PROGMEM =
|
||||
"\"type\":\"Extended color light\","
|
||||
"\"name\":\"{j1}\","
|
||||
"\"modelid\":\"LWB004\","
|
||||
"\"manufacturername\":\"Philips\","
|
||||
"\"modelid\":\"LCT007\","
|
||||
"\"uniqueid\":\"{j2}\","
|
||||
"\"swversion\":\"66012040\""
|
||||
"\"swversion\":\"5.50.1.19085\""
|
||||
"}";
|
||||
const char HUE_LIGHT_RESPONSE_JSON[] PROGMEM =
|
||||
"{\"success\":{\"{api}/{id}/{cmd}\":{res}}}";
|
||||
const char HUE_GROUP0_STATUS_JSON[] PROGMEM =
|
||||
"{\"name\":\"Group 0\","
|
||||
"\"lights\":[{l1}],"
|
||||
"\"type\":\"LightGroup\","
|
||||
"\"action\":{";
|
||||
// "\"scene\":\"none\",";
|
||||
const char HUE_CONFIG_RESPONSE_JSON[] PROGMEM =
|
||||
"{\"name\":\"Philips hue\","
|
||||
"\"mac\":\"{mac}\","
|
||||
@@ -327,8 +394,9 @@ const char HUE_CONFIG_RESPONSE_JSON[] PROGMEM =
|
||||
"\"ipaddress\":\"{ip}\","
|
||||
"\"netmask\":\"{mask}\","
|
||||
"\"gateway\":\"{gw}\","
|
||||
"\"proxyaddress\":\"\","
|
||||
"\"proxyaddress\":\"none\","
|
||||
"\"proxyport\":0,"
|
||||
"\"bridgeid\":\"{bid}\","
|
||||
"\"UTC\":\"{dt}\","
|
||||
"\"whitelist\":{\"{id}\":{"
|
||||
"\"last use date\":\"{dt}\","
|
||||
@@ -340,60 +408,37 @@ const char HUE_CONFIG_RESPONSE_JSON[] PROGMEM =
|
||||
"\"linkbutton\":false,"
|
||||
"\"portalservices\":false"
|
||||
"}";
|
||||
const char HUE_LIGHT_RESPONSE_JSON[] PROGMEM =
|
||||
"{\"success\":{\"/lights/{id}/state/{cmd}\":{res}}}";
|
||||
const char HUE_ERROR_JSON[] PROGMEM =
|
||||
"[{\"error\":{\"type\":901,\"address\":\"/\",\"description\":\"Internal Error\"}}]";
|
||||
|
||||
void handleUPnPevent()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle WeMo basic event"));
|
||||
|
||||
String request = webServer->arg(0);
|
||||
if (request.indexOf("State>1</Binary") > 0) {
|
||||
do_cmnd_power(1, 1);
|
||||
}
|
||||
if (request.indexOf("State>0</Binary") > 0) {
|
||||
do_cmnd_power(1, 0);
|
||||
}
|
||||
webServer->send(200, "text/plain", "");
|
||||
}
|
||||
|
||||
void handleUPnPservice()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle WeMo event service"));
|
||||
|
||||
String eventservice_xml = FPSTR(WEMO_EVENTSERVICE_XML);
|
||||
webServer->send(200, "text/plain", eventservice_xml);
|
||||
}
|
||||
|
||||
void handleUPnPsetupWemo()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle WeMo setup"));
|
||||
|
||||
String setup_xml = FPSTR(WEMO_SETUP_XML);
|
||||
setup_xml.replace("{x1}", sysCfg.friendlyname[0]);
|
||||
setup_xml.replace("{x2}", wemo_UUID());
|
||||
setup_xml.replace("{x3}", wemo_serial());
|
||||
webServer->send(200, "text/xml", setup_xml);
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
String hue_deviceId(uint8_t id)
|
||||
{
|
||||
char deviceid[16];
|
||||
|
||||
snprintf_P(deviceid, sizeof(deviceid), PSTR("5CCF7F%03X-%0d"), ESP.getChipId(), id);
|
||||
return String(deviceid);
|
||||
String deviceid = WiFi.macAddress() + F(":00:11-") + String(id);
|
||||
deviceid.toLowerCase();
|
||||
return deviceid; // 5c:cf:7f:13:9f:3d:00:11-1
|
||||
}
|
||||
|
||||
String hue_userId()
|
||||
{
|
||||
char userid[7];
|
||||
|
||||
snprintf_P(userid, sizeof(userid), PSTR("%03x"), ESP.getChipId());
|
||||
return String(userid);
|
||||
}
|
||||
|
||||
void handleUPnPsetupHue()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle Hue Bridge setup"));
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Hue Bridge setup"));
|
||||
|
||||
String description_xml = FPSTR(HUE_DESCRIPTION_XML);
|
||||
description_xml.replace("{x1}", WiFi.localIP().toString());
|
||||
description_xml.replace("{x2}", hue_UUID());
|
||||
webServer->send(200, "text/xml", description_xml);
|
||||
description_xml.replace("{x3}", hue_serial());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), description_xml);
|
||||
}
|
||||
|
||||
void hue_todo(String *path)
|
||||
@@ -402,6 +447,8 @@ void hue_todo(String *path)
|
||||
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: HUE API not implemented (%s)"),path->c_str());
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
}
|
||||
|
||||
void hue_config_response(String *response)
|
||||
@@ -411,7 +458,35 @@ void hue_config_response(String *response)
|
||||
response->replace("{ip}", WiFi.localIP().toString());
|
||||
response->replace("{mask}", WiFi.subnetMask().toString());
|
||||
response->replace("{gw}", WiFi.gatewayIP().toString());
|
||||
response->replace("{dt}", getDateTime());
|
||||
response->replace("{bid}", hue_bridgeid());
|
||||
response->replace("{dt}", getUTCDateTime());
|
||||
response->replace("{id}", hue_userId());
|
||||
}
|
||||
|
||||
void hue_config(String *path)
|
||||
{
|
||||
String response = "";
|
||||
hue_config_response(&response);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_light_status(byte device, String *response)
|
||||
{
|
||||
*response += FPSTR(HUE_LIGHT_STATUS_JSON);
|
||||
response->replace("{state}", (power & (0x01 << (device-1))) ? "true" : "false");
|
||||
|
||||
if (sfl_flg) {
|
||||
sl_replaceHSB(response);
|
||||
#ifdef USE_WS2812
|
||||
}
|
||||
else if (pin[GPIO_WS2812] < 99) {
|
||||
ws2812_replaceHSB(response);
|
||||
#endif // USE_WS2812
|
||||
} else {
|
||||
response->replace("{h}", "0");
|
||||
response->replace("{s}", "0");
|
||||
response->replace("{b}", "0");
|
||||
}
|
||||
}
|
||||
|
||||
void hue_global_cfg(String *path)
|
||||
@@ -419,51 +494,31 @@ void hue_global_cfg(String *path)
|
||||
String response;
|
||||
|
||||
path->remove(0,1); // cut leading / to get <id>
|
||||
response = "{\"lights\":{\"";
|
||||
response = F("{\"lights\":{\"");
|
||||
for (uint8_t i = 1; i <= Maxdevice; i++) {
|
||||
response += i;
|
||||
response += "\":";
|
||||
response += FPSTR(HUE_LIGHT_STATUS_JSON);
|
||||
response += F("\":{\"state\":{");
|
||||
hue_light_status(i, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
if (i < Maxdevice) {
|
||||
response += ",\"";
|
||||
}
|
||||
response.replace("{state}", (power & (0x01 << (i-1))) ? "true" : "false");
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
if (pin[GPIO_WS2812] < 99) {
|
||||
#ifdef USE_WS2812
|
||||
ws2812_replaceHSB(&response);
|
||||
#endif // USE_WS2812
|
||||
} else {
|
||||
response.replace("{h}", "0");
|
||||
response.replace("{s}", "0");
|
||||
response.replace("{b}", "0");
|
||||
}
|
||||
}
|
||||
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
||||
|
||||
hue_config_response(&response);
|
||||
response.replace("{id}", *path);
|
||||
response += "}";
|
||||
webServer->send(200, "application/json", response);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_auth(String *path)
|
||||
{
|
||||
char response[38];
|
||||
|
||||
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%03x\"}}]"), ESP.getChipId());
|
||||
webServer->send(200, "application/json", response);
|
||||
}
|
||||
|
||||
void hue_config(String *path)
|
||||
{
|
||||
String response = "";
|
||||
|
||||
path->remove(0,1); // cut leading / to get <id>
|
||||
hue_config_response(&response);
|
||||
response.replace("{id}", *path);
|
||||
webServer->send(200, "application/json", response);
|
||||
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%s\"}}]"), hue_userId().c_str());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_lights(String *path)
|
||||
@@ -471,13 +526,15 @@ void hue_lights(String *path)
|
||||
/*
|
||||
* http://sonoff/api/username/lights/1/state?1={"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40}
|
||||
*/
|
||||
String response;
|
||||
String response;
|
||||
uint8_t device = 1;
|
||||
uint16_t tmp=0;
|
||||
uint16_t tmp = 0;
|
||||
int16_t pos = 0;
|
||||
float bri = 0;
|
||||
float hue = 0;
|
||||
float sat = 0;
|
||||
float bri = 0;
|
||||
float hue = 0;
|
||||
float sat = 0;
|
||||
uint16_t ct = 0;
|
||||
bool resp = false;
|
||||
bool on = false;
|
||||
bool change = false;
|
||||
char id[4];
|
||||
@@ -487,26 +544,18 @@ void hue_lights(String *path)
|
||||
response = "{\"";
|
||||
for (uint8_t i = 1; i <= Maxdevice; i++) {
|
||||
response += i;
|
||||
response += "\":";
|
||||
response += FPSTR(HUE_LIGHT_STATUS_JSON);
|
||||
response += F("\":{\"state\":{");
|
||||
hue_light_status(i, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
if (i < Maxdevice) {
|
||||
response += ",\"";
|
||||
}
|
||||
response.replace("{state}", (power & (0x01 << (i-1))) ? "true" : "false");
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
if (pin[GPIO_WS2812] < 99) {
|
||||
#ifdef USE_WS2812
|
||||
ws2812_replaceHSB(&response);
|
||||
#endif // USE_WS2812
|
||||
} else {
|
||||
response.replace("{h}", "0");
|
||||
response.replace("{s}", "0");
|
||||
response.replace("{b}", "0");
|
||||
}
|
||||
}
|
||||
response += "}";
|
||||
webServer->send(200, "application/json", response);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else if (path->endsWith("/state")) { // Got ID/state
|
||||
path->remove(0,8); // Remove /lights/
|
||||
@@ -515,15 +564,17 @@ void hue_lights(String *path)
|
||||
if ((device < 1) || (device > Maxdevice)) {
|
||||
device = 1;
|
||||
}
|
||||
response = "[";
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{api}", "/lights");
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "state/on");
|
||||
if (1 == webServer->args()) {
|
||||
response = "[";
|
||||
|
||||
StaticJsonBuffer<400> jsonBuffer;
|
||||
JsonObject &hue_json = jsonBuffer.parseObject(webServer->arg(0));
|
||||
if (hue_json.containsKey("on")) {
|
||||
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "on");
|
||||
|
||||
on = hue_json["on"];
|
||||
switch(on)
|
||||
{
|
||||
@@ -536,54 +587,90 @@ void hue_lights(String *path)
|
||||
default : response.replace("{res}", (power & (0x01 << (device-1))) ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
resp = true;
|
||||
}
|
||||
|
||||
if (sfl_flg) {
|
||||
sl_getHSB(&hue,&sat,&bri);
|
||||
#ifdef USE_WS2812
|
||||
ws2812_getHSB(&hue,&sat,&bri);
|
||||
}
|
||||
else if (pin[GPIO_WS2812] < 99) {
|
||||
ws2812_getHSB(&hue,&sat,&bri);
|
||||
#endif // USE_WS2812
|
||||
}
|
||||
|
||||
if (hue_json.containsKey("bri")) {
|
||||
tmp = hue_json["bri"];
|
||||
bri = (float)tmp/254.0f;
|
||||
response += ",";
|
||||
bri = (float)tmp / 254.0f;
|
||||
if (resp) {
|
||||
response += ",";
|
||||
}
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{api}", "/lights");
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "state/bri");
|
||||
response.replace("{cmd}", "bri");
|
||||
response.replace("{res}", String(tmp));
|
||||
resp = true;
|
||||
change = true;
|
||||
}
|
||||
if (hue_json.containsKey("hue")) {
|
||||
tmp = hue_json["hue"];
|
||||
hue = (float)tmp/65535.0f;
|
||||
response += ",";
|
||||
hue = (float)tmp / 65535.0f;
|
||||
if (resp) {
|
||||
response += ",";
|
||||
}
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{api}", "/lights");
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "state/hue");
|
||||
response.replace("{cmd}", "hue");
|
||||
response.replace("{res}", String(tmp));
|
||||
resp = true;
|
||||
change = true;
|
||||
}
|
||||
if (hue_json.containsKey("sat")) {
|
||||
tmp = hue_json["sat"];
|
||||
sat = (float)tmp/254.0f;
|
||||
response += ",";
|
||||
sat = (float)tmp / 254.0f;
|
||||
if (resp) {
|
||||
response += ",";
|
||||
}
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{api}", "/lights");
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "state/sat");
|
||||
response.replace("{cmd}", "sat");
|
||||
response.replace("{res}", String(tmp));
|
||||
change = true;
|
||||
}
|
||||
if (change && (pin[GPIO_WS2812] < 99)) {
|
||||
ws2812_setHSB(hue, sat, bri);
|
||||
if (hue_json.containsKey("ct")) { // Color temperature 153 (Cold) to 500 (Warm)
|
||||
ct = hue_json["ct"];
|
||||
if (resp) {
|
||||
response += ",";
|
||||
}
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{id}", String(device));
|
||||
response.replace("{cmd}", "ct");
|
||||
response.replace("{res}", String(ct));
|
||||
change = true;
|
||||
}
|
||||
if (change) {
|
||||
if (sfl_flg) {
|
||||
sl_setHSB(hue, sat, bri, ct);
|
||||
#ifdef USE_WS2812
|
||||
}
|
||||
else if (pin[GPIO_WS2812] < 99) {
|
||||
ws2812_setHSB(hue, sat, bri);
|
||||
#endif // USE_WS2812
|
||||
}
|
||||
change = false;
|
||||
}
|
||||
#endif // USE_WS2812
|
||||
response += "]";
|
||||
webServer->send(200, "application/json", response);
|
||||
if (2 == response.length()) {
|
||||
response = FPSTR(HUE_ERROR_JSON);
|
||||
}
|
||||
}
|
||||
else {
|
||||
response=FPSTR(HUE_ERROR_JSON);
|
||||
webServer->send(200, "application/json", response);
|
||||
response = FPSTR(HUE_ERROR_JSON);
|
||||
}
|
||||
|
||||
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID
|
||||
path->remove(0,8); // Remove /lights/
|
||||
@@ -591,22 +678,38 @@ void hue_lights(String *path)
|
||||
if ((device < 1) || (device > Maxdevice)) {
|
||||
device = 1;
|
||||
}
|
||||
response = FPSTR(HUE_LIGHT_STATUS_JSON);
|
||||
response.replace("{state}", (power & (0x01 << (device -1))) ? "true" : "false");
|
||||
response.replace("{j1}", sysCfg.friendlyname[device -1]);
|
||||
response += F("{\"state\":{");
|
||||
hue_light_status(device, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[device-1]);
|
||||
response.replace("{j2}", hue_deviceId(device));
|
||||
if (pin[GPIO_WS2812] < 99) {
|
||||
#ifdef USE_WS2812
|
||||
ws2812_replaceHSB(&response);
|
||||
#endif // USE_WS2812
|
||||
} else {
|
||||
response.replace("{h}", "0");
|
||||
response.replace("{s}", "0");
|
||||
response.replace("{b}", "0");
|
||||
}
|
||||
webServer->send(200, "application/json", response);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else webServer->send(406, "application/json", "{}");
|
||||
else {
|
||||
webServer->send(406, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
}
|
||||
}
|
||||
|
||||
void hue_groups(String *path)
|
||||
{
|
||||
/*
|
||||
* http://sonoff/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"})
|
||||
*/
|
||||
String response = "{}";
|
||||
|
||||
if (path->endsWith("/0")) {
|
||||
response = FPSTR(HUE_GROUP0_STATUS_JSON);
|
||||
String lights = F("\"1\"");
|
||||
for (uint8_t i = 2; i <= Maxdevice; i++) {
|
||||
lights += ",\"" + String(i) + "\"";
|
||||
}
|
||||
response.replace("{l1}", lights);
|
||||
hue_light_status(1, &response);
|
||||
response += F("}}");
|
||||
}
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void handle_hue_api(String *path)
|
||||
@@ -621,8 +724,9 @@ void handle_hue_api(String *path)
|
||||
char log[LOGSZ];
|
||||
uint8_t args = 0;
|
||||
|
||||
path->remove(0, 4); // remove /api
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: Handle Hue API (%s)"), path->c_str());
|
||||
path->remove(0, 4); // remove /api
|
||||
uint16_t apilen = path->length();
|
||||
snprintf_P(log, sizeof(log), PSTR("HTTP: Hue API (%s)"), path->c_str());
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, log);
|
||||
for (args = 0; args < webServer->args(); args++) {
|
||||
String json = webServer->arg(args);
|
||||
@@ -631,10 +735,11 @@ void handle_hue_api(String *path)
|
||||
}
|
||||
|
||||
if (path->endsWith("/invalid/")) {} // Just ignore
|
||||
else if (!apilen) hue_auth(path); // New HUE App setup
|
||||
else if (path->endsWith("/")) hue_auth(path); // New HUE App setup
|
||||
else if (path->endsWith("/config")) hue_config(path);
|
||||
else if (path->indexOf("/lights") >= 0) hue_lights(path);
|
||||
else if (path->endsWith("/groups")) hue_todo(path);
|
||||
else if (path->indexOf("/groups") >= 0) hue_groups(path);
|
||||
else if (path->endsWith("/schedules")) hue_todo(path);
|
||||
else if (path->endsWith("/sensors")) hue_todo(path);
|
||||
else if (path->endsWith("/scenes")) hue_todo(path);
|
||||
|
||||
+114
-119
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xdrv_ws2812.ino - ws2812 led string support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_WS2812
|
||||
@@ -28,7 +22,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
* WS2812 Leds using NeopixelBus library
|
||||
\*********************************************************************************************/
|
||||
|
||||
#include <NeoPixelBus.h>
|
||||
//#include <NeoPixelBus.h> // Global defined as also used by Sonoff Led
|
||||
|
||||
#ifdef USE_WS2812_DMA
|
||||
#if (USE_WS2812_CTYPE == 1)
|
||||
@@ -82,37 +76,20 @@ uint8_t repeatValues[5] = {
|
||||
2, // Largest
|
||||
1 }; // All
|
||||
uint8_t speedValues[6] = {
|
||||
0, // None
|
||||
18, // Slowest
|
||||
14, // Slower
|
||||
10, // Slow
|
||||
6, // Fast
|
||||
2 }; // Fastest
|
||||
/*
|
||||
uint8_t ledTable[] = {
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4,
|
||||
4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
|
||||
8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
|
||||
14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22,
|
||||
22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32,
|
||||
33, 33, 34, 35, 36, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45,
|
||||
46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
||||
61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78,
|
||||
80, 81, 82, 83, 85, 86, 87, 89, 90, 91, 93, 94, 95, 97, 98, 99,
|
||||
101,102,104,105,107,108,110,111,113,114,116,117,119,121,122,124,
|
||||
125,127,129,130,132,134,135,137,139,141,142,144,146,148,150,151,
|
||||
153,155,157,159,161,163,165,166,168,170,172,174,176,178,180,182,
|
||||
184,186,189,191,193,195,197,199,201,204,206,208,210,212,215,217,
|
||||
219,221,224,226,228,231,233,235,238,240,243,245,248,250,253,255 };
|
||||
*/
|
||||
0, // None
|
||||
9 * (STATES / 10), // Slowest
|
||||
7 * (STATES / 10), // Slower
|
||||
5 * (STATES / 10), // Slow
|
||||
3 * (STATES / 10), // Fast
|
||||
1 * (STATES / 10) }; // Fastest
|
||||
|
||||
uint8_t lany = 0;
|
||||
RgbColor dcolor;
|
||||
RgbColor tcolor;
|
||||
RgbColor lcolor;
|
||||
|
||||
uint8_t wakeupDimmer = 0;
|
||||
uint8_t ws_bit = 0;
|
||||
uint16_t wakeupCntr = 0;
|
||||
unsigned long stripTimerCntr = 0; // Bars and Gradient
|
||||
|
||||
@@ -168,37 +145,6 @@ void ws2812_setColor(uint16_t led, char* colstr)
|
||||
}
|
||||
}
|
||||
|
||||
void ws2812_replaceHSB(String *response)
|
||||
{
|
||||
ws2812_setDim(sysCfg.ws_dimmer);
|
||||
HsbColor hsb = HsbColor(dcolor);
|
||||
response->replace("{h}", String((uint16_t)(65535.0f * hsb.H)));
|
||||
response->replace("{s}", String((uint8_t)(254.0f * hsb.S)));
|
||||
response->replace("{b}", String((uint8_t)(254.0f * hsb.B)));
|
||||
}
|
||||
|
||||
void ws2812_getHSB(float *hue, float *sat, float *bri)
|
||||
{
|
||||
ws2812_setDim(sysCfg.ws_dimmer);
|
||||
HsbColor hsb = HsbColor(dcolor);
|
||||
*hue = hsb.H;
|
||||
*sat = hsb.S;
|
||||
*bri = hsb.B;
|
||||
}
|
||||
|
||||
void ws2812_setHSB(float hue, float sat, float bri)
|
||||
{
|
||||
char rgb[7];
|
||||
|
||||
HsbColor hsb;
|
||||
hsb.H = hue;
|
||||
hsb.S = sat;
|
||||
hsb.B = bri;
|
||||
RgbColor tmp = RgbColor(hsb);
|
||||
sprintf(rgb,"%02X%02X%02X", tmp.R, tmp.G, tmp.B);
|
||||
ws2812_setColor(0,rgb);
|
||||
}
|
||||
|
||||
void ws2812_getColor(uint16_t led, char* svalue, uint16_t ssvalue)
|
||||
{
|
||||
RgbColor mcolor;
|
||||
@@ -282,18 +228,18 @@ void ws2812_clock()
|
||||
ws2812_stripShow();
|
||||
}
|
||||
|
||||
void ws2812_gradientColor(struct wsColor* mColor, uint8_t range, uint8_t gradRange, uint8_t i)
|
||||
void ws2812_gradientColor(struct wsColor* mColor, uint16_t range, uint16_t gradRange, uint16_t i)
|
||||
{
|
||||
/*
|
||||
* Compute the color of a pixel at position i using a gradient of the color scheme.
|
||||
* This function is used internally by the gradient function.
|
||||
*/
|
||||
ColorScheme scheme = schemes[sysCfg.ws_scheme -3];
|
||||
uint8_t curRange = i / range;
|
||||
uint8_t rangeIndex = i % range;
|
||||
uint8_t colorIndex = rangeIndex / gradRange;
|
||||
uint8_t start = colorIndex;
|
||||
uint8_t end = colorIndex +1;
|
||||
uint16_t curRange = i / range;
|
||||
uint16_t rangeIndex = i % range;
|
||||
uint16_t colorIndex = rangeIndex / gradRange;
|
||||
uint16_t start = colorIndex;
|
||||
uint16_t end = colorIndex +1;
|
||||
if (curRange % 2 != 0) {
|
||||
start = (scheme.count -1) - start;
|
||||
end = (scheme.count -1) - end;
|
||||
@@ -322,9 +268,9 @@ void ws2812_gradient()
|
||||
}
|
||||
|
||||
uint8_t repeat = repeatValues[sysCfg.ws_width]; // number of scheme.count per ledcount
|
||||
uint8_t range = (uint8_t)ceil((float)sysCfg.ws_pixels / (float)repeat);
|
||||
uint8_t gradRange = (uint8_t)ceil((float)range / (float)(scheme.count - 1));
|
||||
uint8_t offset = speedValues[sysCfg.ws_speed] > 0 ? stripTimerCntr / speedValues[sysCfg.ws_speed] : 0;
|
||||
uint16_t range = (uint16_t)ceil((float)sysCfg.ws_pixels / (float)repeat);
|
||||
uint16_t gradRange = (uint16_t)ceil((float)range / (float)(scheme.count - 1));
|
||||
uint16_t offset = speedValues[sysCfg.ws_speed] > 0 ? stripTimerCntr / speedValues[sysCfg.ws_speed] : 0;
|
||||
|
||||
wsColor oldColor, currentColor;
|
||||
ws2812_gradientColor(&oldColor, range, gradRange, offset);
|
||||
@@ -363,7 +309,7 @@ void ws2812_bars()
|
||||
|
||||
ColorScheme scheme = schemes[sysCfg.ws_scheme -3];
|
||||
|
||||
uint8_t maxSize = sysCfg.ws_pixels / scheme.count;
|
||||
uint16_t maxSize = sysCfg.ws_pixels / scheme.count;
|
||||
if (widthValues[sysCfg.ws_width] > maxSize) {
|
||||
maxSize = 0;
|
||||
}
|
||||
@@ -400,7 +346,7 @@ void ws2812_animate()
|
||||
uint8_t fadeValue;
|
||||
|
||||
stripTimerCntr++;
|
||||
if (0 == power) { // Power Off
|
||||
if (0 == bitRead(power, ws_bit)) { // Power Off
|
||||
sleep = sysCfg.sleep;
|
||||
stripTimerCntr = 0;
|
||||
tcolor = 0;
|
||||
@@ -414,23 +360,24 @@ void ws2812_animate()
|
||||
tcolor = dcolor;
|
||||
} else {
|
||||
if (tcolor != dcolor) {
|
||||
uint8_t ws_speed = speedValues[sysCfg.ws_speed];
|
||||
if (tcolor.R < dcolor.R) {
|
||||
tcolor.R += ((dcolor.R - tcolor.R) >> sysCfg.ws_speed) +1;
|
||||
tcolor.R += ((dcolor.R - tcolor.R) / ws_speed) +1;
|
||||
}
|
||||
if (tcolor.G < dcolor.G) {
|
||||
tcolor.G += ((dcolor.G - tcolor.G) >> sysCfg.ws_speed) +1;
|
||||
tcolor.G += ((dcolor.G - tcolor.G) / ws_speed) +1;
|
||||
}
|
||||
if (tcolor.B < dcolor.B) {
|
||||
tcolor.B += ((dcolor.B - tcolor.B) >> sysCfg.ws_speed) +1;
|
||||
tcolor.B += ((dcolor.B - tcolor.B) / ws_speed) +1;
|
||||
}
|
||||
if (tcolor.R > dcolor.R) {
|
||||
tcolor.R -= ((tcolor.R - dcolor.R) >> sysCfg.ws_speed) +1;
|
||||
tcolor.R -= ((tcolor.R - dcolor.R) / ws_speed) +1;
|
||||
}
|
||||
if (tcolor.G > dcolor.G) {
|
||||
tcolor.G -= ((tcolor.G - dcolor.G) >> sysCfg.ws_speed) +1;
|
||||
tcolor.G -= ((tcolor.G - dcolor.G) / ws_speed) +1;
|
||||
}
|
||||
if (tcolor.B > dcolor.B) {
|
||||
tcolor.B -= ((tcolor.B - dcolor.B) >> sysCfg.ws_speed) +1;
|
||||
tcolor.B -= ((tcolor.B - dcolor.B) / ws_speed) +1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,8 +395,9 @@ void ws2812_animate()
|
||||
if (wakeupDimmer <= sysCfg.ws_dimmer) {
|
||||
ws2812_setDim(wakeupDimmer);
|
||||
tcolor = dcolor;
|
||||
} else
|
||||
} else {
|
||||
sysCfg.ws_scheme = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -470,7 +418,7 @@ void ws2812_animate()
|
||||
}
|
||||
}
|
||||
|
||||
if ((sysCfg.ws_scheme <= 1) || (!(power &1))) {
|
||||
if ((sysCfg.ws_scheme <= 1) || (0 == bitRead(power, ws_bit))) {
|
||||
if ((lcolor != tcolor) || lany) {
|
||||
lany = 0;
|
||||
lcolor = tcolor;
|
||||
@@ -505,8 +453,9 @@ void ws2812_pixels()
|
||||
lany = 1;
|
||||
}
|
||||
|
||||
void ws2812_init()
|
||||
void ws2812_init(uint8_t powerbit)
|
||||
{
|
||||
ws_bit = powerbit -1;
|
||||
#ifdef USE_WS2812_DMA
|
||||
#if (USE_WS2812_CTYPE == 1)
|
||||
strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(WS2812_MAX_LEDS); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
@@ -524,6 +473,41 @@ void ws2812_init()
|
||||
ws2812_pixels();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Hue support
|
||||
\*********************************************************************************************/
|
||||
|
||||
void ws2812_replaceHSB(String *response)
|
||||
{
|
||||
ws2812_setDim(sysCfg.ws_dimmer);
|
||||
HsbColor hsb = HsbColor(dcolor);
|
||||
response->replace("{h}", String((uint16_t)(65535.0f * hsb.H)));
|
||||
response->replace("{s}", String((uint8_t)(254.0f * hsb.S)));
|
||||
response->replace("{b}", String((uint8_t)(254.0f * hsb.B)));
|
||||
}
|
||||
|
||||
void ws2812_getHSB(float *hue, float *sat, float *bri)
|
||||
{
|
||||
ws2812_setDim(sysCfg.ws_dimmer);
|
||||
HsbColor hsb = HsbColor(dcolor);
|
||||
*hue = hsb.H;
|
||||
*sat = hsb.S;
|
||||
*bri = hsb.B;
|
||||
}
|
||||
|
||||
void ws2812_setHSB(float hue, float sat, float bri)
|
||||
{
|
||||
char rgb[7];
|
||||
|
||||
HsbColor hsb;
|
||||
hsb.H = hue;
|
||||
hsb.S = sat;
|
||||
hsb.B = bri;
|
||||
RgbColor tmp = RgbColor(hsb);
|
||||
sprintf(rgb,"%02X%02X%02X", tmp.R, tmp.G, tmp.B);
|
||||
ws2812_setColor(0,rgb);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Commands
|
||||
\*********************************************************************************************/
|
||||
@@ -533,7 +517,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
|
||||
boolean serviced = true;
|
||||
|
||||
if (!strcmp_P(type,PSTR("PIXELS"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload <= WS2812_MAX_LEDS)) {
|
||||
if ((payload > 0) && (payload <= WS2812_MAX_LEDS)) {
|
||||
sysCfg.ws_pixels = payload;
|
||||
ws2812_pixels();
|
||||
}
|
||||
@@ -541,31 +525,30 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("LED")) && (index > 0) && (index <= sysCfg.ws_pixels)) {
|
||||
if (6 == data_len) {
|
||||
// ws2812_setColor(index, dataBufUc);
|
||||
ws2812_setColor(index, dataBuf);
|
||||
}
|
||||
ws2812_getColor(index, svalue, ssvalue);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("COLOR"))) {
|
||||
if (6 == data_len) {
|
||||
// ws2812_setColor(0, dataBufUc);
|
||||
ws2812_setColor(0, dataBuf);
|
||||
power = 1;
|
||||
bitSet(power, ws_bit);
|
||||
}
|
||||
ws2812_getColor(0, svalue, ssvalue);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("DIMMER"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 100)) {
|
||||
if ((payload >= 0) && (payload <= 100)) {
|
||||
sysCfg.ws_dimmer = payload;
|
||||
power = 1;
|
||||
bitSet(power, ws_bit);
|
||||
#ifdef USE_DOMOTICZ
|
||||
mqtt_publishDomoticzPowerState(index);
|
||||
// mqtt_publishDomoticzPowerState(index);
|
||||
mqtt_publishDomoticzPowerState(ws_bit +1);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Dimmer\":%d}"), sysCfg.ws_dimmer);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("LEDTABLE"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 2)) {
|
||||
if ((payload >= 0) && (payload <= 2)) {
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
@@ -580,33 +563,31 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"LedTable\":\"%s\"}"), getStateText(sysCfg.ws_ledtable));
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("FADE"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 2)) {
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.ws_fade = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.ws_fade ^= 1;
|
||||
break;
|
||||
}
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.ws_fade = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.ws_fade ^= 1;
|
||||
break;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Fade\":\"%s\"}"), getStateText(sysCfg.ws_fade));
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SPEED"))) { // 1 - fast, 5 - slow
|
||||
if ((data_len > 0) && (payload > 0) && (payload <= 5)) {
|
||||
if ((payload > 0) && (payload <= 5)) {
|
||||
sysCfg.ws_speed = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Speed\":%d}"), sysCfg.ws_speed);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("WIDTH"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 4)) {
|
||||
if ((payload >= 0) && (payload <= 4)) {
|
||||
sysCfg.ws_width = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Width\":%d}"), sysCfg.ws_width);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("WAKEUP"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload < 3601)) {
|
||||
if ((payload > 0) && (payload < 3001)) {
|
||||
sysCfg.ws_wakeup = payload;
|
||||
if (1 == sysCfg.ws_scheme) {
|
||||
sysCfg.ws_scheme = 0;
|
||||
@@ -615,16 +596,30 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"WakeUp\":%d}"), sysCfg.ws_wakeup);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SCHEME"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload <= 9)) {
|
||||
if ((payload >= 0) && (payload <= 9)) {
|
||||
sysCfg.ws_scheme = payload;
|
||||
if (1 == sysCfg.ws_scheme) {
|
||||
ws2812_resetWakupState();
|
||||
}
|
||||
power = 1;
|
||||
bitSet(power, ws_bit);
|
||||
ws2812_resetStripTimer();
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"Scheme\":%d}"), sysCfg.ws_scheme);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("UNDOCA"))) { // Theos WS2812 legacy status
|
||||
RgbColor mcolor;
|
||||
char mtopic[TOPSZ];
|
||||
getTopic_P(mtopic, 1, sysCfg.mqtt_topic, type);
|
||||
ws2812_setDim(sysCfg.ws_dimmer);
|
||||
mcolor = dcolor;
|
||||
uint32_t color = (uint32_t)mcolor.R << 16;
|
||||
color += (uint32_t)mcolor.G << 8;
|
||||
color += (uint32_t)mcolor.B;
|
||||
snprintf_P(svalue, ssvalue, PSTR("%06X, %d, %d, %d, %d, %d"),
|
||||
color, sysCfg.ws_fade, sysCfg.ws_ledtable, sysCfg.ws_scheme, sysCfg.ws_speed, sysCfg.ws_width);
|
||||
mqtt_publish(mtopic, svalue);
|
||||
svalue[0] = '\0';
|
||||
}
|
||||
else {
|
||||
serviced = false; // Unknown command
|
||||
}
|
||||
|
||||
+13
-19
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_bh1750.ino - BH1750 ambient light sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
|
||||
+13
-19
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Heiko Krupp and Theo Arends. All rights reserved.
|
||||
xsns_bmp.ino - BMP pressure, temperature and humidity sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
xsns_counter.ino - Counter sensors (water meters, electricity meters etc.) sensor support for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Maarten Damen and Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Counter sensors (water meters, electricity meters etc.)
|
||||
\*********************************************************************************************/
|
||||
|
||||
unsigned long pTimeLast[MAX_COUNTERS]; // Last counter time in milli seconds
|
||||
|
||||
void counter_update(byte index)
|
||||
{
|
||||
// char log[LOGSZ];
|
||||
|
||||
unsigned long pTime = millis() - pTimeLast[index -1];
|
||||
if (pTime > sysCfg.pCounterDebounce) {
|
||||
pTimeLast[index -1] = millis();
|
||||
if (bitRead(sysCfg.pCounterType, index -1)) {
|
||||
rtcMem.pCounter[index -1] = pTime;
|
||||
} else {
|
||||
rtcMem.pCounter[index -1]++;
|
||||
}
|
||||
|
||||
// snprintf_P(log, sizeof(log), PSTR("CNTR: Interrupt %d"), index);
|
||||
// addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
}
|
||||
|
||||
void counter_update1()
|
||||
{
|
||||
counter_update(1);
|
||||
}
|
||||
|
||||
void counter_update2()
|
||||
{
|
||||
counter_update(2);
|
||||
}
|
||||
|
||||
void counter_update3()
|
||||
{
|
||||
counter_update(3);
|
||||
}
|
||||
|
||||
void counter_update4()
|
||||
{
|
||||
counter_update(4);
|
||||
}
|
||||
|
||||
void counter_savestate()
|
||||
{
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
sysCfg.pCounter[i] = rtcMem.pCounter[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void counter_init()
|
||||
{
|
||||
typedef void (*function) () ;
|
||||
function counter_callbacks[] = { counter_update1, counter_update2, counter_update3, counter_update4 };
|
||||
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
pinMode(pin[GPIO_CNTR1 +i], INPUT_PULLUP);
|
||||
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void counter_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
|
||||
{
|
||||
char stemp[16];
|
||||
|
||||
byte dsxflg = 0;
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
if (bitRead(sysCfg.pCounterType, i)) {
|
||||
dtostrf((double)rtcMem.pCounter[i] / 1000, 1, 3, stemp);
|
||||
} else {
|
||||
dsxflg++;
|
||||
dtostrf(rtcMem.pCounter[i], 1, 0, stemp);
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("%s, \"Counter%d\":%s"), svalue, i +1, stemp);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (1 == dsxflg) {
|
||||
domoticz_sensor6(rtcMem.pCounter[i]);
|
||||
dsxflg++;
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_SNS_COUNTER[] PROGMEM =
|
||||
"<tr><th>Counter%d</th><td>%s%s</td></tr>";
|
||||
|
||||
String counter_webPresent()
|
||||
{
|
||||
String page = "";
|
||||
char stemp[16];
|
||||
char sensor[80];
|
||||
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
if (bitRead(sysCfg.pCounterType, i)) {
|
||||
dtostrf((double)rtcMem.pCounter[i] / 1000, 1, 3, stemp);
|
||||
} else {
|
||||
dtostrf(rtcMem.pCounter[i], 1, 0, stemp);
|
||||
}
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_COUNTER, i+1, stemp, (bitRead(sysCfg.pCounterType, i)) ? " Sec" : "");
|
||||
page += sensor;
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
+19
-22
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_dht.ino - DHTxx and AM23xx temperature and humidity sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_DHT
|
||||
@@ -202,13 +196,16 @@ void dht_init()
|
||||
dht[i].lastreadtime = -MIN_INTERVAL;
|
||||
switch (dht[i].type) {
|
||||
case GPIO_DHT11:
|
||||
snprintf_P(dht[i].stype, sizeof(dht[i].stype), PSTR("DHT11-%02d"), dht[i].pin);
|
||||
strcpy_P(dht[i].stype, PSTR("DHT11"));
|
||||
break;
|
||||
case GPIO_DHT21:
|
||||
snprintf_P(dht[i].stype, sizeof(dht[i].stype), PSTR("AM2301-%02d"), dht[i].pin);
|
||||
strcpy_P(dht[i].stype, PSTR("AM2301"));
|
||||
break;
|
||||
case GPIO_DHT22:
|
||||
snprintf_P(dht[i].stype, sizeof(dht[i].stype), PSTR("DHT22-%02d"), dht[i].pin);
|
||||
strcpy_P(dht[i].stype, PSTR("DHT22"));
|
||||
}
|
||||
if (dht_sensors > 1) {
|
||||
snprintf_P(dht[i].stype, sizeof(dht[i].stype), PSTR("%s-%02d"), dht[i].stype, dht[i].pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-19
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_ds18b20.ino - DS18B20 temperature sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_DS18B20
|
||||
|
||||
+14
-20
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_ds18x20.ino - DS18x20 temperature sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_DS18x20
|
||||
@@ -207,7 +201,7 @@ void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
|
||||
svalue, stemp1, i +1, dsbstype, ds18x20_address(i).c_str(), stemp2);
|
||||
strcpy(stemp1, ", ");
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (dsxflg == 1) domoticz_sensor1(stemp2);
|
||||
if (1 == dsxflg) domoticz_sensor1(stemp2);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
|
||||
+174
-100
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_hlw8012.ino - sonoff pow HLW8012 energy sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
@@ -116,15 +110,17 @@ void hlw_200mS()
|
||||
hlw_fifth_second = 0;
|
||||
|
||||
if (hlw_EDcntr) {
|
||||
hlw_len = 1000000 / hlw_EDcntr;
|
||||
hlw_len = 10000 / hlw_EDcntr;
|
||||
hlw_EDcntr = 0;
|
||||
hlw_temp = (HLW_PREF * sysCfg.hlw_pcal) / hlw_len;
|
||||
hlw_kWhtoday += (hlw_temp * 100) / 36;
|
||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / 36;
|
||||
hlw_kWhtoday += hlw_temp;
|
||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
||||
}
|
||||
if (rtcTime.Valid) {
|
||||
if (rtc_loctime() == rtc_midnight()) {
|
||||
sysCfg.hlw_kWhyesterday = hlw_kWhtoday;
|
||||
sysCfg.hlw_kWhtotal += (hlw_kWhtoday / 1000);
|
||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
||||
hlw_kWhtoday = 0;
|
||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
||||
hlw_mkwh_state = 3;
|
||||
@@ -174,10 +170,15 @@ void hlw_savestate()
|
||||
{
|
||||
sysCfg.hlw_kWhdoy = (rtcTime.Valid) ? rtcTime.DayOfYear : 0;
|
||||
sysCfg.hlw_kWhtoday = hlw_kWhtoday;
|
||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
||||
}
|
||||
|
||||
boolean hlw_readEnergy(byte option, float &ed, uint16_t &e, uint16_t &w, uint16_t &u, float &i, float &c)
|
||||
void hlw_readEnergy(byte option, float &et, float &ed, uint16_t &e, uint16_t &w, float &u, float &i, float &c)
|
||||
{
|
||||
/* option 0 = do not calculate period energy usage
|
||||
* option 1 = calculate period energy usage
|
||||
*/
|
||||
unsigned long cur_kWhtoday = hlw_kWhtoday;
|
||||
unsigned long hlw_len;
|
||||
unsigned long hlw_temp;
|
||||
unsigned long hlw_w;
|
||||
@@ -190,59 +191,52 @@ boolean hlw_readEnergy(byte option, float &ed, uint16_t &e, uint16_t &w, uint16_
|
||||
//snprintf_P(log, sizeof(log), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_plen, hlw_cf1u_plen, hlw_cf1u_pcntmax, hlw_cf1i_plen, hlw_cf1i_pcntmax);
|
||||
//addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
if (hlw_kWhtoday) {
|
||||
ed = (float)hlw_kWhtoday / 100000000;
|
||||
} else {
|
||||
ed = 0;
|
||||
et = (float)(rtcMem.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
|
||||
ed = 0;
|
||||
if (cur_kWhtoday) {
|
||||
ed = (float)cur_kWhtoday / 100000000;
|
||||
}
|
||||
|
||||
e = 0;
|
||||
if (option) {
|
||||
if (!hlw_lasttime) {
|
||||
hlw_period = sysCfg.tele_period;
|
||||
} else {
|
||||
hlw_period = rtc_loctime() - hlw_lasttime;
|
||||
}
|
||||
hlw_lasttime = rtc_loctime();
|
||||
hlw_interval = 3600 / hlw_period;
|
||||
if (hlw_Ecntr) {
|
||||
hlw_len = hlw_period * 1000000 / hlw_Ecntr;
|
||||
hlw_Ecntr = 0;
|
||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval;
|
||||
e = hlw_temp / 10;
|
||||
} else {
|
||||
e = 0;
|
||||
if (hlw_period) {
|
||||
hlw_lasttime = rtc_loctime();
|
||||
hlw_interval = 3600 / hlw_period;
|
||||
if (hlw_Ecntr) {
|
||||
hlw_len = hlw_period * 1000000 / hlw_Ecntr;
|
||||
hlw_Ecntr = 0;
|
||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval;
|
||||
e = hlw_temp / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w = 0;
|
||||
if (hlw_cf_plen) {
|
||||
hlw_w = (HLW_PREF * sysCfg.hlw_pcal) / hlw_cf_plen;
|
||||
w = hlw_w / 10;
|
||||
} else {
|
||||
w = 0;
|
||||
}
|
||||
u = 0;
|
||||
if (hlw_cf1u_plen && (w || (power &1))) {
|
||||
hlw_u = (HLW_UREF * sysCfg.hlw_ucal) / hlw_cf1u_plen;
|
||||
u = hlw_u / 10;
|
||||
} else {
|
||||
u = 0;
|
||||
u = (float)hlw_u / 10;
|
||||
}
|
||||
i = 0;
|
||||
if (hlw_cf1i_plen && w) {
|
||||
hlw_i = (HLW_IREF * sysCfg.hlw_ical) / hlw_cf1i_plen;
|
||||
i = (float)hlw_i / 1000;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
c = 0;
|
||||
if (hlw_i && hlw_u && hlw_w && w) {
|
||||
hlw_temp = (hlw_w * 100) / ((hlw_u * hlw_i) / 1000);
|
||||
if (hlw_temp > 100) {
|
||||
hlw_temp = 100;
|
||||
}
|
||||
c = (float)hlw_temp / 100;
|
||||
} else {
|
||||
c = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void hlw_init()
|
||||
@@ -311,14 +305,16 @@ void hlw_margin_chk()
|
||||
{
|
||||
char log[LOGSZ];
|
||||
char svalue[200]; // was MESSZ
|
||||
float pet;
|
||||
float ped;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
uint16_t uped;
|
||||
uint16_t puv;
|
||||
uint16_t piv;
|
||||
uint16_t pe;
|
||||
uint16_t pw;
|
||||
uint16_t pu;
|
||||
boolean flag;
|
||||
boolean jsonflg;
|
||||
|
||||
@@ -327,8 +323,9 @@ void hlw_margin_chk()
|
||||
return;
|
||||
}
|
||||
|
||||
hlw_readEnergy(0, ped, pe, pw, pu, pi, pc);
|
||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
||||
if (power && (sysCfg.hlw_pmin || sysCfg.hlw_pmax || sysCfg.hlw_umin || sysCfg.hlw_umax || sysCfg.hlw_imin || sysCfg.hlw_imax)) {
|
||||
puv = (uint16_t)(pu);
|
||||
piv = (uint16_t)(pi * 1000);
|
||||
|
||||
// snprintf_P(log, sizeof(log), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
|
||||
@@ -344,11 +341,11 @@ void hlw_margin_chk()
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"PowerHigh\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(0, sysCfg.hlw_umin, pu, flag, hlw_uminflg)) {
|
||||
if (hlw_margin(0, sysCfg.hlw_umin, puv, flag, hlw_uminflg)) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"VoltageLow\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(1, sysCfg.hlw_umax, pw, flag, hlw_umaxflg)) {
|
||||
if (hlw_margin(1, sysCfg.hlw_umax, puv, flag, hlw_umaxflg)) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"VoltageHigh\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
@@ -362,7 +359,8 @@ void hlw_margin_chk()
|
||||
}
|
||||
if (jsonflg) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue);
|
||||
mqtt_publish_topic_P(1, PSTR("MARGINS"), svalue);
|
||||
mqtt_publish_topic_P(2, PSTR("MARGINS"), svalue);
|
||||
hlw_mqttPresent(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,10 +374,11 @@ void hlw_margin_chk()
|
||||
hlw_mplh_counter--;
|
||||
if (!hlw_mplh_counter) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxPowerReached\":\"%d%s\"}"), pw, (sysCfg.flag.value_units) ? " W" : "");
|
||||
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
|
||||
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
|
||||
hlw_mqttPresent(0);
|
||||
do_cmnd_power(1, 0);
|
||||
if (!hlw_mplr_counter) {
|
||||
hlw_mplr_counter = MAX_POWER_RETRY +1;
|
||||
hlw_mplr_counter = sysCfg.param[P_MAX_POWER_RETRY] +1;
|
||||
}
|
||||
hlw_mplw_counter = sysCfg.hlw_mplw;
|
||||
}
|
||||
@@ -398,11 +397,12 @@ void hlw_margin_chk()
|
||||
hlw_mplr_counter--;
|
||||
if (hlw_mplr_counter) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"PowerMonitor\":\"%s\"}"), getStateText(1));
|
||||
mqtt_publish_topic_P(4, PSTR("POWERMONITOR"), svalue);
|
||||
mqtt_publish_topic_P(5, PSTR("POWERMONITOR"), svalue);
|
||||
do_cmnd_power(1, 1);
|
||||
} else {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxPowerReachedRetry\":\"%s\"}"), getStateText(0));
|
||||
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
|
||||
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
|
||||
hlw_mqttPresent(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,14 +415,15 @@ void hlw_margin_chk()
|
||||
if (!hlw_mkwh_state && (rtcTime.Hour == sysCfg.hlw_mkwhs)) {
|
||||
hlw_mkwh_state = 1;
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"EnergyMonitor\":\"%s\"}"), getStateText(1));
|
||||
mqtt_publish_topic_P(4, PSTR("ENERGYMONITOR"), svalue);
|
||||
mqtt_publish_topic_P(5, PSTR("ENERGYMONITOR"), svalue);
|
||||
do_cmnd_power(1, 1);
|
||||
}
|
||||
else if ((1 == hlw_mkwh_state) && (uped >= sysCfg.hlw_mkwh)) {
|
||||
hlw_mkwh_state = 2;
|
||||
dtostrf(ped, 1, 3, svalue);
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxEnergyReached\":\"%s%s\"}"), svalue, (sysCfg.flag.value_units) ? " kWh" : "");
|
||||
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
|
||||
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
|
||||
hlw_mqttPresent(0);
|
||||
do_cmnd_power(1, 0);
|
||||
}
|
||||
}
|
||||
@@ -436,107 +437,151 @@ void hlw_margin_chk()
|
||||
boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
|
||||
{
|
||||
boolean serviced = true;
|
||||
uint8_t caltext = 0;
|
||||
|
||||
if (!strcmp_P(type,PSTR("POWERLOW"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_pmin = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"PowerLow\":\"%d%s\"}"), sysCfg.hlw_pmin, (sysCfg.flag.value_units) ? " W" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("POWERHIGH"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_pmax = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"PowerHigh\":\"%d%s\"}"), sysCfg.hlw_pmax, (sysCfg.flag.value_units) ? " W" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("VOLTAGELOW"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 501)) {
|
||||
if ((payload >= 0) && (payload < 501)) {
|
||||
sysCfg.hlw_umin = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"VoltageLow\":\"%d%s\"}"), sysCfg.hlw_umin, (sysCfg.flag.value_units) ? " V" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("VOLTAGEHIGH"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 501)) {
|
||||
if ((payload >= 0) && (payload < 501)) {
|
||||
sysCfg.hlw_umax = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("[\"VoltageHigh\":\"%d%s\"}"), sysCfg.hlw_umax, (sysCfg.flag.value_units) ? " V" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("CURRENTLOW"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 16001)) {
|
||||
if ((payload >= 0) && (payload < 16001)) {
|
||||
sysCfg.hlw_imin = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"CurrentLow\":\"%d%s\"}"), sysCfg.hlw_imin, (sysCfg.flag.value_units) ? " mA" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("CURRENTHIGH"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 16001)) {
|
||||
if ((payload >= 0) && (payload < 16001)) {
|
||||
sysCfg.hlw_imax = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"CurrentHigh\":\"%d%s\"}"), sysCfg.hlw_imax, (sysCfg.flag.value_units) ? " mA" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWPCAL"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_pcal = (payload > 9999) ? payload : HLW_PREF_PULSE; // 12530
|
||||
else if (!strcmp_P(type,PSTR("ENERGYRESET"))) {
|
||||
if ((payload >= 1) && (payload <= 3)) {
|
||||
switch (payload) {
|
||||
case 1:
|
||||
hlw_kWhtoday = 0;
|
||||
rtcMem.hlw_kWhtoday = 0;
|
||||
sysCfg.hlw_kWhtoday = 0;
|
||||
break;
|
||||
case 2:
|
||||
sysCfg.hlw_kWhyesterday = 0;
|
||||
break;
|
||||
case 3:
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("(\"HlwPcal\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
char stemp0[10];
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
dtostrf((float)sysCfg.hlw_kWhyesterday / 100000000, 1, sysCfg.flag.energy_resolution, stemp0);
|
||||
dtostrf((float)rtcMem.hlw_kWhtoday / 100000000, 1, sysCfg.flag.energy_resolution, stemp1);
|
||||
dtostrf((float)(rtcMem.hlw_kWhtotal + (hlw_kWhtoday / 1000)) / 100000, 1, sysCfg.flag.energy_resolution, stemp2);
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"EnergyReset\":{\"Total\":%s, \"Yesterday\":%s, \"Today\":%s}}"), stemp2, stemp0, stemp1);
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWPCAL"))) {
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_pcal = (payload > 4000) ? payload : HLW_PREF_PULSE; // 12530
|
||||
}
|
||||
caltext = 1;
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWPSET"))) {
|
||||
if ((payload > 0) && (payload < 3601) && hlw_cf_plen) {
|
||||
sysCfg.hlw_pcal = (payload * 10 * hlw_cf_plen) / HLW_PREF;
|
||||
}
|
||||
caltext = 1;
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWUCAL"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload < 32001)) {
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_ucal = (payload > 999) ? payload : HLW_UREF_PULSE; // 1950
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"HlwUcal\":\"%d%s\"}"), sysCfg.hlw_ucal, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
caltext = 2;
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWUSET"))) {
|
||||
if ((payload > 0) && (payload < 501) && hlw_cf1u_plen) {
|
||||
sysCfg.hlw_ucal = (payload * 10 * hlw_cf1u_plen) / HLW_UREF;
|
||||
}
|
||||
caltext = 2;
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWICAL"))) {
|
||||
if ((data_len > 0) && (payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_ical = (payload > 2499) ? payload : HLW_IREF_PULSE; // 3500
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_ical = (payload > 1100) ? payload : HLW_IREF_PULSE; // 3500
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"HlwIcal\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
caltext = 3;
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("HLWISET"))) {
|
||||
if ((payload > 0) && (payload < 16001) && hlw_cf1i_plen) {
|
||||
sysCfg.hlw_ical = (payload * hlw_cf1i_plen) / HLW_IREF;
|
||||
}
|
||||
caltext = 3;
|
||||
}
|
||||
#if FEATURE_POWER_LIMIT
|
||||
else if (!strcmp_P(type,PSTR("MAXPOWER"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mpl = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"MaxPower\":\"%d%s\"}"), sysCfg.hlw_mpl, (sysCfg.flag.value_units) ? " W" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("MAXPOWERHOLD"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mplh = (1 == payload) ? MAX_POWER_HOLD : payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"MaxPowerHold\":\"%d%s\"}"), sysCfg.hlw_mplh, (sysCfg.flag.value_units) ? " Sec" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("MAXPOWERWINDOW"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mplw = (1 == payload) ? MAX_POWER_WINDOW : payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"MaxPowerWindow\":\"%d%s\"}"), sysCfg.hlw_mplw, (sysCfg.flag.value_units) ? " Sec" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SAFEPOWER"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mspl = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"SafePower\":\"%d%s\"}"), sysCfg.hlw_mspl, (sysCfg.flag.value_units) ? " W" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SAFEPOWERHOLD"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_msplh = (1 == payload) ? SAFE_POWER_HOLD : payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"SafePowerHold\":\"%d%s\"}"), sysCfg.hlw_msplh, (sysCfg.flag.value_units) ? " Sec" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("SAFEPOWERWINDOW"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 1440)) {
|
||||
if ((payload >= 0) && (payload < 1440)) {
|
||||
sysCfg.hlw_msplw = (1 == payload) ? SAFE_POWER_WINDOW : payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"SafePowerWindow\":\"%d%s\"}"), sysCfg.hlw_msplw, (sysCfg.flag.value_units) ? " Min" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("MAXENERGY"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 3601)) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mkwh = payload;
|
||||
hlw_mkwh_state = 3;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"MaxEnergy\":\"%d%s\"}"), sysCfg.hlw_mkwh, (sysCfg.flag.value_units) ? " Wh" : "");
|
||||
}
|
||||
else if (!strcmp_P(type,PSTR("MAXENERGYSTART"))) {
|
||||
if ((data_len > 0) && (payload >= 0) && (payload < 24)) {
|
||||
if ((payload >= 0) && (payload < 24)) {
|
||||
sysCfg.hlw_mkwhs = payload;
|
||||
}
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"MaxEnergyStart\":\"%d%s\"}"), sysCfg.hlw_mkwhs, (sysCfg.flag.value_units) ? " Hr" : "");
|
||||
@@ -545,6 +590,17 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
||||
else {
|
||||
serviced = false;
|
||||
}
|
||||
switch (caltext) {
|
||||
case 1:
|
||||
snprintf_P(svalue, ssvalue, PSTR("(\"HlwPcal\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
break;
|
||||
case 2:
|
||||
snprintf_P(svalue, ssvalue, PSTR("{\"HlwUcal\":\"%d%s\"}"), sysCfg.hlw_ucal, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
break;
|
||||
case 3:
|
||||
snprintf_P(svalue, ssvalue, PSTR("(\"HlwIcal\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " uS" : "");
|
||||
break;
|
||||
}
|
||||
return serviced;
|
||||
}
|
||||
|
||||
@@ -554,40 +610,53 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
||||
|
||||
void hlw_mqttStat(byte option, char* svalue, uint16_t ssvalue)
|
||||
{
|
||||
/* option 0 = do not show period energy usage
|
||||
* option 1 = show period energy usage
|
||||
*/
|
||||
char stemp0[10];
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
char stemp3[10];
|
||||
char stemp4[10];
|
||||
char stemp5[10];
|
||||
char speriod[20];
|
||||
float pet;
|
||||
float ped;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
uint16_t pe;
|
||||
uint16_t pw;
|
||||
uint16_t pu;
|
||||
|
||||
hlw_readEnergy(option, ped, pe, pw, pu, pi, pc);
|
||||
hlw_readEnergy(option, pet, ped, pe, pw, pu, pi, pc);
|
||||
dtostrf((float)sysCfg.hlw_kWhyesterday / 100000000, 1, sysCfg.flag.energy_resolution, stemp0);
|
||||
dtostrf(ped, 1, sysCfg.flag.energy_resolution, stemp1);
|
||||
dtostrf(pc, 1, 2, stemp2);
|
||||
dtostrf(pi, 1, 3, stemp3);
|
||||
dtostrf(pet, 1, sysCfg.flag.energy_resolution, stemp4);
|
||||
dtostrf(pu, 1, sysCfg.flag.voltage_resolution, stemp5);
|
||||
snprintf_P(speriod, sizeof(speriod), PSTR(", \"Period\":%d"), pe);
|
||||
snprintf_P(svalue, ssvalue, PSTR("%s\"Yesterday\":%s, \"Today\":%s%s, \"Power\":%d, \"Factor\":%s, \"Voltage\":%d, \"Current\":%s}"),
|
||||
svalue, stemp0, stemp1, (option) ? speriod : "", pw, stemp2, pu, stemp3);
|
||||
snprintf_P(svalue, ssvalue, PSTR("%s\"Total\":%s, \"Yesterday\":%s, \"Today\":%s%s, \"Power\":%d, \"Factor\":%s, \"Voltage\":%s, \"Current\":%s}"),
|
||||
svalue, stemp4, stemp0, stemp1, (option) ? speriod : "", pw, stemp2, stemp5, stemp3);
|
||||
#ifdef USE_DOMOTICZ
|
||||
dtostrf(ped * 1000, 1, 1, stemp1);
|
||||
domoticz_sensor4(pw, stemp1);
|
||||
if (option) { // Only send if telemetry
|
||||
dtostrf(pet * 1000, 1, 1, stemp1);
|
||||
domoticz_sensor4(pw, stemp1);
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
void hlw_mqttPresent()
|
||||
void hlw_mqttPresent(byte option)
|
||||
{
|
||||
// {"Time":"2017-03-04T13:37:24", "Yesterday":0.013, "Today":0.000, "Period":0, "Power":0, "Factor":0.00, "Voltage":0, "Current":0.000}
|
||||
/* option 0 = do not show period energy usage
|
||||
* option 1 = show period energy usage
|
||||
*/
|
||||
// {"Time":"2017-03-04T13:37:24", "Total":0.013, "Yesterday":0.013, "Today":0.000, "Period":0, "Power":0, "Factor":0.00, "Voltage":0, "Current":0.000}
|
||||
char svalue[200]; // was MESSZ
|
||||
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Time\":\"%s\", "), getDateTime().c_str());
|
||||
hlw_mqttStat(1, svalue, sizeof(svalue));
|
||||
mqtt_publish_topic_P(1, PSTR("ENERGY"), svalue);
|
||||
hlw_mqttStat(option, svalue, sizeof(svalue));
|
||||
mqtt_publish_topic_P(2, PSTR("ENERGY"), svalue);
|
||||
}
|
||||
|
||||
void hlw_mqttStatus(char* svalue, uint16_t ssvalue)
|
||||
@@ -599,12 +668,13 @@ void hlw_mqttStatus(char* svalue, uint16_t ssvalue)
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_ENERGY_SNS[] PROGMEM =
|
||||
"<tr><th>Voltage</th><td>%d V</td></tr>"
|
||||
"<tr><th>Voltage</th><td>%s V</td></tr>"
|
||||
"<tr><th>Current</th><td>%s A</td></tr>"
|
||||
"<tr><th>Power</th><td>%d W</td></tr>"
|
||||
"<tr><th>Power Factor</th><td>%s</td></tr>"
|
||||
"<tr><th>Energy Today</th><td>%s kWh</td></tr>"
|
||||
"<tr><th>Energy Yesterday</th><td>%s kWh</td></tr>";
|
||||
"<tr><th>Energy Yesterday</th><td>%s kWh</td></tr>"
|
||||
"<tr><th>Energy Total</th><td>%s kWh</td></tr>";
|
||||
|
||||
String hlw_webPresent()
|
||||
{
|
||||
@@ -613,21 +683,25 @@ String hlw_webPresent()
|
||||
char stemp2[10];
|
||||
char stemp3[10];
|
||||
char stemp4[10];
|
||||
char sensor[300];
|
||||
char stemp5[10];
|
||||
char stemp6[10];
|
||||
char sensor[320];
|
||||
float pet;
|
||||
float ped;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
uint16_t pe;
|
||||
uint16_t pw;
|
||||
uint16_t pu;
|
||||
|
||||
hlw_readEnergy(0, ped, pe, pw, pu, pi, pc);
|
||||
|
||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
||||
dtostrf(pu, 1, sysCfg.flag.voltage_resolution, stemp6);
|
||||
dtostrf(pi, 1, 3, stemp);
|
||||
dtostrf(pc, 1, 2, stemp2);
|
||||
dtostrf(ped, 1, sysCfg.flag.energy_resolution, stemp3);
|
||||
dtostrf((float)sysCfg.hlw_kWhyesterday / 100000000, 1, sysCfg.flag.energy_resolution, stemp4);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, pu, stemp, pw, stemp2, stemp3, stemp4);
|
||||
dtostrf(pet, 1, sysCfg.flag.energy_resolution, stemp5);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, stemp6, stemp, pw, stemp2, stemp3, stemp4, stemp5);
|
||||
page += sensor;
|
||||
return page;
|
||||
}
|
||||
|
||||
+13
-19
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Heiko Krupp. All rights reserved.
|
||||
xsns_htu21.ino - HTU21 temperature and humidity sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Heiko Krupp and Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
|
||||
+13
-19
@@ -1,26 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2017 Theo Arends. All rights reserved.
|
||||
xsns_sht1x.ino - SHT1x temperature and sensor support for Sonoff-Tasmota
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
|
||||
Reference in New Issue
Block a user