Louisvdw / dbus-serialbattery

Battery Monitor driver for serial battery in VenusOS GX systems
MIT License
541 stars 165 forks source link

Jkbms_Can: Cell count: 1 | Cells populated: 0 && TypeError: '>' not supported between instances of 'float' and 'NoneType' #950

Closed p0l0us closed 9 months ago

p0l0us commented 9 months ago

Describe the bug

Hi, I'm trying to run my Jk bms over CAN bus using this project. When I setup everything and make running, the bms entry is appearing and disappearing from the VenusOS screen - most likely the driver is constantly restarting or so. When it is visible, no data shown (all fields empty).

image

image

See logs bellow for details. It looks like there is Cells populated: 0 which leads to TypeError: '>' not supported between instances of 'float' and 'NoneType'. Can anyone give me any ideas ?

Similar problem with zero cells I noticed with Daly_Can.

I tested with master (commit e3206f7) and dev (commit 5e025e6). Project didn't run with latest release since I had a python wheels issue.

Hardware: RaspberryPI zero 2w with clean VenusOS 3.14 large image, CAN Bus adapter MCP2515/TJA1050, JK BMS B2A8S20P heat can.

CAN adapter is connected according to: https://forums.raspberrypi.com/viewtopic.php?t=141052, with dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=12 in boot config.txt. I confirmed that my can0 works against computer at 250kbps. I see "some" can messages from the JK bms on the computer as well in the canable cangaroo app (all are on the same can bus).

image

candump can0

  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DD 0C 01 DC 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DC 0C 01 DC 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DC 0C 01 DD 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DC 0C 01 DD 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DC 0C 01 DD 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01
  can0  4F5   [8]  DC 0C 01 DD 0C 02 55 AA
  can0  5F5   [8]  3A 01 3A 00 11 55 00 AA
  can0  2F5   [8]  83 00 9F 0F 04 AA 4A 01

How to reproduce

  1. Installed clean venus os on my rpi zero 2w, connected to wifi, made ssh
  2. connected CAN adaper, set CAN speed to 250kbps
  3. tested CAN with PC (both, JK bms and rpi with venus)
  4. installed dbus_serialbattery according to documentation (dev and master)
  5. enabled DVCC
  6. set the config.ini
  7. reinstall dbus_serialbattery & reboot

Expected behavior

I see the Jk bms entry on the venusos board.

Driver version

e3206f7

Venus OS device type

Raspberry Pi 2

Venus OS version

3.14

BMS type

Daly Smart BMS, JKBMS / Heltec BMS

Cell count

4

Battery count

1

Connection type

Serial USB adapter to TTL

Config file

[DEFAULT]
LOGGING = DEBUG
CAN_PORT = can0
BMS_TYPE = Jkbms, Jkbms_Can

Relevant log output

2024-02-04 12:58:53.026649500 INFO:SerialBattery:
2024-02-04 12:58:53.027291500 INFO:SerialBattery:Starting dbus-serialbattery
2024-02-04 12:58:53.028287500 INFO:SerialBattery:dbus-serialbattery v1.0.20231117dev
2024-02-04 12:58:53.766530500 INFO:SerialBattery:-- Testing BMS: 1 of 3 rounds
2024-02-04 12:58:53.767151500 INFO:SerialBattery:Testing Jkbms_Can
2024-02-04 12:58:53.768072500 DEBUG:SerialBattery:Can bus init
2024-02-04 12:58:53.842501500 DEBUG:SerialBattery:Can bus init done
2024-02-04 12:58:55.192490500 INFO:SerialBattery:Connection established to Jkbms_Can
2024-02-04 12:58:55.193168500 INFO:SerialBattery:Battery Jkbms_Can connected to dbus from can0
2024-02-04 12:58:55.193757500 INFO:SerialBattery:========== Settings ==========
2024-02-04 12:58:55.194309500 INFO:SerialBattery:> Connection voltage: NoneV | Current: NoneA | SoC: None%
2024-02-04 12:58:55.194822500 INFO:SerialBattery:> Cell count: 1 | Cells populated: 0
2024-02-04 12:58:55.195345500 INFO:SerialBattery:> LINEAR LIMITATION ENABLE: True
2024-02-04 12:58:55.195894500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 50.0A | MAX BATTERY DISCHARGE CURRENT:                                                                                                                         60.0A
2024-02-04 12:58:55.196417500 INFO:SerialBattery:> CVCM:     True
2024-02-04 12:58:55.196960500 INFO:SerialBattery:> MIN CELL VOLTAGE: 2.9V | MAX CELL VOLTAGE: 3.45V
2024-02-04 12:58:55.197496500 INFO:SerialBattery:> CCCM CV:  True  | DCCM CV:  True
2024-02-04 12:58:55.198020500 INFO:SerialBattery:> CCCM T:   True  | DCCM T:   True
2024-02-04 12:58:55.198544500 INFO:SerialBattery:> CCCM SOC: True  | DCCM SOC: True
2024-02-04 12:58:55.199069500 INFO:SerialBattery:Serial Number/Unique Identifier: NoneAh
2024-02-04 12:58:55.235715500 INFO:SerialBattery:DeviceInstance = 4
2024-02-04 12:58:55.236534500 INFO:SerialBattery:com.victronenergy.battery.can0
2024-02-04 12:58:55.257097500 INFO:SerialBattery:publish config values = 1
2024-02-04 12:58:56.820386500 Traceback (most recent call last):
2024-02-04 12:58:56.820393500   File "/opt/victronenergy/dbus-serialbattery/dbushelper.py", line 389, in publish_batt                                                                                                                        ery
2024-02-04 12:58:56.820398500     self.battery.manage_charge_current()
2024-02-04 12:58:56.820401500   File "/opt/victronenergy/dbus-serialbattery/battery.py", line 580, in manage_charge_c                                                                                                                        urrent
2024-02-04 12:58:56.820406500     if utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current:
2024-02-04 12:58:56.820410500 TypeError: '>' not supported between instances of 'float' and 'NoneType'
2024-02-04 12:58:57.037272500
2024-02-04 12:58:58.125645500 INFO:SerialBattery:
2024-02-04 12:58:58.126370500 INFO:SerialBattery:Starting dbus-serialbattery
2024-02-04 12:58:58.127602500 INFO:SerialBattery:dbus-serialbattery v1.0.20231117dev

