Mqtt Toolkit - @octave_mqtt/subscribe
- :
subs =subscribe(obj, topic) - :
subs =subscribe(obj, topic, [propname, propvalue ....]) Subscribe to a topic
Inputs
objA previously created octave_mqtt object
topicString topic to subscribe to.
propname, propvalueOptional property name / value pairs.
Known property name / value pairs:
QualityOfServiceNumeric QualityOfService [0-2] (default 0)
CallbackCallback function name or handle (default "")
If provided, the callback will be called with the topic name and message as arguments.
Outputs
subsa 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.