diff options
author | Marcel Müller <neikos@neikos.email> | 2024-03-27 16:21:50 +0100 |
---|---|---|
committer | Marcel Müller <neikos@neikos.email> | 2024-03-27 16:46:02 +0100 |
commit | 736f8da046483d810732f480e5e8816218599bbf (patch) | |
tree | 14f184e1c6992b5ef39842c7a6480ef54a240621 | |
parent | 49d932302a198186c4d489d6093bbc223f56b826 (diff) |
Add a rudimentary mqtt client
Signed-off-by: Marcel Müller <neikos@neikos.email>
-rw-r--r-- | cloudmqtt-bin/Cargo.toml | 3 | ||||
-rw-r--r-- | cloudmqtt-bin/src/bin/client.rs | 38 | ||||
-rw-r--r-- | cloudmqtt-bin/src/main.rs | 9 |
3 files changed, 41 insertions, 9 deletions
diff --git a/cloudmqtt-bin/Cargo.toml b/cloudmqtt-bin/Cargo.toml index 98164ae..6c76656 100644 --- a/cloudmqtt-bin/Cargo.toml +++ b/cloudmqtt-bin/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.5.4", features = ["derive"] } +cloudmqtt = { version = "0.5.0", path = ".." } +tokio = { version = "1.36.0", features = ["full"] } diff --git a/cloudmqtt-bin/src/bin/client.rs b/cloudmqtt-bin/src/bin/client.rs new file mode 100644 index 0000000..5188edc --- /dev/null +++ b/cloudmqtt-bin/src/bin/client.rs @@ -0,0 +1,38 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use clap::Parser; +use cloudmqtt::client::MqttClientConnector; +use cloudmqtt::transport::MqttConnectTransport; +use tokio::net::TcpStream; + +#[derive(Debug, Parser)] +#[command(version, about, long_about = None)] +struct Args { + #[arg(long)] + hostname: String, +} + +#[tokio::main] +async fn main() { + let args = Args::parse(); + + let socket = TcpStream::connect(args.hostname).await.unwrap(); + + let connection = MqttConnectTransport::TokioTcp(socket); + let client_id = cloudmqtt::client_identifier::ClientIdentifier::PotentiallyServerProvided; + + let connector = MqttClientConnector::new( + connection, + client_id, + cloudmqtt::client::CleanStart::Yes, + cloudmqtt::keep_alive::KeepAlive::Disabled, + ); + + let _client = connector.connect().await.unwrap(); + + println!("Yay, we connected! That's all for now"); +} diff --git a/cloudmqtt-bin/src/main.rs b/cloudmqtt-bin/src/main.rs deleted file mode 100644 index 6f15778..0000000 --- a/cloudmqtt-bin/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// - -fn main() { - println!("Hello, world!"); -} |