Crate minimq[][src]

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 above AtMostOnce
  • Session timeouts
  • Server keep alive timeouts (ping)
  • 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::{MqttClient, consts, QoS, embedded_nal::{IpAddr, Ipv4Addr}};

// Construct an MQTT client with a maximum packet size of 256 bytes.
// Connect to a broker at 192.168.0.254 - Use a client ID of "test".
let client: MqttClient<consts::U256, _> = MqttClient::new(
        IpAddr::V4(Ipv4Addr::new(192, 168, 0, 254)),
        "test",
        tcp_stack).unwrap();

let mut subscribed = false;

loop {
    if client.is_connected() && !subscribed {
        client.subscribe("topic").unwrap();
        subscribed = true;
    }

    client.poll(|client, topic, message, properties| {
        match topic {
            "topic" => {
               println!("{:?}", message);
               client.publish("echo", message, QoS::AtMostOnce, &[]).unwrap();
            },
            topic => println!("Unknown topic: {}", topic),
        };
    }).unwrap();
}

Re-exports

pub use embedded_nal;
pub use generic_array;

Modules

consts

Type aliases for many constants.

Structs

MqttClient

A client for interacting with an MQTT Broker.

Enums

Error

Possible errors encountered during an MQTT connection.

Property

All of the possible properties that MQTT version 5 supports.

ProtocolError

Errors that are specific to the MQTT protocol implementation.

QoS

The quality-of-service for an MQTT message.