esp_wifi::esp_now

Struct EspNow

Source
pub struct EspNow<'d> { /* private fields */ }
Expand description

ESP-NOW is a kind of connectionless Wi-Fi communication protocol that is defined by Espressif. In ESP-NOW, application data is encapsulated in a vendor-specific action frame and then transmitted from one Wi-Fi device to another without connection. CTR with CBC-MAC Protocol(CCMP) is used to protect the action frame for security. ESP-NOW is widely used in smart light, remote controlling, sensor, etc.

Currently this implementation (when used together with traditional Wi-Fi) ONLY support STA mode.

Implementations§

Source§

impl EspNow<'_>

Source

pub fn receive_async(&mut self) -> ReceiveFuture<'_>

This function takes mutable reference to self because the implementation of ReceiveFuture is not logically thread safe.

Source

pub fn send_async<'s, 'r>( &'s mut self, dst_addr: &'r [u8; 6], data: &'r [u8], ) -> SendFuture<'s, 'r>

The returned future must not be dropped before it’s ready to avoid getting wrong status for sendings.

Source§

impl<'d> EspNow<'d>

Source

pub fn new( inited: &'d EspWifiController<'d>, device: impl Peripheral<P = WIFI> + 'd, ) -> Result<EspNow<'d>, EspNowError>

Creates an EspNow instance.

Source

pub fn new_with_wifi( inited: &'d EspWifiController<'d>, _token: EspNowWithWifiCreateToken, ) -> Result<EspNow<'d>, EspNowError>

Creates an EspNow instance with support for Wi-Fi coexistence.

Source

pub fn split(self) -> (EspNowManager<'d>, EspNowSender<'d>, EspNowReceiver<'d>)

Splits the EspNow instance into its manager, sender, and receiver components.

Source

pub fn set_protocol( &self, protocols: EnumSet<Protocol>, ) -> Result<(), EspNowError>

Set the wifi protocol.

This will set the wifi protocol to the desired protocol

§Arguments:
  • protocols - The desired protocols
Source

pub fn set_channel(&self, channel: u8) -> Result<(), EspNowError>

Set primary WiFi channel. Should only be used when using ESP-NOW without AP or STA.

Source

pub fn version(&self) -> Result<u32, EspNowError>

Get the version of ESP-NOW.

Source

pub fn add_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>

Add a peer to the list of known peers.

Source

pub fn remove_peer(&self, peer_address: &[u8; 6]) -> Result<(), EspNowError>

Remove the given peer.

Source

pub fn modify_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>

Modify a peer information.

Source

pub fn peer(&self, peer_address: &[u8; 6]) -> Result<PeerInfo, EspNowError>

Get peer by MAC address.

Source

pub fn fetch_peer(&self, from_head: bool) -> Result<PeerInfo, EspNowError>

Fetch a peer from peer list.

Only returns peers which address is unicast, for multicast/broadcast addresses, the function will skip the entry and find the next in the peer list.

Source

pub fn peer_exists(&self, peer_address: &[u8; 6]) -> bool

Check is peer is known.

Source

pub fn peer_count(&self) -> Result<PeerCount, EspNowError>

Get the number of peers.

Source

pub fn set_pmk(&self, pmk: &[u8; 16]) -> Result<(), EspNowError>

Set the primary master key.

Source

pub fn set_wake_window(&self, wake_window: u16) -> Result<(), EspNowError>

Set wake window for esp_now to wake up in interval unit.

Window is milliseconds the chip keep waked each interval, from 0 to 65535.

Source

pub fn set_rate(&self, rate: WifiPhyRate) -> Result<(), EspNowError>

Configure ESP-NOW rate.

Source

pub fn send<'s>( &'s mut self, dst_addr: &[u8; 6], data: &[u8], ) -> Result<SendWaiter<'s>, EspNowError>

Send data to peer.

The peer needs to be added to the peer list first.

Source

pub fn receive(&self) -> Option<ReceivedData>

Receive data.

Auto Trait Implementations§

§

impl<'d> Freeze for EspNow<'d>

§

impl<'d> RefUnwindSafe for EspNow<'d>

§

impl<'d> Send for EspNow<'d>

§

impl<'d> Sync for EspNow<'d>

§

impl<'d> Unpin for EspNow<'d>

§

impl<'d> UnwindSafe for EspNow<'d>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.