3#if defined(USE_ESP32) || defined(USE_ESP8266)
13using packet_interface::PacketBuffer;
14using packet_interface::PacketMetaData;
18static constexpr uint32_t WARNING_INTERVAL_MS = 60000;
21 peer_address_t peer_address)
22 : packet_interface::PacketInterface(tx_buffer.
size()),
24 tx_buffer_(tx_buffer),
25 peer_address_(peer_address) {
33 this->
parent_->register_receive_handler(
this);
35 this->
parent_->register_broadcast_handler(
this);
36 this->
parent_->register_unknown_peer_handler(
this);
41 char peer_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
44 "ESP-NOW Packet Interface '%s':\n"
46 " Max Packet Size: %zu",
56 ESP_LOGW(TAG,
"%s: Packet of %zu bytes is larger than %zu", this->
name_, size, this->
max_packet_size_);
59 const uint8_t *payload;
60 if (data.is_contiguous()) {
61 payload = data.as_span().data();
71 this->delivery_failed_();
84 if (err == ESP_ERR_ESPNOW_NO_MEM || err == ESP_ERR_ESPNOW_NOT_INIT ||
99 ESP_LOGV(TAG,
"%s: Packet not acknowledged by the peer", this->
name_);
104 ESP_LOGW(TAG,
"%s: Packet not acknowledged by the peer; it may be off, out of range, or have another address",
112 ESP_LOGV(TAG,
"%s: Packet of %u bytes is larger than %zu, dropped", this->
name_, size, this->
max_packet_size_);
117 ESP_LOGW(TAG,
"%s: Packet of %u bytes is larger than %zu, dropped; set the same max_packet_size on both devices",
133 if (this->
parent_->get_auto_add_peer())
135 if (!ESPNOW_REPORTS_DESTINATION || memcmp(info.
des_addr, ESPNOW_BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0)
143 if (!this->
is_broadcast_() && memcmp(info.
src_addr, this->peer_address_.data(), ESP_NOW_ETH_ALEN) != 0)
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 receive_(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size)
uint32_t last_send_warning_ms_
bool on_broadcast(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
bool on_unknown_peer(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
peer_address_t peer_address_
bool send_to_interface(const packet_interface::PacketBuffer &data, const packet_interface::PacketMetaData &meta_data) override
bool on_receive(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
uint32_t last_size_warning_ms_
ESPNowComponent * parent_
const std::span< uint8_t > tx_buffer_
void send_failed_(esp_err_t err)
ESPNowPacketInterface(ESPNowComponent *parent, std::span< uint8_t > tx_buffer, peer_address_t peer_address)
bool is_broadcast_() const
void oversized_(uint16_t size)
void dump_config() override
uint32_t last_delivery_warning_ms_
A buffer class that efficiently represents a composite buffer with three sections:
size_t size() const
Get the total size of the buffer.
const size_t max_packet_size_
void on_receive_from_interface_(const PacketBuffer &data, const PacketMetaData &meta_data)
This function should be called by implementing classes with received data to be passed to any listene...
const LogString * espnow_error_to_str(esp_err_t error)
ESPHOME_LOG_TAG(TAG, "espnow")
Application App
Global storage of Application pointer - only one Application can exist.
char * format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase, colon separators)
rx_ctrl_t * rx_ctrl
Rx control info of ESPNOW packet.
uint8_t des_addr[ESP_NOW_ETH_ALEN]
Destination address of ESPNOW packet.
uint8_t src_addr[ESP_NOW_ETH_ALEN]
Source address of ESPNOW packet.