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 JK-PB bms compatibility. Target: 1 ESP in a "listening mode" connected to RS485 network. #464

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

Conversation

txubelaxu
Copy link

JK-PB2A16S-20P model jk-bms.
Two bms connected to that RS485 internal network.
ubuntu connected in a "listening mode" using a USB<->RS485 adaptor.

JK-PB2A16S-20P model jk-bms.
Two bms connected to that RS485 internal network.
ubuntu connected in a "listening mode" using a USB<->RS485 adaptor.
Copy link
Author

@txubelaxu txubelaxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have installed clang-format (v14 now)

@txubelaxu txubelaxu changed the title script to sniffing traffic from the RS485 network Add JK-PB bms compatibility. Target: 1 ESP in a "listening mode" connected to RS485 network. Mar 3, 2024
@txubelaxu txubelaxu closed this Mar 3, 2024
@txubelaxu txubelaxu reopened this Mar 3, 2024
@txubelaxu
Copy link
Author

txubelaxu commented Mar 3, 2024

I have created a new component: "jk_rs485". It is for JK-PB HW v14.
This is a sniffing way to gather information across the RS485 network.
The goal to achieve is to gathering information about every jk-bms using only one ESP. This way, Bluetooth remains free.

To compile:
esphome compile esp32-example-rs485.yaml

Pending:

  • testing
  • configure yaml with multiple BMSs. Each one: 1 address [0x00,0x0f]. So, address paramether to insert inside yaml config is pending.

Copy link
Author

@txubelaxu txubelaxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I have changed erroneusly components/jk_bms_ble/jk_bms_ble.cpp file.
I do know how to solve this error.
Other changes are new files.

Copy link
Author

@txubelaxu txubelaxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something wrong here?
It is marked as failed.

@syssi
Copy link
Owner

syssi commented Mar 4, 2024

I will have a look as soon as possible. Please give me some time! :-)

@txubelaxu
Copy link
Author

Sorry!! I am very newbie at github.
👏👏😉

@syssi
Copy link
Owner

syssi commented Mar 5, 2024

No problem. Feel free to ask any questions.

@txubelaxu
Copy link
Author

No problem. Feel free to ask any questions.

Many thanks, Sebastian. Certainly, I do not know how to manage/arrange the "code + configuration.yaml" to demultiplex the info arraiving from RS485. So, I have got the info about every BMS connected to the RS485 network (it does not matter how many are: max 16). I know how to pass the UART information to the jk_rs485 component (but only one). But I have achieve the goal of sharing the same UART with two jk_rs485 components. I would like to:

  1. remake the configuration.yaml structure in order to place inside that file each jk_rs485 node: each one with a identifyer and an address.
  2. "publish_state" info and settings, but signaling the identifyer (not address) of the jk_rs485 node.

I do not know if this is possible.

Many thanks!!

@brycelarge
Copy link

any chance you could put a wiring diagram together so I can test with my 3 new JK BMS?

@txubelaxu
Copy link
Author

any chance you could put a wiring diagram together so I can test with my 3 new JK BMS?

#463 (comment)

@brycelarge
Copy link

any chance you could put a wiring diagram together so I can test with my 3 new JK BMS?

#463 (comment)

Which Ethernet wires go to tx and rx on the ESP board?

@txubelaxu
Copy link
Author

any chance you could put a wiring diagram together so I can test with my 3 new JK BMS?

#463 (comment)

Which Ethernet wires go to tx and rx on the ESP board?

image

@txubelaxu
Copy link
Author

it is not ethernet. It is RS485, ok?
You need a USB to RS485 adaptor.

@brycelarge
Copy link

it is not ethernet. It is RS485, ok? You need a USB to RS485 adaptor.

USB plugs into the ESP32 dev board and RJ45 into the RS485 port in the inverter?

@txubelaxu
Copy link
Author

txubelaxu commented Mar 10, 2024 via email

@denveronly
Copy link

denveronly commented Mar 10, 2024

Can you point to a code that should be loaded to ESPHome please?
Is it working already? Master and Slave Sniff? I have 1 Master and 6 Slaves right now lol.

 + uart1 & uart2 protocol numbers
 + device_info settings
