|
static void | mqtt_set_initialized_status (gboolean status) |
| Set the global init status.
|
|
gboolean | mqtt_is_initialized () |
| Get the global init status.
|
|
static void | mqtt_set_global_server_uri (const char *server_uri_in) |
| Set the global mqtt server URI.
|
|
static const char * | mqtt_get_global_server_uri () |
| Get global server URI.
|
|
static mqtt_t * | mqtt_get_global_client () |
|
static void | mqtt_set_global_client (mqtt_t *mqtt) |
| Set global client.
|
|
static int | mqtt_disconnect (mqtt_t *mqtt) |
| Disconnect from the Broker.
|
|
static void | mqtt_client_destroy (mqtt_t *mqtt) |
| Destroy the MQTTClient client of the mqtt_t.
|
|
static void | mqtt_client_data_destroy (mqtt_t **mqtt) |
| Destroy the mqtt_t data.
|
|
void | mqtt_reset () |
| Destroy MQTTClient handle and free mqtt_t.
|
|
static MQTTClient | mqtt_create (mqtt_t *mqtt, const char *address) |
| Create a new mqtt client.
|
|
static char * | mqtt_set_client_id (mqtt_t *mqtt) |
| Set a random client ID.
|
|
static int | mqtt_set_client (mqtt_t *mqtt, MQTTClient client) |
| Set MQTTClient of mqtt_t.
|
|
static int | mqtt_connect (mqtt_t *mqtt, const char *server_uri) |
| Make new client and connect to mqtt broker.
|
|
int | mqtt_init (const char *server_uri) |
| Init MQTT communication.
|
|
static void | mqtt_reinit () |
| Reinitializes communication after mqtt_reset was used.
|
|
static int | mqtt_client_publish (mqtt_t *mqtt, const char *topic, const char *msg) |
| Use the provided client to publish message on a topic.
|
|
int | mqtt_publish (const char *topic, const char *msg) |
| Publish a message on topic using the global client.
|
|
int | mqtt_publish_single_message (const char *server_uri_in, const char *topic, const char *msg) |
| Send a single message.
|
|
static int | mqtt_subscribe_r (mqtt_t *mqtt, int qos, const char *topic) |
| subscribes to a single topic.
|
|
int | mqtt_subscribe (const char *topic) |
| subscribes to a single topic.
|
|
static int | mqtt_unsubscribe_r (mqtt_t *mqtt, const char *topic) |
| unsubscribe a single topic.
|
|
int | mqtt_unsubscribe (const char *topic) |
| unsubscribe a single topic.
|
|
static int | mqtt_retrieve_message_r (mqtt_t *mqtt, char **topic, int *topic_len, char **payload, int *payload_len, const unsigned int timeout) |
| wait for a given timeout in ms to retrieve any message of subscribed topics
|
|
int | mqtt_retrieve_message (char **topic, int *topic_len, char **payload, int *payload_len, const unsigned int timeout) |
| wait for a given timeout in ms to retrieve any message of subscribed topics
|
|
Implementation of API to handle MQTT communication.
This file contains all methods to handle MQTT communication.
Before communicating via MQTT a handle has to be created and a connection established. This is done by calling mqtt_init(). Mmessages can be published via mqtt_publish() afterwards.
mqtt_init() should be called only once at program init. After forking mqtt_reset() has to be called in the child. mqtt_publish() can be used after mqtt_reset(). No additional mqtt_init() is needed. A new connection will be established on first call to publish for the current process.
mqtt_publish_single_message() is a convenience function for sending single messages. Do not send repeated messages via this function as a new connection is established every call.
int mqtt_retrieve_message |
( |
char ** |
topic, |
|
|
int * |
topic_len, |
|
|
char ** |
payload, |
|
|
int * |
payload_len, |
|
|
const unsigned int |
timeout |
|
) |
| |
wait for a given timeout in ms to retrieve any message of subscribed topics
This function performs a synchronous receive of incoming messages. Using this function allows a single-threaded client subscriber application to be written. When called, this function blocks until the next message arrives or the specified timeout expires.
Important note: The application must free() the memory allocated to the topic and payload when processing is complete.
- Parameters
-
[out] | topic | The address of a pointer to a topic. This function allocates the memory for the topic and returns it to the application by setting topic to point to the topic. |
[out] | topic_len | The length of the topic. |
[out] | payload | The address of a pointer to the received message. This function allocates the memory for the payload and returns it to the application by setting payload to point to the received message. The pointer is set to NULL if the timeout expires. |
[out] | payload_len | The length of the payload. |
| timeout | The length of time to wait for a message in milliseconds. |
- Returns
- 0 on message retrieved, 1 on timeout and -1 on an error.
static int mqtt_retrieve_message_r |
( |
mqtt_t * |
mqtt, |
|
|
char ** |
topic, |
|
|
int * |
topic_len, |
|
|
char ** |
payload, |
|
|
int * |
payload_len, |
|
|
const unsigned int |
timeout |
|
) |
| |
|
static |
wait for a given timeout in ms to retrieve any message of subscribed topics
This function performs a synchronous receive of incoming messages. Using this function allows a single-threaded client subscriber application to be written. When called, this function blocks until the next message arrives or the specified timeout expires.
Important note: The application must free() the memory allocated to the topic and payload when processing is complete.
- Parameters
-
| mqtt | an already created and connected mqtt client. |
[out] | topic | The address of a pointer to a topic. This function allocates the memory for the topic and returns it to the application by setting topic to point to the topic. |
[out] | topic_len | The length of the topic. |
[out] | payload | The address of a pointer to the received message. This function allocates the memory for the payload and returns it to the application by setting payload to point to the received message. The pointer is set to NULL if the timeout expires. |
[out] | payload_len | The length of the payload. |
| timeout | The length of time to wait for a message in milliseconds. |
- Returns
- 0 on message retrieved, 1 on no message retrieved and -1 on an error.