5.5. mqtt_client
— MQTT client¶
Source code: src/inet/mqtt_client.h, src/inet/mqtt_client.c
Test code: tst/inet/mqtt_client/main.c
Test coverage: src/inet/mqtt_client.c
Typedefs
- typedef
Prototype of the on-publish callback function.
- Return
- Number of bytes read from the input channel.
- Parameters
client_p
: The client.topic_p
: The received topic.chin_p
: The channel to read the value from.size
: Number of bytes of the value to read from chin_p.
- typedef
Prototype of the on-error callback function.
- Return
- zero(0) or nagative error code.
- Parameters
client_p
: The client.error
: The number of error that occured.
Enums
-
enum type
mqtt_client_state_t
¶ Values:
-
enum type
mqtt_qos_t
¶ Quality of Service.
Values:
- = 0
- = 1
- = 2
Functions
-
int
mqtt_client_init
(struct mqtt_client_t *self_p, const char *name_p, struct log_object_t *log_object_p, void *chout_p, void *chin_p, mqtt_on_publish_t on_publish, mqtt_on_error_t on_error)¶ Initialize given MQTT client.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.name_p
: Name of the thread.log_object_p
: Log object.chout_p
: Output channel for client to server packets.chin_p
: Input channel for server to client packets.on_publish
: On-publish callback function. Called when the server publishes a message.on_error
: On-error callback function. Called when an error occurs.
-
void *
mqtt_client_main
(void *arg_p)¶ MQTT client thread.
- Return
- Never returns.
- Parameters
arg_p
: MQTT client.
-
int
mqtt_client_connect
(struct mqtt_client_t *self_p)¶ Establish a connection to the server.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.
-
int
mqtt_client_disconnect
(struct mqtt_client_t *self_p)¶ Disconnect from the server.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.
-
int
mqtt_client_ping
(struct mqtt_client_t *self_p)¶ Send a ping request to the server (broker) and wait for the ping response.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.
-
int
mqtt_client_publish
(struct mqtt_client_t *self_p, struct mqtt_application_message_t *message_p)¶ Publish given topic.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.topic_p
: Topic.payload_p
: Payload to publish. May be NULL.payload_size
: Number of bytes in the payload.
-
int
mqtt_client_subscribe
(struct mqtt_client_t *self_p, struct mqtt_application_message_t *message_p)¶ Subscribe to given message.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.message_p
: The message to subscribe to. The payload part of the message is not used. The topic may use wildcards, given that the server supports it.
-
int
mqtt_client_unsubscribe
(struct mqtt_client_t *self_p, struct mqtt_application_message_t *message_p)¶ Unsubscribe from given message.
- Return
- zero(0) or negative error code.
- Parameters
self_p
: MQTT client.message_p
: The message to unsubscribe from. Only the topic in the message is used.
- struct
- #include <mqtt_client.h>
MQTT client.
Public Members
-
const char *
mqtt_client_t::
name_p
¶
-
struct log_object_t *
mqtt_client_t::
log_object_p
¶
-
int
mqtt_client_t::
state
¶
-
int
mqtt_client_t::
type
¶
-
void *
mqtt_client_t::
data_p
¶
-
struct mqtt_client_t::@48 mqtt_client_t::message
-
void *
mqtt_client_t::
out_p
¶
-
void *
mqtt_client_t::
in_p
¶
-
struct mqtt_client_t::@49 mqtt_client_t::transport
-
struct mqtt_client_t::@50 mqtt_client_t::control
-
mqtt_on_publish_t
mqtt_client_t::
on_publish
¶
-
mqtt_on_error_t
mqtt_client_t::
on_error
¶
-
const char *
- struct
- #include <mqtt_client.h>
MQTT application message.
Public Members
-
const char *
mqtt_application_message_t::
buf_p
¶
-
size_t
mqtt_application_message_t::
size
¶
-
struct mqtt_application_message_t::@51 mqtt_application_message_t::topic
-
const void *
mqtt_application_message_t::
buf_p
¶
-
struct mqtt_application_message_t::@52 mqtt_application_message_t::payload
-
mqtt_qos_t
mqtt_application_message_t::
qos
¶
-
const char *