* RS485:
 + Network Nodes available (text sensor). Automatically detects nodes in the network.
 + status heating binary sensor bug corrected
 + temperature 5
 + more params
 + developing talk pin for rs485 request or settings (not ready yet)
@dgbiuro
Copy link

dgbiuro commented Apr 1, 2024

Hi, I'm trying to install the 1 master 6 slaves yaml file and it always fails.
This is what I get from logs:

`INFO ESPHome 2024.3.1
INFO Reading configuration /config/esphome/jk-bms.yaml...
INFO Updating https://github.com/txubelaxu/esphome-jk-bms.git@main
INFO Generating C++ source...
INFO Compiling app...
Processing esp-rs485-gw (board: esp32dev; framework: espidf; platform: platformio/espressif32@5.4.0)

HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash

  • framework-espidf @ 3.40406.240122 (4.4.6)
  • tool-cmake @ 3.16.4
  • tool-ninja @ 1.7.1
  • toolchain-esp32ulp @ 2.35.0-20220830
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
    Reading CMake configuration...
    Generating assembly for certificate bundle...
    Dependency Graph
    |-- noise-c @ 0.1.4
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_connection.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_frame_helper.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2_service.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_server.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/list_entities.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/proto.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/subscribe_state.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/user_services.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/automation.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/binary_sensor.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/filter.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/core.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/gpio.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/preferences.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o
    In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:8,
    from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1:
    src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory


#include "binary_output.h"
^~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1
In file included from src/esphome/components/jk_rs485_bms/switch/../jk_rs485_bms.h:8,
from src/esphome/components/jk_rs485_bms/switch/jk_switch.h:3,
from src/esphome/components/jk_rs485_bms/switch/jk_switch.cpp:1:
src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory



#include "binary_output.h"
^~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o] Error 1
========================== [FAILED] Took 8.25 seconds ==========================`

I'm installing the yaml file via esphome addon in home assistant.
What am I doing wrong here?
Help will be much appreciated, thanks!

@txubelaxu
Copy link
Author

Hi, I'm trying to install the 1 master 6 slaves yaml file and it always fails. This is what I get from logs:

`INFO ESPHome 2024.3.1

INFO Reading configuration /config/esphome/jk-bms.yaml...
INFO Updating https://github.com/txubelaxu/esphome-jk-bms.git@main
INFO Generating C++ source...
INFO Compiling app...
Processing esp-rs485-gw (board: esp32dev; framework: espidf; platform: platformio/espressif32@5.4.0)
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash

  • framework-espidf @ 3.40406.240122 (4.4.6)

  • tool-cmake @ 3.16.4

  • tool-ninja @ 1.7.1

  • toolchain-esp32ulp @ 2.35.0-20220830

  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
    Reading CMake configuration...
    Generating assembly for certificate bundle...
    Dependency Graph
    |-- noise-c @ 0.1.4
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_connection.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_frame_helper.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2_service.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_server.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/list_entities.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/proto.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/subscribe_state.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/user_services.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/automation.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/binary_sensor.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/filter.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/core.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/gpio.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/preferences.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o
    Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o
    In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:8,
    from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1:
    src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory

  • Looking for binary_output.h dependency? Check our library registry!

  • CLI > platformio lib search "header:binary_output.h"

  • Web > https://registry.platformio.org/search?q=header:binary_output.h

#include "binary_output.h" ^~~~~~~~~~~~~~~~~ compilation terminated. *** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1 In file included from src/esphome/components/jk_rs485_bms/switch/../jk_rs485_bms.h:8, from src/esphome/components/jk_rs485_bms/switch/jk_switch.h:3, from src/esphome/components/jk_rs485_bms/switch/jk_switch.cpp:1: src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory

#include "binary_output.h" ^~~~~~~~~~~~~~~~~ compilation terminated. *** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o] Error 1 ========================== [FAILED] Took 8.25 seconds ==========================`

I'm installing the yaml file via esphome addon in home assistant. What am I doing wrong here? Help will be much appreciated, thanks!

