gmanic / daly_bms_bt Goto Github PK
View Code? Open in Web Editor NEWBT data retrieval utility for Daly Smart BMS
License: MIT License
BT data retrieval utility for Daly Smart BMS
License: MIT License
Thank you for the software!
Is it normal that it takes many attempts to connect?
Hi there,
Great script!
I am however having some trouble getting MQTT/Telegraf/influxdb configured to accept data - if there any chance that you could give some pointers on correct configuration in Telegraf for MQTT data type etc?
I'm getting some error entries in the log for Telegraf:
Mar 10 09:58:16 pi64 telegraf[12758]: 2023-03-10T09:58:16Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:16 pi64 telegraf[12758]: 2023-03-10T09:58:16Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:16 pi64 telegraf[12758]: 2023-03-10T09:58:16Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: discharging
Mar 10 09:58:16 pi64 telegraf[12758]: 2023-03-10T09:58:16Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: True
Mar 10 09:58:16 pi64 telegraf[12758]: 2023-03-10T09:58:16Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: True
Mar 10 09:58:17 pi64 telegraf[12758]: 2023-03-10T09:58:17Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:17 pi64 telegraf[12758]: 2023-03-10T09:58:17Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:17 pi64 telegraf[12758]: 2023-03-10T09:58:17Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:17 pi64 telegraf[12758]: 2023-03-10T09:58:17Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: False
Mar 10 09:58:18 pi64 telegraf[12758]: 2023-03-10T09:58:18Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: 32_221130_100T
Mar 10 09:58:18 pi64 telegraf[12758]: 2023-03-10T09:58:18Z E! [inputs.mqtt_consumer] Error in plugin: invalid JSON provided, unable to parse: BMS-GD230-303E
Any clues would be most appreciated!
Cheers
โ daly_bms_bt git:(main) โ ./daly_bms_bt.py --bt 46:64:01:XX:XX:XX --hci hci1 --mqtt-user tempuser123--mqtt-password tempuser123 --mqtt-broker 192.168.1.100
INFO [daly_bms_bluetooth.py:24] Set up Bleak client, adapter hci1
INFO [daly_bms_bluetooth.py:46] Bluetooth connecting...
INFO [daly_bms_bluetooth.py:52] Bluetooth connected
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 94 response
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 94 response
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 94 response
ERROR [daly_bms_bluetooth.py:77] 94 failed after 3 tries
ERROR [base_events.py:1758] Task exception was never retrieved
future: <Task finished name='Task-1' coro=<main() done, defined at /home/adminsshuser/daly_bms_bt/./daly_bms_bt.py:123> exception=TypeError("a bytes-like object is required, not 'coroutine'")>
Traceback (most recent call last):
File "/home/adminsshuser/daly_bms_bt/./daly_bms_bt.py", line 132, in main
await con._data_point("Status", await con.bt_bms.get_status())
File "/home/adminsshuser/daly_bms_bt/modules/daly_bms_bluetooth.py", line 179, in get_status
return super().get_status(response_data=response_data)
File "/home/adminsshuser/daly_bms_bt/modules/daly_bms.py", line 252, in get_status
parts = struct.unpack('>b b ? ? b h x', response_data)
TypeError: a bytes-like object is required, not 'coroutine'
/usr/lib/python3.10/asyncio/base_events.py:1910: RuntimeWarning: coroutine 'DalyBMSBluetooth._read_request' was never awaited
handle = None # Needed to break cycles when an exception occurs.
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
^CINFO [daly_bms_bt.py:188] Keyboard break
Hello,
I have this problem:
INFO [daly_bms_bluetooth.py:46] Bluetooth connecting...
INFO [daly_bms_bluetooth.py:52] Bluetooth connected
INFO [daly_bms_bluetooth.py:113] did not receive 13 or 26 bytes, not implemented bytes: 78
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 95 response
INFO [daly_bms_bluetooth.py:113] did not receive 13 or 26 bytes, not implemented bytes: 78
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 95 response
INFO [daly_bms_bluetooth.py:113] did not receive 13 or 26 bytes, not implemented bytes: 78
WARNING [daly_bms_bluetooth.py:134] Timeout while waiting for 95 response
ERROR [daly_bms_bluetooth.py:77] 95 failed after 3 tries
ERROR [base_events.py:1738] Task exception was never retrieved
future: <Task finished name='Task-1' coro=<main() done, defined at /home/vincent/DALYBMS/daly_bms_bt/daly_bms_bt.py:123> exception=TypeError("_read_request() got an unexpected keyword argument 'return_list'")>
Traceback (most recent call last):
File "/home/vincent/DALYBMS/daly_bms_bt/daly_bms_bt.py", line 134, in main
await con._data_point("CellVoltages", await con.bt_bms.get_cell_voltages())
File "/home/vincent/DALYBMS/daly_bms_bt/modules/daly_bms_bluetooth.py", line 188, in get_cell_voltages
return super().get_cell_voltages(response_data=response_data)
File "/home/vincent/DALYBMS/daly_bms_bt/modules/daly_bms.py", line 281, in get_cell_voltages
response_data = self._read_request("95", max_responses=max_responses, return_list=True)
TypeError: _read_request() got an unexpected keyword argument 'return_list'
Can you help me ?
Hi, I have found solution to get the cell_voltages.
This ist my first time on Github for writing an issue.
Down you will find changed code, thats working for me.
In Python I'm a dirty progger.
Regards Andy
def _calc_num_responses(self, status_field, num_per_frame):
if not self.status:
self.logger.error("get_status has to be called at least once before calling get_cell_voltages")
return False
# now on my BT BMS it also replies only required frames, hence this is not necessary
# # each response message includes 3 cell voltages
if self.address == 8:
# # via Bluetooth the BMS returns all frames, even when they don't have data
#self.logger.error("status_field %s" % status_field)
if status_field == 'cell_voltages':
#compare to cells
max_responses = 8
elif status_field == 'cells':
#compare to cells
max_responses = 8
elif status_field == 'temperature_sensors':
max_responses = 1
elif status_field == 'temperatures':
max_responses = 3
else:
self.logger.error("unkonwn status_field %s" % status_field)
return False
else:
# via UART/USB the BMS returns only frames that have data
return math.ceil(self.status[status_field] / num_per_frame)
return max_responses
===============================
def get_cell_voltages(self, response_data=None):
if not response_data:
max_responses = self._calc_num_responses(status_field="cells", num_per_frame=3)
if not max_responses:
return
response_data = self._read_request("95", max_responses=max_responses, return_list=True)
if not response_data:
return False
#cell_voltages = self._split_frames(response_data=response_data, status_field="cells", structure=">b 3h x")
#only 7 Byte return
cell_voltages = self._split_frames(response_data=response_data, status_field="cells", structure=">b 3h")
for id in cell_voltages:
cell_voltages[id] = cell_voltages[id] / 1000
return cell_voltages
===============================
def _notification_callback(self, handle, data):
self.logger.debug("handle %s, data %s, len %s" % (handle, repr(data), len(data)))
responses = []
if len(data) == 13:
if int.from_bytes(self._calc_crc(data[:12]), 'little') != data[12]:
self.logger.info("Return from BMS: CRC wrong")
return
responses.append(data)
elif len(data) == 26:
if (int.from_bytes(self._calc_crc(data[:12]), 'little') != data[12]) or (int.from_bytes(self._calc_crc(data[13:25]), 'little') != data[25]):
self.logger.info("Return from BMS: CRC wrong")
return
responses.append(data[:13])
responses.append(data[13:])
#compare to cells
elif len(data) == 143:
if (int.from_bytes(self._calc_crc(data[:12]), 'little') != data[12]) or (int.from_bytes(self._calc_crc(data[13:25]), 'little') != data[25]) or (int.from_bytes(self._calc_crc(data[26:38]), 'little') != data[38]) or (int.from_bytes(self._calc_crc(data[39:51]), 'little') != data[51]) or (int.from_bytes(self._calc_crc(data[52:64]), 'little') != data[64]) or (int.from_bytes(self._calc_crc(data[65:77]), 'little') != data[77]) or (int.from_bytes(self._calc_crc(data[78:90]), 'little') != data[90]) or (int.from_bytes(self._calc_crc(data[91:103]), 'little') != data[103]):
self.logger.info("Return from BMS: CRC wrong")
return
responses.append(data[0:12])
responses.append(data[13:25])
responses.append(data[26:38])
responses.append(data[39:51])
responses.append(data[52:64])
responses.append(data[65:77])
responses.append(data[78:90])
responses.append(data[91:103])
else:
self.logger.info("did not receive 13 or 26 or 143 bytes, not implemented bytes: %i" % len(data))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.