11static const char *
const TAG =
"espnow.transport";
16 PacketTransport::setup();
19 ESP_LOGE(TAG,
"ESPNow component not set");
25 "Registering ESP-NOW handlers\n"
26 "Peer address: %02X:%02X:%02X:%02X:%02X:%02X",
31 this->
parent_->register_received_handler(
this);
34 this->
parent_->register_broadcasted_handler(
this);
39 ESP_LOGE(TAG,
"ESPNow component not set");
44 ESP_LOGW(TAG,
"Attempted to send empty packet");
48 if (buf.size() > ESP_NOW_MAX_DATA_LEN) {
49 ESP_LOGE(TAG,
"Packet too large: %zu bytes (max %d)", buf.size(), ESP_NOW_MAX_DATA_LEN);
56 ESP_LOGW(TAG,
"Send failed: %d", err);
61bool ESPNowTransport::on_received(
const ESPNowRecvInfo &info,
const uint8_t *data, uint8_t
size) {
62 ESP_LOGV(TAG,
"Received packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X",
size, info.
src_addr[0],
65 if (data ==
nullptr ||
size == 0) {
66 ESP_LOGW(TAG,
"Received empty or null packet");
70 this->packet_buffer_.resize(
size);
71 memcpy(this->packet_buffer_.data(), data,
size);
72 this->process_(this->packet_buffer_);
76bool ESPNowTransport::on_broadcasted(
const ESPNowRecvInfo &info,
const uint8_t *data, uint8_t
size) {
77 ESP_LOGV(TAG,
"Received broadcast packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X",
size, info.
src_addr[0],
80 if (data ==
nullptr ||
size == 0) {
81 ESP_LOGW(TAG,
"Received empty or null broadcast packet");
85 this->packet_buffer_.resize(
size);
86 memcpy(this->packet_buffer_.data(), data,
size);
87 this->process_(this->packet_buffer_);
virtual 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_
Providing packet encoding functions for exchanging data with a remote host.
uint8_t src_addr[ESP_NOW_ETH_ALEN]
Source address of ESPNOW packet.