WifiEspNow
ESP-NOW Arduino library for ESP8266 and ESP32
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | List of all members
WifiEspNowClass Class Reference

#include <WifiEspNow.h>

Public Types

using RxCallback = void(*)(const uint8_t mac[WIFIESPNOW_ALEN], const uint8_t *buf, size_t count, void *arg)
 

Public Member Functions

bool begin ()
 Initialize ESP-NOW. More...
 
void end ()
 Stop ESP-NOW. More...
 
bool setPrimaryKey (const uint8_t key[WIFIESPNOW_KEYLEN])
 Set primary key, also known as KOK or PMK. More...
 
int listPeers (WifiEspNowPeerInfo *peers, int maxPeers) const
 List current peers. More...
 
bool hasPeer (const uint8_t mac[WIFIESPNOW_ALEN]) const
 Test whether peer exists. More...
 
bool addPeer (const uint8_t mac[WIFIESPNOW_ALEN], int channel=0, const uint8_t key[WIFIESPNOW_KEYLEN]=nullptr, int netif=ESP_IF_WIFI_AP)
 Add a peer or change peer channel. More...
 
bool removePeer (const uint8_t mac[WIFIESPNOW_ALEN])
 Remove a peer. More...
 
void onReceive (RxCallback cb, void *arg)
 Set receive callback. More...
 
bool send (const uint8_t mac[WIFIESPNOW_ALEN], const uint8_t *buf, size_t count)
 Send a message. More...
 
WifiEspNowSendStatus getSendStatus () const
 Retrieve status of last sent message. More...
 

Member Typedef Documentation

◆ RxCallback

using WifiEspNowClass::RxCallback = void (*)(const uint8_t mac[WIFIESPNOW_ALEN], const uint8_t* buf, size_t count, void* arg)

Member Function Documentation

◆ addPeer()

bool WifiEspNowClass::addPeer ( const uint8_t  mac[WIFIESPNOW_ALEN],
int  channel = 0,
const uint8_t  key[WIFIESPNOW_KEYLEN] = nullptr,
int  netif = ESP_IF_WIFI_AP 
)

Add a peer or change peer channel.

Parameters
macpeer MAC address.
channelpeer channel, 0 for current channel.
keyencryption key, nullptr to disable encryption.
netif(ESP32 only) WiFi interface.
Returns
whether success.

◆ begin()

bool WifiEspNowClass::begin ( )

Initialize ESP-NOW.

Returns
whether success.

◆ end()

void WifiEspNowClass::end ( )

Stop ESP-NOW.

◆ getSendStatus()

WifiEspNowSendStatus WifiEspNowClass::getSendStatus ( ) const
inline

Retrieve status of last sent message.

◆ hasPeer()

bool WifiEspNowClass::hasPeer ( const uint8_t  mac[WIFIESPNOW_ALEN]) const

Test whether peer exists.

Parameters
macpeer MAC address.
Returns
whether peer exists.

◆ listPeers()

int WifiEspNowClass::listPeers ( WifiEspNowPeerInfo peers,
int  maxPeers 
) const

List current peers.

Parameters
[out]peersbuffer for peer information.
maxPeersbuffer size.
Returns
total number of peers, std::min(retval,maxPeers) is written to peers .

◆ onReceive()

void WifiEspNowClass::onReceive ( RxCallback  cb,
void *  arg 
)

Set receive callback.

Parameters
cbthe callback.
argan arbitrary argument passed to the callback.
Note
Only one callback is allowed; this replaces any previous callback.

◆ removePeer()

bool WifiEspNowClass::removePeer ( const uint8_t  mac[WIFIESPNOW_ALEN])

Remove a peer.

Parameters
macpeer MAC address.
Returns
whether success.

◆ send()

bool WifiEspNowClass::send ( const uint8_t  mac[WIFIESPNOW_ALEN],
const uint8_t *  buf,
size_t  count 
)

Send a message.

Parameters
macdestination MAC address, nullptr for all peers.
bufpayload.
countpayload size, must not exceed WIFIESPNOW_MAXMSGLEN .
Returns
whether success (message queued for transmission).

◆ setPrimaryKey()

bool WifiEspNowClass::setPrimaryKey ( const uint8_t  key[WIFIESPNOW_KEYLEN])

Set primary key, also known as KOK or PMK.

Parameters
keyprimary encryption key.
Returns
whether success.

The documentation for this class was generated from the following files: