mqttsubscribe
Subscribe to a topic.
Attention: Available only with Twin Activate commercial edition.
Syntax
[mid,status,messageinfo] = mqttsubscribe(clientid, topic, qos)
Inputs
- clientid
- client id, an output of mqttclient.
- topic
- topic to be subscribe.
- qos
- the requested Quality of Service for this subscription, valid options are 0,1,2.
Outputs
- mid
- message id of publish command.
- status
- status return codes.
- messageinfo
- description of publish status flag
Examples
subscribe to a given topic
cld = mqttclient('test.mosquitto.org','port',1883);
[mid, rc, Mqttmessageinfo] = mqttsubscribe(cld, 'topic100',2)
mid = 1
rc = 0
Mqttmessageinfo = success
subscribe to a topic with on_subscribe callback
function test_subscribecallback(clientid, mid, grant_qos)
printf('Subscribe callback is triggered successfully\n');
printf('message id: %s\n', num2str(mid));
printf('grant_qos: %s\n', num2str(grant_qos));
end
cld = mqttclient('test.mosquitto.org','port',1883,'on_subscribe','test_subscribecallback');
[mid, rc, Mqttmessageinfo] = mqttsubscribe(cld, 'topic100',2)
mid = 1
rc = 0
Mqttmessageinfo = success
Subscribe callback is triggered successfully
message id: 1
grant_qos: 1