Skip to main content

MeshCore

Struct MeshCore 

Source
pub struct MeshCore { /* private fields */ }
Expand description

MeshCore client for communicating with MeshCore devices

Implementations§

Source§

impl MeshCore

Source

pub async fn ble_discover(scan_duration: Duration) -> Result<Vec<String>>

Find MeshCore radios on BTLE upto the time specified by scan_duration and return their names

Source

pub async fn ble_connect(name: &str) -> Result<MeshCore>

This method connects to a MeshCore radio by BTLE device name

Source§

impl MeshCore

Source

pub async fn serial(port: &str, baud_rate: u32) -> Result<MeshCore>

Create a MeshCore client connected via serial port

Source§

impl MeshCore

Source

pub async fn tcp(host: &str, port: u16) -> Result<MeshCore>

Create a MeshCore client connected via TCP

Source§

impl MeshCore

Source

pub async fn is_connected(&self) -> bool

Check if connected

Source

pub fn commands(&self) -> &Arc<Mutex<CommandHandler>>

Get the command handler

Source

pub async fn contacts(&self) -> HashMap<String, Contact>

Get cached contacts

Source

pub async fn self_info(&self) -> Option<SelfInfo>

Get cached self-info

Source

pub async fn device_time(&self) -> Option<u32>

Get cached device time

Source

pub async fn contacts_dirty(&self) -> bool

Check if the contact cache is dirty

Source

pub async fn get_contact_by_name(&self, name: &str) -> Option<Contact>

Get contact by name

Source

pub async fn get_contact_by_prefix(&self, prefix: &[u8]) -> Option<Contact>

Get contact by public key prefix

Source

pub async fn ensure_contacts(&self) -> Result<()>

Ensure contacts are loaded

Source

pub async fn subscribe<F>( &self, event_type: EventType, filters: HashMap<String, String>, callback: F, ) -> Subscription
where F: Fn(MeshCoreEvent) + Send + Sync + 'static,

Subscribe to events

Source

pub async fn wait_for_event( &self, event_type: Option<EventType>, filters: HashMap<String, String>, timeout: Duration, ) -> Option<MeshCoreEvent>

Wait for an event, either matching a specific EventType or all

Source

pub async fn start_auto_message_fetching(&self)

Start auto-fetching messages when MESSAGES_WAITING is received

Source

pub async fn stop_auto_message_fetching(&self)

Stop auto-fetching messages

Source

pub async fn disconnect(&self) -> Result<()>

Disconnect from the device

Source

pub async fn set_default_timeout(&self, timeout: Duration)

Set default timeout

Source

pub fn dispatcher(&self) -> &Arc<EventDispatcher>

Get the event dispatcher

Source

pub fn reader(&self) -> &Arc<MessageReader>

Get the message reader

Source

pub fn event_stream(&self) -> impl Stream<Item = MeshCoreEvent> + Unpin

Create a stream of all events

Returns a stream that yields all events emitted by the device. Use StreamExt methods to filter or process events.

§Example
use futures::StreamExt;

let mut stream = meshcore.event_stream();
while let Some(event) = stream.next().await {
    println!("Received: {:?}", event.event_type);
}
Source

pub fn event_stream_filtered( &self, event_type: EventType, ) -> impl Stream<Item = MeshCoreEvent> + Unpin

Create a filtered stream of events by type

Returns a stream that yields only events matching the specified type.

§Example
use futures::StreamExt;
use meshcore_rs::EventType;

let mut stream = meshcore.event_stream_filtered(EventType::ContactMsgRecv);
while let Some(event) = stream.next().await {
    println!("Message received: {:?}", event.payload);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more