Hi @dgbiuro, could you try with the last update just uploaded now?

Many thanks!!

@jogybaer0815
Copy link

jogybaer0815 commented Apr 8, 2024

Latest ESPhome update needs changes:

'talk_pin' is a required option for [0]

  • id: sniffer0
    protocol_version: JK02_32S
    rx_timeout: 500ms
    uart_id: uart_0

Where should talk_pin assigned?

@txubelaxu
Copy link
Author

Latest ESPhome update needs changes:

'talk_pin' is a required option for [0]

  • id: sniffer0
    protocol_version: JK02_32S
    rx_timeout: 500ms
    uart_id: uart_0

Where should talk_pin assigned?

Any pin of your choice. It is not mandatory to connect tx_pin to TTL to RS485 converter. It is not mandatory to connect talk_pin to TTL to RS485 converter. Assign to "talk_pin" any free pin that can act as "output".

I have got the code to act as "master" or "pseudo-master". I am publishing this soon. Today or tomorrow, maybe.

@txubelaxu
Copy link
Author

@denveronly, have you tried last version with your 7 BMSs? Did it work?

+Temperature sensor absent alarm bug corrected as well.
+ Added:
   discharging_overcurrent_protection_release_time_sensor_;
   discharging_short_circuit_protection_release_time_sensor_
   charging_overcurrent_protection_release_time_sensor_
   charging_short_circuit_protection_release_time_sensor_
   cell_undervoltage_protection_release_time_sensor_
   cell_overvoltage_protection_release_time_sensor_

Updated two examples yaml
Updated HASS Dashboards
+PRECHARGING_TIME_FROM_DISCHARGE

Two examples updated
HASS Dashboard updated. Renewed Protection dashboards.
@kommando828
Copy link

When this is fully merged will it allow the outputs to be used to feed an MQTT broker, looking forward to this one now I have my SMA SI's in closed loop with a JK-PB2A16S20P using canbus.

@dgbiuro
Copy link

dgbiuro commented Apr 25, 2024

Hi @txubelaxu, sorry it took me so long to respond.
The new code is compiling and running but the esp cannot read any data. Here is a part of the logs:

[19:41:45][I][jk_rs485_sniffer:244]: SILENCE: 207.000000 ms [19:41:45][D][jk_rs485_sniffer:261]: .......................................... [19:41:45][D][jk_rs485_sniffer:264]: Buffer before number 1: FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.7F.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.DF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF [19:41:45][D][jk_rs485_sniffer:266]: Response: 4: [19:41:45][W][component:237]: Component jk_rs485_sniffer took a long time for an operation (104 ms). [19:41:45][W][component:238]: Components should block for at most 30 ms. [19:41:45][D][uart_debug:114]: <<< FF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 display_always_on' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:television' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 emergency' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:exit-run' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 heating' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:radiator' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 charging float mode' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:battery-charging-80' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 disable temperature sensors' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:thermometer-off' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 smart sleep on' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:sleep' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 disable pcl module' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:power-plug-off' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][I][jk_rs485_sniffer:330]: SCANNING NEXT UNAVAILABLE...0x02 [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 timed stored data' [19:41:45][C][jk_rs485_bms.switch:070]: Icon: 'mdi:calendar-clock' [19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][D][uart_debug:114]: >>> 02:10:16:20:00:01:02:00:00:C2:01 [19:41:45][D][jk_rs485_sniffer:261]: ..........................................

My DIP switches and addresses in yaml file are the same. I have one master jk-bms and two slaves. I have shortened the code to just bms-0, 1 and 2. I didn't connect the talk pin as you said it is not mandatory.

Many thanks for helping

@txubelaxu
Copy link
Author

hi @dgbiuro,

that is anormal network data. Is it correctly connected to the network?

Talk pin is not mandatory if you want ESP to acting only in "listening mode".
It has been impossible for me to get "frame type 3rd" from master (because it is not possible to ask for that information to 0x00). It has been successed to asking for that information to any of the slaves.

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.

None yet

7 participants