mandulaj / PZEM-004T-v30

Arduino library for the Updated PZEM-004T v3.0 Power and Energy meter
MIT License
256 stars 108 forks source link

Constructor overload for better ESP32 support #55

Closed vortigont closed 2 years ago

vortigont commented 3 years ago

Closes #20

Signed-off-by: Emil Muratov gpm@hotplug.ru

mandulaj commented 2 years ago

Hey @vortigont , I finally found some time for closing all the old PRs, including #31 and now noticed that you have also provided a similar fix here. I will therefore not be merging your Constructor overload however I could cherry pick your Fix for the compiler warning.

mandulaj commented 2 years ago

In the new update, I cherry picked your change, However there is now a different error showing up.

PZEM004Tv30.cpp: In destructor 'PZEM004Tv30::~PZEM004Tv30()':
PZEM004Tv30.cpp:142:9: warning: deleting object of polymorphic class type 'SoftwareSerial' which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor]
  142 |         delete this->localSWserial;

So this hasn't really improved the situation. As I have already suggested, the best thing would be to move away from local SoftwareSerial instance and instead require one to be passed as reference during the initialization. This way, we don't have to handle any destruction.