MQTT Connector Professional Documentation - API Reference (2)
MQTT Connector Professional Documentation - API Reference (2)
0
DECEMBER 14, 2017
MQTT CONNECTOR
PROFESSIONAL
API REFERENCE
Developer guide
4EACH S.R.O.
WWW.4EACH.CZ
Copyright © 2017 4Each s.r.o.
MQTT_INITIALIZE
initializes connection details using credentials.
It takes the following arguments:
• Hostname – the hostname or IP address of the remote broker [string]
• Port - the network port of the server host to connect to [int]
• User – username to access to remote broker [string]
• Password - password to access to remote broker [string]
Note, that some brokers will accept anonymous users, even though they provide username and
password.
MQTT_INITIALIZE_ANONYMOUS
initializes connection details using anonymous access (without username and password).
It takes the following arguments:
• Hostname – the hostname or IP address of the remote broker [string]
• Port - the network port of the server host to connect to [int]
MQTT_SET_MAX_QUEUE
Sets maximum outgoing messages queue length. This is important in case of connection loss, because
every queued message is send after connection is restored. This can cause temporary network
overload. Parameter with value 0 sets unlimited queue length. When the queue is full, any further
outgoing messages would be dropped.
• Length - maximum outgoing messages queue length [int]
MQTT_SET_LAST_WILL
Set a Will to be sent to the broker. If the client disconnects without calling disconnect(), the broker will
publish the message on its behalf.
• Topic - the topic that the will message should be published on [string]
• Message - the message to send as a will [string]
• Qos - the quality of service level to use for the will [int]
• Retained - if set to True, the will message will be set as the “last known good”/retained message
for the topic [bool]
Note, that this function must be called after initialize function and before connect function.
MQTT_CONNECT
Connects the client to a broker, using default timeout period of 5 seconds.
12/14/2017 1
Copyright © 2017 4Each s.r.o.
MQTT_CONNECT_TIMEOUT
Connects the client to a broker, using custom timeout period defined by parameter.
• Timeout - Ensures maximum blocking duration of function call. Time is defined in milliseconds,
and changes in 100ms increments. [int]
MQTT_SUBSCRIBE
Subscribe the client to one topic.
• Topic - subscription topic to subscribe to [string]
MQTT_UNSUBSCRIBE
Unsubscribe the client from one topic.
• Topic - subscription topic to unsubscribe from [string]
MQTT_UNSUBSCRIBE_ALL
Unsubscribe the client from all topics.
MQTT_GET_MESSAGE
Function used to lookup incoming messages buffer. Returns latest received value from given topic.
• Topic – Specifies topic to search for [string]
Note, that this function has different communication interface than other methods. It doesn’t return
OK status code, but actual message payload. If error is present, error codes are returned.
MQTT_PUBLISH
This function causes a message to be sent to the broker and subsequently from the broker to any
clients subscribing to matching topics, using default timeout period of 1 second. It takes the following
arguments:
• Topic - the topic that the will message should be published on [string]
• Message - the message to send as a will [string]
• Qos - the quality of service level to use for the will [int]
• Retained - if set to True, the will message will be set as the “last known good”/retained message
for the topic [bool]
12/14/2017 2
Copyright © 2017 4Each s.r.o.
MQTT_PUBLISH_TIMEOUT
This function causes a message to be sent to the broker and subsequently from the broker to any
clients subscribing to matching topics, using custom timeout period defined by parameter. It takes the
following arguments:
• Topic - the topic that the will message should be published on [string]
• Message - the message to send as a will [string]
• Qos - the quality of service level to use for the will [int]
• Retained - if set to True, the will message will be set as the “last known good”/retained message
for the topic [bool]
• Timeout - Ensures maximum blocking duration of function call. Time is defined in milliseconds,
and changes in 100ms increments. [int]
MQTT_DISCONNECT
Disconnects from the broker cleanly. Using disconnect() will not result in a will message being sent by
the broker. Disconnect will not wait for all queued message to be sent.
12/14/2017 3
Copyright © 2017 4Each s.r.o.
12/14/2017 4