Skip to content
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

Unsigned negative current #90

Closed
alfs opened this issue May 26, 2024 · 2 comments
Closed

Unsigned negative current #90

alfs opened this issue May 26, 2024 · 2 comments

Comments

@alfs
Copy link

alfs commented May 26, 2024

I noticed current measurement at 6552 amps appearing after installing solar:

image

After troubleshooting, it turns out that the utility meter display is showing negative current (i.e. exporting to grid) when this occurs, but p1reader sends the unsigned value. (2^16)/10 - current explains the numbers around 6552.

This is for the HDLC code, in combination with solar production. All other metrics work as expected (voltage, import/export power) so I assume it's somewhere around https://github.com/psvanstrom/esphome-p1reader/blob/main/p1reader.h#L378

@Megamannen @forsberg if you are exporting power measured by HDLC meter, is the current correctly reported for you?

@alfs
Copy link
Author

alfs commented May 26, 2024

I added some debugging prints for tag 0x10:

      } else if (tag == 0x10) {
        Serial.readBytes(buffer, 2);
        //value = buffer[0] | buffer[1] << 8; //
        is_signed = true;
        value = buffer[1] | buffer[0] << 8;
        if (strncmp(obis, "31.7.0", 6) == 0)
          ESP_LOGD("hdlc", "tag 0x10 - Value of value is %d", value);

Getting the print

[12:09:30][D][hdlc:400]: tag 0x10 - Value of value is 65506

Value is a 32 bit signed int:

int32_t value = 0;

... and packing a 16 bit signed integer into 32 bits then drops the sign.

@alfs
Copy link
Author

alfs commented May 26, 2024

I implemented a bugfix, see PR #91

Tested and the p1reader now delivers expected negative/export values for current sensors.

@alfs alfs closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant