ESPHome UART forwarding

I’m currently trying to get my Autonomous.ai desk integrated into Home Assistant, using ESPHome.
The Connection between the control panel and the desk controller is UART, my current progress so far:

Using this repository I was able to get a working ESPHome config going, allowing me to control the desk. When the ESP is not connected, I can also control the desk from the control panel, but as soon as I connect the ESP again, the control panel doesn’t work anymore.
I’m actually not that surprised, seeing as UART is not designed to work with more than 2 devices at the same time.

What I’m thinking of doing now, is using the ESP as a forward node for the UART messages, using 2 UART busses on the ESP itself. 1 bus connected to the control panel, the other to the desk. It seems I couldn’t find any examples on this yet, maybe nobody has done this before?

I think I should create a custom UART component (Custom UART Device — ESPHome), that depends on both UART busses, that would allow me to read data and write it to the other bus?

2 Likes

Hello.
I am currently struggling with something similar.
Have You made any progres ?

1 Like

Take a look at ssieb’s “Man In the Middle”.

You can forward and inject UART.

I’ve also had some success without using a custom component using something similar to @mulcmu 's UART read approach.

uart:
  - id: uart_p #pendant side
    rx_pin: GPIO16  #Green wire | Transmits commands from pendant to robot via mitm uart_p. Wire confusingly (?) labelled RX on pendant!!!! 
    # tx_pin: GPIO17  #Yellow wire | Fowards messages from the robot to the pendant. Note: not used. Bypass used.
    baud_rate: 9600
    data_bits: 8
    stop_bits: 2
    parity: NONE
    rx_buffer_size: 256
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 1ms
        # delimiter: "N"
      sequence:  
         #Used.
        - uart.write: #Write rx to tx.
            id: uart_r
            data: !lambda return bytes ;
        - lambda: 
            UARTDebug::log_string(direction , bytes);

  - id: uart_r #robot_side
    rx_pin: GPIO18 #Yellow wire tranmits data from robot to mitm rx uart_r
    tx_pin: GPIO19 #Green wire transmits/forwards commands from the pendant and mitm to the robot
    baud_rate: 9600
    data_bits: 8
    stop_bits: 2
    parity: NONE
    rx_buffer_size: 256
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 1ms
      sequence:
        #Not Used.
        # - uart.write:
            # #Write rx to tx.
            # id: uart_p
            # data: !lambda return bytes ;
        - lambda: UARTDebug::log_string(direction, bytes);

1 Like

I checked the source code, the structure of this code is so simple, but the things it can do are amazing.

1 Like