#rust-mqtt This library is a Rust wrapper around paho.mqtt.c lib. Currently only async lib is implemented.
Build paho.mqtt.c lib from develop branch.
cd ~/Downloads
git clone https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
git checkout develop
make
sudo make install
Mac OS X
Rust-mqtt links to libpaho-mqtt3a
. Mac OS X is not able find it from original files therefore create symlinks:
ln -s /usr/local/lib/libpaho-mqtt3a.so.1.0 /usr/local/lib/libpaho-mqtt3a.dylib
ln -s /usr/local/lib/libpaho-mqtt3a.so.1.0 /usr/local/lib/libpaho-mqtt3a.so.1
Put this in your Cargo.toml
:
[dependencies.mqtt]
git = "https://github.com/cubehub/rust-mqtt.git"
And this in your crate root:
extern crate mqtt;
Install and start mosquitto broker.
Mac OS X
brew install mosquitto
/usr/local/sbin/mosquitto
Ubuntu
sudo apt-get install mosquitto mosquitto-clients
mosquitto
Start rust-mqtt loopback example:
cargo run --example loopback
Tool called rust-bindgen is used to generate Rust functions from C files.
Mac OS X:
echo export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/:$DYLD_LIBRARY_PATH >> ~/.profile
Build rust-bindgen
git clone https://github.com/crabtw/rust-bindgen.git
cd rust-bindgen
cargo build
Generate Rust bindings
./target/debug/bindgen -l paho-mqtt3a -match MQTTAsync.h -match MQTTClientPersistence.h -o ~/Development/rust-mqtt/src/ffimqttasync.rs ~/Downloads/paho.mqtt.c/src/MQTTAsync.h
Notice that there are some issues with rust-bindgen generated code for callbacks. Therefore some manual modifications must be made to ffimqttasync.rs. Here is an example how to do it correctly: