question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JKBMS: Sometimes wrong readings

See original GitHub issue

Describe the bug I sometimes get wrong readings from the jkbms code. I already added code to test the checksum and the various framing bits (command type, etc), but e.g. the SoC (offset 0x85) sometimes goes to 133%, while battery voltage stays in the correct range (offset 0x83).

The captured status_data in this case is Invalid soc: [bytearray(b"\x01y0\x01\r\'\x02\r,\x03\r+\x04\r\'\x05\r-\x06\r(\x07\r,\x08\r+\t\r2\n\r\'\x0b\r-\x0c\r(\r\r+\x0e\r-\x0f\r\'\x10\r,\x80\x00\x1d\x81\x00\x18\x82\x00\x18\x83\x15\x10\x84\x85\xc3\x85M\x86\x02\x87\x00\x03\x89\x00\x00\x03\x00\x8a\x00\x10\x8b\x00\x00\x8c\x00\x07\x8e\x16\x80\x8f\x10@\x90\x0e\x10\x91\rH\x92\x00\x05\x93\n(\x94\x0b\xb8\x95\x00\x05\x96\x01,\x97\x00d\x98\x01,\x99\x002\x9a\x00\x1e\x9b\x05\xdc\x9c\x00\x03\x9d\x01\x9e\x00Z\x9f\x00F\xa0\x00d\xa1\x00d\xa2\x00\x14\xa3\x00F\xa4\x00F\xa5\xff\xec\xa6\xff\xf6\xa7\xff\xec\xa8\xff\xf6\xa9\x10\xaa\x00\x00\x01\x18\xab\x01\xac\x01\xad\x04\x0f\xae\x01\xaf\x01\xb0\x00\n\xb1\x14\xb2123456\x00\x00\x00\x00\xb3\x00\xb4Input Us\xb52101\xb6\x00\x00\xd6\x00\xb7H6.X__S6.1.0S__\xb8\x00\xb9\x00\x00\x01\x00\xbaBT307202012000")]

A correct case right next to the wrong frame is like this: [bytearray(b"\x01y0\x01\r\'\x02\r,\x03\r+\x04\r\'\x05\r-\x06\r(\x07\r,\x08\r+\t\r8\n\r,\x0b\r+\x0c\r(\r\r-\x0e\r\'\x0f\r,\x10\r+\x80\x00\x1d\x81\x00\x18\x82\x00\x18\x83\x15\x11\x84\x86\x01\x85M\x86\x02\x87\x00\x03\x89\x00\x00\x03\x00\x8a\x00\x10\x8b\x00\x00\x8c\x00\x07\x8e\x16\x80\x8f\x10@\x90\x0e\x10\x91\rH\x92\x00\x05\x93\n(\x94\x0b\xb8\x95\x00\x05\x96\x01,\x97\x00d\x98\x01,\x99\x002\x9a\x00\x1e\x9b\x05\xdc\x9c\x00\x03\x9d\x01\x9e\x00Z\x9f\x00F\xa0\x00d\xa1\x00d\xa2\x00\x14\xa3\x00F\xa4\x00F\xa5\xff\xec\xa6\xff\xf6\xa7\xff\xec\xa8\xff\xf6\xa9\x10\xaa\x00\x00\x01\x18\xab\x01\xac\x01\xad\x04\x0f\xae\x01\xaf\x01\xb0\x00\n\xb1\x14\xb2123456\x00\x00\x00\x00\xb3\x00\xb4Input Us\xb52101\xb6\x00\x00\xd6\x00\xb7H6.X__S6.1.0S__\xb8\x00\xb9\x00\x00\x01\x00\xbaBT307202012000")]

In this particular case (it’s unfortunately not the only ones), the following bytes are flipped (some might be due to different values):

Offset 0x1d Wrong 0x32 OK 0x38
Offset 0x20 Wrong 0x27 OK 0x2c
Offset 0x23 Wrong 0x2d OK 0x2b
Offset 0x29 Wrong 0x2b OK 0x2d
Offset 0x2c Wrong 0x2d OK 0x27
Offset 0x2f Wrong 0x27 OK 0x2c
Offset 0x32 Wrong 0x2c OK 0x2b
Offset 0x3e Wrong 0x10 OK 0x11
Offset 0x40 Wrong 0x85 OK 0x86
Offset 0x41 Wrong 0xc3 OK 0x01

What I believe is that the find() function in get_data is brittle as it doesn’t differentiate between value and idcodes. I think it would be better to parse the bytes continuously, ie. first read the ID, then read the number of bytes associated to it, then continue, etc. I’m happy to write up a patch if you agree with the approach.

ps: Modified code to test for checksum and print framing bits (in read_serial_data_jkbms):

` start, length = unpack_from(‘>HH’, data) terminal = unpack_from(‘>L’, data[4:])[0] cmd, src, tt = unpack_from(‘>bbb’, data[8:]) frame = unpack_from(‘>H’, data[-9:])[0] end, crc_hi, crc_lo = unpack_from(‘>BHH’, data[-5:])

    s = sum(data[0:-4])
    logger.info('S%d C%d C%d' % (s, crc_lo, crc_hi))
    logger.info('T%d C%d S%d F%d TT%d' % (terminal, cmd, src, frame, tt))

    if s != crc_lo:
        logger.error('CRC checksum mismatch: Expected 0x%04x, Got 0x%04x' % (crc_lo, s))

`

update formatting

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
trixingcommented, Sep 10, 2021

I already got something rudimentary working and confirming my theory. I can clean this up over the weekend and send a patch.

On Fri, Sep 10, 2021 at 11:04 AM Louis Van Der Walt < @.***> wrote:

Hi @trixing https://github.com/trixing Thank you for the detailed feedback. You might be correct about the find. I’ve been seeing some issues as well every now and then. You are welcome to look at a patch and create a pull request, else I will look at it as soon as I get some time.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/43#issuecomment-916751197, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATM2TB7M22X3MW6YQ4473UBHC2HANCNFSM5DY3JBEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

– Jan Dittmer @.***>, https://l4x.org

0reactions
Louisvdwcommented, Sep 12, 2021

I assume you are going to merge that branch as a quick fix, given my approach would be a lot more intrusive?

Correct, that is the idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JK BMS Erratic current readings? - DIY Solar Power Forum
It is more often caused by connection issues between battery, ... If inverter is operating fairly normally you likely have a bad connection ......
Read more >
JK-BMS 4S-Edition, Heltec shows wrong current, decode your ...
While we're still offline after the recent weather event, I do this video with small stories and updates what is coming next here...
Read more >
Doesn't seem to work with device that contains both BMS and ...
Here are the values I get when I run your script (with debug option) : pi@rpi:~/new/jkbms/jkbms $ jkbms -D -p Query BMS via...
Read more >
JK-B1A24S / JK-B2A24S Active Balancer
Quick update. Got the jkbms python script running through grafana and did some tests with some good results. Took 4 18650 and had...
Read more >
Victron VenusOS driver for serial battery BMS - LLT/JBD / Daly ...
Contact @Mike Dorsett for information; JKBMS / Heltec ... the Victron BMV-712 suddenly started using the wrong driver causing below errors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found