Any other information that may be helpful

No response

p0l0us commented 9 months ago

After changing CAN_FRAMES in the jkbms_can.py to following, some BMS data was read correctly:

Connection voltage: 13.1V | Current: -4.5A | SoC: 4%

but cell count 3 still doesn't seem to be correct and I'm still facing the TypeError

    CAN_FRAMES = {
        BATT_STAT: 0x02F5,
        CELL_VOLT: 0x04F5,
        CELL_TEMP: 0x05F5,
        ALM_INFO: 0x07F5,
    }
2024-02-04 15:32:55.582081500 INFO:SerialBattery:
2024-02-04 15:32:55.582713500 INFO:SerialBattery:Starting dbus-serialbattery
2024-02-04 15:32:55.583704500 INFO:SerialBattery:dbus-serialbattery v1.0.20231117dev
2024-02-04 15:32:56.323313500 INFO:SerialBattery:-- Testing BMS: 1 of 3 rounds
2024-02-04 15:32:56.323938500 INFO:SerialBattery:Testing Jkbms_Can
2024-02-04 15:32:56.324844500 DEBUG:SerialBattery:Can bus init
2024-02-04 15:32:56.399649500 DEBUG:SerialBattery:Can bus init done
2024-02-04 15:32:57.748679500 INFO:SerialBattery:Connection established to Jkbms_Can
2024-02-04 15:32:57.749491500 INFO:SerialBattery:Battery Jkbms_Can connected to dbus from can0
2024-02-04 15:32:57.750182500 INFO:SerialBattery:========== Settings ==========
2024-02-04 15:32:57.750917500 INFO:SerialBattery:> Connection voltage: 13.1V | Current: -4.5A | SoC: 4%
2024-02-04 15:32:57.751556500 INFO:SerialBattery:> Cell count: 3 | Cells populated: 3
2024-02-04 15:32:57.752282500 INFO:SerialBattery:> LINEAR LIMITATION ENABLE: True
2024-02-04 15:32:57.752952500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 50.0A | MAX BATTERY DISCHARGE CURRENT: 60.0A
2024-02-04 15:32:57.753781500 INFO:SerialBattery:> CVCM:     True
2024-02-04 15:32:57.754468500 INFO:SerialBattery:> MIN CELL VOLTAGE: 2.9V | MAX CELL VOLTAGE: 3.45V
2024-02-04 15:32:57.755121500 INFO:SerialBattery:> CCCM CV:  True  | DCCM CV:  True
2024-02-04 15:32:57.755853500 INFO:SerialBattery:> CCCM T:   True  | DCCM T:   True
2024-02-04 15:32:57.756706500 INFO:SerialBattery:> CCCM SOC: True  | DCCM SOC: True
2024-02-04 15:32:57.757466500 INFO:SerialBattery:Serial Number/Unique Identifier: JKBMSCAN3cells_NoneAh
2024-02-04 15:32:57.811788500 INFO:SerialBattery:DeviceInstance = 4
2024-02-04 15:32:57.812386500 INFO:SerialBattery:com.victronenergy.battery.can0
2024-02-04 15:32:57.834986500 INFO:SerialBattery:publish config values = 1
2024-02-04 15:32:59.406252500 Traceback (most recent call last):
2024-02-04 15:32:59.406258500   File "/opt/victronenergy/dbus-serialbattery/dbushelper.py", line 389, in publish_battery
2024-02-04 15:32:59.406263500     self.battery.manage_charge_current()
2024-02-04 15:32:59.406266500   File "/opt/victronenergy/dbus-serialbattery/battery.py", line 580, in manage_charge_current
2024-02-04 15:32:59.406271500     if utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current:
2024-02-04 15:32:59.406275500 TypeError: '>' not supported between instances of 'float' and 'NoneType'
2024-02-04 15:32:59.630628500
2024-02-04 15:33:00.765353500 INFO:SerialBattery:
2024-02-04 15:33:00.766070500 INFO:SerialBattery:Starting dbus-serialbattery
2024-02-04 15:33:00.767314500 INFO:SerialBattery:dbus-serialbattery v1.0.20231117dev
2024-02-04 15:33:01.537696500 INFO:SerialBattery:-- Testing BMS: 1 of 3 rounds
2024-02-04 15:33:01.538409500 INFO:SerialBattery:Testing Jkbms_Can
2024-02-04 15:33:01.539847500 DEBUG:SerialBattery:Can bus init
2024-02-04 15:33:01.616658500 DEBUG:SerialBattery:Can bus init done
p0l0us commented 9 months ago

It seems exception and rest of troubles are fixed by following:

jkbms_can.py

self.max_battery_current = MAX_BATTERY_CHARGE_CURRENT

change to

self.max_battery_charge_current = MAX_BATTERY_CHARGE_CURRENT

Same self.max_battery_charge_current issue seems to be in daly_can.py

p0l0us commented 8 months ago

I found the CAN_FRAMES are different for Black and Silver JK Bms. So I introduced another fix to deal with it: https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/24

image image