Commit Graph

2551 Commits

Author SHA1 Message Date
Bernhard Kirchen
9911dec279 HTTP request config component: do not mutate prop
use an event-driven mutation scheme, i.e., adapt the common v-model
approach to bind data to the child component.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
6b19b877c6 power meter refactoring: split loop task init from init()
when performing a test request using the web UI, we need to init() the
respective power meter, but we do not want to start the polling task.
hence we move initialization of the polling task to the poll() function.
it will return if the task is setup already, otherwise setup the task.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
6b09ca056e Feature: SML power meters: reset SML decoder
implement a function which allows to reset the SML decoder. this new
function is used after a datagram ends. for the SML HTTP power meter
this is simple: after all bytes from the request's answer have been
decoded, we reset the decoder. for the SML serial power meter, we
perform the reset after a datagram ended based on timing (no new bytes
have been received for a specific amount of time).
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
ea454972b9 Feature: SML power meter: handle checksum error
cache the values decoded in the SML datagram and only copy them to the
local stash of values if the checksum of the SML datagram matched. also
makes sure that values from incomplete SML datagrams are not used.

moreover, we now only publish values to the MQTT broker that we actually
decoded (successfully) from an SML datagram (we previously published 0.0
as values to topics we never decoded a value for).
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
5be1615f4e SML parser: add new OBIS handlers for Hertz and Degrees
copied from the original library.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
19a8f6a7bd SML parser: pass SML char by value
there is no use in passing it by reference, especially a non-const
reference.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
7f724ce561 SML parser: remove commented-out code
the comparison is part of the original library code, but the compiler
rightfully complains that the comparison byte <= 0xFF is always true,
since byte is uint8_t. the comparison was commented out, and is now
removed.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
1afa9a6d90 SML parser: prevent out-of-bound array access
array nodes has MAX_TREE_SIZE elements, so the maximum index allowed to
use to access an element of nodes is one less, not MAX_TREE_SIZE.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
a1138a2202 Feature: Serial SML power meter: poll asynchronously 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
7b962f58b0 update EspSoftwareSerial to 8.2.0
also ghostl is now a dependency of EspSoftwareSerial and hence there is
no need to list it explicitly in platformio.ini.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
fb7b710cb7 SML power meter: improve message output
* when printing a message, tell the name of the derived class.
* print total power only when state SML_FINAL reached.
* tell if a checksum verification error occurred.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
6c06e71fd0 Feature: SDM power meter: switch to software serial
a 9600 baud serial interface does not need a hardware UART. these
changes switch the SDM power meter implementation to use a software
serial instance instead. this is desirable as hardware UARTs are scarce
and users need them for JK BMS and VE.Direct interfaces.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
8202bb23cd update SDM power meter library to version 2.2.3
in particular, this brings improved timing (settings). the values are
now read out much quicker in succession.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
a5ba24fdd8 SDM power meter: check stop flag in between transactions
the destructor will block for way too long if we keep holding the
polling mutex while performing a transcation with the SDM power meter.
when reading, we now release the lock. afterwards, i.e., in between
transactions, we check the stop flag so the task terminates in a timely
manner once asked to do so.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
ea84bb9229 power meter web UI: remove JSON path placeholder
this causes too much confusion, as many users don't understand that this
is a placeholder, not an actual configured value.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
40423b0e07 SDM power meter: evaluate error code after polling value 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
24f701020c SDM 1-phase power meter: only publish known values
a 1-phase SDM power meter does not know about power or voltage of phase
2 or 3. do not publish values to the respective MQTT topics when using a
single phase SDM power meter.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
4ad8e88e77 fix: SDM power meter: free HW serial port 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
db869a1144 powermeter refactor: use HTTP1.0
avoid problems with chunked transfer encoding when using the client's
stream to parse a JSON document. fixes the HTTP+JSON power meter to work
with shelly and hichi (Tasmota).
2024-06-27 22:18:41 +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
347dd67684 Feature: SDM power meter: poll asynchronously 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
8a46ba9541 Feature: HTTP+JSON power meter: poll asynchronously 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
f6f62a604d Feature: HTTP+SML power meter: poll asynchronously 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
9520d8d394 powermeter refactor: polish web UI 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
a2a9debd02 Feature: make power meter polling intervals configurable
this change makes the respective setting accessible from the web UI.
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
e1778eba76 powermeter refactor: use HttpGetter in HTTP SML implementation 2024-06-27 22:18:41 +02:00
Bernhard Kirchen
a08ef4cb43 powermeter refactor: test HTTP+JSON power meter as a whole
apply all config values from the webfrontend, then perform one polling
cycle. display values seperately in the result, and show the resulting
value as well.
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
20ecf2a66b powermeter refactor: add and use HttpGetter class
this new class uses the newly introduced HttpRequestConfig and performs
HTTP requests using this config. it will be reused for other power
meters (SML over HTTP(S)) and may be reused by other features in the
future (battery provider, solar power provider, etc.).
2024-06-27 22:18:41 +02:00
Bernhard Kirchen
4d99e87ef4 powermeter: add example URL with non-default TCP port 2024-06-26 21:25:08 +02:00
Bernhard Kirchen
6da90de765 remove extraction of basic auth params from URL
the extractUrlComponents method did extract username and password
from the URL and encoded it for basic authentication. however, the
respective result string was never used. we only perform basic
authentication if the auth type is "basic" and if username and
password were supplied through the respective inputs.
2024-06-26 21:25:08 +02:00
Bernhard Kirchen
297b149f84 powermeter refactor: generalize HTTP request config
the parameters to peform an HTTP request by the HTTP(S)+JSON power meter
have been generalized by introducing a new config struct. this is now
used for all values which the HTTP(S)+JSON power meter can retrieve, and
also used by the HTTP+SML power meter implementation. we anticipate that
other feature will use this config as well.

