psvanstrom / esphome-p1reader

ESPHome custom component for reading P1 data from electricity meters.
MIT License
251 stars 106 forks source link

SlimmeLezer+ with HDLC stops working #76

Open morotsgurka opened 1 year ago

morotsgurka commented 1 year ago

Hi!

Recently purchased a SlimmeLezer+ v1.2 for my Aidon 6534 electricity meter. Using the sample config for the slimmelezer works. But when changing the meter_sensor from P1Reader to P1ReaderHDLC it stops working. I cant open the web portal, upload ota or connect using Home Assistant. Re-flashing using ESPHome flasher without HDLC makes everything work again.

Compiled using latest ESPHome v2023.6.3, I've also tried to pin the container to the lastest working according to the readme (2022.12.1) but still the same issue.

When compiling with HDLC enabled i also get this warning:

In file included from src/main.cpp:65:
src/p1reader.h: In member function 'bool P1ReaderHDLC::readHDLCStruct(ParsedMessage*)':
src/p1reader.h:364:21: warning: '.' directive writing 1 byte into a region of size between 0 and 4 [-Wformat-overflow=]
  364 |       sprintf(obis, "%d.%d.%d", buffer[2], buffer[3], buffer[4]);
      |                     ^~~~~~~~~~
src/p1reader.h:364:21: note: directive argument in the range [0, 255]
src/p1reader.h:364:14: note: 'sprintf' output between 6 and 12 bytes into a destination of size 7
  364 |       sprintf(obis, "%d.%d.%d", buffer[2], buffer[3], buffer[4]);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

but it still compiles successfully. But after uploaded the sensor stops responding. My simple guess from some googling is that it might be causing some buffer overflow? Changing line 346 from char obis[8]; to char obis[12]; does remove the warning but the device still does not respond... so i might just caused other issues, or i am looking in the wrong spot.

morotsgurka commented 12 months ago

UPDATE. It works... but with some modification. I first found this post after posting my initial issue. He seemed to have the same issue as me:

It flashes OK but the SL+ never starts afterwards.

So i followed his steps using forsbers fork. I then used his yaml config that he posted in his thread. The differences being that i did all of this in ESPHome docker container running v2023.6.3. This gave me compile issues from forsbers p1reader.h but after implementing the changes that MrGlad8 wrote in issue #44 everything works. Adopted into Home Assistant and i am getting readings from the meter now.

So. Something is not working correctly in the current main branch to support Aidon meters on Slimmelezer+ v1.2. But the changes that were suggested in issue #44 seems to be implemented in the current main branch from what i can see.