Expand description
MiniMQ
Provides a minimal MQTTv5 client and message parsing for the MQTT version 5 protocol.
This crate provides a minimalistic MQTT 5 client that can be used to publish topics to an MQTT broker and subscribe to receive messages on specific topics.
Limitations
This library does not currently support the following elements:
- Quality-of-service
ExactlyOnce
- Quality-of-service above
AtMostOnce
for inbound messages. - Bulk subscriptions
- Server Authentication
- Encryption
- Topic aliases
Requirements
This library requires that the user provide it an object that implements a basic TcpStack that can be used as the transport layer for MQTT communications.
The maximum message size is configured through generic parameters. This allows the maximum message size to be configured by the user. Note that buffers will be allocated on the stack, so it is important to select a size such that the stack does not overflow.
Example
Below is a sample snippet showing how this library is used. An example application is provided
in examples/minimq-stm32h7
, which targets the Nucleo-H743 development board with an external
temperature sensor installed.
use minimq::{Minimq, QoS, Retain};
// Construct an MQTT client with a maximum packet size of 256 bytes
// and a maximum of 16 messages that are allowed to be "in flight".
// Messages are "in flight" if QoS::AtLeastOnce has not yet been acknowledged (PUBACK)
// or QoS::ExactlyOnce has not been completed (PUBCOMP).
// Connect to a broker at localhost - Use a client ID of "test".
let mut mqtt: Minimq<_, _, 256, 16> = Minimq::new(
"127.0.0.1".parse().unwrap(),
"test",
std_embedded_nal::Stack::default(),
std_embedded_time::StandardClock::default()).unwrap();
let mut subscribed = false;
loop {
if mqtt.client.is_connected() && !subscribed {
mqtt.client.subscribe("topic", &[]).unwrap();
subscribed = true;
}
mqtt.poll(|client, topic, message, properties| {
match topic {
"topic" => {
println!("{:?}", message);
client.publish("echo", message, QoS::AtMostOnce, Retain::NotRetained, &[]).unwrap();
},
topic => println!("Unknown topic: {}", topic),
};
}).unwrap();
}
Re-exports
Modules
Enums
Possible errors encountered during an MQTT connection.
All of the possible properties that MQTT version 5 supports.
Errors that are specific to the MQTT protocol implementation.
The quality-of-service for an MQTT message.
The retained status for an MQTT message.