8 releases (4 breaking)

0.5.3 Feb 14, 2022
0.5.2 Dec 14, 2021
0.4.0 Oct 8, 2021
0.3.0 Aug 6, 2021
0.1.0 Aug 27, 2020

#249 in Embedded development

Download history 146/week @ 2022-04-21 226/week @ 2022-04-28 421/week @ 2022-05-05 444/week @ 2022-05-12 218/week @ 2022-05-19 184/week @ 2022-05-26 270/week @ 2022-06-02 134/week @ 2022-06-09 213/week @ 2022-06-16 159/week @ 2022-06-23 146/week @ 2022-06-30 283/week @ 2022-07-07 141/week @ 2022-07-14 379/week @ 2022-07-21 275/week @ 2022-07-28 501/week @ 2022-08-04

1,332 downloads per month
Used in 4 crates

MIT license

99KB
2K SLoC

QUARTIQ Matrix Chat

MiniMQ

A minimal no_std MQTT v5.0 client implementation.

MiniMQ provides a no_std client for interfacing with MQTT v5.0 brokers.

Usage

There is an example targeting the Nucleo-H743zi2 board that can be used as a reference design.

There is also an example on a standard computer in tests/integration_test.rs

Not yet implemented features.

  • Support all QoS levels
  • Allow batch subscriptions to multiple topics

lib.rs:

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();
}

Dependencies

~1.4–2.1MB
~43K SLoC