4 releases (breaking)

0.4.0 Oct 8, 2021
0.3.0 Aug 6, 2021
0.2.0 Feb 15, 2021
0.1.0 Aug 27, 2020

#104 in Embedded development

Download history 1/week @ 2021-07-04 2/week @ 2021-07-18 2/week @ 2021-07-25 64/week @ 2021-08-01 386/week @ 2021-08-08 203/week @ 2021-08-15 101/week @ 2021-08-22 72/week @ 2021-08-29 68/week @ 2021-09-05 138/week @ 2021-09-12 64/week @ 2021-09-19 60/week @ 2021-09-26 187/week @ 2021-10-03 255/week @ 2021-10-10 61/week @ 2021-10-17

420 downloads per month
Used in miniconf

MIT license

91KB
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
  • 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::{Minimq, QoS};

// Construct an MQTT client with a maximum packet size of 256 bytes.
// 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, &[]).unwrap();
            },
            topic => println!("Unknown topic: {}", topic),
        };
    }).unwrap();
}

Dependencies

~1.4–2MB
~42K SLoC