generalizing also allows to share serialization and deserialization
methods in the configuration handler and the web API handler, leading to
de-duplication of code and reduced flash memory usage.

a new web UI component is implemented to manage a set of HTTP request
settings.
2024-06-26 21:25:08 +02:00
Bernhard Kirchen
ccba7d8036 move JSON path resolver to Utils class for re-use 2024-06-26 21:25:05 +02:00
Bernhard Kirchen
673b9f4fa8 powermeter refactor: use destructors to de-initialize 2024-06-26 20:51:56 +02:00
Bernhard Kirchen
e78f5849c1 Feature: decode more OBIS values in SML power meters
supersedes #951.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
75c07c17f2 powermeter refactor: SML lib: replace double by float
avoid additional conversions and avoid double for the fact that
calculations on type double are implemented in software, whereas
float is handled in hardware on ESP32.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
6108d24795 powermeter refactor: introduce PowerMeterSml
this new class handles SML data. it uses the SML lib to decode values
and manages those. this de-duplicates code as the class is applicable
to all power meters that collect SML data.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
6e44a6d750 powermeter refactor: allow destruction of httpClient
make sure the wifiClient used by the httpClient lives longer than the
httpClient, as it accesses the pointer to the wifiClient in its
destructor.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
54c04aed61 SDM power meter: remove baud rate setting
this setting was not used. the baud rate for the SDM is set to 9600 in
the source code. until the baud rate being customizable is actually
required by somebody, we remove the setting altogether.
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
9eb4f1714c powermeter refactor: make timestamp of last update atomic
the timestamp is potentially updated from a different thread, e.g., MQTT
task, than the main loop, which typically reads that timestamp.
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
5cd6334880 powermeter refactor: avoid reboot on settings change
the current power meter provider will be de-initialized, and a new
instance will be initialized with the new settings.
2024-06-26 20:51:56 +02:00
Bernhard Kirchen
33683d26c8 powermeter refactor: rename providers in enum
the enum values did not change, but their name (only relevant in the
code) are now more expressive.
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
Marvin Carstensen
8ec1695d1b Feature: support Tibber bridge as power meter interface 2024-06-26 20:50:50 +02:00
Bernhard Kirchen
83c59d7811 convert files with CRLF endings to LF endings
this only changes line endings. inspect this commit with command `git
show <commit-sha> --ignore-space-at-eol` and it will tell you that the
commit appears to be "empty" (since all changes are whitespace changes
near the end of a line, which are ignored in that git show command).

the files to be changed were found and updated using this command:
find lib src include webapp/src -type f | \
    xargs grep --binary-files=without-match --files-with-matches \
    $(printf '\r\n') | xargs dos2unix

the following files were restored afterwards, as they are using CRLF
line endings in the upstream as well:
 - lib/CMT2300a/cmt2300a_defs.h
 - lib/README
 - include/README
2024-06-24 21:57:12 +02:00
Bernhard Kirchen
2cc086335f BREAKING CHANGE: repartition: double sketch size
this updates the partition scheme for devices with 4 MB of flash memory
to have only a single app partition, doubling its size, but sacrificing
their OTA update capability. the replacement environment for
"generic_esop32" is called "generic_esp32_4mb_no_ota".

the new default partition scheme is targeted for devices with at least 8
MB of flash memory. the previous two app partitions are merged into one,
and one additional app partition of the same new size is added to the
back of the table. the change preserves the littlefs partition (position
and size), allowing for upgrades without loosing the configuration.

another new environment is added, called "generic_esp32_8mb", which uses
the new default partition layout.

environment "generic" is removed. it was merely a variant of
"generic_esp32" with some pins pre-defined. we want users to install a
pin_mapping.json and use the generic firmwares.

environments for boards that have no version with at least 8 MB of flash
memory are setup using the 4 MB partition layout (no OTA updates).

all users must flash the factory.bin for their respective environment
using esptool (or compatible software) using the USB port of their
board. in other words: updating to the new partition scheme using an OTA
update is NOT possible.

hint: the ESP32-S3 builds have a smaller code footprint. this means
ESP32-S3 boards can be updated using OTA without updating the partition
layout on the devices for some unspecified time longer, i.e., until
their firmware binary actually becomes too large for the old sketch
partition size.

the non-factory binary for generic_esp32_4mb_no_ota is NOT collected as
an artifact. going forward, users must update using the factory binary
and using the USB connection to their boards.
2024-06-24 21:39:31 +02:00
Andreas Böhm
79214d750f
refactor PylontechCanBattery to be more generic (#1064) 2024-06-23 19:42:04 +02:00