14void UartTcp::setup() {
16#ifdef USE_SOCKET_TCP_LISTENER
19#ifdef USE_BINARY_SENSOR
20 PUBLISH_STATE(this->connected_binary_sensor_,
false);
23 PUBLISH_STATE(this->disconnects_sensor_, 0);
27void UartTcp::dump_config() {
31 " Reconnect Interval: %" PRIu32
"ms\n"
32 " Timeout: %" 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(), this->link_.idle_timeout());
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 UartTcp::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_);
84 size_t want = std::min(room,
sizeof(tmp));
103 size_t n = std::min(left,
sizeof(dump));
118void UartTcp::loop() {
119#ifdef USE_SOCKET_TCP_LISTENER
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.
void close()
Close without scheduling a reconnect (shutdown).
void tx_commit(size_t len)
void poll()
Connect state machine; call every loop while acting as a client.
void check_idle()
Close when no byte has moved for idle_timeout(). Inline: the close runs only once that time has passe...
void note_io()
Restart the idle clock.
void begin(const char *tag)
Call from setup(). tag names this link's log lines.
ssize_t read(uint8_t *buf, size_t len)
Returns bytes moved, 0 when nothing can move now, -1 when the link dropped.
const char * host() const
bool flush_tx()
Send the front of the buffer; true once it is empty.
uint8_t * tx_tail()
Direct access to the buffer's free tail.
void begin(const char *tag)
Call from setup(); tag names the log lines.
void dump_config() const
One config line per allowed network.
void poll(TcpClientLinkBase &link, bool may_accept)
Server state machine; call every loop.
size_t paced_write_room(uint32_t last_write_ms)
optional< std::array< uint8_t, N > > read_array()
void write_array(const uint8_t *data, size_t len)
static constexpr size_t DISCARD_CHUNK
socket::TcpClientLink link_
static constexpr size_t READ_CHUNK
socket::TcpListener listener_
ESPHOME_LOG_TAG(TAG, "uart_tcp")
Application App
Global storage of Application pointer - only one Application can exist.