Rust

Getting Started

Before getting started, make sure that Rust and required dependencies are installed by visiting the setup page

Import Dependencies

use paho_mqtt as mqtt;
use std::process;
use futures::executor::block_on;

Define Variables

let host = "HOST";
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

Qubitro MQTT Publish Rust Example