fvilmos / power_meter_mqtt

esp32 power meter for sensors with pulse output. Implements MQTT for status reporting. Accurate and easily can be integrated with Home Automation systems.
GNU General Public License v3.0
24 stars 5 forks source link

Is it correct? #2

Closed jaroslavas closed 1 year ago

jaroslavas commented 1 year ago

Are you sure it works properly? Looking at void IRAM_ATTR isr() function, it takes the time of the first pulse, then waits for the seconds and counts power. This part looks ok. Then after power is counted, it sets bPulseDetected to false. This means, that when third pulse comes, it doesn't count the power, only starts waiting for the fourth pulse. Looks like it should miss about half of power consumption this way. Am I missing something?

fvilmos commented 1 year ago

The esp32 chip has some hw bugs (https://www.espressif.com/sites/default/files/documentation/esp32_errata_en.pdf), see section 3.14 for the isr issue. This is whay the implementation was done as it is. I do not have an oscilloscope to test this, maybe you have.

jaroslavas commented 1 year ago

No I don't, but after a month of using it reported me less kWh than the power meter itself. I've made some changes in code and now after a week it shows exactly the same number as the meter itself :) I can make a pull request if you are interested.

fvilmos commented 1 year ago

Sounds great, please do a pull request.

SleepyBear-Ship-It commented 1 year ago

@jaroslavas i'm interested to as im seeing the same, if you have some improvements please share :) @fvilmos thank you for your work, the power monitoring is really nice.

jaroslavas commented 1 year ago

@SleepyBear-Ship-It I finally found time to push these few lines of code :D https://github.com/fvilmos/power_meter_mqtt/pull/4

fvilmos commented 1 year ago

@jaroslavas, thanks for your contribution!