mqttclient
Create a MQTT Client connection.
Syntax
cid = mqttclient(brokeraddress)
cid = mqttclient(brokeraddress,property,value)
Inputs
- brokeraddress
- broker address tag
- property, values
- Properties that control the appearance or behavior of the graphics object.
Outputs
- cid
- client id of the mqtt broker connected to.
Examples
function test_connectcallback(clientid, rc, Mqttmessageinfo)
printf('connectcallback clientid=: %s\n', clientid);
printf('return code: %s\n', num2str(rc));
printf('return message: %s\n', Mqttmessageinfo);
end
function test_publishcallback(clientid, mid)
printf('publishcallback clientid=: %s\n', clientid);
printf('message id: %s\n', num2str(mid));
end
function test_subscribecallback(clientid, mid,grand_qos)
printf('subscribecallback clientid=: %s\n', clientid);
printf('message id: %s\n', num2str(mid));
printf('grant_qos: %s\n', num2str(grand_qos));
end
function test_messcallback(clientid, topic,msg)
printf('messcallback clientid=: %s\n', clientid);
printf('topic: %s\n', topic);
printf('msg: %s\n', msg);
end
function test_disconnectcallback(clientid, rc, Mqttmessageinfo)
printf('disconnectcallback clientid=: %s\n', clientid);
printf('return code: %s\n', num2str(rc));
printf('return message: %s\n', Mqttmessageinfo);
end
cld = mqttclient('test.mosquitto.org','port',1883, 'client_id', 'c1'...
,'on_connect','test_connectcallback'...
,'on_publish','test_publishcallback'...
,'on_subscribe','test_subscribecallback'...
,'on_message','test_messcallback' ...
, 'on_disconnect', 'test_disconnectcallback')
cld = c1
connectcallback clientid=: c1
return code: 0
return message: Connection Accepted.
Comments
If user didn’t provide client id,a random generated string which includes characters anywhere between 5 characters to 23 characters.
Return code of the connection response in connection callback are defined by the MQTT protocol version in use. For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html. For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html