aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-12-09 22:30:42 +0000
committerdiogo464 <[email protected]>2025-12-09 22:30:42 +0000
commita5845673cf052b606f722be10d48c5d963958050 (patch)
treee21bf5848163d07fce4bf8e3d7474bfeed5d1aff
parent6bb6d358f39c31b5486621b49da463f97226fea5 (diff)
moved embedded-mqtt crate to a module
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml1
-rw-r--r--embedded-mqtt/Cargo.lock25
-rw-r--r--embedded-mqtt/Cargo.toml13
-rw-r--r--mqtt-wire-format.md (renamed from embedded-mqtt/mqtt-wire-format.md)0
-rw-r--r--src/lib.rs14
-rw-r--r--src/mqtt/connect_code.rs (renamed from embedded-mqtt/src/connect_code.rs)2
-rw-r--r--src/mqtt/field.rs (renamed from embedded-mqtt/src/field.rs)2
-rw-r--r--src/mqtt/mod.rs (renamed from embedded-mqtt/src/lib.rs)8
-rw-r--r--src/mqtt/packet_id.rs (renamed from embedded-mqtt/src/packet_id.rs)0
-rw-r--r--src/mqtt/protocol.rs (renamed from embedded-mqtt/src/protocol.rs)0
-rw-r--r--src/mqtt/qos.rs (renamed from embedded-mqtt/src/qos.rs)0
-rw-r--r--src/mqtt/rx.rs (renamed from embedded-mqtt/src/rx.rs)2
-rw-r--r--src/mqtt/transport.rs (renamed from embedded-mqtt/src/transport.rs)2
-rw-r--r--src/mqtt/tx.rs (renamed from embedded-mqtt/src/tx.rs)2
-rw-r--r--src/mqtt/varint.rs (renamed from embedded-mqtt/src/varint.rs)0
16 files changed, 14 insertions, 65 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9db673d..780e0e1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -159,7 +159,6 @@ dependencies = [
159 "embassy-sync", 159 "embassy-sync",
160 "embassy-time", 160 "embassy-time",
161 "embedded-io-async", 161 "embedded-io-async",
162 "embedded-mqtt",
163 "heapless 0.9.2", 162 "heapless 0.9.2",
164 "rand", 163 "rand",
165 "serde", 164 "serde",
@@ -289,13 +288,6 @@ dependencies = [
289] 288]
290 289
291[[package]] 290[[package]]
292name = "embedded-mqtt"
293version = "0.1.0"
294dependencies = [
295 "embedded-io-async",
296]
297
298[[package]]
299name = "embedded-nal" 291name = "embedded-nal"
300version = "0.9.0" 292version = "0.9.0"
301source = "registry+https://github.com/rust-lang/crates.io-index" 293source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 2b46089..6fa49c4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,6 @@ defmt = ["dep:defmt", "embassy-net/defmt", "embassy-sync/defmt"]
16tracing = ["dep:tracing"] 16tracing = ["dep:tracing"]
17 17
18[dependencies] 18[dependencies]
19embedded-mqtt = { version = "0.1", path = "./embedded-mqtt" }
20embassy-net = { version = "0.7", features = ["medium-ip", "proto-ipv4", "tcp", "dns"] } 19embassy-net = { version = "0.7", features = ["medium-ip", "proto-ipv4", "tcp", "dns"] }
21heapless = "0.9" 20heapless = "0.9"
22embassy-time = { version = "0.5" } 21embassy-time = { version = "0.5" }
diff --git a/embedded-mqtt/Cargo.lock b/embedded-mqtt/Cargo.lock
deleted file mode 100644
index 8f52b7a..0000000
--- a/embedded-mqtt/Cargo.lock
+++ /dev/null
@@ -1,25 +0,0 @@
1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing.
3version = 4
4
5[[package]]
6name = "embedded-io"
7version = "0.6.1"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
10
11[[package]]
12name = "embedded-io-async"
13version = "0.6.1"
14source = "registry+https://github.com/rust-lang/crates.io-index"
15checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f"
16dependencies = [
17 "embedded-io",
18]
19
20[[package]]
21name = "embedded-mqtt"
22version = "0.1.0"
23dependencies = [
24 "embedded-io-async",
25]
diff --git a/embedded-mqtt/Cargo.toml b/embedded-mqtt/Cargo.toml
deleted file mode 100644
index 405efab..0000000
--- a/embedded-mqtt/Cargo.toml
+++ /dev/null
@@ -1,13 +0,0 @@
1[package]
2name = "embedded-mqtt"
3version = "0.1.0"
4edition = "2024"
5authors = ["diogo464 <[email protected]>"]
6description = "mqtt client for embedded devices"
7license = "MIT OR Apache-2.0"
8repository = "https://github.com/diogo464/embassy-ha"
9keywords = ["mqtt", "iot", "embedded"]
10categories = ["embedded", "network-programming"]
11
12[dependencies]
13embedded-io-async = "0.6"
diff --git a/embedded-mqtt/mqtt-wire-format.md b/mqtt-wire-format.md
index b4d4f65..b4d4f65 100644
--- a/embedded-mqtt/mqtt-wire-format.md
+++ b/mqtt-wire-format.md
diff --git a/src/lib.rs b/src/lib.rs
index 3e91272..714e186 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,8 @@ use heapless::{
28}; 28};
29use serde::Serialize; 29use serde::Serialize;
30 30
31mod mqtt;
32
31pub mod log; 33pub mod log;
32pub use log::Format; 34pub use log::Format;
33 35
@@ -215,7 +217,7 @@ pub struct DeviceResources {
215 waker: AtomicWaker, 217 waker: AtomicWaker,
216 entities: [RefCell<Option<EntityData>>; Self::ENTITY_LIMIT], 218 entities: [RefCell<Option<EntityData>>; Self::ENTITY_LIMIT],
217 219
218 mqtt_resources: embedded_mqtt::ClientResources, 220 mqtt_resources: mqtt::ClientResources,
219 publish_buffer: Vec<u8, 2048>, 221 publish_buffer: Vec<u8, 2048>,
220 subscribe_buffer: Vec<u8, 128>, 222 subscribe_buffer: Vec<u8, 128>,
221 discovery_buffer: Vec<u8, 2048>, 223 discovery_buffer: Vec<u8, 2048>,
@@ -422,7 +424,7 @@ pub struct Device<'a> {
422 waker: &'a AtomicWaker, 424 waker: &'a AtomicWaker,
423 entities: &'a [RefCell<Option<EntityData>>], 425 entities: &'a [RefCell<Option<EntityData>>],
424 426
425 mqtt_resources: &'a mut embedded_mqtt::ClientResources, 427 mqtt_resources: &'a mut mqtt::ClientResources,
426 publish_buffer: &'a mut VecView<u8>, 428 publish_buffer: &'a mut VecView<u8>,
427 subscribe_buffer: &'a mut VecView<u8>, 429 subscribe_buffer: &'a mut VecView<u8>,
428 discovery_buffer: &'a mut VecView<u8>, 430 discovery_buffer: &'a mut VecView<u8>,
@@ -585,8 +587,8 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re
585 .expect("device availability buffer too small"); 587 .expect("device availability buffer too small");
586 let availability_topic = device.availability_topic_buffer.as_str(); 588 let availability_topic = device.availability_topic_buffer.as_str();
587 589
588 let mut client = embedded_mqtt::Client::new(device.mqtt_resources, transport); 590 let mut client = mqtt::Client::new(device.mqtt_resources, transport);
589 let connect_params = embedded_mqtt::ConnectParams { 591 let connect_params = mqtt::ConnectParams {
590 will_topic: Some(availability_topic), 592 will_topic: Some(availability_topic),
591 will_payload: Some(NOT_AVAILABLE_PAYLOAD.as_bytes()), 593 will_payload: Some(NOT_AVAILABLE_PAYLOAD.as_bytes()),
592 will_retain: true, 594 will_retain: true,
@@ -744,7 +746,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re
744 client.publish_with( 746 client.publish_with(
745 availability_topic, 747 availability_topic,
746 AVAILABLE_PAYLOAD.as_bytes(), 748 AVAILABLE_PAYLOAD.as_bytes(),
747 embedded_mqtt::PublishParams { 749 mqtt::PublishParams {
748 retain: true, 750 retain: true,
749 ..Default::default() 751 ..Default::default()
750 }, 752 },
@@ -858,7 +860,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re
858 .await 860 .await
859 { 861 {
860 Ok(embassy_futures::select::Either::First(packet)) => match packet { 862 Ok(embassy_futures::select::Either::First(packet)) => match packet {
861 Ok(embedded_mqtt::Packet::Publish(publish)) => publish, 863 Ok(mqtt::Packet::Publish(publish)) => publish,
862 Err(err) => { 864 Err(err) => {
863 crate::log::error!( 865 crate::log::error!(
864 "mqtt receive failed with: {:?}", 866 "mqtt receive failed with: {:?}",
diff --git a/embedded-mqtt/src/connect_code.rs b/src/mqtt/connect_code.rs
index 148eff6..570ce0f 100644
--- a/embedded-mqtt/src/connect_code.rs
+++ b/src/mqtt/connect_code.rs
@@ -1,4 +1,4 @@
1use crate::protocol; 1use super::protocol;
2 2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)] 3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum ConnectCode { 4pub enum ConnectCode {
diff --git a/embedded-mqtt/src/field.rs b/src/mqtt/field.rs
index d921b27..9e67e63 100644
--- a/embedded-mqtt/src/field.rs
+++ b/src/mqtt/field.rs
@@ -1,6 +1,6 @@
1use core::{mem::MaybeUninit, ops::Deref}; 1use core::{mem::MaybeUninit, ops::Deref};
2 2
3use crate::varint; 3use super::varint;
4 4
5const DEFAULT_FIELD_BUFFER_CAP: usize = 32; 5const DEFAULT_FIELD_BUFFER_CAP: usize = 32;
6 6
diff --git a/embedded-mqtt/src/lib.rs b/src/mqtt/mod.rs
index ddf9d21..30e3a33 100644
--- a/embedded-mqtt/src/lib.rs
+++ b/src/mqtt/mod.rs
@@ -1,9 +1,3 @@
1//! mqtt client library for embedded devices.
2//!
3
4
5#![no_std]
6
7mod connect_code; 1mod connect_code;
8mod field; 2mod field;
9mod packet_id; 3mod packet_id;
@@ -20,7 +14,7 @@ pub use packet_id::PacketId;
20pub use qos::Qos; 14pub use qos::Qos;
21pub use transport::Transport; 15pub use transport::Transport;
22 16
23use crate::{field::FieldBuffer, transport::TransportExt as _}; 17use self::{field::FieldBuffer, transport::TransportExt as _};
24 18
25const DEFAULT_CLIENT_RX_BUFFER_SIZE: usize = 512; 19const DEFAULT_CLIENT_RX_BUFFER_SIZE: usize = 512;
26const DEFAULT_CLIENT_TX_BUFFER_SIZE: usize = 512; 20const DEFAULT_CLIENT_TX_BUFFER_SIZE: usize = 512;
diff --git a/embedded-mqtt/src/packet_id.rs b/src/mqtt/packet_id.rs
index 4e0158f..4e0158f 100644
--- a/embedded-mqtt/src/packet_id.rs
+++ b/src/mqtt/packet_id.rs
diff --git a/embedded-mqtt/src/protocol.rs b/src/mqtt/protocol.rs
index bf77d78..bf77d78 100644
--- a/embedded-mqtt/src/protocol.rs
+++ b/src/mqtt/protocol.rs
diff --git a/embedded-mqtt/src/qos.rs b/src/mqtt/qos.rs
index 0d464b4..0d464b4 100644
--- a/embedded-mqtt/src/qos.rs
+++ b/src/mqtt/qos.rs
diff --git a/embedded-mqtt/src/rx.rs b/src/mqtt/rx.rs
index 2d2164f..e81171d 100644
--- a/embedded-mqtt/src/rx.rs
+++ b/src/mqtt/rx.rs
@@ -1,4 +1,4 @@
1use crate::{ConnectCode, PacketId, Qos, protocol, varint}; 1use super::{ConnectCode, PacketId, Qos, protocol, varint};
2 2
3#[derive(Debug)] 3#[derive(Debug)]
4pub enum Error { 4pub enum Error {
diff --git a/embedded-mqtt/src/transport.rs b/src/mqtt/transport.rs
index 5a6a016..780b0ba 100644
--- a/embedded-mqtt/src/transport.rs
+++ b/src/mqtt/transport.rs
@@ -1,4 +1,4 @@
1use crate::{field::Field, varint}; 1use super::{field::Field, varint};
2 2
3pub trait Transport: embedded_io_async::Read + embedded_io_async::Write {} 3pub trait Transport: embedded_io_async::Read + embedded_io_async::Write {}
4 4
diff --git a/embedded-mqtt/src/tx.rs b/src/mqtt/tx.rs
index ae3d641..cdf1c75 100644
--- a/embedded-mqtt/src/tx.rs
+++ b/src/mqtt/tx.rs
@@ -1,4 +1,4 @@
1use crate::{ 1use super::{
2 PacketId, 2 PacketId,
3 field::{self, Field, FieldBuffer}, 3 field::{self, Field, FieldBuffer},
4 protocol, 4 protocol,
diff --git a/embedded-mqtt/src/varint.rs b/src/mqtt/varint.rs
index 63bdd06..63bdd06 100644
--- a/embedded-mqtt/src/varint.rs
+++ b/src/mqtt/varint.rs