The Octave MQTT toolkit is a set of MQTT routines for GNU Octave
The toolkit must be installed and then loaded to be used.
It can be installed in GNU Octave directly from the website, or can be
installed in an off-line mode via a downloaded tarball.
The toolkit has a dependency on the PAHO-MQTT-C library
(https://www.eclipse.org/paho/), so it must be installed in order to
successfully install the toolkit.
The toolkit must be then be loaded once per each GNU Octave session in
order to use its functionality.
With an internet connection available, the octave mqtt package can be
installed from the octave-mqtt website using the following command
within GNU Octave:
pkg install https://sourceforge.net/projects/octave-mqtt/files/v0.0.3/octave-mqtt-0.0.3.tar.gz/download
The latest released version of the toolkit will be downloaded and
installed.
With the toolkit package already downloaded, and in the current
directory when running GNU Octave, the package can be installed using
the following command within GNU Octave:
pkg install octave-mqtt-0.0.3.tar.gz
Regardless of the method of installing the Joystick toolkit, in order to
use its functions, the toolkit must be loaded using the pkg load
command:
pkg load mqtt
The toolkit must be loaded on each GNU Octave session.
The overview connects to the public broker at HiveMQ
(https://www.hivemq.com/public-mqtt-broker/) and follows this general
flow:
Connection to the broker is done using the mqttclient function.
Example:
brokerAddress = "tcp://broker.hivemq.com";
port = 1883;
client = mqttclient(brokerAddress, "Port", port)
client =
Client with properties
BrokerAddress: tcp://broker.hivemq.com
Port: 1883
ClientID:
Timeout: 5
KeepAliveDuration: 60
Subscriptions: [0x3] table
Connected: 1
Additional properties can be included for Timeout, Username, Password
and more.
To get notifications for changes to a topic, subscribe to the topic.
Example:
topic = "octave/test/field1";
subscribe(client, topic)
ans =
scalar structure containing the fields:
Topic = octave/test/field1
QualityOfService = 0
Callback =
To publish data to the broker, use the wrote function.
Example:
write(client, topic, "hello world")
Reading data from a topic can be done using the peek function (which
will not clear the data from the received queue) or the read function
(that will clear the message from the received queue)
Example:
# see if there is message
msg = peek(client)
msg =
scalar structure containing the fields:
Time = 1.6560e+09
Topic = octave/test/field1
Data = hello world
# read message from queue
msg = read(client)
msg =
scalar structure containing the fields:
Time = 1.6560e+09
Topic = octave/test/field1
Data = hello world
To close the client and free any resources, use the clear function.
Example:
clear client
The functions currently available in the toolkit are described below;
==================
flush (OBJ)
Flush a MQTT client connection
Inputs
......
'obj'
A previously created octave_mqtt object
Outputs
.......
None
Examples
........
Open a client and flush the input
client = mqttclient("tcp://127.0.0.1);
flush(client);
See also: mqttclient.
MSG = peek (OBJ)
MSG = peek (OBJ, TOPIC)
Return the most recent message without removing it from the message
queue.
Inputs
......
'obj'
A previously created octave_mqtt object
'topic'
topic to match.
Outputs
.......
'msg'
The most recent message.
If no topic is specified, the last message from any topic will be
returned, otherwise the last matching the input topic.
Examples
........
:::matlab
client = mqttclient("tcp://127.0.0.1);
msg = peek(client);
MSGS = read (OBJ)
MSGS = read (OBJ, TOPIC)
Read available messages and remove from message queue.
Inputs
......
'obj'
A previously created octave_mqtt object
'topic'
topic to match.
Outputs
.......
'msgs'
Messages from the message queue
If no topic is specified, messages from any topic will be returned,
otherwise from the matching input topic.
Examples
........
client = mqttclient("tcp://127.0.0.1);
msgs = read(client, "test");
SUBS = subscribe (OBJ, TOPIC)
SUBS = subscribe (OBJ, TOPIC, [PROPNAME, PROPVALUE ....])
Subscribe to a topic
Inputs
......
'obj'
A previously created octave_mqtt object
'topic'
String topic to subscribe to.
'propname, propvalue'
Optional property name / value pairs.
Known property name / value pairs:
'QualityOfService'
Numeric QualityOfService [0-2] (default 0)
'Callback'
Callback function name or handle (default "")
Outputs
.......
'subs'
a list of current subscriptions for this client.
Examples
........
client = mqttclient("tcp://127.0.0.1);
subs = subscribe(client', "Test");
See also: mqttclient, unsubscribe.
unsubscribe (OBJ, TOPIC)
Unsubscribe from TOPIC
Inputs
......
'obj'
A previously created octave_mqtt object
'topic'
string topic name.
Outputs
.......
None
Examples
........
client = mqttclient("tcp://127.0.0.1);
subscribe(client, "test1");
unsubscribe(client, "test1");
See also: mqttclient, subscribe.
write (OBJ, TOPIC, VALUE)
write (OBJ, TOPIC, VALUE, [PROPNAME, PROPVALUE ....])
Write VALUE to TOPIC.
Inputs
......
'obj'
A previously created octave_mqtt object
'topic'
String topic to write to.
'value'
String value to write to topic.
'propname, propvalue'
Optional property name / value pairs.
Known property options are:
'QualityOfService'
Numeric QualityOfService [0-2] (default 0)
'Retain'
boolean flag value for retaining message (default false)
Outputs
.......
'client'
a octave_mqtt object.
Examples
........
Open a client connection and write some values.
client = mqttclient("tcp://127.0.0.1);
write(client, "mytopic", "test1");
write(client, "mytopic", "test1", "QualityOfService", 1);
See also: mqttclient.
CLIENT = mqttclient (BROKERADDR)
CLIENT = mqttclient (BROKERADDR, [NAME, VALUE ....])
Create a MQTT client connection
Inputs
......
'brokerAddr'
name or ip address with protocol. ie: tcp://127.0.0.1.
'name, value'
Optional name / value pairs.
Known options are:
'Port'
Numeric port number to connect to (default 1883)
'Timeout'
Numeric timeout value in seconds (default 5)
'KeepAliveDuration'
Numeric keep alive value in seconds (default 60)
'ClientID'
String client Id
'Username'
String username
'Password'
String password
'CARootCertificate'
String full file path to a root certificate file when using a secure connection
'ClientCertificate'
String full file path to a client certificate file when using a secure connection
'ClientKey'
String full file path to a private client key file when using a secure connection
'SSLPassword'
String Password to decrypt the client key file
Outputs
.......
'client'
a octave_mqtt object
Properties
..........
A octave_mqtt object has the following properties:
'BrokerAddress'
broker url
'Port'
Numeric port number to connect to (default 1883)
'Timeout'
Numeric timeout value in seconds (default 5)
'KeepAliveDuration'
Numeric keep alive value in seconds (default 60)
'ClientID'
String client Id
Examples
........
Create a new mqttclient
client = mqttclient("tcp://127.0.0.1);