Struct minimq::mqtt_client::Minimq
source · pub struct Minimq<'buf, TcpStack, Clock, Broker>{ /* private fields */ }
Expand description
The general structure for managing MQTT via Minimq.
§Note
To connect and maintain an MQTT connection, the Minimq::poll()
method must be called
regularly.
Implementations§
source§impl<'buf, TcpStack: TcpClientStack, Clock: Clock, Broker: Broker> Minimq<'buf, TcpStack, Clock, Broker>
impl<'buf, TcpStack: TcpClientStack, Clock: Clock, Broker: Broker> Minimq<'buf, TcpStack, Clock, Broker>
sourcepub fn new(
network_stack: TcpStack,
clock: Clock,
config: ConfigBuilder<'buf, Broker>
) -> Self
pub fn new( network_stack: TcpStack, clock: Clock, config: ConfigBuilder<'buf, Broker> ) -> Self
Construct a new MQTT interface.
§Args
broker
- The broker to connect to. See crate::broker::NamedBroker and crate::broker::IpBroker.client_id
The client ID to use for communicating with the broker. If empty, rely on the broker to automatically assign a client ID.network_stack
- The network stack to use for communication.clock
- The clock to use for managing MQTT state timing.
§Returns
A Minimq
object that can be used for publishing messages, subscribing to topics, and
managing the MQTT state.
sourcepub fn poll<F, T>(&mut self, f: F) -> Result<Option<T>, Error<TcpStack::Error>>where
for<'a> F: FnMut(&mut MqttClient<'buf, TcpStack, Clock, Broker>, &'a str, &[u8], &Properties<'a>) -> T,
pub fn poll<F, T>(&mut self, f: F) -> Result<Option<T>, Error<TcpStack::Error>>where
for<'a> F: FnMut(&mut MqttClient<'buf, TcpStack, Clock, Broker>, &'a str, &[u8], &Properties<'a>) -> T,
Check the MQTT interface for available messages.
§Note
This method will processes as many MQTT control packets as possible until a PUBLISH message
is received. The user should thus contintually call this function until it returns
Ok(None)
, as this is indicative that there is no further data to process.
§Args
f
- A closure to process any received messages. The closure should accept the client, topic, message, and list of proprties (in that order).
§Returns
Ok(Option<result>)
- During normal operation, a result
will optionally be returned to
the user software if a value was returned from the f
closure. If the closure was not
executed, None
is returned. Note that None
may be returned even if MQTT packets were
processed.
Err(Error) if an MQTT-related error is encountered. Generally, Error::SessionReset is the only error expected during normal operation. In this case, the client has lost any previous subscriptions or session state.
sourcepub fn client(&mut self) -> &mut MqttClient<'buf, TcpStack, Clock, Broker>
pub fn client(&mut self) -> &mut MqttClient<'buf, TcpStack, Clock, Broker>
Directly access the MQTT client.