espressif / esp-now

A connectionless Wi-Fi communication protocol
Apache License 2.0
477 stars 90 forks source link

What is the Purpose of the priv Field in esp_now_peer_info_t? (AEGHB-437) #99

Closed bhuvanchandra closed 5 months ago

bhuvanchandra commented 8 months ago

I've been working with the ESP-NOW library for ESP32 devices, and I've noticed that the esp_now_peer_info_t structure includes a field called priv. However, I'm curious about the specific purpose and use case of this field.

Here's the structure definition I'm referring to:

typedef struct {
    uint8_t peer_addr[ESP_NOW_ETH_ALEN];  // MAC Address of the peer
    uint8_t channel;                      // Channel of the peer
    bool encrypt;                         // Peer encryption enabled/disabled
    wifi_interface_t ifidx;               // Interface index

    void* priv;                           // Private data pointer
} esp_now_peer_info_t;

From my understanding, it's used for storing custom data associated with a peer, but I've encountered some unexpected behavior and have questions:

Observation: I've observed that when adding or updating peers, the memory address pointed to by priv seems to differ from the address I initially assigned. For instance, when I print the address before and after adding a peer, they are different.

Unexpected Behavior: Interestingly, the memory address pointed to by priv appears to be the same for different peer instances. Even when I add peers for the first time, the priv field points to the same address.

I'm interested in learning more about the intended use and behavior of the priv field within the ESP-NOW library. Does it get copied internally when peers are added or updated? Is it intended for user-defined data?

lhespress commented 8 months ago

@bhuvanchandra Yes, you're correct. Could you provide an example for show how to encounter some unexpected behavior?

lhespress commented 5 months ago

@bhuvanchandra Closing this issue since there has been no update on this. Please feel free to reopen if required.