Struct minimq::MqttClient[][src]

pub struct MqttClient<T, N> where
    T: ArrayLength<u8>,
    N: TcpStack
{ pub network_stack: N, // some fields omitted }

A client for interacting with an MQTT Broker.

Fields

network_stack: N

The network stack originally provided to the client.

Implementations

impl<T, N> MqttClient<T, N> where
    T: ArrayLength<u8>,
    N: TcpStack
[src]

pub fn new<'a>(
    broker: IpAddr,
    client_id: &'a str,
    network_stack: N
) -> Result<Self, Error<N::Error>>
[src]

Construct a new MQTT client.

Args

  • broker - The IP address of the broker to connect to.
  • client_id The client ID to use for communicating with the broker.
  • network_stack - The network stack to use for communication.

Returns

An MqttClient that can be used for publishing messages and subscribing to topics.

pub fn subscribe<'a, 'b>(
    &self,
    topic: &'a str,
    properties: &[Property<'b>]
) -> Result<(), Error<N::Error>>
[src]

Subscribe to a topic.

Note

A subscription is not maintained across a disconnection with the broker. In the case of MQTT disconnections, topics will need to be subscribed to again.

Args

  • topic - The topic to subscribe to.
  • properties - A list of properties to attach to the subscription request. May be empty.

pub fn subscriptions_pending(&self) -> bool[src]

Determine if any subscriptions are waiting for completion.

Returns

True if any subscriptions are waiting for confirmation from the broker.

pub fn is_connected(&self) -> Result<bool, Error<N::Error>>[src]

Determine if the client has established a connection with the broker.

Returns

True if the client is connected to the broker.

pub fn publish<'a, 'b>(
    &self,
    topic: &'a str,
    data: &[u8],
    qos: QoS,
    properties: &[Property<'a>]
) -> Result<(), Error<N::Error>>
[src]

Publish a message over MQTT.

Note

If the client is not yet connected to the broker, the message will be silently ignored.

Note

Currently, Only QoS level 1 (at most once) delivery is supported.

Args

  • topic - The topic to publish the message to.
  • data - The data to transmit as the message contents.
  • qos - The desired quality-of-service level of the message. Must be QoS::AtMostOnce
  • properties - A list of properties to associate with the message being published. May be empty.

pub fn poll<F>(&mut self, f: F) -> Result<(), Error<N::Error>> where
    F: FnMut(&Self, &'a str, &[u8], &[Property<'a>]), 
[src]

Check the MQTT interface for available messages.

Args

  • f - A closure to process any received messages. The closure should accept the client, topic, message, and list of proprties (in that order).

Auto Trait Implementations

impl<T, N> Send for MqttClient<T, N> where
    N: Send,
    <N as TcpStack>::TcpSocket: Send
[src]

impl<T, N> !Sync for MqttClient<T, N>[src]

impl<T, N> Unpin for MqttClient<T, N> where
    N: Unpin,
    <T as ArrayLength<u8>>::ArrayType: Unpin,
    <N as TcpStack>::TcpSocket: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.