Skip to content

Commit

Permalink
Merge pull request Louisvdw#942 from mr-manuel/dev
Browse files Browse the repository at this point in the history
Changes 2024.01.28
  • Loading branch information
mr-manuel committed Jan 28, 2024
2 parents 3c2401a + fe52db6 commit 5e025e6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
# v1.0.0alpha20230507
# v1.0.0-beta20230507
# v1.0.0-development-20230507
- "v*.*.[0-9]+-?[a-zA-Z]*"
- "v[0-9]+.[0-9]+.[0-9]+-?[a-zA-Z]*"

jobs:
build:
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@
* `BULK_CELL_VOLTAGE` -> `SOC_RESET_VOLTAGE`
* `BULK_AFTER_DAYS` -> `SOC_RESET_AFTER_DAYS`

## v1.0.x
## v1.1.x

* Changed: JKBMS BLE - Fix driver gets unresponsive, if connection is lost https://github.com/Louisvdw/dbus-serialbattery/issues/720 with https://github.com/Louisvdw/dbus-serialbattery/pull/941 by @cupertinomiranda
* Changed: JKBMS BLE - Fix temperature issue https://github.com/Louisvdw/dbus-serialbattery/issues/916 by @mr-manuel

## v1.1.20240121

* Changed: Exit the driver with error, when port is excluded in config, else the serialstarter does not continue by @mr-manuel
* Changed: Fix issue on first driver startup, when no device setting in dbus exists by @mr-manuel
* Changed: Fixed some smaller errors by @mr-manuel
* Changed: More detailed error output when an exception happens by @mr-manuel


## v1.0.20240102beta

* Added: Bluetooth: Show signal strength of BMS in log by @mr-manuel
Expand Down
10 changes: 8 additions & 2 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,10 @@ def manage_charge_current(self) -> None:

# if BMS limit is lower then config limit and therefore the values are not the same,
# then the limit was also read from the BMS
if utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current:
if (
isinstance(self.max_battery_charge_current, (int, float))
and utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current
):
charge_limits.update({self.max_battery_charge_current: "BMS Settings"})

if utils.CCCM_CV_ENABLE:
Expand Down Expand Up @@ -747,7 +750,10 @@ def manage_charge_current(self) -> None:

# if BMS limit is lower then config limit and therefore the values are not the same,
# then the limit was also read from the BMS
if utils.MAX_BATTERY_DISCHARGE_CURRENT > self.max_battery_discharge_current:
if (
isinstance(self.max_battery_discharge_current, (int, float))
and utils.MAX_BATTERY_DISCHARGE_CURRENT > self.max_battery_discharge_current
):
discharge_limits.update(
{self.max_battery_discharge_current: "BMS Settings"}
)
Expand Down
16 changes: 11 additions & 5 deletions etc/dbus-serialbattery/bms/jkbms_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ def refresh_data(self):
for c in range(self.cell_count):
self.cells[c].voltage = st["cell_info"]["voltages"][c]

self.to_temp(0, st["cell_info"]["temperature_mos"])
self.to_temp(1, st["cell_info"]["temperature_sensor_1"])
self.to_temp(2, st["cell_info"]["temperature_sensor_2"])
temp_mos = st["cell_info"]["temperature_mos"]
self.to_temp(0, temp_mos if temp_mos < 32767 else (65535 - temp_mos) * -1)

temp1 = st["cell_info"]["temperature_sensor_1"]
self.to_temp(1, temp1 if temp1 < 32767 else (65535 - temp1) * -1)

temp2 = st["cell_info"]["temperature_sensor_2"]
self.to_temp(1, temp2 if temp2 < 32767 else (65535 - temp2) * -1)

self.current = round(st["cell_info"]["current"], 1)
self.voltage = round(st["cell_info"]["total_voltage"], 2)

Expand All @@ -197,8 +203,8 @@ def refresh_data(self):
self.balancing = False if st["cell_info"]["balancing_action"] == 0.000 else True
self.balancing_current = (
st["cell_info"]["balancing_current"]
if st["cell_info"]["balancing_current"] < 32768
else (65536 / 1000 - st["cell_info"]["balancing_current"]) * -1
if st["cell_info"]["balancing_current"] < 32767
else (65535 / 1000 - st["cell_info"]["balancing_current"]) * -1
)
self.balancing_action = st["cell_info"]["balancing_action"]

