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

Control the BMS via serial interface #20

Closed
syssi opened this issue Nov 16, 2021 · 45 comments
Closed

Control the BMS via serial interface #20

syssi opened this issue Nov 16, 2021 · 45 comments

Comments

@syssi
Copy link
Owner

syssi commented Nov 16, 2021

Follow-up: #19

@diybateriaslifepo4 @rem72

I am in contact with a JK engineer through WECHAT, but they are hard to extract information ... but he told me that the GPS module
they have is capable of controlling the BMS remotely, as a remote control for robberies, from what I understand that it should be
possible to change parameters through the serial port.

@syssi
Copy link
Owner Author

syssi commented Nov 16, 2021

@diybateriaslifepo4 We are talking about this value:

https://github.com/syssi/esphome-jk-bms/blob/main/components/jk_modbus/jk_modbus.cpp#L135

If we change the value from 0x03 to 0x02 we simulate a communication between the BMS and a GPS device. It's possible to BMS response differs a bit in this case. In best case the response is the same and commands we issue are executed properly (if the frame source is GPS).

@diybateriaslifepo4
Copy link

I am trying to get jk me information about this communication, but they insist that I must use their adapter to rs485 and their documentation for communication by rs485, I do not know if you already have it, how could I send it to you?

@syssi
Copy link
Owner Author

syssi commented Nov 17, 2021

You could attach the docs here by drag&drop.

@diybateriaslifepo4
Copy link

diybateriaslifepo4 commented Nov 17, 2021

BMS CAN instruction.pdf
BMS 485 instruction.pdf

I see that it is the same information that you have in the readme...

@syssi
Copy link
Owner Author

syssi commented Nov 17, 2021

The "BMS 485 instruction.pdf" describes the implemented protocol and doesn't contain new details.

@ortegafernando
Copy link

hi, how to write settings via serial? Thanks

@syssi
Copy link
Owner Author

syssi commented Dec 12, 2021

This compoent doesn't support write operations right now. It's also unconfirmed it's possible or not.

@diybateriaslifepo4
Copy link

image
in the protocol it says RW

@diybateriaslifepo4 We are talking about this value:

https://github.com/syssi/esphome-jk-bms/blob/main/components/jk_modbus/jk_modbus.cpp#L135

If we change the value from 0x03 to 0x02 we simulate a communication between the BMS and a GPS device. It's possible to BMS response differs a bit in this case. In best case the response is the same and commands we issue are executed properly (if the frame source is GPS).

have you been able to try this? I would do it but I don't have much idea about programming... Thanks for your job

@syssi
Copy link
Owner Author

syssi commented Dec 12, 2021

I will give it a try but my powerwall isn't assembled at the moment so my feedback / testing will take a few weeks.

@diybateriaslifepo4
Copy link

ok, there is no rush, in case you don't know you can turn on the bms with a power supply, with about 40v, only putting the negative in b0 & B- and positive in b+, without cells

@SeByDocKy
Copy link

Any update for such control ? :) ... .Now my JK BMS runs like a charm thanks your component, I would like to see these switch really working.... would be also amazing :)

@diybateriaslifepo4
Copy link

Any update for such control ? :) ... .Now my JK BMS runs like a charm thanks your component, I would like to see these switch really working.... would be also amazing :)

I have tried to do it and it has not worked, I have tried creating an external component, changing the value to bms, bluetooth, gps and computer, and not able to change values in any way
But maybe I haven't done it correctly, let's hope that Sysssi can test it one of these days.

@syssi
Copy link
Owner Author

syssi commented Feb 26, 2022

The switch entities are now able to send some instructions to the BMS:

[switch:017]: 'jk-bms charging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:00:00:00:00:00:68:00:00:01:6A
[switch:013]: 'jk-bms charging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:01:00:00:00:00:68:00:00:01:6B

[switch:017]: 'jk-bms discharging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:00:00:00:00:00:68:00:00:01:6B
[switch:013]: 'jk-bms discharging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:01:00:00:00:00:68:00:00:01:6C

[switch:017]: 'jk-bms balancing' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:00:00:00:00:00:68:00:00:01:5C
[switch:013]: 'jk-bms balancing' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:01:00:00:00:00:68:00:00:01:5D

[switch:013]: 'jk-bms dedicated charger' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:01:00:00:00:00:68:00:00:01:73
[switch:017]: 'jk-bms dedicated charger' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:00:00:00:00:00:68:00:00:01:72

Is somebody willing to test the new feature?

