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
Methods
AddPeer(byte[], byte)
Add peer to which data will be sent.
public void AddPeer(byte[] peerMac, byte channel)
Parameters
Exceptions
- ArgumentException
peerMacis null.-or-
peerMacis 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
peerMacbyte[]MAC address of peer.
channelbyteWiFi channel to be used.
encryptedbooltrue to enable ESP-NOW encryption for this peer.
localMasterKeybyte[]16-byte local master key used when encryption is enabled.
Exceptions
- ArgumentException
peerMacis null.-or-
peerMacis not 6 bytes long.-or-
localMasterKeyis 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
timeoutintMilliseconds to wait for a packet.
0polls the queue and returns immediately.
Returns
- DataReceivedEventArgs
The next received packet, or null when
timeoutis0and no packet was queued.
Exceptions
- ArgumentOutOfRangeException
timeoutis 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
peerMacbyte[]MAC address of already added peer.
databyte[]Data to be sent.
dataLenintLength of data.
Exceptions
- EspNowException
Native ESP-NOW send failed.
Events
DataReceived
Event raised when data is received.
public event DataReceivedEventHandler DataReceived
Event Type
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