Rust

Getting Started

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

Import Dependencies

use std::{
env,
process,
time::Duration,
thread
};
use futures::{
executor::block_on,
stream::StreamExt,
};
use paho_mqtt as mqtt;

Define Variables

let host = "ssl://broker.qubitro.com:8883";
let dev_id = "PASTE_DEVICE_ID_HERE";
let dev_token = "PASTE_DEVICE_TOKEN_HERE";

Setup MQTT Client

Client Options:

let create_opts = mqtt::CreateOptionsBuilder::new()
.server_uri(host)
.persistence(mqtt::PersistenceType::None)
.client_id(dev_id)
.finalize();

MQTT Client:

let cli = mqtt::AsyncClient::new(create_opts).unwrap_or_else(|err| {
println!("Error creating the client: {}", err);
process::exit(1);
});

Examples

Publish

Qubitro MQTT Publish Rust Example

Subscribe

Qubitro MQTT Subscribe Rust Example

​