Table of Contents

Class EspNowController

Namespace
nanoFramework.EspNow
Assembly
nanoFramework.EspNow.dll

ESP-NOW controller class.

public sealed class EspNowController : IDisposable
Inheritance
EspNowController
Implements
Inherited Members
Extension Methods

Constructors

EspNowController()

Represents an ESP-NOW controller.

public EspNowController()

Exceptions

InvalidOperationException

Only one EspNowController instance is allowed per device.

EspNowException

Native ESP-NOW initialization failed.

Properties

ReceiveOverflowCount

Gets the number of packets discarded because the receive queue was full.

public int ReceiveOverflowCount { get; }

Property Value

int

Methods

AddPeer(byte[], byte)

Add peer to which data will be sent.

public void AddPeer(byte[] peerMac, byte channel)

Parameters

peerMac byte[]

MAC address of peer.

channel byte

WiFi channel to be used.

Exceptions

ArgumentException

peerMac is null.

-or-

peerMac is not 6 bytes long.

-or-

Trying to enable encryption for a broadcast peer [FF-FF-FF-FF-FF-FF].

EspNowException

Native ESP-NOW peer registration failed.

AddPeer(byte[], byte, bool, byte[])

Add peer to which data will be sent.

public void AddPeer(byte[] peerMac, byte channel, bool encrypted, byte[] localMasterKey)

Parameters

peerMac byte[]

MAC address of peer.

channel byte

WiFi channel to be used.

encrypted bool

true to enable ESP-NOW encryption for this peer.

localMasterKey byte[]

16-byte local master key used when encryption is enabled.

Exceptions

ArgumentException

peerMac is null.

-or-

peerMac is not 6 bytes long.

-or-

localMasterKey is not 16 bytes long.

-or-

Trying to enable encryption for a broadcast peer [FF-FF-FF-FF-FF-FF].

EspNowException

Native ESP-NOW peer registration failed.

Dispose()

Dispose()

public void Dispose()

Finalize()

Destructor to assure Dispose will be called.

protected override void Finalize()

ReadPacket(int)

Reads the next complete packet from the native receive queue.

public DataReceivedEventArgs ReadPacket(int timeout)

Parameters

timeout int

Milliseconds to wait for a packet. 0 polls the queue and returns immediately.

Returns

DataReceivedEventArgs

The next received packet, or null when timeout is 0 and no packet was queued.

Exceptions

ArgumentOutOfRangeException

timeout is negative.

TimeoutException

No packet arrived within timeout.

Send(byte[], byte[], int)

Send data to already registered peer. Fire-and-forget: this call only queues the frame for transmission. Subscribe to DataSent to be notified of the MAC-layer delivery result.

public void Send(byte[] peerMac, byte[] data, int dataLen)

Parameters

peerMac byte[]

MAC address of already added peer.

data byte[]

Data to be sent.

dataLen int

Length of data.

Exceptions

EspNowException

Native ESP-NOW send failed.

Events

DataReceived

Event raised when data is received.

public event DataReceivedEventHandler DataReceived

Event Type

DataReceivedEventHandler

DataSent

Event raised when a previously sent packet completes at the MAC layer (either delivered or failed). Only one send is expected to be in flight at a time.

public event DataSentEventHandler DataSent

Event Type

DataSentEventHandler