-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[P102] PZEM004Tv3 change Wh to kWh #4966
Conversation
Some energy meters do only show "Wh" values upto some value and then switch to kWh. |
I did a bit of research and at first glance it seemed to be like that.... /*! * PZEM004Tv30::energy *
* Get Active energy in kWh since last reset *
* @return active energy in kWh*/
float PZEM004Tv30::energy()
{
if(!updateValues()) // Update vales if necessary
return NAN; // Update did not work, return NAN
return _currentValues.energy;
} |
forgot to attach that: _currentValues.energy = ((uint32_t)response[13] << 8 | // Raw Energy in 1Wh
(uint32_t)response[14] |
(uint32_t)response[15] << 24 |
(uint32_t)response[16] << 16) / 1000.0; |
Ah so the output is indeed kWh and not Wh. Strange byte order by the way. |
I wish i could agree but I am working right now to understand what this bit shifting means anyway. :) |
Bitshift is literally what the name suggests. Thus So let's assume the response bytes have the hex values 0x13, 0x14, 0x15 and 0x16 on those positions in the response array, then the value becomes: So there's a rather strange bit order. It is probably OK, but still looks a bit 'odd'. |
Ah glad to see chatGPT also understands why things might look strange :) |
I found it misleading, that the value name is called
Energy_Wh
since the value is in kWhTook me a while to figure out why the formula
%value%/1000
didn´t give me the expected kWh value.Can anybody confirm or do i have maybe a different revision of this device?