ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
espnow_types.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#if defined(USE_ESP32)
7
8#include <esp_err.h>
9#include <esp_now.h>
10
11#elif defined(USE_ESP8266)
12
13extern "C" {
14#include <c_types.h>
15#include <espnow.h>
16#include <user_interface.h>
17}
18
19#endif
20
21namespace esphome::espnow {
22
24 int8_t rssi; // Received Signal Strength Indicator (RSSI) of packet, unit: dBm
25 uint32_t timestamp; // Timestamp in microseconds when the packet was received, precise only if modem sleep or
26 // light sleep is not enabled
27};
28
29#if defined(USE_ESP32)
30
31// Handlers read rx_ctrl through the ESP-IDF type so existing lambdas keep compiling
32using rx_ctrl_t = wifi_pkt_rx_ctrl_t;
33static constexpr bool ESPNOW_REPORTS_DESTINATION = true;
34
35// Maximum size of the ESPNow event queues - must be a power of 2 for the lock-free queue
36static constexpr size_t MAX_ESP_NOW_SEND_QUEUE_SIZE = 16;
37static constexpr size_t MAX_ESP_NOW_RECEIVE_QUEUE_SIZE = 16;
38
39#elif defined(USE_ESP8266)
40
41// The NONOS SDK has no esp_err_t vocabulary. These are the ESP-IDF names and values the shared espnow code
42// uses, so it reads the same on both platforms.
43using esp_err_t = int32_t;
44
45static constexpr esp_err_t ESP_OK = 0;
46static constexpr esp_err_t ESP_FAIL = -1;
47static constexpr esp_err_t ESP_ERR_INVALID_MAC = 0x10B;
48static constexpr esp_err_t ESP_ERR_ESPNOW_BASE = 0x3064;
49static constexpr esp_err_t ESP_ERR_ESPNOW_NOT_INIT = ESP_ERR_ESPNOW_BASE + 1;
50static constexpr esp_err_t ESP_ERR_ESPNOW_ARG = ESP_ERR_ESPNOW_BASE + 2;
51static constexpr esp_err_t ESP_ERR_ESPNOW_NO_MEM = ESP_ERR_ESPNOW_BASE + 3;
52static constexpr esp_err_t ESP_ERR_ESPNOW_NOT_FOUND = ESP_ERR_ESPNOW_BASE + 5;
53static constexpr esp_err_t ESP_ERR_ESPNOW_INTERNAL = ESP_ERR_ESPNOW_BASE + 6;
54static constexpr esp_err_t ESP_ERR_ESPNOW_IF = ESP_ERR_ESPNOW_BASE + 8;
55
56inline const char *esp_err_to_name(esp_err_t err) { return err == ESP_OK ? "ESP_OK" : "ESP_FAIL"; }
57
58static constexpr uint8_t ESP_NOW_ETH_ALEN = 6;
59static constexpr uint8_t ESP_NOW_MAX_DATA_LEN = 250;
60
61// NOLINTNEXTLINE(readability-identifier-naming)
66
67using rx_ctrl_t = WifiPacketRxControl;
68// The SDK reports neither the destination address nor the signal strength of a received frame
69static constexpr bool ESPNOW_REPORTS_DESTINATION = false;
70
71// Half the ESP32 depth: the heap is far smaller and only one send is ever in flight
72static constexpr size_t MAX_ESP_NOW_SEND_QUEUE_SIZE = 8;
73static constexpr size_t MAX_ESP_NOW_RECEIVE_QUEUE_SIZE = 8;
74
75#endif
76
77} // namespace esphome::espnow
wifi_pkt_rx_ctrl_t rx_ctrl_t
const char * esp_err_to_name(esp_err_t err)
static void uint32_t