10static const char *
const TAG =
"espnow.transport";
15 PacketTransport::setup();
18 ESP_LOGE(TAG,
"ESPNow component not set");
23 ESP_LOGI(TAG,
"Registering ESP-NOW handlers, peer: %02X:%02X:%02X:%02X:%02X:%02X", this->
peer_address_[0],
28 this->
parent_->register_receive_handler(
this);
31 this->
parent_->register_broadcast_handler(
this);
36 ESP_LOGE(TAG,
"ESPNow component not set");
41 ESP_LOGW(TAG,
"Attempted to send empty packet");
45 if (buf.size() > ESPNOW_MAX_DATA_LEN) {
46 ESP_LOGE(TAG,
"Packet too large: %zu bytes (max %u)", buf.size(), (
unsigned) ESPNOW_MAX_DATA_LEN);
53 ESP_LOGW(TAG,
"Send failed: %d", err);
58bool ESPNowTransport::on_receive(
const ESPNowRecvInfo &info,
const uint8_t *data, uint16_t
size) {
59 ESP_LOGV(TAG,
"Received packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X", (
unsigned)
size, info.
src_addr[0],
62 if (data ==
nullptr ||
size == 0) {
63 ESP_LOGW(TAG,
"Received empty or null packet");
67 this->packet_buffer_.resize(
size);
68 memcpy(this->packet_buffer_.data(), data,
size);
69 this->process_(this->packet_buffer_);
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->packet_buffer_.resize(
size);
83 memcpy(this->packet_buffer_.data(), data,
size);
84 this->process_(this->packet_buffer_);
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_
uint8_t src_addr[ESP_NOW_ETH_ALEN]
Source address of ESPNOW packet.