@syssi syssi mentioned this issue Feb 26, 2022
@SeByDocKy
Copy link

The switch entities are now able to send some instructions to the BMS:

[switch:017]: 'jk-bms charging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:00:00:00:00:00:68:00:00:01:6A
[switch:013]: 'jk-bms charging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:01:00:00:00:00:68:00:00:01:6B

[switch:017]: 'jk-bms discharging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:00:00:00:00:00:68:00:00:01:6B
[switch:013]: 'jk-bms discharging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:01:00:00:00:00:68:00:00:01:6C

[switch:017]: 'jk-bms balancing' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:00:00:00:00:00:68:00:00:01:5C
[switch:013]: 'jk-bms balancing' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:01:00:00:00:00:68:00:00:01:5D

[switch:013]: 'jk-bms dedicated charger' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:01:00:00:00:00:68:00:00:01:73
[switch:017]: 'jk-bms dedicated charger' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:00:00:00:00:00:68:00:00:01:72

Is somebody willing to test the new feature?

Sure I wil ltest right now

@SeByDocKy
Copy link

Ok ... seems to not working for me :( .... I can see the OFF command sent ... but the switch is returning to its initial state (ON)

@rob-oravec
Copy link

Same for me.

@SeByDocKy
Copy link

I tried whatever the password is entered before or not .... switch control does not work for me...

@syssi
Copy link
Owner Author

syssi commented Mar 1, 2022

I talked to the seller of my BMS and he told me the serial interface is read only. :-( I fear it is the truth.

@SeByDocKy
Copy link

I talked to the seller of my BMS and he told me the serial interface is read only. :-( I fear it is the truth.

Damned :(

@SeByDocKy
Copy link

I just checked the protocol pdf I got, effectively, we car read

R 0 X 84 The current data 2 Hex 10000 (10000-11000) * 0.01 = 10.00), a (discharge)
(10000-9500) *0.01= 5.00A (charging) P r e c i s i o n 1 0 mAunit:0 1 A
Note: C 0:0 x 01 redefines the 0 x 84 current data in 10 mA, with the highest bit being0"1" means "discharge" and "1" means charge
If the discharge is 20 A, the transmitted data is 2000 (0x 07 D0)
If the charge is 20 A, the transmission data is 34768 (0x 87 D0

in Read only :( :( .... what's a pity. Maybe time to change them into binary sensor so ?

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

I cannot follow / I didn't understand. Could you rephrase your statement? :-)

@SeByDocKy
Copy link

I mean if it's only in read only .... no need to define them in switch but more in binary sensors ?

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

Yes. I will convert the switches into binary sensors soon and yes the sign of the current sensor is inverted for my BMS software/hardware version too. If we are doing breaking changes we can fix/improve this as well.

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

FYI: #50

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

I've converted the switch into binary sensors: #51

@diybateriaslifepo4
Copy link

The strange thing is that they told me that the mosfets could be controlled from the gps, and the gps uses the same serial interface...

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

Do you know the exact product (GPS) I've to buy? As soon we have two devices talking to each other the communication can be captured easily. I've captured the traffic between the bluetooth module and the MCU already. I had the hope the same protocol is used here but it looks like this isn't the case: #49

Funny thing: The bluetooth password (123456) isn't passed to the MCU at all. It's used to unlock the bluetooth module but it's not part of the traffic between the bluetooth module and the MCU of the BMS.

@diybateriaslifepo4
Copy link

Do you know the exact product (GPS) I've to buy? As soon we have two devices talking to each other the communication can be captured easily. I've captured the traffic between the bluetooth module and the MCU already. I had the hope the same protocol is used here but it looks like this isn't the case: #49

Funny thing: The bluetooth password (123456) isn't passed to the MCU at all. It's used to unlock the bluetooth module but it's not part of the traffic between the bluetooth module and the MCU of the BMS.

tomorrow I ask the distributor, to see if I can ensure the functions of the GPS, I was going to send one pars test, but he told me that not all the functions would work in Spain, because it is designed to work in China

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

I asked my seller (HankzorBMS Store) about connecting an GPS/GSM device and he told me I need a customized version of the BMS.

@SeByDocKy
Copy link

I asked my seller (HankzorBMS Store) about connecting an GPS/GSM device and he told me I need a customized version of the BMS.

Custom firmware ? or also hardware modified ?

@syssi
Copy link
Owner Author

syssi commented Mar 2, 2022

In general the seller wants to sell 1000 pieces of a special BMS version. The difference will be the firmware only. I don't think we will receive an alternative/updated firmware ever.

@diybateriaslifepo4
Copy link

Do you know the exact product (GPS) I've to buy? As soon we have two devices talking to each other the communication can be captured easily. I've captured the traffic between the bluetooth module and the MCU already. I had the hope the same protocol is used here but it looks like this isn't the case: #49

Funny thing: The bluetooth password (123456) isn't passed to the MCU at all. It's used to unlock the bluetooth module but it's not part of the traffic between the bluetooth module and the MCU of the BMS.

sure enough, my dealer is now telling me that the port is read only, sorry 😭

@syssi
Copy link
Owner Author

syssi commented Mar 3, 2022

The minimum quantity for customized devices is 100.

@SeByDocKy
Copy link

The minimum quantity for customized devices is 100.

It's 99 more that I need :) :) ... Any way are the UVP? UVPR, LVP, LVPR writable ? Coz we could fake charging/discharging by this way ?

@syssi
Copy link
Owner Author

syssi commented Mar 3, 2022

I think UVP, UVPR, LVP and LVPR can be written/controlled via BLE. Whats the goal of faking charging/discharging? I think I didn't get the point.

@SeByDocKy
Copy link

I think UVP, UVPR, LVP and LVPR can be written/controlled via BLE. Whats the goal of faking charging/discharging? I think I didn't get the point.

By setting UVP=UVPR=LVP=LVPR is disabling charging/discharing de facto

@syssi
Copy link
Owner Author

syssi commented Mar 3, 2022

No write operations are possible via the serial interface. We have to use BLE to control the device.

@rem72
Copy link

rem72 commented Mar 3, 2022 via email

@syssi
Copy link
Owner Author

syssi commented Apr 23, 2022

I've implemented a BLE verison of this component a few days ago:

https://github.com/syssi/esphome-jk-bms/blob/main/esp32-ble-example.yaml

The switches (charging, discharging, balancer) can be controlled already.

@syssi
Copy link
Owner Author

syssi commented Apr 23, 2022

I will close this issue because it cannot be solved. I assume we must accept the serial connection is "read-only".

@syssi syssi closed this as completed Apr 23, 2022
@Wiebo
Copy link

Wiebo commented Oct 4, 2022

The switch entities are now able to send some instructions to the BMS:

[switch:017]: 'jk-bms charging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:00:00:00:00:00:68:00:00:01:6A
[switch:013]: 'jk-bms charging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AB:01:00:00:00:00:68:00:00:01:6B

[switch:017]: 'jk-bms discharging' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:00:00:00:00:00:68:00:00:01:6B
[switch:013]: 'jk-bms discharging' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:AC:01:00:00:00:00:68:00:00:01:6C

[switch:017]: 'jk-bms balancing' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:00:00:00:00:00:68:00:00:01:5C
[switch:013]: 'jk-bms balancing' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:9D:01:00:00:00:00:68:00:00:01:5D

[switch:013]: 'jk-bms dedicated charger' Turning ON.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:01:00:00:00:00:68:00:00:01:73
[switch:017]: 'jk-bms dedicated charger' Turning OFF.
[uart_debug:114]: >>> 4E:57:00:14:00:00:00:00:02:02:02:B3:00:00:00:00:00:68:00:00:01:72

Is somebody willing to test the new feature?
The CRC is calculated wrong...

@syssi
Copy link
Owner Author

syssi commented Oct 4, 2022

@Wiebo Why do you think so? :-)

@Wiebo
Copy link

Wiebo commented Oct 4, 2022

The checksum of this line:
4E:57:00:14:00:00:00:00:02:02:02:9D:00:00:00:00:00:68:00:00:01:5C
does not give me a response from the BMS. Also adding the END marker 0x68 gives checksum 0x01 0xC4
So,
4E:57:00:14:00:00:00:00:02:02:02:9D:00:00:00:00:00:68:00:00:01:C4
does give me a response from the BMS.

Still nothing changed though...

@syssi
Copy link
Owner Author

syssi commented Oct 4, 2022

Thanks for your feedback! Too bad it's not working anyway. Did you try different frame sources (f.e. GPS)?

@Wiebo
Copy link

Wiebo commented Oct 5, 2022

Yes, but also looking into command code 0x5, but don't really understand what they mean with that chinglish that's put into the manual...
"Pair code instruction - To modify the parameters, the first command is correct before the change"

If i make any progress i'll post it here. The manual clearly states these registers as R/W, but don't know if it's only for BLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants