Mqttrust
A lightweight, no_std async MQTT client for embedded systems
Install / Use
/learn @FactbirdHQ/MqttrustREADME
mqttrust
A lightweight, #![no_std] async MQTT client for embedded systems.
Features
- Minimal footprint designed for resource-constrained environments
- Fully asynchronous, built on top of the Embassy async ecosystem
- Supports both MQTTv3.1.1 and MQTTv5
- Pluggable transport layer (bring your own TCP/TLS stack)
- Optional
embedded-tlsintegration for secure connections - QoS 0, 1, and 2 (QoS 2 via feature flag)
- Configurable buffer sizes via compile-time feature flags
- Automatic reconnection with configurable backoff
- Topic filter matching with wildcard support (
+and#) defmtandloglogging support
Quick start
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use mqttrust::{
transport::embedded_nal::NalTransport, Config, IpBroker, Publish, State, Subscribe,
};
// Create state with TX/RX buffer sizes
static STATE: StaticCell<State<NoopRawMutex, 1024, 1024>> = StaticCell::new();
let state = STATE.init(State::new());
// Configure the client
let broker = IpBroker::new(Ipv4Addr::new(192, 168, 1, 100), 1883);
let config = Config::builder()
.client_id("my-device".try_into().unwrap())
.keepalive_interval(Duration::from_secs(30))
.build();
let (mut mqtt_stack, client) = mqttrust::new(state, config);
// Run the stack in a background task
spawner.spawn(mqtt_task(mqtt_stack, broker)).unwrap();
// Subscribe and publish
let topics = ["sensor/temperature".into()];
let mut subscription = client
.subscribe::<1>(Subscribe::builder().topics(&topics).build())
.await
.unwrap();
client
.publish(Publish::builder().topic_name("sensor/temperature").payload(b"23.5").build())
.await
.unwrap();
Feature flags
| Feature | Default | Description |
|---------|---------|-------------|
| mqttv5 | Yes | Enable MQTTv5 protocol support |
| mqttv3 | No | Enable MQTTv3.1.1 protocol support |
| embedded-tls | Yes | TLS transport via embedded-tls |
| qos2 | No | Enable QoS 2 (Exactly Once) support |
| std | No | Enable standard library support |
| defmt | No | Logging via defmt |
| log | No | Logging via the log crate |
| thumbv6 | No | Cortex-M0/M0+ support |
Exactly one of mqttv5 or mqttv3 must be enabled.
Buffer size configuration
Internal buffer sizes are configured via feature flags. Each setting has a default value (shown below) and can be overridden by enabling the corresponding feature:
| Prefix | Default | Options |
|--------|---------|---------|
| max-client-id-len- | 64 | 16, 32, 64, 128, 256 |
| max-topic-len- | 128 | 32, 64, 128, 256 |
| max-sub-topics-per-msg- | 8 | 2, 4, 8, 16 |
| max-subscribers- | 8 | 2, 4, 8, 16 |
| max-inflight- | 8 | 2, 4, 8, 16 |
| max-pubsub-messages- | 16 | 8, 16, 32, 64, 128, 256 |
For example, to allow up to 256-byte topic names:
[dependencies]
mqttrust = { version = "1.0", features = ["mqttv5", "max-topic-len-256"] }
Contributing
Contributions are welcome. Please follow these guidelines:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
