How do I? - ESP32 - RS232 - Split hex buffer to ascii

I have serial buffer - RS232 to PACE BMS - that i need to split and then convert to ascii / decimal values.
I do not understand how to split the receive buffer.
Here are two examples of the data i receive and how i need to split them.

<- Incoming data:  b'~25014600602850313653323030412D4132313038342D312E3035F57F\r'
BMS Version: P16S200A-A21084-1.05           # BYTE 8 - 27
<- Incoming data:  b'~25014600400C4CF236B14E20FAF1\r'
Pack Remaining Capacity: 196980 mAh         # BYTE 7-8 - (0x4CF2)*10
Pack Full Capacity: 140010 mAh              # BYTE 9-10 - (0x36B1)*10
Pack Design Capacity: 200000 mAh            # BYTE 11-12 - (0x4E20)*10
Pack SOC: 140.69 %                          Calculated - (Remaining Capacity / Full Capacity)*100
Pack SOH: 70.0 %                            Calculated - (Full Capacity / Design Capacity) *100
My UART settings is as follow:
# ##############################################################
# Battery RS232 UART Setup
# #############################################################
uart:
  id: uart_2
  baud_rate: 9600
  tx_pin: GPIO17
  rx_pin: GPIO16
  debug:
    direction: RX
    dummy_receiver: true
    after:
      delimiter: "\r"
    sequence:
      - lambda: |-
          
          UARTDebug::log_string(direction, bytes);

Each of the incoming date has different lengths, so i can use.

if (bytes.size()==xx) {
            "Split buffer"
          }

This is the part i do not understand on how to.
If someone can point me on how do i split the bytes, that will help.

did you get to read all the data from the Pace BMS, I am about to start researching on how to get the data from the BMS into HA. Any tip would be a great help

Hi Darryl

Yes, No, Sort of…

I had some buffer issues while trying to do this on my ESP32.

In the meantime, i uses a different approach until i can get this working direct from ESPHome.

  1. Setup an ESP32 as a Stream Server. configured your ESP the way you want it to be and at the end, paste this code.
external_components:
  - source: github://oxan/esphome-stream-server
 
# ##############################################################
# Battery RS232 UART Setup
# #############################################################
uart:
  id: bat_uart
  baud_rate: 9600
  tx_pin: GPIO17
  rx_pin: GPIO16
 
stream_server:
   uart_id: bat_uart
   port: 5000
   buffer_size: 512
 
binary_sensor:
  - platform: stream_server
    connected:
      name: Connected
  1. Then depending on what you want, you can install either: - Use the “dev” one
    a. BMSPace - mqtt into HA
    b. BMSPace - Direct into Influx

I am planning to move to influx this weekend and then take my time to see where my coding issues are on my ESPHome code.

1 Like