diff options
| author | diogo464 <[email protected]> | 2025-12-09 22:30:42 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-12-09 22:30:42 +0000 |
| commit | a5845673cf052b606f722be10d48c5d963958050 (patch) | |
| tree | e21bf5848163d07fce4bf8e3d7474bfeed5d1aff | |
| parent | 6bb6d358f39c31b5486621b49da463f97226fea5 (diff) | |
moved embedded-mqtt crate to a module
| -rw-r--r-- | Cargo.lock | 8 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | embedded-mqtt/Cargo.lock | 25 | ||||
| -rw-r--r-- | embedded-mqtt/Cargo.toml | 13 | ||||
| -rw-r--r-- | mqtt-wire-format.md (renamed from embedded-mqtt/mqtt-wire-format.md) | 0 | ||||
| -rw-r--r-- | src/lib.rs | 14 | ||||
| -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
| @@ -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]] |
| 292 | name = "embedded-mqtt" | ||
| 293 | version = "0.1.0" | ||
| 294 | dependencies = [ | ||
| 295 | "embedded-io-async", | ||
| 296 | ] | ||
| 297 | |||
| 298 | [[package]] | ||
| 299 | name = "embedded-nal" | 291 | name = "embedded-nal" |
| 300 | version = "0.9.0" | 292 | version = "0.9.0" |
| 301 | source = "registry+https://github.com/rust-lang/crates.io-index" | 293 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -16,7 +16,6 @@ defmt = ["dep:defmt", "embassy-net/defmt", "embassy-sync/defmt"] | |||
| 16 | tracing = ["dep:tracing"] | 16 | tracing = ["dep:tracing"] |
| 17 | 17 | ||
| 18 | [dependencies] | 18 | [dependencies] |
| 19 | embedded-mqtt = { version = "0.1", path = "./embedded-mqtt" } | ||
| 20 | embassy-net = { version = "0.7", features = ["medium-ip", "proto-ipv4", "tcp", "dns"] } | 19 | embassy-net = { version = "0.7", features = ["medium-ip", "proto-ipv4", "tcp", "dns"] } |
| 21 | heapless = "0.9" | 20 | heapless = "0.9" |
| 22 | embassy-time = { version = "0.5" } | 21 | embassy-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. | ||
| 3 | version = 4 | ||
| 4 | |||
| 5 | [[package]] | ||
| 6 | name = "embedded-io" | ||
| 7 | version = "0.6.1" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" | ||
| 10 | |||
| 11 | [[package]] | ||
| 12 | name = "embedded-io-async" | ||
| 13 | version = "0.6.1" | ||
| 14 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 15 | checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" | ||
| 16 | dependencies = [ | ||
| 17 | "embedded-io", | ||
| 18 | ] | ||
| 19 | |||
| 20 | [[package]] | ||
| 21 | name = "embedded-mqtt" | ||
| 22 | version = "0.1.0" | ||
| 23 | dependencies = [ | ||
| 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] | ||
| 2 | name = "embedded-mqtt" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2024" | ||
| 5 | authors = ["diogo464 <[email protected]>"] | ||
| 6 | description = "mqtt client for embedded devices" | ||
| 7 | license = "MIT OR Apache-2.0" | ||
| 8 | repository = "https://github.com/diogo464/embassy-ha" | ||
| 9 | keywords = ["mqtt", "iot", "embedded"] | ||
| 10 | categories = ["embedded", "network-programming"] | ||
| 11 | |||
| 12 | [dependencies] | ||
| 13 | embedded-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 | |||
| @@ -28,6 +28,8 @@ use heapless::{ | |||
| 28 | }; | 28 | }; |
| 29 | use serde::Serialize; | 29 | use serde::Serialize; |
| 30 | 30 | ||
| 31 | mod mqtt; | ||
| 32 | |||
| 31 | pub mod log; | 33 | pub mod log; |
| 32 | pub use log::Format; | 34 | pub 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 @@ | |||
| 1 | use crate::protocol; | 1 | use super::protocol; |
| 2 | 2 | ||
| 3 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 3 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 4 | pub enum ConnectCode { | 4 | pub 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 @@ | |||
| 1 | use core::{mem::MaybeUninit, ops::Deref}; | 1 | use core::{mem::MaybeUninit, ops::Deref}; |
| 2 | 2 | ||
| 3 | use crate::varint; | 3 | use super::varint; |
| 4 | 4 | ||
| 5 | const DEFAULT_FIELD_BUFFER_CAP: usize = 32; | 5 | const 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 | |||
| 7 | mod connect_code; | 1 | mod connect_code; |
| 8 | mod field; | 2 | mod field; |
| 9 | mod packet_id; | 3 | mod packet_id; |
| @@ -20,7 +14,7 @@ pub use packet_id::PacketId; | |||
| 20 | pub use qos::Qos; | 14 | pub use qos::Qos; |
| 21 | pub use transport::Transport; | 15 | pub use transport::Transport; |
| 22 | 16 | ||
| 23 | use crate::{field::FieldBuffer, transport::TransportExt as _}; | 17 | use self::{field::FieldBuffer, transport::TransportExt as _}; |
| 24 | 18 | ||
| 25 | const DEFAULT_CLIENT_RX_BUFFER_SIZE: usize = 512; | 19 | const DEFAULT_CLIENT_RX_BUFFER_SIZE: usize = 512; |
| 26 | const DEFAULT_CLIENT_TX_BUFFER_SIZE: usize = 512; | 20 | const 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 @@ | |||
| 1 | use crate::{ConnectCode, PacketId, Qos, protocol, varint}; | 1 | use super::{ConnectCode, PacketId, Qos, protocol, varint}; |
| 2 | 2 | ||
| 3 | #[derive(Debug)] | 3 | #[derive(Debug)] |
| 4 | pub enum Error { | 4 | pub 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 @@ | |||
| 1 | use crate::{field::Field, varint}; | 1 | use super::{field::Field, varint}; |
| 2 | 2 | ||
| 3 | pub trait Transport: embedded_io_async::Read + embedded_io_async::Write {} | 3 | pub 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 @@ | |||
| 1 | use crate::{ | 1 | use 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 | |||
