jblance / mpp-solar

Python package to communicate to MPP Solar PIP-4048MS inverters (and similar)
MIT License
355 stars 149 forks source link

JKBMS - After some time it blocks the bluetooth #120

Open miguel300477 opened 3 years ago

miguel300477 commented 3 years ago

Hi, im using JKBMS bms with 2A ballacing, and I'm using the config file.

I have noticed that every time we request cell data, it connects to bluetooth. After some time the communications is locked and stops getting data to graphana. I have to restart the PI 4.

Is there any way to stay connected to the BMS, like the app and keep getting data without connecting and disconnecting the bluetooth?

Since i have the device paired in the raspberry pi, can i omit the port ( bms MAC ) in the config file and get data like that?

jblance commented 3 years ago

Hi The code needs the MAC to connect, so you cant omit it. I have been thinking of the best way to avoid the reconnecting each time, but it requires a fundamental change in the way the code works so havent come up with the best way yet. I currently work around the problem you have by restarting the bluetooth service (and the jkbms service) regularly with cron

It is something I'm planning on fixing once I determine the best way to do it though

trixing commented 3 years ago

One bug in the code is that sometimes jkabstractprotocol is_record_complete is not terminating if the record is corrupt. handleNotification in jkBleDelegate will then just spin and read data. Not sure what the best way to fix this is, but maybe handleNotification should just clear notificationData if the data gets infeasibly long?

trixing commented 3 years ago

The real problem being obviously that the BMS keeps sending these packets. Not sure how to stop it - disconnect?

The data I get repeatedly is this packet bytearray(b'U\xaa\xeb\x90\x02!\xc9\x0c\xc9\x0c\xc9\x0c\xc9\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xcb\x0c\xc9\x0c\xcb\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xca\x0c\x02\x00\x04\x00N\x00P\x00T\x00X\x00\x00e\x00f\x00d\x00e\x00d\x00d\x00d\x00e\x00\x00Z\x00T\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa5\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdb\x00\xdd\x00\xf3\x00\x00\x00\x00\x00\x00\x1c\xd5:\x01\x00\xc0E\x04\x00\x00\x00\x00\x00\xb8\x05\x00\x00d\x00\x0b\x06&G\x05\x00\x00\x00\xf6\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x01\x00\x00\x00\x0f\x04\x00\x00\x00\x00\n\x05@@\x00\x00\x00\x00\xd9\x03\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x003')

jeca32 commented 2 years ago

I currently work around the problem you have by restarting the bluetooth service (and the jkbms service) regularly with cron

It is something I'm planning on fixing once I determine the best way to do it though

I also have this problem, I have to manually reboot my raspberry every 2 or 3 hours. Can you provide us with your "cron" files to restart these 2 services (bluetooth and jkbms)?