Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jkbms_ble: 32s-Support and connection workaround for bt-fail #466

Merged
merged 27 commits into from
Apr 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
getting things together, removed most obvious mistakes; connection te…
…st is executed, further work required
Eike Baran committed Dec 25, 2022
commit f214263f2b1b7821f7cac08cf7b34140cc0158e1
3 changes: 2 additions & 1 deletion buildfiles.lst
Original file line number Diff line number Diff line change
@@ -24,8 +24,9 @@ etc/dbus-serialbattery/ant.py
etc/dbus-serialbattery/util_max17853.py
etc/dbus-serialbattery/mnb.py
etc/dbus-serialbattery/jkbms.py
etc/dbus-serialbattery/jkbms_ble.py
etc/dbus-serialbattery/sinowealth.py
etc/dbus-serialbattery/renogy.py
etc/dbus-serialbattery/revov.py
etc/dbus-serialbattery/ecs.py
etc/dbus-serialbattery/lifepower.py
etc/dbus-serialbattery/lifepower.py
1 change: 1 addition & 0 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
from daly import Daly
from ant import Ant
from jkbms import Jkbms
from jkbms_ble import Jkbms_Ble
from sinowealth import Sinowealth
from renogy import Renogy
from revov import Revov
34 changes: 21 additions & 13 deletions etc/dbus-serialbattery/jkbms_ble.py
Original file line number Diff line number Diff line change
@@ -2,55 +2,63 @@
from battery import Protection, Battery, Cell
from utils import *
from struct import *
from jkbms import JkBmsBle
from jkbms_brn import JkBmsBle
from bleak import BleakScanner
import asyncio
import time

class Jkbms_Ble(Battery):
BATTERYTYPE = "Jkbms BLE"
def __init__(self, port,baud, address):
super(Jkbms_Ble, self).__init__(port,baud)
self.type = self.BATTERYTYPE
self.jk = JkBmsBLE(address)
self.jk = JkBmsBle(address)

logger.error("init of jkbmsble")

def test_connection(self):
# call a function that will connect to the battery, send a command and retrieve the result.
# The result or call should be unique to this BMS. Battery name or version, etc.
# Return True if success, False for failure

# check if device with given mac is found, otherwise abort
devices = await BleakScanner.discover()

logger.error("test of jkbmsble")
loop = asyncio.get_event_loop()
t = loop.create_task(BleakScanner.discover())
devices = loop.run_until_complete(t)

found=False
for d in devices
if d.address=self.jk.address
for d in devices:
if d.address == self.jk.address:
found=True
if not found:
return False

#device was found, presumeably a jkbms so start scraping
jk.start_scraping()
self.jk.start_scraping()
tries = 1

while jk.get_status() == None and tries < 20:
while self.jk.get_status() == None and tries < 20:
time.sleep(0.5)
tries += 1

# load initial data, from here on get_status has valid values to be served to the dbus
status=jk.get_status()
status=self.jk.get_status()
if status == None:
return False

if not status["device_info"]["vendor_id"].startswith("JK-")
if not status["device_info"]["vendor_id"].startswith("JK-"):
return False

logger.info("JK BMS found!")
return true
return True

def get_settings(self):
# After successful connection get_settings will be call to set up the battery.
# Set the current limits, populate cell count, etc
# Return True if success, False for failure
st=jk.get_status()["settings"]
st=self.jk.get_status()["settings"]
self.cell_count=st["cell_count"]
self.max_battery_charge_current = st["max_charge_current"]
self.max_battery_discharge_current = status["max_discharge_current"]
@@ -61,7 +69,7 @@ def get_settings(self):
self.cells.append(Cell(False))

self.hardware_version = "JKBMS "+ jk.get_status()["device_info"]["hw_rev"]+" " + str(self.cell_count) + " cells"

logger.info("BAT: "+self.hardware_version)
return True

def refresh_data(self):
@@ -71,7 +79,7 @@ def refresh_data(self):

#result = self.read_soc_data()
#TODO: check for errors
st=jk.get_status()
st=self.jk.get_status()
if status == None:
return False
if time.time() - st["last_update"] > 30:
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
{"bms" : "Daly", "address" : b"\x40"},
{"bms" : "Daly", "address" : b"\x80"},
{"bms" : "Jkbms", "baud" : 115200},
{"bms" : "Jkbms_Ble" "address" : "C8:47:8C:E4:54:0E"},
{"bms" : "Jkbms_Ble", "address" : "C8:47:8C:E4:54:0E"},
{"bms" : "Sinowealth"},
{"bms" : "Lifepower"},
{"bms" : "Renogy", "address": b"\x30"},