mampfes / esphome_obis_d0

esphome external component to support meters with OBIS D0 interface
MIT License
45 stars 6 forks source link

Support for ESP01 #15

Closed 749 closed 10 months ago

749 commented 10 months ago

This modification uses https://github.com/kokke/tiny-regex-c library instead of the default ccp #include <regex>. This reduces the size of the resulting binary below 512KB for the eZB dd3 example, making it possible to use an ESP01.

This provides support for https://www.amazon.de/dp/B0CH95T7X4, a IR-Reader with ESP-01 included.

The regex library comes with some limitations, which I tried to document in the README.md.

mampfes commented 10 months ago

Hi, thanks for your contribution.

I tried it out with my setup, but found a problem with the textual sensors: image

Do you have an idea why this fails?

749 commented 10 months ago

Hi, thanks for your contribution.

I tried it out with my setup, but found a problem with the textual sensors: image

Do you have an idea why this fails?

I think the internal buffer for the charsequence matcher might be too small. I'll push an update with a larger buffer. I am really dissatisfied, that the count operation is not working, I will try to add support for fixed length matches {N} where N >= 1 to the library.

EDIT:

If you would like to try out the repetition patch, I am currently testing it on branch feature/repetitions. I also added rudimentary regex parse errors, which should be logged as errors. Include using:

external_components:
- source: 
    type: git
    url: https://github.com/749/esphome_obis_d0
    ref: "feature/repetitions"
  refresh: 10s

EDIT 2: I have tested the code in the branch with my setup and fixed the docs. Let me know if I should merge the changes into my main or if you would like the current main.

mampfes commented 10 months ago

Hi, I tested both variants and both are working fine. I would prefer the one from branch feature/repetitions, because the syntax is much cleaner. So, could you please merge this branch into main.

FYI: I plan to add a configuration switch, so that the users can switch between the std::regex variant and the small size variant. This ensures that the config of legacy users will not break.

PS: Please keep the existing code formatting.

749 commented 10 months ago

Hi,

I merged the changes into my main branch and reset as much of the formatting as I could. It would really help if you could share your formatting settings ;-) The reformat I did was based on the style guide from esphome, which said to use Google C++ formatting.

I also added the configuration switch you mentioned and updated the README.md to include a description on how to switch.

mampfes commented 10 months ago

Works like a charm. Thanks!

mampfes commented 10 months ago

And it seems to be faster than std::regex. Nice!