Expand Down
23 changes: 13 additions & 10 deletions etc/dbus-serialbattery/bms/jkbms_brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from time import sleep, time
import asyncio
import threading
import sys

# if used as standalone script then use custom logger
# else import logger from utils
Expand Down Expand Up @@ -139,10 +140,12 @@ class Jkbms_Brn:
# translate info placeholder, since it depends on the bms_max_cell_count
translate_cell_info = []

def __init__(self, addr, reset_bt_callback = None):
def __init__(self, addr, reset_bt_callback=None):
self.address = addr
self.bt_thread = None
self.bt_thread_monitor = threading.Thread(target=self.monitor_scraping)
self.bt_thread_monitor = threading.Thread(
target=self.monitor_scraping, name="Thread-JKBMS-Monitor"
)
self.bt_reset = reset_bt_callback
self.should_be_scraping = False
self.trigger_soc_reset = False
Expand Down Expand Up @@ -497,8 +500,10 @@ async def asy_connect_and_scrape(self):
logger.info("--> asy_connect_and_scrape(): Exit")

def monitor_scraping(self):
while(self.should_be_scraping == True):
self.bt_thread = threading.Thread(target=self.connect_and_scrape)
while self.should_be_scraping == True:
self.bt_thread = threading.Thread(
target=self.connect_and_scrape, name="Thread-JKBMS-Connect-and-Scrape"
)
self.bt_thread.start()
logger.debug(
"scraping thread started -> main thread id: "
Expand All @@ -507,9 +512,9 @@ def monitor_scraping(self):
+ str(self.bt_thread.ident)
)
self.bt_thread.join()
if (self.should_be_scraping == True):
if self.should_be_scraping == True:
logger.debug("scraping thread ended: reseting bluetooth and restarting")
if (not self.bt_reset == None):
if not self.bt_reset == None:
self.bt_reset()
sleep(2)

Expand All @@ -519,7 +524,7 @@ def start_scraping(self):
logger.debug("scraping thread already running")
return
self.should_be_scraping = True
self.bt_thread_monitor.start();
self.bt_thread_monitor.start()

def stop_scraping(self):
self.run = False
Expand All @@ -532,7 +537,7 @@ def stop_scraping(self):
return True

def is_running(self):
if (self.bt_thread is not None):
if self.bt_thread is not None:
return self.bt_thread.is_alive()
return False

Expand Down Expand Up @@ -586,8 +591,6 @@ async def reset_soc_jk(self, c):


if __name__ == "__main__":
import sys

jk = Jkbms_Brn(sys.argv[1])
if not jk.test_connection():
logger.error(">>> ERROR: Unable to connect")
Expand Down
3 changes: 2 additions & 1 deletion etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def get_port() -> str:
+ " is excluded trough the config file"
)
sleep(60)
sys.exit(0)
# exit with error in order that the serialstarter goes on
sys.exit(1)
else:
# just for MNB-SPI
logger.info("No Port needed")
Expand Down
8 changes: 4 additions & 4 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,10 @@ def setSetting(
settings_iface = dbus.Interface(obj, "com.victronenergy.BusItem")
method = settings_iface.get_dbus_method("SetValue")
try:
print(f"Setted setting {object_path}/{setting_name} to {value}")
logger.debug(f"Setted setting {object_path}/{setting_name} to {value}")
return True if method(value) == 0 else False
except dbus.exceptions.DBusException as e:
print(f"Failed to remove setting: {e}")
logger.error(f"Failed to set setting: {e}")

def removeSetting(
self, bus, service: str, object_path: str, setting_name: list
Expand All @@ -1054,10 +1054,10 @@ def removeSetting(
settings_iface = dbus.Interface(obj, "com.victronenergy.Settings")
method = settings_iface.get_dbus_method("RemoveSettings")
try:
print(f"Removed setting at {object_path}")
logger.debug(f"Removed setting at {object_path}")
return True if method(setting_name) == 0 else False
except dbus.exceptions.DBusException as e:
print(f"Failed to remove setting: {e}")
logger.error(f"Failed to remove setting: {e}")

def create_nested_dict(self, path, value) -> dict:
keys = path.strip("/").split("/")
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 @@ -37,7 +37,7 @@ def _get_list_from_config(


# Constants
DRIVER_VERSION = "1.1.20240112dev"
DRIVER_VERSION = "1.1.20240128dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit 5e025e6

Please sign in to comment.