3#if defined(USE_ESP32) || defined(USE_ESP8266)
17 PacketTransport::setup();
20 ESP_LOGE(TAG,
"ESPNow component not set");
25 ESP_LOGI(TAG,
"Registering ESP-NOW handlers, peer: %02X:%02X:%02X:%02X:%02X:%02X", this->
peer_address_[0],
30 this->
parent_->register_receive_handler(
this);
33 this->
parent_->register_broadcast_handler(
this);
38 ESP_LOGE(TAG,
"ESPNow component not set");
43 ESP_LOGW(TAG,
"Attempted to send empty packet");
47 if (buf.size() > ESPNOW_MAX_DATA_LEN) {
48 ESP_LOGE(TAG,
"Packet too large: %zu bytes (max %u)", buf.size(), (
unsigned) ESPNOW_MAX_DATA_LEN);
55 ESP_LOGW(TAG,
"Send failed: %d", err);
60bool ESPNowTransport::on_receive(
const ESPNowRecvInfo &info,
const uint8_t *data, uint16_t
size) {
61 ESP_LOGV(TAG,
"Received packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X", (
unsigned)
size, info.
src_addr[0],
64 if (data ==
nullptr ||
size == 0) {
65 ESP_LOGW(TAG,
"Received empty or null packet");
69 this->process_(std::span<const uint8_t>(data,
size));
73bool ESPNowTransport::on_broadcast(
const ESPNowRecvInfo &info,
const uint8_t *data, uint16_t
size) {
74 ESP_LOGV(TAG,
"Received broadcast packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X", (
unsigned)
size,
77 if (data ==
nullptr ||
size == 0) {
78 ESP_LOGW(TAG,
"Received empty or null broadcast packet");
82 this->process_(std::span<const uint8_t>(data,
size));
void mark_failed()
Mark this component as failed.
ESPNowComponent * parent_
void send_packet(const std::vector< uint8_t > &buf) const override
bool should_send() override
peer_address_t peer_address_
ESPHOME_LOG_TAG(TAG, "espnow")
uint8_t src_addr[ESP_NOW_ETH_ALEN]
Source address of ESPNOW packet.