Crates.io | mqtt-tiny |
lib.rs | mqtt-tiny |
version | 0.1.0 |
source | src |
created_at | 2023-12-31 17:05:20.444188 |
updated_at | 2024-10-05 20:34:43.850602 |
description | A tiny MQTT v3.1.1 codec implementation |
homepage | |
repository | https://github.com/KizzyCode/mqtt-tiny-rust |
max_upload_size | |
id | 1084916 |
size | 153,653 |
mqtt-tiny
Welcome to mqtt-tiny
🎉
mqtt-tiny
is a tiny, no-std
-compatible
MQTT 3.1.1 codec implementation. It is currently
limited to packet en- and decoding, and does not handle state or transport-level stuff.
use mqtt_tiny::{
packets::{ToWriter, TryFromReader},
Connack, Connect, Disconnect,
};
use std::{net::TcpStream, thread, time::Duration};
// Connect to a server
let mut connection = TcpStream::connect("127.0.0.1:1883").expect("failed to connect to server");
Connect::new(30, true, b"mqtttinyexamplesconnect").expect("failed to create CONNECT packet")
.write(&mut connection).expect("failed to send CONNECT packet");
// Await CONNACK
let connack = Connack::try_read(&mut connection).expect("failed to read CONNACK packet");
assert_eq!(connack.return_code(), 0, "connection was refused");
// Sleep 3s
const PAUSE: Duration = Duration::from_secs(3);
thread::sleep(PAUSE);
// Disconnect
Disconnect::new().write(&mut connection).expect("failed to write DISCONNECT packet");