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

Add legacy protocol support #14

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Add legacy protocol support #14

wants to merge 5 commits into from

Conversation

syssi
Copy link
Owner

@syssi syssi commented Oct 31, 2021

@inorhan: Could you download this feature branch and flash the esp32-example.yaml to your esp32:

wget https://raw.githubusercontent.com/syssi/esphome-jk-bms/add-protocol-v4-support/esp32-example.yaml
esphome run esp32-example.yaml

I've added a single query to this feature branch. Your BMS should respond if it supports the protocol v4. You should see something like this:

[20:36:28][VV][scheduler:152]: Running interval 'update' with interval=5000 last_execution=4294966687 (now=4391)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b11011101 (0xDD)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b10100101 (0xA5)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b00000011 (0x03)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b00000000 (0x00)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b11111111 (0xFF)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b11111101 (0xFD)
[20:36:28][VV][uart.arduino_esp32:121]:     Wrote 0b01110111 (0x77)
[20:36:28][VV][uart.arduino_esp32:142]:     Flushing...
# The BMS responds should follow here...

Please provide some responses of your BMS.

Closes: #13

@inorhan
Copy link

inorhan commented Nov 1, 2021

I receive the same messages being connected/disconnected to the BMS.

disconnected:

[17:54:57][VV][scheduler:152]: Running interval 'update' with interval=5000 last_execution=78911 (now=83911)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b11011101 (0xDD)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b10100101 (0xA5)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b00000011 (0x03)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b00000000 (0x00)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b11111111 (0xFF)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b11111101 (0xFD)
[17:54:57][VV][uart.arduino_esp32:121]: Wrote 0b01110111 (0x77)
[17:54:57][VV][uart.arduino_esp32:142]: Flushing...
[17:55:02][VV][scheduler:152]: Running interval 'update' with interval=5000 last_execution=83911 (now=88915)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b11011101 (0xDD)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b10100101 (0xA5)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b00000011 (0x03)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b00000000 (0x00)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b11111111 (0xFF)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b11111101 (0xFD)
[17:55:02][VV][uart.arduino_esp32:121]: Wrote 0b01110111 (0x77)
[17:55:02][VV][uart.arduino_esp32:142]: Flushing...

connected:

[17:58:32][VV][scheduler:152]: Running interval 'update' with interval=5000 last_execution=94285 (now=99290)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b11011101 (0xDD)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b10100101 (0xA5)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b00000011 (0x03)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b00000000 (0x00)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b11111111 (0xFF)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b11111101 (0xFD)
[17:58:32][VV][uart.arduino_esp32:121]: Wrote 0b01110111 (0x77)
[17:58:32][VV][uart.arduino_esp32:142]: Flushing...
[17:58:37][VV][scheduler:152]: Running interval 'update' with interval=5000 last_execution=99285 (now=104286)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b11011101 (0xDD)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b10100101 (0xA5)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b00000011 (0x03)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b00000000 (0x00)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b11111111 (0xFF)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b11111101 (0xFD)
[17:58:37][VV][uart.arduino_esp32:121]: Wrote 0b01110111 (0x77)
[17:58:37][VV][uart.arduino_esp32:142]: Flushing...
[17:58:37][V][component:186]: Component esphome.coroutine took a long time for an operation (0.05 s).
[17:58:37][V][component:187]: Components should block for at most 20-30ms.

I'm using the original RS232-485 JKBMS converter + a XY-017 RS485-TTL converter to the esp:

platform: ESP32
board: nodemcu-32s

baud_rate: 9600
rx_buffer_size: 384
tx_pin: GPIO14
rx_pin: GPIO4

@syssi
Copy link
Owner Author

syssi commented Nov 1, 2021

Does the TX led of the rs485 module blink periodically? Please make sure the TX led is blinking and not the RX led. Did you try to swap the RS485 (A/B) wires once?

@inorhan
Copy link

inorhan commented Nov 1, 2021 via email

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

Could you try to swap the GPIOs at the yaml once. Does the RX led blink this time? I want to make sure the GPIOs are connected properly. You have to swap the GPIOs later again because the TX led must blink / the ESPs sends periodically.

The last step would be dropping both rs485 converters. You can connect the ESP directly to the BMS because of the TTL level (3.3V). This time it is super important to identify the RX and TX pin of the BMS. Don't use VBAT by mistake. You could measure the voltage between the outer pins to identify VBAT and GND. If the measured voltage is positive you now the exact positions. If the voltage is negative you have to swap the voltmeter probes.

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

Can i just change the code in esphome? Pin4 <->14

Yes. This is the idea! So we can be sure the GPIOs are properly connected (without re-wiring).

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

This is super strange. I talked to some aliexpress seller of the BMS. He told me something like: Every BMS with firmware version <=6.x uses the old protocol (request: 0xDD 0xA5 0x03 0x00 0xFF 0xFD 0x77). A BMS with a firmware version >6 (f.e. 7.x and 8.x) should use the new protocol. And it looks like the baudrate has changed over time, so you should test 9600 bauds and 115200 bauds.

IMO your device should work with the original code of this component. Could you try to connect the ESP32 directly to your BMS?

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

How many cables did you connect to the BMS?

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

A side note: If your BMS doesn't provide VBAT the original RS485 adapter won't be powered properly and cannot work.

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@inorhan
Copy link

inorhan commented Nov 2, 2021 via email

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

Yes. It's the same protocol. The is the command to query the current status:

https://github.com/Louisvdw/dbus-serialbattery/blob/master/etc/dbus-serialbattery/jkbms.py#L19

This component does the same here:

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

@syssi
Copy link
Owner Author

syssi commented Nov 2, 2021

Could you try to use the python implementation by connecting the BMS to a TTL-to-USB adapter?

@syssi syssi changed the title Add protocol v4 support Add legacy protocol support Nov 5, 2021
@syssi syssi force-pushed the add-protocol-v4-support branch 2 times, most recently from 567c006 to 7aa5227 Compare February 27, 2022 19:19
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

Successfully merging this pull request may close these issues.

Add legacy protocol support
2 participants