mqttpublish
Publish a message on a topic.
Attention: Available only with Twin Activate commercial edition.
Syntax
[mid,status,messageinfo] = mqttpublish(clientid, topic, Payload, qos, retain)
Inputs
- clientid
- client id, an output of mqttclient.
- topic
- topic to which message to be published.
- payload
- Message to publish.
- qos
- Quality of service, valid options are 0,1,2.
- retain
- to specify whether to retain the the message.Valid values are falseand true.
Outputs
- mid
- message id of publish command.
- status
- status return codes.
- messageinfo
- description of publish status flag.
Examples
publish to a topic with
cld = mqttclient('test.mosquitto.org','port',1883);
[mid, rc, Mqttmessageinfo] = mqttpublish(cld, 'topic100','hello - test mqtt broker',2,true);
mid = 1
rc = 0
Mqttmessageinfo = on success.
publish to a topic with on_publish callback
function test_publishcallback(clientid, mid)
printf('publish callback is triggered successfully\n');
printf('message id: %s\n', num2str(mid));
%printf('return message: %s\n', Mqttmessageinfo);
end
cld = mqttclient('test.mosquitto.org','port',1883,'on_publish','test_publishcallback');
[mid, rc, Mqttmessageinfo] = mqttpublish(cld, 'topic100','hello - test mqtt broker',2,true);
publish callback is triggered successfully
message id: 1