This repository is the bundle of crates devoted to the MQTT protocol.
The client has the following functionality:
let netopt = NetworkOptions::new();
let mut opts = ClientOptions::new();
opts.set_reconnect(ReconnectMethod::ReconnectAfter(Duration::from_secs(1)));
let mut client = opts.connect("127.0.0.1:1883", netopt).expect("Can't connect to server");
client.publish("a/b/c", "hello", PubOpt.at_least_once()).unwrap();
while (client.await().unwrap().is_some()) {};
client.subscribe("a/b/c").unwrap();
loop {
match client.await().unwrap() {
Some(message) => {
println!("{:?}", message);
},
None => {}
}
}
MQTT Client installation:
git clone https://github.com/inre/rust-mq.git
cd rust-mq
make && make install
Subscribe to all topics:
mqttc sub
Or try,
mqttc sub -a test.mosquitto.org
mqttc sub -a iot.eclipse.org
mqttc sub -a test.mosca.io
mqttc sub -a broker.hivemq.com
Publish to the topic:
mqttc pub -t a/b/c -m "hello"
Maybe in future