Compare commits

...
29 Commits
Author SHA1 Message Date
arendst 22ef93a2c4 v5.4.0
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)
2017-07-25 18:05:47 +02:00
arendst 7e6b3a2bb1 v5.3.0
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)
2017-07-15 15:07:30 +02:00
arendst 88ec2c6a94 Enforce use of flash mode DOUT
To solve boot problems on increasing amount of esp8285 based devices
using the wrong firmware image. Dout works fine with both esp8266 and
esp8285
2017-07-14 13:00:08 +02:00
Theo Arends 3a4210e0e2 Update planned support 2017-07-03 18:06:55 +02:00
Theo Arends dd44bdb471 Updated planned support 2017-07-03 18:01:57 +02:00
arendst 2d8947d1c7 v5.2.4
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)
2017-07-03 11:52:15 +02:00
arendst 39a65e230b v5.2.4
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
2017-07-03 11:45:15 +02:00
arendst c768f7d610 Add support for BN-SZ01 2017-07-03 11:43:45 +02:00
arendst ee883bdcb8 v5.2.3
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)
2017-06-30 17:54:19 +02:00
arendst e914053041 v5.2.2
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)
2017-06-25 23:07:51 +02:00
arendst 2195ddd496 v5.2.2
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)
2017-06-25 23:01:41 +02:00
arendst 92958f4bdd v5.2.1
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)
2017-06-22 22:00:09 +02:00
arendst b88ec7f5a9 v5.2.0
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)
2017-06-19 22:54:49 +02:00
arendst d763fd52eb v5.1.7
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)
2017-06-16 14:33:49 +02:00
arendst 98d06e8809 v5.1.6
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)
2017-06-06 23:23:23 +02:00
arendst 0f103db4c6 v5.1.5
5.1.5 20170604
* Shrink code in preparation to ESP8266-Arduino 2.4.0-rc1
* Add effect parameter to HUE Device (#464)
2017-06-04 17:40:27 +02:00
Theo ArendsandGitHub 9e2159c1c6 Merge pull request #499 from ThomDietrich/patch-1
Add commented pio default environment config lines
2017-06-04 10:45:37 +02:00
Thomas DietrichandGitHub d8eda2ff13 Fix typo 2017-06-03 22:18:58 +02:00
Thomas DietrichandGitHub e2468b58bc Add commented default environment config lines 2017-06-03 22:13:35 +02:00
arendst 5aa8457a85 Add ESP8266-Arduino 2.4.0-rc1 updates 2017-06-02 11:24:08 +02:00
arendst 44b69bfd97 v5.1.4
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)
2017-06-01 17:37:30 +02:00
arendst 70ccdfe9b9 v5.1.3
5.1.3 20170520
* Add Domoticz Counter
2017-05-20 14:03:34 +02:00
arendst 26d3a8c191 v5.1.2
5.1.2 20170519
* Fix Counter/Timer JSON message and update Counter/Timer on webpage
* Fix WS2812 Domoticz related regression issues
2017-05-19 16:09:25 +02:00
arendst 88648a8099 v5.1.1
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
2017-05-17 22:49:22 +02:00
arendst afc7b96b7c v5.1.0
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)
2017-05-13 13:11:39 +02:00
arendst ec8b41903b v5.1.0
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)
2017-05-13 13:09:54 +02:00
arendst ceb6fab51d v5.1.0
5.1.0 20170513
* Fix Offline/Removal of retained topic when FullTopic is changed
* Add FullTopic to MQTT Configuration and Information web page
* Add license model GPLv3 (#188)
2017-05-13 13:04:28 +02:00
arendst f6f6616c9d v5.1.0
5.1.0 20170513
* Fix Offline/Removal of retained topic when FullTopic is changed
* Add FullTopic to MQTT Configuration and Information web page
* Adde license model GPLv3 (#188)
2017-05-13 13:02:10 +02:00
arendst 3143b6e65e Update to released 1m0.ld script and boards 2017-05-12 11:23:57 +02:00
35 changed files with 5064 additions and 1317 deletions
+5 -2
View File
@@ -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
View File
@@ -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>.
+11 -2
View File
@@ -1,9 +1,9 @@
## 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.7** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **5.4.0** - 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 Version 5.x.x 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).
@@ -34,15 +34,24 @@ 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 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 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)
- [Electrodragon IoT Relay Board](http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/)
Planned support:
- [iTead Sonoff T1](https://www.itead.cc/smart-home/sonoff-t1.html)
- [iTead Sonoff B1](https://www.itead.cc/smart-home/sonoff-b1.html)
Optional future support:
- iTead RF Bridge
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonofftoucheu.jpg" height="280" align="left" />
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff4ch.jpg" height="250" align="right" />
Binary file not shown.
Binary file not shown.
-6
View File
@@ -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
+131
View File
@@ -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"
+24 -10
View File
@@ -10,20 +10,34 @@
[platformio]
src_dir = sonoff
; Sonoff et al (ESP8266 based)
[env:sonoff]
platform = espressif8266
framework = arduino
board = esp01_1m
board_flash_mode = qio
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=512
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON
; Uncomment one of the lines below to build/upload only one environment
;env_default = sonoff
;env_default = sonoff-minimal
;env_default = sonoff-ds18x20
; Sonoff Touch and Sonoff 4CH (ESP8285 based)
[env:sonoff-touch-4ch]
; Sonoff et al
[env:sonoff]
platform = espressif8266
framework = arduino
board = esp01_1m
board_flash_mode = dout
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=512
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
+94 -1
View File
@@ -1,4 +1,97 @@
/* 5.0.7 20170511
/* 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
+54 -31
View File
@@ -1,24 +1,41 @@
/*********************************************************************************************\
* Config settings
\*********************************************************************************************/
/*
settings.h - setting variables for Sonoff-Tasmota
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
uint32_t data; // Allow bit manipulation using SetOption
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;
uint32_t mqtt_response : 1; // bit 4
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 temperature_conversion : 1; // bit 8
uint32_t mqtt_sensor_retain : 1;
uint32_t mqtt_offline : 1; // bit 10
uint32_t spare11 : 1;
uint32_t spare12 : 1;
uint32_t spare13 : 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 spare14 : 1;
uint32_t spare15 : 1;
uint32_t spare16 : 1;
@@ -39,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;
@@ -69,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];
@@ -108,7 +125,7 @@ struct SYSCFG {
uint16_t hlw_mkwhs; // MaxEnergyStart
// 3.0.6
uint16_t mqtt_retry; // was ex_pulsetime until 4.0.4
uint16_t mqtt_retry; // was ex_pulsetime until 4.0.4
// 3.1.1
uint8_t poweronstate;
@@ -135,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;
@@ -157,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];
@@ -181,14 +198,20 @@ struct SYSCFG {
// 5.0.4a
char mqtt_fulltopic[101];
// 5.1.1
unsigned long pCounter[MAX_COUNTERS];
uint16_t pCounterType;
uint16_t pCounterDebounce;
} 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
+137 -47
View File
@@ -1,26 +1,20 @@
/*
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/>.
*/
/*********************************************************************************************\
@@ -65,6 +59,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,8 +129,11 @@ 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;
/********************************************************************************************/
/*
@@ -168,15 +171,6 @@ void setFlashMode(byte option, byte mode)
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 +186,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 +242,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,14 +251,33 @@ 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)) {
CFG_Default();
}
*/
if (sysCfg.cfg_holder != CFG_HOLDER) {
/*
// Auto upgrade
if ((sysCfg.version < 0x04020000) || (sysCfg.version > VERSION)) {
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));
@@ -242,7 +292,19 @@ void CFG_Load()
} else {
CFG_Default();
}
*/
// 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 +319,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++) {
@@ -325,10 +387,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 +448,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,7 +503,7 @@ 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
@@ -458,6 +518,13 @@ void CFG_DefaultSet2()
// 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;
}
/********************************************************************************************/
@@ -540,6 +607,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()
@@ -590,7 +658,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;
@@ -639,7 +707,29 @@ void CFG_Delta()
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;
}
sysCfg.version = VERSION;
CFG_Save(1);
}
}
+636 -336
View File
File diff suppressed because it is too large Load Diff
+75 -9
View File
@@ -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
@@ -122,6 +145,9 @@ enum module_t {
SONOFF_DEV,
H801,
SONOFF_SC,
SONOFF_BN,
SONOFF_4CHPRO,
HUAFAN_SS,
MAXMODULE };
/********************************************************************************************/
@@ -148,7 +174,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 +258,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 +294,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 +312,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 +320,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 +436,45 @@ 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
}
};
+19
View File
@@ -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
+107 -21
View File
@@ -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,6 +166,73 @@ 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
\*********************************************************************************************/
@@ -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;
}
+26 -7
View File
@@ -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
@@ -64,6 +81,7 @@
#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
@@ -84,8 +102,8 @@
// -- 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 ----------------------------------------
@@ -123,7 +141,8 @@
#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)
@@ -146,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
/*********************************************************************************************\
+19 -2
View File
@@ -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.
+137 -143
View File
@@ -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
@@ -87,6 +81,7 @@ 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;}"
".q{float:right;width:200px;text-align:right;}"
"</style>"
"</head>"
@@ -137,50 +132,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>&nbsp;Module parameters&nbsp;</b></legend><form method='post' action='sv'>"
"<fieldset><legend><b>&nbsp;Module parameters&nbsp;</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>&nbsp;<span class='q {i}'>{r}%</span></div>";
"<div><a href='#p' onclick='c(this)'>{v}</a>&nbsp;<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>&nbsp;Wifi parameters&nbsp;</b></legend><form method='post' action='sv'>"
"<fieldset><legend><b>&nbsp;Wifi parameters&nbsp;</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 +177,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>&nbsp;MQTT parameters&nbsp;</b></legend><form method='post' action='sv'>"
"<fieldset><legend><b>&nbsp;MQTT parameters&nbsp;</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>&nbsp;Logging parameters&nbsp;</b></legend><form method='post' action='sv'>"
"<fieldset><legend><b>&nbsp;Logging parameters&nbsp;</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 +202,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>&nbsp;Other parameters&nbsp;</b></legend><form method='post' action='sv'>"
"<fieldset><legend><b>&nbsp;Other parameters&nbsp;</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>&nbsp;Emulation&nbsp;</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>&nbsp;Emulation&nbsp;</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>&nbsp;Restore configuration&nbsp;</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>&nbsp;Restore configuration&nbsp;</b></legend>";
const char HTTP_FORM_UPG[] PROGMEM =
"<div id='f1' name='f1' style='display:block;'>"
"<fieldset><legend><b>&nbsp;Upgrade by web server&nbsp;</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>&nbsp;Upgrade by file upload&nbsp;</b></legend>"
"<fieldset><legend><b>&nbsp;Upgrade by file upload&nbsp;</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,8 +261,11 @@ const char HTTP_END[] PROGMEM =
"</body>"
"</html>";
const char HDR_CCNTL[] PROGMEM = "Cache-Control";
const char HDR_REVAL[] PROGMEM = "no-cache, no-store, must-revalidate";
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};
@@ -393,6 +379,13 @@ 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)) {
@@ -407,16 +400,13 @@ void showPage(String &page)
}
}
page += FPSTR(HTTP_END);
webServer->sendHeader(FPSTR(HDR_CCNTL), FPSTR(HDR_REVAL));
webServer->sendHeader(F("Pragma"), F("no-cache"));
webServer->sendHeader(F("Expires"), F("-1"));
webServer->send(200, F("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;
@@ -432,7 +422,7 @@ void handleRoot()
page += F("<div id='l1' name='l1'></div>");
if (Maxdevice) {
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;
@@ -469,6 +459,7 @@ void handleAjax2()
}
String tpage = "";
tpage += counter_webPresent();
if (hlw_flg) {
tpage += hlw_webPresent();
}
@@ -518,7 +509,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;
}
@@ -526,13 +516,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->send(200, F("text/html"), page);
webServer->send(200, FPSTR(HDR_CTYPE_HTML), page);
}
boolean httpUser()
@@ -549,7 +539,7 @@ 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(F("{v}"), F("Configuration"));
@@ -611,7 +601,7 @@ void handleModule()
}
char stemp[20], line[128];
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(F("{v}"), F("Config module"));
@@ -675,11 +665,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(F("{v}"), F("Configure Wifi"));
page.replace(F("</style>"), FPSTR(HTTP_LNK_STYLE));
if (scan) {
#ifdef USE_EMULATION
@@ -740,11 +729,8 @@ void handleWifi(boolean scan)
rssiQ += quality;
item.replace(F("{v}"), WiFi.SSID(indices[i]));
item.replace(F("{r}"), rssiQ);
if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) {
item.replace(F("{i}"), F("l"));
} else {
item.replace(F("{i}"), "");
}
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 {
@@ -778,7 +764,7 @@ 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(F("{v}"), F("Configure MQTT"));
@@ -792,6 +778,7 @@ void handleMqtt()
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,7 +789,7 @@ 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(F("{v}"), F("Config logging"));
@@ -850,7 +837,7 @@ 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);
@@ -863,10 +850,15 @@ void handleOther()
page.replace(F("{2"), FRIENDLY_NAME);
page.replace(F("{3"), sysCfg.friendlyname[0]);
#ifdef USE_EMULATION
page += FPSTR(HTTP_FORM_OTHER3);
page.replace(F("{r2}"), (EMUL_NONE == sysCfg.flag.emulation) ? F(" checked") : F(""));
page.replace(F("{r3}"), (EMUL_WEMO == sysCfg.flag.emulation) ? F(" checked") : F(""));
page.replace(F("{r4}"), (EMUL_HUE == sysCfg.flag.emulation) ? F(" checked") : F(""));
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(F("{1"), String(i +1));
@@ -886,7 +878,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)];
@@ -897,7 +889,7 @@ void handleDownload()
snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"),
sysCfg.friendlyname[0], Version);
webServer->sendHeader(F("Content-Disposition"), attachment);
webServer->send(200, F("application/octet-stream"), "");
webServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
memcpy(buffer, &sysCfg, sizeof(sysCfg));
buffer[0] = CONFIG_FILE_SIGN;
buffer[1] = (!CONFIG_FILE_XOR)?0:1;
@@ -917,6 +909,7 @@ void handleSave()
char log[LOGSZ +20];
char stemp[TOPSZ];
char stemp2[TOPSZ];
byte what = 0;
byte restart;
String result = "";
@@ -943,17 +936,21 @@ void handleSave()
break;
case 2:
strlcpy(stemp, (!strlen(webServer->arg("mt").c_str())) ? MQTT_TOPIC : webServer->arg("mt").c_str(), sizeof(stemp));
if (strcmp(stemp, sysCfg.mqtt_topic)) {
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));
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:
@@ -1005,7 +1002,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);
@@ -1059,11 +1055,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(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);
@@ -1076,12 +1074,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(F("{v}"), F("Firmware upgrade"));
page += FPSTR(HTTP_FORM_UPG);
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);
@@ -1136,24 +1136,21 @@ void handleUploadDone()
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;
@@ -1187,6 +1184,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) {
@@ -1199,9 +1197,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;
}
@@ -1229,10 +1224,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
@@ -1244,12 +1236,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;
}
@@ -1294,9 +1284,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) {
@@ -1344,7 +1334,7 @@ void handleCmnd()
} else {
message = F("Need user=<username>&password=<password>\n");
}
webServer->send(200, F("text/plain"), message);
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), message);
}
void handleConsole()
@@ -1353,7 +1343,7 @@ 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(F("{v}"), F("Console"));
@@ -1370,7 +1360,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,7 +1408,7 @@ void handleAjax()
} while (counter != logidx);
}
message += F("</l></r>");
webServer->send(200, F("text/xml"), message);
webServer->send(200, FPSTR(HDR_CTYPE_XML), message);
}
void handleInfo()
@@ -1426,7 +1416,9 @@ 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();
@@ -1440,7 +1432,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++) {
@@ -1449,8 +1442,8 @@ void handleInfo()
page += F("</th><td>"); page += sysCfg.friendlyname[i]; page += F("</td></tr>");
}
page += F("<tr><td>&nbsp;</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>");
@@ -1473,10 +1466,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>&nbsp;</td></tr>");
page += F("<tr><th>Emulation</th><td>");
#ifdef USE_EMULATION
if (EMUL_WEMO == sysCfg.flag.emulation) {
@@ -1560,18 +1557,15 @@ void handleNotFound()
String message = F("File Not Found\n\nURI: ");
message += webServer->uri();
message += F("\nMethod: ");
message += ( webServer->method() == HTTP_GET ) ? F("GET") : F("POST");
message += (webServer->method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += webServer->args();
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(FPSTR(HDR_CCNTL), FPSTR(HDR_REVAL));
webServer->sendHeader(F("Pragma"), F("no-cache"));
webServer->sendHeader(F("Expires"), F("-1"));
webServer->send(404, F("text/plain"), message);
setHeader();
webServer->send(404, FPSTR(HDR_CTYPE_PLAIN), message);
}
}
@@ -1582,7 +1576,7 @@ boolean captivePortal()
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Request redirected to captive portal"));
webServer->sendHeader(F("Location"), String("http://") + webServer->client().localIP().toString(), true);
webServer->send(302, F("text/plain"), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
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;
}
+62 -73
View File
@@ -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>&nbsp;Domoticz parameters&nbsp;</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
}
@@ -144,7 +144,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
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;
}
@@ -171,7 +171,7 @@ 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("/DIMMER%s"), (Maxdevice > 1) ? stemp1 : "");
@@ -210,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);
@@ -268,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;
@@ -289,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);
}
}
@@ -329,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
\*********************************************************************************************/
@@ -347,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);
@@ -380,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());
@@ -395,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
+13 -19
View File
@@ -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
+127 -107
View File
@@ -1,30 +1,24 @@
/*
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 Led and BN-SZ01
\*********************************************************************************************/
uint8_t ledTable[] = {
@@ -55,54 +49,82 @@ 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;
}
/********************************************************************************************/
void sl_setDim(uint8_t myDimmer)
{
if ((1 == sfl_flg) && (100 == myDimmer)) {
myDimmer = 99; // BN-SZ01 starts flickering at dimmer = 100
}
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;
float fmyWrm = (float)sysCfg.led_color[1] / newDim;
sl_dcolor[1] = (uint8_t)fmyWrm;
}
/********************************************************************************************/
void sl_init(void)
{
sysCfg.pwmvalue[0] = 0; // We use led_color
sysCfg.pwmvalue[1] = 0; // We use led_color
sysCfg.pwmvalue[0] = 0; // We use dimmer / led_color
if (2 == sfl_flg) {
sysCfg.pwmvalue[1] = 0; // We use led_color
}
sl_power = 0;
sl_any = 0;
sl_wakeupActive = 0;
}
void sl_setColor(char* colstr)
{
uint8_t my_color[2];
char *p;
uint16_t temp = strtol(colstr, &p, 16);
my_color[1] = temp & 0xFF; // Warm
temp >>= 8;
my_color[0] = temp & 0xFF; // Cold
if (temp < my_color[1]) {
temp = my_color[1];
}
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;
}
void sl_prepPower(char *svalue, uint16_t ssvalue)
{
// 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
sl_setDim(sysCfg.led_dimmer[0]);
if (2 == sfl_flg) {
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);
} 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();
}
@@ -123,24 +145,26 @@ void sl_animate()
sl_tcolor[0] = sl_dcolor[0];
sl_tcolor[1] = sl_dcolor[1];
} else {
if ((sl_tcolor[0] != sl_dcolor[0]) || (sl_tcolor[1] != sl_dcolor[1])) {
if (sl_tcolor[0] != sl_dcolor[0]) {
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 ((2 == sfl_flg) && (sl_tcolor[1] != sl_dcolor[1])) {
if (sl_tcolor[1] < sl_dcolor[1]) {
sl_tcolor[1] += ((sl_dcolor[1] - sl_tcolor[1]) >> sysCfg.led_speed) +1;
}
if (sl_tcolor[1] > sl_dcolor[1]) {
sl_tcolor[1] -= ((sl_tcolor[1] - sl_dcolor[1]) >> sysCfg.led_speed) +1;
}
}
}
} else { // Power On using wake up duration
if (1 == sl_wakeupActive) {
sl_wakeupActive = 2;
if (2 == sl_wakeupActive) {
sl_wakeupActive = 1;
sl_tcolor[0] = 0;
sl_tcolor[1] = 0;
sl_wakeupCntr = 0;
@@ -166,7 +190,7 @@ void sl_animate()
sl_any = 0;
sl_lcolor[0] = sl_tcolor[0];
sl_lcolor[1] = sl_tcolor[1];
for (byte i = 0; i < 2; i++) {
for (byte i = 0; i < sfl_flg; 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));
}
@@ -174,6 +198,34 @@ void sl_animate()
}
}
/*********************************************************************************************\
* Hue support
\*********************************************************************************************/
void sl_replaceHSB(String *response)
{
response->replace("{h}", "0");
response->replace("{s}", "0");
response->replace("{b}", String((uint8_t)(2.54f * (float)sysCfg.led_dimmer[0])));
}
void sl_getHSB(float *hue, float *sat, float *bri)
{
*hue = 0;
*sat = 0;
*bri = (2.54f * (float)sysCfg.led_dimmer[0]);
}
void sl_setHSB(float hue, float sat, float bri)
{
char svalue[MESSZ];
uint8_t tmp = (uint8_t)(bri * 100);
sysCfg.led_dimmer[0] = tmp;
sl_prepPower(svalue, sizeof(svalue));
mqtt_publish_topic_P(5, "DIMMER", svalue);
}
/*********************************************************************************************\
* Commands
\*********************************************************************************************/
@@ -183,27 +235,11 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
boolean serviced = true;
boolean coldim = false;
if (!strcmp_P(type,PSTR("COLOR"))) {
uint8_t my_color[5];
if ((2 == sfl_flg) && !strcmp_P(type,PSTR("COLOR"))) {
uint8_t my_color[2];
char *p;
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];
}
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(dataBufUc);
coldim = true;
} else {
sl_setDim(sysCfg.led_dimmer[0]);
@@ -213,7 +249,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
}
}
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 +257,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 +272,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 < 3601)) {
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
View File
@@ -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 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/>.
*/
/*********************************************************************************************\
* 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 };
+315 -228
View File
@@ -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()
{
@@ -217,10 +222,20 @@ void pollUDP()
// 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();
}
}
@@ -230,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>"
@@ -284,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}\","
@@ -330,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}\","
@@ -343,58 +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, F("text/plain"), "");
}
void handleUPnPservice()
{
addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle WeMo event service"));
webServer->send_P(200, PSTR("text/plain"), WEMO_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, F("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, F("text/xml"), description_xml);
description_xml.replace("{x3}", hue_serial());
webServer->send(200, FPSTR(HDR_CTYPE_XML), description_xml);
}
void hue_todo(String *path)
@@ -403,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)
@@ -412,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)
@@ -420,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, F("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, F("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, F("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)
@@ -472,13 +526,14 @@ 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;
bool resp = false;
bool on = false;
bool change = false;
char id[4];
@@ -488,26 +543,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, F("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/
@@ -516,15 +563,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)
{
@@ -537,53 +586,76 @@ 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 (change) {
if (sfl_flg) {
sl_setHSB(hue, sat, bri);
#ifdef USE_WS2812
}
else if (pin[GPIO_WS2812] < 99) {
ws2812_setHSB(hue, sat, bri);
#endif // USE_WS2812
}
change = false;
}
#endif // USE_WS2812
response += "]";
if (2 == response.length()) {
response = FPSTR(HUE_ERROR_JSON);
}
}
else {
response=FPSTR(HUE_ERROR_JSON);
response = FPSTR(HUE_ERROR_JSON);
}
webServer->send(200, F("application/json"), response);
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 +663,35 @@ 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, F("application/json"), response);
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
}
else webServer->send(406, F("application/json"), "{}");
else {
webServer->send(406, FPSTR(HDR_CTYPE_JSON), "{}");
}
}
void hue_groups(String *path)
{
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 +706,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 +717,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);
+52 -45
View File
@@ -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
@@ -113,6 +107,7 @@ RgbColor tcolor;
RgbColor lcolor;
uint8_t wakeupDimmer = 0;
uint8_t ws_bit = 0;
uint16_t wakeupCntr = 0;
unsigned long stripTimerCntr = 0; // Bars and Gradient
@@ -400,7 +395,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;
@@ -470,7 +465,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 +500,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.
@@ -533,7 +529,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 +537,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 +575,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 < 3601)) {
sysCfg.ws_wakeup = payload;
if (1 == sysCfg.ws_scheme) {
sysCfg.ws_scheme = 0;
@@ -615,16 +608,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
View File
@@ -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
View File
@@ -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
+139
View File
@@ -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
+13 -19
View File
@@ -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
+13 -19
View File
@@ -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
View File
@@ -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
}
}
+32 -41
View File
@@ -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 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/>.
*/
/*********************************************************************************************\
@@ -271,9 +265,6 @@ void hlw_init()
hlw_Ecntr = 0;
hlw_EDcntr = 0;
hlw_kWhtoday = (RTC_Valid()) ? rtcMem.hlw_kWhtoday : 0;
if (sysCfg.hlw_kWhtotal > rtcMem.hlw_kWhtotal) {
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
}
hlw_SELflag = 0; // Voltage;
@@ -389,7 +380,7 @@ void hlw_margin_chk()
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
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;
}
@@ -448,43 +439,43 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
boolean serviced = true;
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("ENERGYRESET"))) {
if ((data_len > 0) && (payload >= 1) && (payload <= 3)) {
if ((payload >= 1) && (payload <= 3)) {
switch (payload) {
case 1:
hlw_kWhtoday = 0;
@@ -509,69 +500,69 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
snprintf_P(svalue, ssvalue, PSTR("{\"EnergyReset\":{\"Total\":%s, \"Yesterday\":%s, \"Today\":%s}}"), stemp2, stemp0, stemp1);
}
else if (!strcmp_P(type,PSTR("HLWPCAL"))) {
if ((data_len > 0) && (payload > 0) && (payload < 32001)) {
if ((payload > 0) && (payload < 32001)) {
sysCfg.hlw_pcal = (payload > 9999) ? payload : HLW_PREF_PULSE; // 12530
}
snprintf_P(svalue, ssvalue, PSTR("(\"HlwPcal\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " uS" : "");
}
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" : "");
}
else if (!strcmp_P(type,PSTR("HLWICAL"))) {
if ((data_len > 0) && (payload > 0) && (payload < 32001)) {
if ((payload > 0) && (payload < 32001)) {
sysCfg.hlw_ical = (payload > 2499) ? payload : HLW_IREF_PULSE; // 3500
}
snprintf_P(svalue, ssvalue, PSTR("{\"HlwIcal\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " uS" : "");
}
#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" : "");
+13 -19
View File
@@ -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
View File
@@ -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