Hi Guys,
I need a bit help in case of a UART string return.
To readout data from a RS485 I have to send a command like
~22014A42E00201FD28\r
and get back an answer like
~22014A00E0C601221B14B8100CF60CF00CF50CF40CF40CF30CF30CF20CF20CF40CF50CF20CF50CF30CF20CF201180118010E040118011801180118FDD500000064002710221B0016000000020000000000230000000000000000000000000000000000000000000000D48A\r
Out of this answer I’d like to extract for example: Position 10 to 12
and convert this HEX data to decimal data
Which means, if I convert:
hex: 0CF3 to decimal: 3315
and collect it in a sensor
I’m not good in custom_uart components, so I tried to solve it like this in my YAML
substitutions:
tx_pin: GPIO18
rx_pin: GPIO19
uart:
- id: uart_0
baud_rate: 9600
tx_pin: ${tx_pin}
rx_pin: ${rx_pin}
stop_bits: 1
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: “\r\n”
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
std::string str(bytes.begin(), bytes.end());
interval:
- interval: 30s
then:
- uart.write: “~22014A42E00201FD28\r”
I receive the string back … but I don’t know how to extract the exact position of the HEX and than convert it to decimal
Thought there should be a function like
split(“string”, “position1”,“position2”)
and than with
format_hex_pretty()
to format it to decimal numbers?
can somebody give me support ?
thanks to all