Skip to content

Commit

Permalink
Changes 2023.04.28
Browse files Browse the repository at this point in the history
* Added: `self.unique_identifier` to the battery class. Used to identify a BMS when multiple BMS are connected - planned for future use by @mr-manuel
* Changed: Fixed wrong file execution in `installble.sh`
* Changed: Moved BMS scripts to subfolder by @mr-manuel
  • Loading branch information
mr-manuel committed Apr 28, 2023
2 parents 362916c + d882937 commit 0aed855
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 36 deletions.
9 changes: 4 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[flake8]
max-line-length = 120
exclude =
./etc/dbus-serialbattery/battery_template.py,
./etc/dbus-serialbattery/bms/battery_template.py,
./etc/dbus-serialbattery/bms/mnb_test_max17853.py,
./etc/dbus-serialbattery/bms/mnb_utils_max17853.py,
./etc/dbus-serialbattery/bms/revov.py,
#./etc/dbus-serialbattery/dbus-serialbattery.py,
./etc/dbus-serialbattery/dbushelper.py,
./etc/dbus-serialbattery/minimalmodbus.py,
./etc/dbus-serialbattery/mnb.py,
./etc/dbus-serialbattery/revov.py,
./etc/dbus-serialbattery/test_max17853.py,
./etc/dbus-serialbattery/util_max17853.py,
./velib_python
venv
extend-ignore:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added: Balancing status for JKBMS by @mr-manuel
* Added: Balancing switch status for JKBMS by @mr-manuel
* Added: Balancing switch status to the GUI -> SerialBattery -> IO by @mr-manuel
* Added: `self.unique_identifier` to the battery class. Used to identify a BMS when multiple BMS are connected - planned for future use by @mr-manuel
* Added: Charge Mode display by @mr-manuel
* Added: Choose how battery temperature is assembled (mean temp 1 & 2, only temp 1 or only temp 2) by @mr-manuel
* Added: Config file by @ppuetsch
Expand Down Expand Up @@ -50,7 +51,8 @@
* Changed: Fixed Time-To-Go is not working, if `TIME_TO_SOC_VALUE_TYPE` is set to other than `1` https://github.com/Louisvdw/dbus-serialbattery/pull/424#issuecomment-1440511018 by @mr-manuel
* Changed: Improved JBD BMS soc calculation https://github.com/Louisvdw/dbus-serialbattery/pull/439 by @aaronreek
* Changed: Logging to get relevant data by @mr-manuel
* Changed: Moved ble part to `installble.sh` by @mr-manuel
* Changed: Moved Bluetooth part to `installble.sh` by @mr-manuel
* Changed: Moved BMS scripts to subfolder by @mr-manuel
* Changed: Optimized installation scripts by @mr-manuel
* Changed: Removed wildcard imports from several BMS drivers and fixed black lint errors by @mr-manuel
* Changed: Serial-Starter file is now created from `reinstalllocal.sh`. Fixes also https://github.com/Louisvdw/dbus-serialbattery/issues/520 by @mr-manuel
Expand Down
3 changes: 3 additions & 0 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def __init__(self, port, baud, address):
self.max_battery_charge_current = None
self.max_battery_discharge_current = None

# used to identify a BMS when multiple BMS are connected - planned for future use
self.unique_identifier = None

@abstractmethod
def test_connection(self) -> bool:
"""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from battery import Battery, Cell
from utils import logger
from jkbms_brn import JkBmsBle
from bms.jkbms_brn import JkBmsBle
from bleak import BleakScanner, BleakError
import asyncio
import time
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# -*- coding: utf-8 -*-

# disable MNB battery by default
# https://github.com/Louisvdw/dbus-serialbattery/commit/65241cbff36feb861ff43dbbcfb2b495f14a01ce
# remove duplicate MNB lines
# https://github.com/Louisvdw/dbus-serialbattery/commit/23afec33c2fd87fd4d4c53516f0a25f290643c82

from battery import Protection, Battery, Cell
from struct import *
from utils import logger
from bms.mnb_utils_max17853 import data_cycle, init_max

# from test_max17853 import *#{these two lines are mutually}
# from util_max17853 import * # {exclusive. use test for testing}
# from struct import *
# from bms.mnb_test_max17853 import * # use test for testing


class MNBProtection(Protection):
Expand Down Expand Up @@ -90,8 +97,9 @@ def test_connection(self):
result = False
try:
result = self.read_status_data()
except:
pass
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
result = False

return result

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-

# Deprecate Revov driver - replaced by LifePower
# https://github.com/Louisvdw/dbus-serialbattery/pull/353/commits/c3ac9558fc86b386e5a6aefb313408165c86d240

from battery import Protection, Battery, Cell
from utils import *
from struct import *
import struct


# Author: L Sheed
# Date: 3 May 2022
# Version 0.1.3
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-

# remove Sinowealth by default as it causes other issues but can be enabled manually
# https://github.com/Louisvdw/dbus-serialbattery/commit/7aab4c850a5c8d9c205efefc155fe62bb527da8e

from battery import Battery, Cell
from utils import kelvin_to_celsius, read_serial_data, logger
import utils
Expand Down
26 changes: 14 additions & 12 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
from battery import Battery

# import battery classes
from ant import Ant
from daly import Daly
from ecs import Ecs
from hlpdatabms4s import HLPdataBMS4S
from jkbms import Jkbms
from lifepower import Lifepower
from lltjbd import LltJbd
from renogy import Renogy
from seplos import Seplos

# from sinowealth import Sinowealth
from bms.ant import Ant
from bms.daly import Daly
from bms.ecs import Ecs
from bms.hlpdatabms4s import HLPdataBMS4S
from bms.jkbms import Jkbms
from bms.lifepower import Lifepower
from bms.lltjbd import LltJbd
from bms.renogy import Renogy
from bms.seplos import Seplos

# from bms.mnb import MNB
# from bms.sinowealth import Sinowealth

supported_bms_types = [
{"bms": Ant, "baud": 19200},
Expand All @@ -46,6 +47,7 @@
{"bms": Renogy, "baud": 9600, "address": b"\x30"},
{"bms": Renogy, "baud": 9600, "address": b"\xF7"},
{"bms": Seplos, "baud": 19200},
# {"bms": MNB, "baud": 9600},
# {"bms": Sinowealth},
]
expected_bms_types = [
Expand Down Expand Up @@ -107,7 +109,7 @@ def get_port() -> str:
"""
if port == "Jkbms_Ble":
# noqa: F401 --> ignore flake "imported but unused" error
from jkbms_ble import Jkbms_Ble # noqa: F401
from bms.jkbms_ble import Jkbms_Ble # noqa: F401

