Rust

Getting Started

1
[dependencies]
2
paho-mqtt = {git = "https://github.com/eclipse/paho.mqtt.rust", branch = "master"}
3
futures = { version = "0.3", features = ["compat"] }
Copied!

Import Dependencies

1
use std::{
2
env,
3
process,
4
time::Duration,
5
thread
6
};
7
use futures::{
8
executor::block_on,
9
stream::StreamExt,
10
};
11
use paho_mqtt as mqtt;
Copied!

Define Variables

1
let host = "ssl://broker.qubitro.com:8883";
2
let dev_id = "PASTE_DEVICE_ID_HERE";
3
let dev_token = "PASTE_DEVICE_TOKEN_HERE";
Copied!

Setup MQTT Client

Client Options:
1
let create_opts = mqtt::CreateOptionsBuilder::new()
2
.server_uri(host)
3
.persistence(mqtt::PersistenceType::None)
4
.client_id(dev_id)
5
.finalize();
Copied!
MQTT Client:
1
let cli = mqtt::AsyncClient::new(create_opts).unwrap_or_else(|err| {
2
println!("Error creating the client: {}", err);
3
process::exit(1);
4
});
Copied!

Examples

Publish

Qubitro MQTT Publish Rust Example

Subscribe

Qubitro MQTT Subscribe Rust Example
Last modified 5mo ago