Skip to content

Commit

Permalink
Fixes for Renogy BMS, code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Jun 29, 2024
1 parent e7faa51 commit af773cc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@

## v1.4.x
* Added: EG4 LL BMS by @tuxntoast
* Added: JKBMS PB Model with https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/39 by @KoljaWindeler
* Added: Show details about driver internals in GUI -> Serialbattery -> Parameters by setting `GUI_PARAMETERS_SHOW_ADDITIONAL_INFO` to `True` by @mr-manuel
* Changed: Optimized code and error handling by @mr-manuel
* Changed: Renamed Lifepower to EG4_Lifepower by @mr-manuel
* Changed: Renogy BMS - Fixes for unknown serial number by @mr-manuel

## v1.3.20240624
* Added: Fields for debugging switch to float/bulk by @mr-manuel
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ The driver will communicate with a Battery Management System (BMS) that support

## History
The first version of this driver was released by [Louisvdw](https://github.com/Louisvdw/dbus-serialbattery) in September 2020.
In February 2023 I (mr-manuel) made my first PR, since Louis did not have time anymore to contribute to this project.
With the release of `v1.0.0` I became the main developer of this project and since then I'm maintaining and updating it.

In February 2023 I ([mr-manuel](https://github.com/mr-manuel)) made my first PR, since Louis did not have time anymore to contribute to this project.

With the release of `v1.0.0` I became the main developer of this project. From then on, I have been maintaining the project and developing it further. I'm also solving 99% of the issues on GitHub.

A big thanks to [Louisvdw](https://github.com/Louisvdw/dbus-serialbattery) for the initiation of this project.

Expand Down
16 changes: 14 additions & 2 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ def unique_identifier(self) -> str:
:return: the unique identifier
"""
if utils.USE_PORT_AS_UNIQUE_ID:
return self.port
return self.port + (
"__" + utils.bytearray_to_string(self.address).replace("\\", "0")
if self.address is not None
else ""
)
else:
string = (
"".join(filter(str.isalnum, str(self.hardware_version))) + "_"
Expand All @@ -185,7 +189,15 @@ def unique_identifier(self) -> str:
return string

def connection_name(self) -> str:
return "Serial " + self.port
return (
"Serial "
+ self.port
+ (
"__" + utils.bytearray_to_string(self.address).replace("\\", "0")
if self.address is not None
else ""
)
)

def custom_name(self) -> str:
return "SerialBattery(" + self.type + ")"
Expand Down
21 changes: 12 additions & 9 deletions etc/dbus-serialbattery/bms/daly.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def refresh_data(self):
result = self.read_soc_data(ser)
self.reset_soc = self.soc if self.soc else 0
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_soc_data - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -124,7 +124,7 @@ def refresh_data(self):

result = self.read_fed_data(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_fed_data - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -134,7 +134,7 @@ def refresh_data(self):

result = self.read_cell_voltage_range_data(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_cell_voltage_range_data - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -144,7 +144,7 @@ def refresh_data(self):

self.write_soc_and_datetime(ser)
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: write_soc_and_datetime - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -154,7 +154,7 @@ def refresh_data(self):

result = self.read_alarm_data(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_alarm_data - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -164,7 +164,7 @@ def refresh_data(self):

result = self.read_temperature_range_data(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_temperature_range_data - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -174,7 +174,7 @@ def refresh_data(self):

result = self.read_balance_state(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_balance_state - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -184,7 +184,7 @@ def refresh_data(self):

result = self.read_cells_volts(ser) and result
if self.runtime > 0.200: # TROUBLESHOOTING for no reply errors
logger.info(
logger.debug(
" |- refresh_data: read_cells_volts - result: "
+ str(result)
+ " - runtime: "
Expand All @@ -201,7 +201,10 @@ def refresh_data(self):
logger.warning("Couldn't open serial port")

if not result: # TROUBLESHOOTING for no reply errors
logger.info("refresh_data: result: " + str(result))
logger.info(
f"refresh_data: result: {result}."
+ " If you don't see this warning very often, you can ignore it."
)

return result

Expand Down
17 changes: 14 additions & 3 deletions etc/dbus-serialbattery/bms/renogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ def __init__(self, port, baud, address):
# BMS warning and protection config

def unique_identifier(self) -> str:
return self.serial_number
"""
Override the unique_identifier method to return the serial number if it exists, else restore default method.
"""
if self.serial_number is not None:
return self.serial_number
else:
return Battery.unique_identifier(self)

def test_connection(self):
# call a function that will connect to the battery, send a command and retrieve the result.
Expand Down Expand Up @@ -128,8 +134,13 @@ def read_gen_data(self):
capacity = self.read_serial_data_renogy(self.command_capacity)
self.capacity = unpack(">L", capacity)[0] / 1000.0

serial_number = self.read_serial_data_renogy(self.command_serial_number)
self.serial_number = unpack("16s", serial_number)[0].decode("utf-8")
try:
serial_number = self.read_serial_data_renogy(self.command_serial_number)
self.serial_number = unpack("16s", serial_number)[0].decode("utf-8")
except Exception:
logger.debug(f"serial number: {serial_number}")
self.serial_number = None
pass

return True

Expand Down
7 changes: 5 additions & 2 deletions 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.4.20240627dev"
DRIVER_VERSION = "1.4.20240629dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down Expand Up @@ -364,6 +364,9 @@ def _get_list_from_config(
if config["DEFAULT"]["POLL_INTERVAL"] != ""
else None
)
"""
Poll interval in milliseconds
"""

# Auto reset SoC
AUTO_RESET_SOC: bool = "True" == config["DEFAULT"]["AUTO_RESET_SOC"]
Expand Down Expand Up @@ -415,7 +418,7 @@ def _get_list_from_config(
# -- Seplos V3 settings
SEPLOS_USE_BMS_VALUES: bool = "True" == config["DEFAULT"]["SEPLOS_USE_BMS_VALUES"]

# --------- Battery monitor specific settings ---------
# --------- Voltage drop ---------
VOLTAGE_DROP: float = float(config["DEFAULT"]["VOLTAGE_DROP"])


Expand Down

0 comments on commit af773cc

Please sign in to comment.