13static constexpr uint32_t DROP_LOG_INTERVAL_MS = 5000;
15void TcpUart::setup() {
17#ifdef USE_SOCKET_TCP_LISTENER
20#ifdef USE_BINARY_SENSOR
21 PUBLISH_STATE(this->connected_binary_sensor_,
false);
24 PUBLISH_STATE(this->disconnects_sensor_, 0);
28void TcpUart::dump_config() {
32 " Reconnect Interval: %" PRIu32
"ms",
33 this->
server_ ? LOG_STR_LITERAL(
"Listen") : LOG_STR_LITERAL(
"Host"),
34 this->
server_ ? LOG_STR_LITERAL(
"*") : this->
link_.
host(), this->link_.port(),
35 this->link_.reconnect_interval());
36#ifdef USE_SOCKET_TCP_LISTENER
39#ifdef USE_BINARY_SENSOR
40 LOG_BINARY_SENSOR(
" ",
"Connected", this->connected_binary_sensor_);
43 LOG_SENSOR(
" ",
"Disconnects", this->disconnects_sensor_);
47void TcpUart::on_shutdown() {
49#ifdef USE_SOCKET_TCP_LISTENER
61#ifdef USE_BINARY_SENSOR
62 PUBLISH_STATE(this->connected_binary_sensor_, up);
66 if (!up && this->disconnects_sensor_ !=
nullptr) {
68 this->disconnects_sensor_->publish_state(this->
disconnects_);
92 this->rx_end_ +=
static_cast<uint16_t
>(
count);
97#ifdef USE_SOCKET_TCP_LISTENER
120void TcpUart::write_array(
const uint8_t *data,
size_t len) {
125 ESP_LOGW(TAG,
"%s, dropped %u bytes",
126 this->
link_.
connected() ? LOG_STR_LITERAL(
"TX buffer full") : LOG_STR_LITERAL(
"Not connected"),
127 static_cast<unsigned>(
len - queued));
133bool TcpUart::peek_byte(uint8_t *data) {
141bool TcpUart::read_array(uint8_t *data,
size_t len) {
142 if (this->available() <
len) {
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
const char * host() const
bool flush_tx()
Send the front of the buffer; true once it is empty.
void close()
Close without scheduling a reconnect (shutdown).
ssize_t read(uint8_t *buf, size_t len)
Returns bytes moved, 0 when nothing can move now, -1 when the link dropped.
void begin(const char *tag)
Call from setup(). tag names this link's log lines.
size_t queue(const uint8_t *data, size_t len)
Copy into the outgoing buffer; returns how many bytes fit.
void poll()
Connect state machine; call every loop while acting as a client.
void poll(TcpClientLink &link, bool may_accept)
Server state machine; call every loop.
void begin(const char *tag)
Call from setup(); tag names the log lines.
void dump_config() const
One config line per allowed network.
socket::TcpClientLink link_
static constexpr size_t RX_BUFFER_SIZE
uint32_t last_drop_log_ms_
uint8_t rx_[RX_BUFFER_SIZE]
socket::TcpListener listener_
ESPHOME_LOG_TAG(TAG, "tcp_uart")
UARTFlushResult
Result of a flush() call.
@ UART_FLUSH_RESULT_SUCCESS
Confirmed: all bytes left the TX FIFO.
@ UART_FLUSH_RESULT_FAILED
Confirmed: driver or hardware error.
@ UART_FLUSH_RESULT_TIMEOUT
Confirmed: timed out before TX completed.
Application App
Global storage of Application pointer - only one Application can exist.