### Set up ESP-NOW encryption with PMK and LMK for multiple peers Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Configures ESP-NOW encryption for three devices (A, B, C) by setting a shared PMK and per-peer LMKs. Each device must add the other as a peer with `encrypt = true` and the same LMK to exchange encrypted messages. The example shows using LMK1 for A-B and B-C pairs and LMK2 for A-C, demonstrating that LMKs can differ per pair. ```c uint8_t PMK[] = {0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F, 0x7A, 0x8B, 0x9C, 0xAD, 0xBE, 0xCF, 0xDA, 0xEB, 0xFC, 0x0D}; uint8_t LMK1[] = {0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}; uint8_t LMK2[] = {0xFB, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}; // On sketches for Device A, B, C esp_now_init(); esp_now_set_pmk(PMK); // On device A adding B as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_B, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK1, 16); esp_now_add_peer(&peerInfo); // On device B adding A as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_A, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK1, 16); esp_now_add_peer(&peerInfo); /* Now A and B can talk in encrypted way using ESP-NOW API */ /////////////////////////////////////////////////////////////////////// // On device A adding C as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_C, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK2, 16); esp_now_add_peer(&peerInfo); // On device C adding A as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_A, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK2, 16); esp_now_add_peer(&peerInfo); /* Now A and C can talk in encrypted way using ESP-NOW API */ /////////////////////////////////////////////////////////////////////// // On device B adding C as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_C, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK1, 16); esp_now_add_peer(&peerInfo); // On device C adding B as a peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, MAC_B, 6); peerInfo.channel = some_channel; peerInfo.encrypt = true; memcpy(peerInfo.lmk, LMK1, 16); esp_now_add_peer(&peerInfo); /* Now B and C can talk in encrypted way using ESP-NOW API */ /** Bottom line: * A uses LMK1 to talk to B and LMK2 to talk to C * B uses LMK1 to talk to A and LMK1 to talk to C * C uses LMK2 to talk to A and LMK1 to talk to B */ ``` -------------------------------- ### Format and print MAC address with EASYMAC macros Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Macros to format and print a MAC address in upper case. The example shows using EASYMAC2STR and EASYMACSTR with the MONITOR logging macro. ```c #define EASYMAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define EASYMACSTR "%02X:%02X:%02X:%02X:%02X:%02X" // How to use in code uint8_t some_MAC[] = {0xCD, 0x56, 0x47, 0xFC, 0xAF, 0xB3}; MONITOR(TAG, "Mac: " EASYMACSTR " This was some MAC address" , EASYMAC2STR(some_MAC)); ``` -------------------------------- ### Include EasyEspNow.h Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Include the EasyEspNow library header in a main sketch to use its API. ```c #include ``` -------------------------------- ### EasyEspNow Core Functions Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Core functions of the EasyEspNow library. Note that if synchronous send is enabled, the TX queue size defaults to 1. The PMK must be 16 bytes long. ```c begin(channel, phy_interface, tx_q_size, synch_send) // begin everything, set channel, wifi interface, tx queue size, synchronous send. If synch. send true => tx size will default to 1 setPMK(pmk_to_set) // set Primary Master Key - PMK, must have length of 16 bytes getPMK(pmk_buff) // get PMK, copy content into the buffer that user provided stop() // stop everything easy_send_error_t send(dstAddress, payload, payload_len) // to enqueu message for send with specific length to destination address easy_send_error_t sendBroadcast(payload, payload_len) // just a call to send() with Broadcast address as destination enableTXTask(enable) // enable or disable the TX task responsible for exhausting TX queu and sending the messages readyToSendData() // readinnes to send if TX has space, if full not ready waitForTXQueueToBeEmptied() // blocking function to wait until TX queue is empty onDataReceived(frame_rcvd_cb) // to register user defined callback function upon receiving data. Higher level onDataSent(frame_sent_cb) // to register user defined callback function upon sending data. Higher level ``` -------------------------------- ### Add peer with encryption condition in EasyEspNow Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Shows how EasyEspNow adds a peer, deciding whether to encrypt based on LMK presence, multicast/broadcast MAC, and PMK being set. The peer_info fields are configured before calling esp_now_add_peer(). ```c bool condition_to_not_encrypt = (lmk == nullptr || peer_addr_to_add[0] & 0x01 || pmk_is_set == false); // peer can be in a different interface from the home (this station) and still receive the message. esp_now_peer_info_t peer_info; memset(&peer_info, 0, sizeof(peer_info)); // set everything to zero memcpy(peer_info.peer_addr, peer_addr_to_add, MAC_ADDR_LEN); peer_info.ifidx = wifi_phy_interface; // this does not really matter to set it the same as the peer. This is relevant to the home station WiFi mode and interface. ESP_ERR_ESPNOW_IF peer_info.channel = wifi_primary_channel; if (condition_to_not_encrypt) peer_info.encrypt = false; else { peer_info.encrypt = true; memcpy(peer_info.lmk, lmk, KEY_LENGTH); } err = esp_now_add_peer(&peer_info); ``` -------------------------------- ### Core Functions Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Core functions for initializing, sending, and receiving data with the EasyEspNow library. ```APIDOC ## [C] begin(channel, phy_interface, tx_q_size, synch_send) ### Description Initializes the EasyEspNow library, setting the WiFi channel, PHY interface, TX queue size, and whether sends are synchronous. If synchronous send is enabled, the TX queue size defaults to 1. ### Method C function call ### Parameters - **channel** (uint8_t) - Required - WiFi channel to use. - **phy_interface** (wifi_interface_t) - Required - WiFi interface (e.g., WIFI_IF_STA or WIFI_IF_AP). - **tx_q_size** (uint8_t) - Required - Size of the TX queue. - **synch_send** (bool) - Required - If true, sends are synchronous and TX queue size defaults to 1. ### Request Example ```c begin(1, WIFI_IF_STA, 10, false); ``` ### Response No return value. ``` ```APIDOC ## [C] setPMK(pmk_to_set) ### Description Sets the Primary Master Key (PMK) for encrypted communication. The PMK must be exactly 16 bytes long. ### Method C function call ### Parameters - **pmk_to_set** (const uint8_t*) - Required - Pointer to a 16-byte PMK. ### Request Example ```c uint8_t pmk[16] = {0x01, 0x02, ...}; setPMK(pmk); ``` ### Response No return value. ``` ```APIDOC ## [C] getPMK(pmk_buff) ### Description Retrieves the current PMK and copies it into the provided buffer. ### Method C function call ### Parameters - **pmk_buff** (uint8_t*) - Required - Buffer where the PMK will be copied. ### Request Example ```c uint8_t pmk[16]; getPMK(pmk); ``` ### Response No return value. ``` ```APIDOC ## [C] stop() ### Description Stops all EasyEspNow operations and releases resources. ### Method C function call ### Parameters None. ### Request Example ```c stop(); ``` ### Response No return value. ``` ```APIDOC ## [C] send(dstAddress, payload, payload_len) ### Description Enqueues a message for sending to a specific destination address with a given payload length. Returns an error code indicating success or failure. ### Method C function call ### Parameters - **dstAddress** (uint8_t*) - Required - MAC address of the destination peer. - **payload** (uint8_t*) - Required - Pointer to the data to send. - **payload_len** (size_t) - Required - Length of the payload. ### Request Example ```c uint8_t dest[6] = {0xAA, 0xBB, ...}; const char* msg = "Hello"; send(dest, (uint8_t*)msg, strlen(msg)); ``` ### Response Returns `easy_send_error_t` indicating success or error. ``` ```APIDOC ## [C] sendBroadcast(payload, payload_len) ### Description Sends a message to the broadcast address. This is a convenience wrapper around `send()`. ### Method C function call ### Parameters - **payload** (uint8_t*) - Required - Pointer to the data to send. - **payload_len** (size_t) - Required - Length of the payload. ### Request Example ```c const char* msg = "Broadcast"; sendBroadcast((uint8_t*)msg, strlen(msg)); ``` ### Response Returns `easy_send_error_t` indicating success or error. ``` ```APIDOC ## [C] enableTXTask(enable) ### Description Enables or disables the TX task responsible for exhausting the TX queue and sending messages. ### Method C function call ### Parameters - **enable** (bool) - Required - Set to true to enable the TX task, false to disable. ### Request Example ```c enableTXTask(true); ``` ### Response No return value. ``` ```APIDOC ## [C] readyToSendData() ### Description Checks if the TX queue has space available for sending data. Returns true if ready, false if the queue is full. ### Method C function call ### Parameters None. ### Request Example ```c if (readyToSendData()) { // send data } ``` ### Response Returns `bool` - true if ready to send, false otherwise. ``` ```APIDOC ## [C] waitForTXQueueToBeEmptied() ### Description Blocks until the TX queue is empty. ### Method C function call ### Parameters None. ### Request Example ```c waitForTXQueueToBeEmptied(); ``` ### Response No return value. ``` ```APIDOC ## [C] onDataReceived(frame_rcvd_cb) ### Description Registers a user-defined callback function that is called when data is received. ### Method C function call ### Parameters - **frame_rcvd_cb** (function pointer) - Required - Callback function to handle received data. ### Request Example ```c void onReceive(const uint8_t* mac, const uint8_t* data, size_t len) { // handle data } onDataReceived(onReceive); ``` ### Response No return value. ``` ```APIDOC ## [C] onDataSent(frame_sent_cb) ### Description Registers a user-defined callback function that is called when data is sent. ### Method C function call ### Parameters - **frame_sent_cb** (function pointer) - Required - Callback function to handle sent confirmation. ### Request Example ```c void onSent(const uint8_t* mac, esp_now_send_status_t status) { // handle status } onDataSent(onSent); ``` ### Response No return value. ``` -------------------------------- ### Define EasyEspNow log levels Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Defines the log level constants used by the EasyEspNow debugger. Set the log level in your main sketch; LOG_NONE disables logging. ```c // Define the log levels #define LOG_NONE 0 // to not output any logs #define LOG_MONITOR 1 #define LOG_ERROR 2 #define LOG_WARNING 3 #define LOG_INFO 4 #define LOG_DEBUG 5 #define LOG_VERBOSE 6 ``` -------------------------------- ### ESP-NOW miscellaneous utility functions Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Utility functions for ESP-NOW: error name lookup, interface autoselection, MAC formatting/printing, version/channel/address/message-length getters, random MAC generation, and on-the-fly channel switching. The channel switch updates peer info but may cause message loss; use with caution. ```c const char *easySendErrorToName(easy_send_error_t send_error) // returns the send error as a char array wifi_interface_t autoselect_if_from_mode(wifi_mode_t mode, bool apstaMOD_to_apIF = true) // helper function to determine wifi interface depending on wifi mode char *easyMac2Char(const uint8_t *some_mac, size_t len = MAC_ADDR_LEN, bool upper_case = true) // return a MAC as a char array for easy print, if any issue will default to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} easyPrintMac2Char(const uint8_t *some_mac, size_t len = MAC_ADDR_LEN, bool upper_case = true) // just print the MAC, if any issue will default to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} getEspNowVersion() // esp-now version getPrimaryChannel() // returns channel in which wifi radio is on, same channel in which esp-now frames will be sent wifi_second_chan_t getSecondaryChannel() // secondary channel getAddressLength() // length of a MAC address (6 because there are 6 octets in a MAC) getMaxMessageLength() // max length of a message that can be delivered via ESP-NOW getDeviceMACAddress() // return MAC address of this device uint8_t *generateRandomMAC(bool local = true, bool unicast = true) // generate random mac, can be local/global unicast/multicast switchChannel(uint8_t primary, wifi_second_chan_t second = WIFI_SECOND_CHAN_NONE) // switches operating wifi channel on the fly, updates channel for all peers in their info. The switch of channel for this base station and for the peers it holds may result in messages not being sent to destination or received from source peers due to channel change. Handle carefully. ``` -------------------------------- ### Synchronous send() with delay to avoid packet drop Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Use synchronous mode to guarantee no packet drop when sending. The delay must be larger than the TX exhaust rate (13us) to avoid the warning 'Synchronous send mode. Waiting for free space in TX Queue'. ```c /* SYNCHRONOUS MODE */ // assures no packet drop when sending void loop() { String data = "Hello World"; // Here is doing only Broadcasting easy_send_error_t code = easyEspNow.send(ESPNOW_BROADCAST_ADDRESS, (uint8_t *)data.c_str(), data.length()); MONITOR(MAIN_TAG, "Last send return code value: %s\n", easyEspNow.easySendErrorToName(code)); // add some delay to simulate longer code run // if this is faster than TX exhaust rate (i have set it in the code to be `vTaskDelay(pdMS_TO_TICKS(13)` // you will get this: [115535] [WARNING] [EASY_ESP_NOW]: Synchronous send mode. Waiting for free space in TX Queue // otherwise no WARNING. vTaskDelay(pdMS_TO_TICKS(13)); } ``` -------------------------------- ### EasyEspNow Peer Management Functions Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Peer management functions. The overloaded deletePeer() can delete the oldest peer and optionally keep the broadcast address. getPeerList() returns the complete peer list by value. ```c addPeer(peer_addr_to_add, lmk = nullptr) // add peer with provided MAC address, and encrypts it with LMK deletePeer(peer_addr_to_delete); // delete peer with provided MAC address uint8_t *deletePeer(keep_broadcast_addr = true) // this deletes the oldest peer and returns its MAC. It can delete the broadcast peer too if it is the oldest and `keep_broadcast_addr = false` peer_t *getPeer(peer_addr_to_get, esp_now_peer_info_t &peer_info) // returns peer_t structure for the peer and puts the info in the peer_info structure peerExists(peer_addr) // check if peer exists or no updateLastSeenPeer(peer_addr) // update last seen value for peer with MAC address countPeers(CountPeers count_type) // count peers, total | unencrypted | encrypted printPeerList() // prints the peer list, used more for debugging peer_list_t getPeerList() // this will return the complete peer_list structure for the user's convinience. returns it by value ``` -------------------------------- ### Peer Management Functions Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Functions for managing peers, including adding, deleting, retrieving, and counting peers. ```APIDOC ## [C] addPeer(peer_addr_to_add, lmk = nullptr) ### Description Adds a peer with the provided MAC address. If an LMK is provided, the peer is encrypted with it. ### Method C function call ### Parameters - **peer_addr_to_add** (uint8_t*) - Required - MAC address of the peer to add. - **lmk** (const uint8_t*) - Optional - Local Master Key for encryption. Defaults to nullptr (no encryption). ### Request Example ```c uint8_t peerMac[6] = {0xAA, 0xBB, ...}; addPeer(peerMac); ``` ### Response No return value. ``` ```APIDOC ## [C] deletePeer(peer_addr_to_delete) ### Description Deletes a peer with the provided MAC address. ### Method C function call ### Parameters - **peer_addr_to_delete** (uint8_t*) - Required - MAC address of the peer to delete. ### Request Example ```c uint8_t peerMac[6] = {0xAA, 0xBB, ...}; deletePeer(peerMac); ``` ### Response No return value. ``` ```APIDOC ## [C] deletePeer(keep_broadcast_addr = true) ### Description Deletes the oldest peer and returns its MAC address. If `keep_broadcast_addr` is false, the broadcast peer can be deleted if it is the oldest. ### Method C function call ### Parameters - **keep_broadcast_addr** (bool) - Optional - If true, the broadcast peer will not be deleted. Defaults to true. ### Request Example ```c uint8_t* deletedMac = deletePeer(); ``` ### Response Returns `uint8_t*` - MAC address of the deleted peer. ``` ```APIDOC ## [C] getPeer(peer_addr_to_get, esp_now_peer_info_t &peer_info) ### Description Returns the `peer_t` structure for the specified peer and fills the provided `esp_now_peer_info_t` structure with peer information. ### Method C function call ### Parameters - **peer_addr_to_get** (uint8_t*) - Required - MAC address of the peer to retrieve. - **peer_info** (esp_now_peer_info_t&) - Required - Reference to a structure that will be filled with peer info. ### Request Example ```c uint8_t peerMac[6] = {0xAA, 0xBB, ...}; esp_now_peer_info_t info; peer_t* peer = getPeer(peerMac, info); ``` ### Response Returns `peer_t*` - Pointer to the peer structure, or nullptr if not found. ``` ```APIDOC ## [C] peerExists(peer_addr) ### Description Checks if a peer with the given MAC address exists. ### Method C function call ### Parameters - **peer_addr** (uint8_t*) - Required - MAC address to check. ### Request Example ```c uint8_t peerMac[6] = {0xAA, 0xBB, ...}; if (peerExists(peerMac)) { // peer exists } ``` ### Response Returns `bool` - true if peer exists, false otherwise. ``` ```APIDOC ## [C] updateLastSeenPeer(peer_addr) ### Description Updates the last seen timestamp for the peer with the given MAC address. ### Method C function call ### Parameters - **peer_addr** (uint8_t*) - Required - MAC address of the peer to update. ### Request Example ```c uint8_t peerMac[6] = {0xAA, 0xBB, ...}; updateLastSeenPeer(peerMac); ``` ### Response No return value. ``` ```APIDOC ## [C] countPeers(CountPeers count_type) ### Description Counts the number of peers based on the specified count type (total, unencrypted, or encrypted). ### Method C function call ### Parameters - **count_type** (CountPeers) - Required - Enum indicating which peers to count: total, unencrypted, or encrypted. ### Request Example ```c uint8_t total = countPeers(CountPeers::TOTAL); ``` ### Response Returns `uint8_t` - Number of peers matching the count type. ``` ```APIDOC ## [C] printPeerList() ### Description Prints the peer list to the serial output. Used for debugging. ### Method C function call ### Parameters None. ### Request Example ```c printPeerList(); ``` ### Response No return value. ``` ```APIDOC ## [C] getPeerList() ### Description Returns the complete peer list structure by value. ### Method C function call ### Parameters None. ### Request Example ```c peer_list_t list = getPeerList(); ``` ### Response Returns `peer_list_t` - The complete peer list structure. ``` -------------------------------- ### Asynchronous send() with TX queue mitigation Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Mitigate packet dropping in asynchronous mode by checking `readyToSendData()` and waiting for the TX queue to empty with `waitForTXQueueToBeEmptied()` before sending. This condition is only needed for asynchronous sends. ```c /* ASYNCHRONOUS MODE */ // TX queue can hold more than 1 outgoing message // how to mitigate packet dropping when TX queue is full void loop() { String data = "Hello World"; // condition is needed to avoid packet drop only when doing asynch if (!easyEspNow.readyToSendData()) // if TX queue is full, wait for it to completely exhaust easyEspNow.waitForTXQueueToBeEmptied(); easy_send_error_t code = easyEspNow.send(ESPNOW_BROADCAST_ADDRESS, (uint8_t *)data.c_str(), data.length()); MONITOR(MAIN_TAG, "Last send return code value: %s\n", easyEspNow.easySendErrorToName(code)); // add some delay to simulate longer code run // if this is significantly faster than TX exhaust rate (i have set it in the code to be `vTaskDelay(pdMS_TO_TICKS(13)` // packet drop mitigation condition will take place vTaskDelay(pdMS_TO_TICKS(1000)); } ``` -------------------------------- ### Asynchronous send() showing packet drop when TX queue full Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Asynchronous mode can drop packets when the TX queue is full. With a delay of 1000ms, the warning 'TX Queue full. Can not add message to queue. Dropping message...' may appear if the send rate is significantly faster than the TX exhaust rate. ```c /* ASYNCHRONOUS MODE */ // TX queue can hold more than 1 outgoing message // packet dropping can happen when TX queue is full and a message can't be enqued void loop() { String data = "Hello World"; // Here is doing only Broadcasting easy_send_error_t code = easyEspNow.send(ESPNOW_BROADCAST_ADDRESS, (uint8_t *)data.c_str(), data.length()); MONITOR(MAIN_TAG, "Last send return code value: %s\n", easyEspNow.easySendErrorToName(code)); // add some delay to simulate longer code run // if this is significantly faster than TX exhaust rate (i have set it in the code to be `vTaskDelay(pdMS_TO_TICKS(13)` // you will get this: [31220] [WARNING] [EASY_ESP_NOW]: TX Queue full. Can not add message to queue. Dropping message... // packet drop vTaskDelay(pdMS_TO_TICKS(1000)); } ``` -------------------------------- ### Peer Management Structures Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Data structures used for peer management. The peer_t structure tracks the MAC address, encryption flag, and last time the peer was added. The peer_list_t structure holds the total number of peers and an array of peer_t entries. ```c typedef struct { uint8_t mac[MAC_ADDR_LEN]; // MAC address of the peer bool encrypted; // flag to keep track if peer encrypted or no uint32_t time_peer_added = 0; // last time a peer was seen; millis() } peer_t; typedef struct { uint8_t peer_number; // totoal number of peers peer_t peer[MAX_TOTAL_PEER_NUM]; // list of peers } peer_list_t; ``` -------------------------------- ### ESP-NOW frame format structures Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Defines packed structures for parsing ESP-NOW promiscuous packets: common MAC header, unencrypted frame format, encrypted CCMP frame format, and a receive info struct that holds either the unencrypted or encrypted frame (the other must be nullptr). ```c /** * https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_now.html#frame-format * This would be the promiscuous packet * It is an Action frame. On 802.11 managment type (0), subtype 0x0d (13) */ // These are common fields of the MAC header for both encrypted and unencrypted frames typedef struct { unsigned protocol : 2; unsigned type : 2; unsigned subtype : 4; uint8_t flags; uint16_t duration; uint8_t destination_address[6]; uint8_t source_address[6]; uint8_t broadcast_address[6]; uint16_t sequence_control; } __attribute__((packed)) espnow_frame_header_common_t; // Unencrypted frame as a promiscuous packet in ESP typedef struct { espnow_frame_header_common_t esp_now_frame_header; uint8_t category_code; // 0x7f ; set to the value (127) uint8_t organization_identifier[3]; // 0x18fe34 uint8_t random_values[4]; struct { uint8_t element_id; // 0xdd ; set to the value (221) uint8_t length; // The length is the total length of Organization Identifier, Type, Version and Body uint8_t organization_identifier[3]; // 0x18fe34 uint8_t type; // 0x04 ; the Type field is set to the value (4) indicating ESP-NOW uint8_t version; // the Version field is set to the version of ESP-NOW. uint8_t body[0]; } vendor_specific_content; } __attribute__((packed)) espnow_frame_format_t; // Encrypted CCMP frame promiscuous packet in ESP typedef struct { espnow_frame_header_common_t esp_now_frame_header; uint8_t ccmp_parameters[8]; // The rest are the decrypted fields. If you are sniffing in Wireshark the raw 802.11 packets, you will not see the below, only the encrypted data // You can see the following if you print the raw bytes of the packets uint8_t category_code; // 0x7f ; set to the value (127) uint8_t organization_identifier[3]; // 0x18fe34 uint8_t random_values[4]; struct { uint8_t element_id; // 0xdd ; set to the value (221) uint8_t length; // The length is the total length of Organization Identifier, Type, Version and Body uint8_t organization_identifier[3]; // 0x18fe34 uint8_t type; // 0x04 ; the Type field is set to the value (4) indicating ESP-NOW uint8_t version; // the Version field is set to the version of ESP-NOW. uint8_t body[0]; } vendor_specific_content; } __attribute__((packed)) espnow_frame_format_ccmp_t; // If frame received is unencrypted -> `ccmp_encrypted_frame` must be nullptr // If frame received is encrypted -> `unencrypted_frame` must be nullptr typedef struct { wifi_pkt_rx_ctrl_t *radio_header; espnow_frame_format_t *unencrypted_frame; espnow_frame_format_ccmp_t *ccmp_encrypted_frame; } espnow_frame_recv_info_t; ``` -------------------------------- ### Enable ESP-NOW long-range mode with esp_wifi_set_protocol Source: https://github.com/henriberisha/easyespnow/blob/v2.0.0/README.md Enable long-range mode in ESP-NOW by setting the Wi-Fi protocol to include WIFI_PROTOCOL_LR. This is guarded by the CONFIG_ESPNOW_ENABLE_LONG_RANGE configuration flag and is listed as a TODO item in the library documentation. ```c #if CONFIG_ESPNOW_ENABLE_LONG_RANGE ESP_ERROR_CHECK( esp_wifi_set_protocol(ESPNOW_WIFI_IF, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR) ); #endif ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.