Extension of Oxan van Leeuwen's generic stream server customized for exposing Pylontech BMS console over WIFI.
To allow remote connection to the BMS console, the UART connection has to be first set up with baud rate 1200, then a magic console wake-up string has to be entered and then the UART can be switched to target baude rate of 115200. (See the pylontech_setup() method, which is actually the only change to upstream Stream Server code.)
Original stream server's README is below.
Custom component for ESPHome to expose a UART stream over WiFi or Ethernet. Provides a serial-to-wifi bridge as known from ESPLink or ser2net, using ESPHome.
This component creates a TCP server listening on port 6638 (by default), and relays all data between the connected clients and the serial port. It doesn't support any control sequences, telnet options or RFC 2217, just raw data.
Requires ESPHome v2022.3.0 or newer.
external_components:
- source: github://oxan/esphome-stream-server
stream_server:
You can set the UART ID and port to be used under the stream_server
component.
uart:
id: uart_bus
# add further configuration for the UART here
stream_server:
uart_id: uart_bus
port: 1234
The server provides a binary sensor that signals whether there currently is a client connected:
binary_sensor:
- platform: stream_server
connected:
name: Connected
It also provides a numeric sensor that indicates the number of connected clients:
sensor:
- platform: stream_server
connection_count:
name: Number of connections
It is possible to define multiple stream servers for multiple UARTs simultaneously:
uart:
- id: uart1
# ...
- id: uart2
# ...
stream_server:
- uart_id: uart1
port: 1234
- uart_id: uart2
port: 1235
The stream server has an internal buffer into which UART data is read before it is transmitted over TCP. The size of
this buffer can be changed using the buffer_size
option, and must be a power of two. Increasing the buffer size above
the default of 128 bytes can help to achieve optimal throughput, and is especially helpful when using high baudrates. It
can also be necessary to increase the rx_buffer_size
option of the UART itself.
stream_server:
buffer_size: 2048