Links

Rust

Quick guide for Rust library.

Getting Started

Visit the MQTT overview page for conventions, authentication, and more information.
This documentation uses the Paho MQTT library. This library is open-source, so you can check it out on GitHub.
Install the packages
[dependencies]
paho-mqtt = {git = "https://github.com/eclipse/paho.mqtt.rust", branch = "master"}
futures = { version = "0.3", features = ["compat"] }

Import Dependencies

Then import it and initialize it with the required packages. Of course, you’ll want to replace DEVICE_ID and DEVICE_TOKENwith your actual device credentials which you can find under your device settings on Qubitro Portal.
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

We strongly recommend using the 8883 port for MQTT over TLS connectivity.

Publish

Qubitro MQTT Publish Rust Example

Subscribe

Qubitro MQTT Subscribe Rust Example

​
✨
Support and Feedback

If you have further questions or suggestions, feel free to join
👇
-> Qubitro Community Discord via this invitation link.