pub struct EspNow<'d> { /* private fields */ }unstable only.Expand description
ESP-NOW is a kind of connection-less 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.
For convenience, by default there will be a broadcast peer added on the STA interface.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Implementations§
Source§impl<'d> EspNow<'d>
impl<'d> EspNow<'d>
Sourcepub fn split(self) -> (EspNowManager<'d>, EspNowSender<'d>, EspNowReceiver<'d>)
pub fn split(self) -> (EspNowManager<'d>, EspNowSender<'d>, EspNowReceiver<'d>)
Splits the EspNow instance into its manager, sender, and receiver
components.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn set_channel(&self, channel: u8) -> Result<(), EspNowError>
pub fn set_channel(&self, channel: u8) -> Result<(), EspNowError>
Set primary Wi-Fi channel. Should only be used when using ESP-NOW without AP or STA.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn version(&self) -> Result<u32, EspNowError>
pub fn version(&self) -> Result<u32, EspNowError>
Get the version of ESP-NOW.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn add_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>
pub fn add_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>
Add a peer to the list of known peers.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn remove_peer(&self, peer_address: &[u8; 6]) -> Result<(), EspNowError>
pub fn remove_peer(&self, peer_address: &[u8; 6]) -> Result<(), EspNowError>
Remove the given peer.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn modify_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>
pub fn modify_peer(&self, peer: PeerInfo) -> Result<(), EspNowError>
Modify a peer information.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn peer(&self, peer_address: &[u8; 6]) -> Result<PeerInfo, EspNowError>
pub fn peer(&self, peer_address: &[u8; 6]) -> Result<PeerInfo, EspNowError>
Get peer by MAC address.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn fetch_peer(&self, from_head: bool) -> Result<PeerInfo, EspNowError>
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.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn peer_exists(&self, peer_address: &[u8; 6]) -> bool
pub fn peer_exists(&self, peer_address: &[u8; 6]) -> bool
Check is peer is known.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn peer_count(&self) -> Result<PeerCount, EspNowError>
pub fn peer_count(&self) -> Result<PeerCount, EspNowError>
Get the number of peers.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn set_pmk(&self, pmk: &[u8; 16]) -> Result<(), EspNowError>
pub fn set_pmk(&self, pmk: &[u8; 16]) -> Result<(), EspNowError>
Set the primary master key.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn set_wake_window(&self, wake_window: u16) -> Result<(), EspNowError>
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.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn set_rate(&self, rate: WifiPhyRate) -> Result<(), EspNowError>
pub fn set_rate(&self, rate: WifiPhyRate) -> Result<(), EspNowError>
Configure ESP-NOW rate.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn send<'s>(
&'s mut self,
dst_addr: &[u8; 6],
data: &[u8],
) -> Result<SendWaiter<'s>, EspNowError>
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.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn receive(&self) -> Option<ReceivedData>
pub fn receive(&self) -> Option<ReceivedData>
Receive data.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl EspNow<'_>
impl EspNow<'_>
Sourcepub fn receive_async(&mut self) -> ReceiveFuture<'_> ⓘ
pub fn receive_async(&mut self) -> ReceiveFuture<'_> ⓘ
This function takes mutable reference to self because the
implementation of ReceiveFuture is not logically thread
safe.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn send_async<'s, 'r>(
&'s mut self,
dst_addr: &'r [u8; 6],
data: &'r [u8],
) -> SendFuture<'s, 'r> ⓘ
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.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.