Commit Graph

10 Commits

Author SHA1 Message Date
Bernhard Kirchen
1a19f881aa Feature: support JSON payload in MQTT battery provider
this changeset adds support for parsing the MQTT battery provider's SoC
and voltage topics' payloads as JSON to extract a numeric value at a
configurable path.
2024-07-31 15:05:41 +02:00
Bernhard Kirchen
86a49a781a fix: use mutex when writing MQTT power meter value
we previously used the mutex to protect writing the target variable.
however, we would only do that for the old usecase, where a plain float
value in Watts was expected as the topic's payload.
2024-07-22 20:07:38 +02:00
Bernhard Kirchen
5e5a5253f4 fix: initialize MQTT power meter values to zero
avoid using uninitialized memory.
2024-07-22 20:07:38 +02:00
Bernhard Kirchen
15b6a32b92 Feature: support JSON payload in MQTT power meter
the MQTT power meter can now process the messages published at the
respective topics as JSON and extract a power value using a JSON path
(same as in HTTP+JSON power meter). additionally, selecting a unit for
the power value as well as an option to invert the value's sign was
added as well, similar to the HTTPS+JSON power meter.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
b891a4c1a3 powermeter refactor: instanciate power meters with config
instead of reading the main config's powermeter struct(s), the
individual power meters now are instanciated using a copy of their
respective config. this allows to instanciate different power meters
with different configs. as a first step, this simplifies instanciating
power meters for test purposes.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
3f2d9d38fa powermeter refactor: fully structure settings per provider
all power meter providers now have their own configuration struct
defined. a respective method to serialize and deserialize the provider
config is implemented for each provider.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
673b9f4fa8 powermeter refactor: use destructors to de-initialize 2024-06-26 20:51:56 +02:00
Bernhard Kirchen
d99cfd5b31 powermeter refactor: publish values to MQTT in base class
"powertotal" is always published and it is published by the base class
directly. other values are still published by the derived classes, but
use a base class method, which takes care that a common base topic is
used in particular.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
d4c07836d9 MQTT powermeter: avoid iterating subscriptions
instead of iterating a map with subscriptions, we now bind the target
variable to the callback, which is executed once a message is arrived.
this way, the target variable is already linked to the respective topic
when the callback is executed.

lock the mutex when writing the variable, as the MQTT callback is
executed in a different context (MQTT task) than the main loop task,
which otherwise accesses the variables.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
2397e5cdf5 powermeter refactor: split providers into their own classes
it is important to separate the capabilities of each power meter
provider into their own class/source file, as the providers work
fundamentally different and their implementations must not be
intermangled, which made maintenance and improvements a nightmare
in the past.
2024-06-26 20:51:54 +02:00