Commit Graph

3249 Commits

Author SHA1 Message Date
Maxim Prokhorov
eb59726b4f sns: report both used & supported units to the webui
Generic way to find out which units the magnitude type supports.
Clean-up UI related to temperature, energy and power units.
Resolves #2482

Also apply some refactoring to the 'schema'-generated
payloads by using the EnumerableConfig helper class.
Class received some new features:
- optional callback, verifying that index should be used at all
  specific use-case is magnitudes list that needs only 'counted' ones
- std::iota / ranges::iota_view -like helper object for sequences
  starting with something other than 0

Reordered payloads, prefer queueing over sending everything at once.
2021-10-24 14:22:08 +03:00
Maxim Prokhorov
a2c02a38e5 hardware: tweak core and core-webui targets
given that relay, button and led settings may be hardcoded,
explicitly remove from -core and -core-webui
restore telnet debugging though, since the terminal output needs it

for -core-webui, disables mdns and the generic webui server + webui blob
per 56f74cfe, make the resulting .bin even smaller
2021-10-20 13:26:12 +03:00
Maxim Prokhorov
0b64bd0229 core: minimize espurna.h use in headers 2021-10-20 13:07:34 +03:00
Maxim Prokhorov
4441345fce prometheus: enable by default 2021-10-20 13:07:34 +03:00
Maxim Prokhorov
050cbe79ba ota: also log internal updater error for arduino-ota 2021-10-20 11:38:36 +03:00
Maxim Prokhorov
6eaf88c69b utils: normalize hostname setting usage 2021-10-20 11:38:07 +03:00
Patrizio Bekerle
51133a69d9 mqtt: add mqtt.send terminal command (#2477) (#2478)
* Add SERIAL_SENSOR support

* Implement "MQTT.SEND" command, remove all other commands (#2477)

* Move command to mqtt.cpp and drop extra files

* Update CHANGELOG.md

Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>
2021-10-12 18:03:28 +03:00
Maxim Prokhorov
509bbea77d ir: fix missing ctor arguments when using noop classes 2021-10-03 22:07:22 +03:00
Maxim Prokhorov
a69a705cdc pio: normalize .ini override file line-endings 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
a4637aa19c ir: fix building with gcc-4.8 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
b9db535950 light: fix out-of-bounds access when using GPIO16
As noticed in the #2472

Internal implemementation still lacks the support for the GPIO16,
as it needs to use 'special' IO16 registers (and due to the fact that the 'normal'
registers only fit in an u16[16], from 0 to 15, so internals need to change as well)
One possible way is to attach certain implementation funcs to the
struct handling the isr, avoiding a bunch of in-line checks for `pin == 16`

Another option is to just use Core's `analogWrite`, which hides the
implementation from us and should work pretty seamlessly.
(...but, currently has 2 different waveform generator types, and it is
not really clear which one is a better default, as it needs to be set at
build-time)
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
6f132ef3c5 webui: debug SEND button should be type=submit
ref. #2476
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
daa7c4d726 webui: schema payload helper
Instead of typing schema and the actual payload handler twice,
declare the 'key' and the associated function on the same line

ref. #2476
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
de2d5f7350 led: pattern fixes and terminal command
Implement strongly-typed time units via std::chrono,
compile-time checks with static delays and limit possible values in the
pattern parser. Clamp 'repeats' as well, instead of relying on overflow

Rework internal loop & template runners, so there's no need to
proxy status and led struct all over. Instead, simply declare two
separate funcs that are supposed to be run during the pattern and at
it's end.

Instead of cloning the 'delays' array, implement a sequence iterator
that is tracking the currently used delay and it's repeats, and which
also jumps to the next entry in the list.
(but, this uses c++ iterators, and *may* be prone to errors)

Implement small terminal command 'led <ID> [<PATTERN STRING>]'.
Running without the 'PATTERN STRING' resets the LED to the values in settings.

Move re2c-generated parser back into a separate file, use .cpp.inc as
include and .re as the source

ref. #2476, fix 'finite' pattern handling
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
ea525f2f69 ir: implement 'state' encode & decode
Another type of payload from the IRremoteESP8266, intended to be used
with HVAC devices. Also add a bunch of comments in regards to IRac.h

More tweaks to the internal StringView and ParseResult, make
sure the implementation closely follows the STL alternatives.

More configuration options for the:
- Transmitter, support INPUT_PULLUP
- Receiver, allow to set signal inversion and modulation.
  Correctly implement buffer size setting.
- MQTT topics, allow to override both in and out

Also fix the 'simple' parser HEX range, accepting 8byte payloads (16chars)
and allowing lowercase inputs.
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
b36d65057f ir: declare rx and tx stuff closer to the top 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
ddb9f67a5b ir: restructure and add more settings
Declare settings under it's own namespace, where previous version used
function prefix. Allow to have configurable timeout and buffer size for
rx; default series, repeats and delay values for tx.

Values are reloaded with the appropriate configure() function from the
namespace, unless they apply to the IR{send,recv} object itself.

Also, no need to define 'default' fields for either of the Payload
structures. After parsing is done, pass all of string views to the
function defined in the .cpp that will prepare the resulting value.
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
6fd474694c ssdp: typos and concatenation instead of printf 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
d9e37762b6 ir: bump IRremoteESP8266 to 2.7.20 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
f427ea3c1e ir: formatting 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
444fcec890 webui: fix relay and curtain config change detection
resolve #2470
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
cf0315c231 scripts: formatting 2021-10-03 20:44:58 +03:00
Maxim Prokhorov
001ec79c8e ir: clean-up and refactoring of the existing module
- provide a queue for the outgoing messages, don't depend on the MQTT
  callback implementation details and always postpone the actual transfer.
- generate user input parsers using re2c, adds special PlatformIO build handlers
- add terminal command to show GPIO info and send a simple payload
- rework button<->action presets into value<->terminal command presets and custom ones
  through the use of `irCmd<VALUE>` settings, where the VALUE is taken from the simple payload
  (yet, it does not understand repeated codes, but that's something to add later *or* use rpnlib)
- add tx message integration for the relay module via `irRelayOn#` and `irRelayOff#`
- rework simple payload to include 'repeats' value for the 'IRsend::send()'
  also adds internal 'series', 'delay' and includes full 64bit 'value'
  (as uppercase HEX, instead of decimal)
- rework raw payload to use 'series' instead of 'repeats', and provide a
  clear distinction between the usec time and the options of the message
  by moving the required options to the front and separating them using ':'
  (just like the simple variant)
- make RX and TX pin a runtime setting, make RX and TX support a build flag
- small test framework to check whether internal string encode<->decode works

Also updates the hexEncode & hexDecode implementations to use
'iterators' instead of just pointer + index.
2021-10-03 20:44:58 +03:00
hamed
62d83c6194 light: fix rgb hex parser swapped blue and green values (#2474)
This was causing WebUI colorpicker to jump between positions in rgb mode, after the websocket immediately reported back rgb tuple containing different values
2021-09-26 01:38:54 +03:00
Matthieu Sprunck
9087fcf618 sns: fix initialization of _adc_counts (#2471) 2021-09-12 08:12:25 +03:00
Maxim Prokhorov
f748b6487c test: also check for small core webui 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
ef604ea848 api: workaround for espasyncwebserver vs. esp8266webserver includes
When building single source, enums for HTTP status codes have a name conflict.
ESP8266WebServer is included only in the OTA_WEB_SUPPORT=1 and WEB_SUPPORT=0,
so guard by checking for WEB_SUPPORT before including anything related to the async variant.
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
a27b3feb98 ota: port config and changelog 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
a4bc8c690d ota: simplify the include chain 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
56f74cfee5 ota: additional code for when the web server support is disabled
Using Core's ESP8266WebServer + some additional handlers.
Includes barebones page, without authorization.

Allows to explicitly set OTA_WEB_SUPPORT=1 with the ESPURNA_CORE and still get a web page.
Around the same size as ArduinoOTA + MDNS, so it might also be a good
suggestion to disable those when web support is enabled.
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
5134cd17c0 light: limit transition time based on internal details 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
da2c9f3dc1 webui: get rid of the wsSend_P
Replace with a postponed message, where it is actually relevant.
For the NoFUSS - as with all OTA methods, page will be reloaded automatically.

And no more strlen_P into a variable-length array.
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
6afeb88d87 sns: pzem004t initialization clean-up
Indexed address settings & build flags.
Old parsing code is still here, but depends on the old build flag presence.

Remove most of the singleton-related code, update terminal commands to
use ctx instead of just dumping debug strings.
Since the initialization happens in the sensor setup, and we know the
pzem pointer - simply pass the 'sensor' address to the function and
utilize the c++ local static variable feature that allows their use in
the function body and any lambdas declared within it.

Multiplexing is still happening with the index-math, due for a change at
a later date (...with serial / hwserial / stream changes...)
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
f920187a60 mqtt: buffer usage clean-up
Make sure to *not* use variable-length arrays for topics,
and use compile-time concatenation where it is possible.
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
7b4af9ad95 thingspeak: rework request generation
Get rid of variable-length array in favour of a single allocation,
and also do everything through String concat.
2021-09-03 11:05:09 +03:00
Maxim Prokhorov
4bb0c3386a light: more refactoring
Reading clang-tidy reports... Make sure to explicitly handle instances
of float -> (unsigned) long  silently removing the fractional part.
Also, small adjustments to the way these values are parsed.

Specifically:
- calculating step & time in the transition function
- rgb channels temperature adjustment from kelvins

Get rid of input & target as bool param. Replace it with more
specific functions, named accordingly, returning the Rgb struct.
(also fixes `rgb` command not returning what the rest of the API returns)

As a side-effect, make RGB payload conversion use a more paranoid parsing & serialization methods.
2021-09-03 11:03:53 +03:00
Maxim Prokhorov
d527351364 light: trigger an update on brightness function change
So it's no longer required to change any values or the state

Slightly changed the inputValue -> value transformation classes,
actually using the recursive template to apply things in order.
Still a bit quirky, but nothing better comes to mind for this.
2021-08-31 06:07:53 +03:00
Maxim Prokhorov
32aae70374 light: more refactoring related input & value stages
Fixes color+(white or cct) brightness function factor calculation
to actually do what the comment says it does.

No more unsigned char for value, consistent integer math and
explicit clamping of the input & output values.

As a follow-up for the a55cf0b, reworks brightness functions:
- value input and application implemented as part of the channel class
- track value changes externally, no need for OnceFlag
- simple all, only-rgb, color+white and color+cct are distinct
  functions, where brightness classes implement the actual math
- avoid accidentally doing an actual function call through
  `lightChannels()` by not accessing channels elements & size directly
  through the vector (yay c++ strictness regarding *public* symbols)
2021-08-30 14:34:30 +03:00
Maxim Prokhorov
dd4426b77f webui: fix small screen menu toggle
no need to apply 'active' class to anything other than 'layout'
fix #2469
2021-08-30 14:34:30 +03:00
Maxim Prokhorov
1ae7f27253 debug: fix build warning with serial disabled
resolve #2468
2021-08-30 14:34:30 +03:00
Maxim Prokhorov
a55cf0b847 light: stop the update request from running twice
In case the rgb+white(cct) brightness function was selected by the
configuration, internal calculations will always result in 'changed' being 'true'
and as a result it will continiously re-create the transition object.

fix #2467 (at least for now, the brightness function should be actually fixed)
2021-08-27 23:28:10 +03:00
Maxim Prokhorov
188414b431 webui: typo the password pattern
fix #2465
2021-08-27 04:11:53 +03:00
Maxim Prokhorov
ef8e7fa0dd webui: rebuild once again
amends 03573b783e
2021-08-27 04:09:45 +03:00
Maxim Prokhorov
fd913f15a1 thermostat: typo 2021-08-22 06:54:25 +03:00
Maxim Prokhorov
03573b783e webui: apply modules-... style globally
Otherwise, some things are still hidden
(or, depend on the order of incoming messages)

Make thermostat code use those as well, instead of injecting
thermostatVisible in every json payload
2021-08-22 06:42:16 +03:00
Maxim Prokhorov
5b5f104db3 ha: const-correct normalization
And init directly in the members list
2021-08-21 02:50:46 +03:00
Maxim Prokhorov
6087becf86 mqtt: remove unnecessary const_cast of the topic 2021-08-21 02:48:27 +03:00
Maxim Prokhorov
e6a0e505b3 mqtt: payload is not const
Even if std::function compiles with the wrong (but compatible) signature
2021-08-21 02:48:27 +03:00
Maxim Prokhorov
31688f1bf0 ota: missing space in the outgoing http request
fix #2465
2021-08-21 02:42:25 +03:00
Maxim Prokhorov
bdd821db86 pio: check returncode of the git process
Since the Popen instance won't do that by itself. Handles the case
where there is `git` command present, but it's not a git repo underneath.
2021-08-17 14:35:20 +03:00