class_ = eval(port)
testbms = class_("", 9600, sys.argv[2])
Expand Down
4 changes: 4 additions & 0 deletions etc/dbus-serialbattery/disabledriver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ sh /opt/victronenergy/swupdate-scripts/remount-rw.sh

# remove files
rm -f /data/conf/serial-starter.d/$DRIVERNAME.conf
rm -rf /service/dbus-blebattery.*

# remove old drivers before changing from dbus-blebattery-$1 to dbus-blebattery.$1
# can be removed on second release (>1.0.0)
rm -rf /service/dbus-blebattery-*

# kill if running
Expand Down
28 changes: 18 additions & 10 deletions etc/dbus-serialbattery/installble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@ if [ ! -f $filename ]; then
fi
grep -qxF "sh /data/etc/dbus-serialbattery/installble.sh" $filename || echo "sh /data/etc/dbus-serialbattery/installble.sh" >> $filename

# kill if running, needed when an adapter changes
pkill -f "python .*/dbus-serialbattery.py"

# remove old drivers before changing from dbus-blebattery-$1 to dbus-blebattery.$1
# can be removed on second release (>1.0.0)
rm -rf /service/dbus-blebattery-*

install_service() {
mkdir -p /service/dbus-blebattery-$1/log
echo "#!/bin/sh" > /service/dbus-blebattery-$1/log/run
echo "exec multilog t s25000 n4 /var/log/dbus-blebattery-$1" >> /service/dbus-blebattery-$1/log/run
chmod 755 /service/dbus-blebattery-$1/log/run

echo "#!/bin/sh" > /service/dbus-blebattery-$1/run
echo "exec 2>&1" >> /service/dbus-blebattery-$1/run
echo "bluetoothctl disconnect $3" >> /service/dbus-blebattery-$1/run
echo "python /data/etc/dbus-serialbattery/dbus-serialbattery.py $2 $3" >> /service/dbus-blebattery-$1/run
chmod 755 /service/dbus-blebattery-$1/run
mkdir -p /service/dbus-blebattery.$1/log
echo "#!/bin/sh" > /service/dbus-blebattery.$1/log/run
echo "exec multilog t s25000 n4 /var/log/dbus-blebattery.$1" >> /service/dbus-blebattery.$1/log/run
chmod 755 /service/dbus-blebattery.$1/log/run

echo "#!/bin/sh" > /service/dbus-blebattery.$1/run
echo "exec 2>&1" >> /service/dbus-blebattery.$1/run
echo "bluetoothctl disconnect $3" >> /service/dbus-blebattery.$1/run
echo "python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py $2 $3" >> /service/dbus-blebattery.$1/run
chmod 755 /service/dbus-blebattery.$1/run
}


## CONFIG AREA

## Uncomment for each adapter here, increase the number for each adapter/service

install_service 0 Jkbms_Ble C8:47:8C:E8:12:04
# install_service 0 Jkbms_Ble C8:47:8C:12:34:56
# install_service 1 Jkbms_Ble C8:47:8C:78:9A:BC
2 changes: 2 additions & 0 deletions etc/dbus-serialbattery/reinstalllocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ rm -rf /opt/victronenergy/service/$DRIVERNAME
rm -rf /opt/victronenergy/service-templates/$DRIVERNAME
rm -rf /opt/victronenergy/$DRIVERNAME
mkdir /opt/victronenergy/$DRIVERNAME
mkdir /opt/victronenergy/$DRIVERNAME/bms
cp -f /data/etc/$DRIVERNAME/* /opt/victronenergy/$DRIVERNAME &>/dev/null
cp -f /data/etc/$DRIVERNAME/bms/* /opt/victronenergy/$DRIVERNAME/bms &>/dev/null
cp -rf /data/etc/$DRIVERNAME/service /opt/victronenergy/service-templates/$DRIVERNAME
sh /data/etc/$DRIVERNAME/installqml.sh

Expand Down
4 changes: 4 additions & 0 deletions etc/dbus-serialbattery/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ rm -f /data/conf/serial-starter.d/dbus-serialbattery.conf
rm -rf /opt/victronenergy/service/dbus-serialbattery
rm -rf /opt/victronenergy/service-templates/dbus-serialbattery
rm -rf /opt/victronenergy/dbus-serialbattery
rm -rf /service/dbus-blebattery.*

# remove old drivers before changing from dbus-blebattery-$1 to dbus-blebattery.$1
# can be removed on second release (>1.0.0)
rm -rf /service/dbus-blebattery-*

# kill if running
Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_list_from_config(

# Constants - Need to dynamically get them in future
DRIVER_VERSION = "1.0"
DRIVER_SUBVERSION = ".0-jkbms_ble (20230427)"
DRIVER_SUBVERSION = ".0-jkbms_ble (20230428)"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit 0aed855

Please sign in to comment.