pub struct EspThread<'d, T>where
T: NetifMode,{ /* private fields */ }Expand description
EspThread wraps a ThreadDriver Data Link layer instance, and binds the OSI
Layer 3 (network) facilities of ESP IDF to it.
In other words, it connects the ESP IDF Netif interface to the Thread driver. This allows users to utilize the Rust STD APIs for working with TCP and UDP sockets.
This struct should be the default option for a Thread driver in all use cases
but the niche one where bypassing the ESP IDF Netif and lwIP stacks is
desirable. E.g., using smoltcp or other custom IP stacks on top of the
ESP IDF Thread radio.
Implementations§
Source§impl<T> EspThread<'_, T>where
T: NetifMode,
impl<T> EspThread<'_, T>where
T: NetifMode,
Sourcepub fn srp_conf<F, R>(&self, f: F) -> Result<R, EspError>
pub fn srp_conf<F, R>(&self, f: F) -> Result<R, EspError>
Return the current SRP client configuration and SRP client host state to the provided closure.
Arguments:
f: A closure that takes the SRP configuration and SRP host state as arguments.
Sourcepub fn srp_is_empty(&self) -> Result<bool, EspError>
pub fn srp_is_empty(&self) -> Result<bool, EspError>
Return true if there is neither host, nor any service currently registered with the SRP client.
Sourcepub fn srp_set_conf(&self, conf: &SrpConf<'_>) -> Result<(), EspError>
pub fn srp_set_conf(&self, conf: &SrpConf<'_>) -> Result<(), EspError>
Set the SRP client configuration.
Arguments:
conf: The SRP configuration.
Returns:
Ok(())if the configuration was set successfully.Err(OtError)if the configuration could not be set. One reason why the configuration setting might fail is if the configuration had already been set and then not removed withsrp_remove_all.
Sourcepub fn srp_running(&self) -> Result<bool, EspError>
pub fn srp_running(&self) -> Result<bool, EspError>
Return true if the SRP client is running, false otherwise.
Sourcepub fn srp_autostart_enabled(&self) -> Result<bool, EspError>
pub fn srp_autostart_enabled(&self) -> Result<bool, EspError>
Return true if the SRP client is in auto-start mode, false otherwise.
Sourcepub fn srp_autostart(&self) -> Result<(), EspError>
pub fn srp_autostart(&self) -> Result<(), EspError>
Auto-starts the SRP client.
Sourcepub fn srp_start(&self, server_addr: SocketAddrV6) -> Result<(), EspError>
pub fn srp_start(&self, server_addr: SocketAddrV6) -> Result<(), EspError>
Start the SRP client for the given SRP server address.
Arguments:
server_addr: The SRP server address.
Sourcepub fn srp_server_addr(&self) -> Result<Option<SocketAddrV6>, EspError>
pub fn srp_server_addr(&self) -> Result<Option<SocketAddrV6>, EspError>
Return the SRP server address, if the SRP client is running and had connected to a server.
Sourcepub fn srp_services<F>(&self, f: F) -> Result<(), EspError>
pub fn srp_services<F>(&self, f: F) -> Result<(), EspError>
Iterate over the SRP services registered with the SRP client.
Arguments:
f: A closure that receives a tuple of the next SRP service, SRP service state, and SRP service ID. If there are no more SRP services, the closure will receiveNone.
Sourcepub fn srp_add_service<'a, SI, TI>(
&self,
service: &'a SrpService<'a, SI, TI>,
) -> Result<SrpServiceSlot, EspError>where
SI: Iterator<Item = &'a str> + Clone + 'a,
TI: Iterator<Item = (&'a str, &'a [u8])> + Clone + 'a,
pub fn srp_add_service<'a, SI, TI>(
&self,
service: &'a SrpService<'a, SI, TI>,
) -> Result<SrpServiceSlot, EspError>where
SI: Iterator<Item = &'a str> + Clone + 'a,
TI: Iterator<Item = (&'a str, &'a [u8])> + Clone + 'a,
Add an SRP service to the SRP client.
Arguments:
service: The SRP service to add.
Returns:
- The SRP service slot, if the service was added successfully.
Err(OtError)if the service could not be added. One reason why the service addition might fail is if there are no more slots available for services. This can happen even if all services had been removed, as the slots are not freed until the SRP client propagates the removal info to the SRP server.
Sourcepub fn srp_remove_service(
&self,
slot: SrpServiceSlot,
immediate: bool,
) -> Result<(), EspError>
pub fn srp_remove_service( &self, slot: SrpServiceSlot, immediate: bool, ) -> Result<(), EspError>
Remove an SRP service from the SRP client.
Arguments:
slot: The SRP service to remove.immediate: Iftrue, the service will be removed immediately, otherwise, the service will be removed gracefully by propagating the removal info to the SRP server.
Sourcepub fn srp_remove_all(&self, immediate: bool) -> Result<(), EspError>
pub fn srp_remove_all(&self, immediate: bool) -> Result<(), EspError>
Remove the SRP hostname and all SRP services from the SRP client.
Arguments:
immediate: Iftrue, the hostname and services will be removed immediately, otherwise, the hostname and services will be removed gracefully by propagating the removal info to the SRP server.
Source§impl<'d> EspThread<'d, Node>
impl<'d> EspThread<'d, Node>
Sourcepub fn new_spi<S: Spi + 'd>(
_spi: S,
mosi: impl InputPin + 'd,
miso: impl OutputPin + 'd,
sclk: impl InputPin + OutputPin + 'd,
cs: Option<impl InputPin + OutputPin + 'd>,
intr: Option<impl InputPin + OutputPin + 'd>,
config: &Config,
_sysloop: EspSystemEventLoop,
nvs: EspDefaultNvsPartition,
mounted_event_fs: Arc<MountedEventfs>,
) -> Result<Self, EspError>
pub fn new_spi<S: Spi + 'd>( _spi: S, mosi: impl InputPin + 'd, miso: impl OutputPin + 'd, sclk: impl InputPin + OutputPin + 'd, cs: Option<impl InputPin + OutputPin + 'd>, intr: Option<impl InputPin + OutputPin + 'd>, config: &Config, _sysloop: EspSystemEventLoop, nvs: EspDefaultNvsPartition, mounted_event_fs: Arc<MountedEventfs>, ) -> Result<Self, EspError>
Create a new EspThread instance utilizing an SPI connection to another MCU
which is expected to run the Thread RCP driver mode over SPI
Sourcepub fn new_uart<U: Uart + 'd>(
_uart: U,
tx: impl OutputPin + 'd,
rx: impl InputPin + 'd,
config: &Config,
_sysloop: EspSystemEventLoop,
nvs: EspDefaultNvsPartition,
mounted_event_fs: Arc<MountedEventfs>,
) -> Result<Self, EspError>
pub fn new_uart<U: Uart + 'd>( _uart: U, tx: impl OutputPin + 'd, rx: impl InputPin + 'd, config: &Config, _sysloop: EspSystemEventLoop, nvs: EspDefaultNvsPartition, mounted_event_fs: Arc<MountedEventfs>, ) -> Result<Self, EspError>
Create a new EspThread instance utilizing a UART connection to another MCU
which is expected to run the Thread RCP driver mode over UART
Sourcepub fn wrap(driver: ThreadDriver<'d, Host>) -> Result<Self, EspError>
pub fn wrap(driver: ThreadDriver<'d, Host>) -> Result<Self, EspError>
Wrap an already created Thread L2 driver instance
Source§impl<'d, T> EspThread<'d, T>where
T: NetifMode,
impl<'d, T> EspThread<'d, T>where
T: NetifMode,
Sourcepub fn driver(&self) -> &ThreadDriver<'d, Host>
pub fn driver(&self) -> &ThreadDriver<'d, Host>
Return a reference to the underlying ThreadDriver
Sourcepub fn driver_mut(&mut self) -> &mut ThreadDriver<'d, Host>
pub fn driver_mut(&mut self) -> &mut ThreadDriver<'d, Host>
Return a mutable reference to the underlying ThreadDriver
Sourcepub fn enable_ipv6(&self, enabled: bool) -> Result<(), EspError>
pub fn enable_ipv6(&self, enabled: bool) -> Result<(), EspError>
Enable or disable the Thread network interface
Sourcepub fn enable_thread(&self, enabled: bool) -> Result<(), EspError>
pub fn enable_thread(&self, enabled: bool) -> Result<(), EspError>
Enable or disable Thread
When enabling, this should be called after the network interface is enabled
Sourcepub fn role(&self) -> Result<Role, EspError>
pub fn role(&self) -> Result<Role, EspError>
Retrieve the current role of the device in the Thread network
Sourcepub fn tod(&self, buf: &mut [u8]) -> Result<usize, EspError>
pub fn tod(&self, buf: &mut [u8]) -> Result<usize, EspError>
Retrieve the active TOD (Thread Operational Dataset) in the user-supplied buffer
Return the size of the TOD data written to the buffer
The TOD is in Thread TLV format.
Sourcepub fn pending_tod(&self, buf: &mut [u8]) -> Result<usize, EspError>
pub fn pending_tod(&self, buf: &mut [u8]) -> Result<usize, EspError>
Retrieve the pending TOD (Thread Operational Dataset) in the user-supplied buffer
Return the size of the TOD data written to the buffer
The TOD is in Thread TLV format.
Sourcepub fn set_tod(&self, tod: &[u8]) -> Result<(), EspError>
pub fn set_tod(&self, tod: &[u8]) -> Result<(), EspError>
Set the active TOD (Thread Operational Dataset) to the provided data
The TOD data should be in Thread TLV format.
Sourcepub fn set_tod_hexstr(&self, tod: &str) -> Result<(), EspError>
pub fn set_tod_hexstr(&self, tod: &str) -> Result<(), EspError>
Set the active TOD (Thread Operational Dataset) to the provided data
The TOD data should be in Thread TLV format.
Sourcepub fn set_pending_tod(&self, tod: &[u8]) -> Result<(), EspError>
pub fn set_pending_tod(&self, tod: &[u8]) -> Result<(), EspError>
Set the pending TOD (Thread Operational Dataset) to the provided data
The TOD data should be in Thread TLV format.
Sourcepub fn set_pending_tod_hexstr(&self, tod: &str) -> Result<(), EspError>
pub fn set_pending_tod_hexstr(&self, tod: &str) -> Result<(), EspError>
Set the pending TOD (Thread Operational Dataset) to the provided data
The TOD data should be in Thread TLV format.
Sourcepub fn set_tod_from_cfg(&self) -> Result<(), EspError>
pub fn set_tod_from_cfg(&self) -> Result<(), EspError>
Set the active TOD (Thread Operational Dataset) according to the
CONFIG_OPENTHREAD_ TOD-related parameters compiled into the app
during build (via sdkconfig*)
Sourcepub fn scan<F: FnMut(Option<ActiveScanResult<'_>>) + Send + 'static>(
&self,
callback: F,
) -> Result<(), EspError>
pub fn scan<F: FnMut(Option<ActiveScanResult<'_>>) + Send + 'static>( &self, callback: F, ) -> Result<(), EspError>
Perform an active scan for Thread networks The callback will be called for each found network
At the end of the scan, the callback will be called with None
Sourcepub fn is_scan_in_progress(&self) -> Result<bool, EspError>
pub fn is_scan_in_progress(&self) -> Result<bool, EspError>
Check if an active scan is in progress
Sourcepub fn energy_scan<F: FnMut(Option<EnergyScanResult<'_>>) + Send + 'static>(
&self,
callback: F,
) -> Result<(), EspError>
pub fn energy_scan<F: FnMut(Option<EnergyScanResult<'_>>) + Send + 'static>( &self, callback: F, ) -> Result<(), EspError>
Perform an energy scan for Thread networks The callback will be called for each found network
At the end of the scan, the callback will be called with None
Sourcepub fn is_energy_scan_in_progress(&self) -> Result<bool, EspError>
pub fn is_energy_scan_in_progress(&self) -> Result<bool, EspError>
Check if an energy scan is in progress
Sourcepub fn start(&mut self) -> Result<(), EspError>
pub fn start(&mut self) -> Result<(), EspError>
Start the Thread driver
If the driver is already started, an error is returned.
Sourcepub fn stop(&mut self) -> Result<(), EspError>
pub fn stop(&mut self) -> Result<(), EspError>
Stop the Thread driver
If the driver is not started, an error is returned.
Sourcepub fn is_started(&self) -> Result<bool, EspError>
pub fn is_started(&self) -> Result<bool, EspError>
Check if the Thread driver is started
Trait Implementations§
Source§impl<T> Drop for EspThread<'_, T>where
T: NetifMode,
Available on esp_idf_comp_esp_netif_enabled and non-esp_idf_openthread_radio only.
impl<T> Drop for EspThread<'_, T>where
T: NetifMode,
esp_idf_comp_esp_netif_enabled and non-esp_idf_openthread_radio only.impl<T> Send for EspThread<'_, T>where
T: NetifMode,
esp_idf_comp_esp_netif_enabled and non-esp_idf_openthread_radio only.impl<T> Sync for EspThread<'_, T>where
T: NetifMode,
esp_idf_comp_esp_netif_enabled and non-esp_idf_openthread_radio only.