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://wolffshots/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: 1234The server provides a binary sensor that signals whether there currently is a client connected:
binary_sensor:
- platform: stream_server
connected:
name: ConnectedIt also provides a numeric sensor that indicates the number of connected clients:
sensor:
- platform: stream_server
connection_count:
name: Number of connectionsIt 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: 1235The 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: 2048The original project from oxan has been extended to include a whitelist of IPs that the server will connect to. This is not an ironclad protection against ne'er-do-wells but increases the barrier to entry for messing with your serial devices.
One similar thing you could do is a similar change to add a "signing" field to the config so IPs need to do something extra to connect but that is out of scope for my changes.
To include a whitelist you would do the following:
uart:
id: uart_bus
stream_server:
uart_id: uart_bus
port: 1234
whitelist:
- 192.168.1.100
- 192.168.1.102If you want to debug why it wouldn't be connecting then you can enable debug logs with
logger:
baud_rate: 0
level: debugAnd then when a device attempts to connect and is denied you should see a log like this from the component:
[W][stream_server:090]: Client 192.168.1.105 is not whitelisted and will be disconnected.
[D][stream_server:072]: Current whitelist is:
[D][stream_server:074]: '192.168.1.101'
[D][stream_server:074]: '192.168.1.102'