MATLAB interface to MQTT, based on the Paho Java client. Updated versions of the Java client org.eclipse.paho.client.mqttv3-1.2.2.jar included in the jars directory can be found on this page.
Bare bones implementation which allows to connect to a MQTT broker (e.g. EMQ X Broker https://www.emqx.io/products/broker), publish and subscribe to multiple topics. The MqttInterface matlab class allows for an easy interface to the basic functionalities of MQTT-based message exchange. Besides strings and JSON messages, it is also possible to directly send and receive MATLAB objects.
Minimal test:
- run a MQTT broker (e.g. in the case of EMQ X Broker: in a terminal,
cd emqx_downloaded_folder/binand run./emqx start) - open MATLAB and run
example.m - if the class
iMqttClientis not found by MATLAB, follow step 2 below to recompile the Java source.
Extending functionalities:
- the source file
iMqttClient.javain thesrcdirectory can be modified to add the desired functionalities - a
iMqttClient.jarfile can be (re)generated as follows:
javacis required for this to work (on Ubuntu 18.04, for instance, it can be installed throughsudo apt install default-jdk)- run
version -javain the MATLAB command window to get the version of Java of your MATLAB installation (e.g. Java 1.8.0...) - in a terminal, cd to the
jarsdirectory and runpack_to_jar.shpassing the MATLAB Java version as argument (e.g.sh pack_to_jar.sh 1.8) - a file
iMqttClient.jarshould appear in the folderjars
- the updated Java class packed in the
iMqttClient.jarfile in thejarsfolder can be then imported, together with its dependenciesorg.eclipse.paho.client.mqttv3-1.2.2.jar, in MATLAB using thejavaaddpathcommand as done inexample.m