Mqtt Toolkit - @octave_mqtt/subscribe
- :
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 "")
If provided, the callback will be called with the topic name and message as arguments.
Outputs
subs
a list of current subscriptions for this client.
Examples
Subscribe to topic ’Test’:
client = mqttclient("tcp://127.0.0.1"); subs = subscribe(client, "Test");
Subscribe to topic ’Test’ and display any changed via callback:
# define simple function to show callback data function showmessage(t,v), printf("Topic: %s Message: %s\n", t, v); endfunction client = mqttclient("tcp://127.0.0.1"); subs = subscribe(client, "Test", "Callback", @showmessage);
See also: mqttclient, unsubscribe.