11static const char *
const TAG =
"espnow.transport";
16 PacketTransport::setup();
19 ESP_LOGE(TAG,
"ESPNow component not set");
24 ESP_LOGI(TAG,
"Registering ESP-NOW handlers");
29 this->
parent_->register_received_handler(
this);
32 this->
parent_->register_broadcasted_handler(
this);
37 ESP_LOGE(TAG,
"ESPNow component not set");
42 ESP_LOGW(TAG,
"Attempted to send empty packet");
46 if (buf.size() > ESP_NOW_MAX_DATA_LEN) {
47 ESP_LOGE(TAG,
"Packet too large: %zu bytes (max %d)", buf.size(), ESP_NOW_MAX_DATA_LEN);
54 ESP_LOGW(TAG,
"Send failed: %d", err);
59bool ESPNowTransport::on_received(
const ESPNowRecvInfo &info,
const uint8_t *data, uint8_t size) {
60 ESP_LOGV(TAG,
"Received packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X", size, info.
src_addr[0],
63 if (data ==
nullptr || size == 0) {
64 ESP_LOGW(TAG,
"Received empty or null packet");
68 this->packet_buffer_.resize(size);
69 memcpy(this->packet_buffer_.data(), data, size);
70 this->process_(this->packet_buffer_);
74bool ESPNowTransport::on_broadcasted(
const ESPNowRecvInfo &info,
const uint8_t *data, uint8_t size) {
75 ESP_LOGV(TAG,
"Received broadcast packet of size %u from %02X:%02X:%02X:%02X:%02X:%02X", size, info.
src_addr[0],
78 if (data ==
nullptr || size == 0) {
79 ESP_LOGW(TAG,
"Received empty or null broadcast packet");
83 this->packet_buffer_.resize(size);
84 memcpy(this->packet_buffer_.data(), data, size);
85 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.