File syn_mqtt.h¶
FileList > net > syn_mqtt.h
Go to the source code of this file
Lightweight MQTT 3.1.1 client.
#include "../common/syn_defs.h"#include "../port/syn_port_socket.h"#include "../pt/syn_pt.h"#include "../sched/syn_task.h"
Classes¶
| Type | Name |
|---|---|
| struct | SYN_MqttClient MQTT client context structure. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_MqttRxPhase Non-blocking packet reception states. |
| enum | SYN_MqttState MQTT client connection states. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_mqtt_init (SYN_MqttClient * client, const char * host, uint16_t port, const char * client_id, const char * username, const char * password, uint16_t keep_alive_s, uint8_t * rx_buf, size_t rx_buf_size, uint8_t * tx_buf, size_t tx_buf_size) Initialize the MQTT client. |
| SYN_Status | syn_mqtt_ping (SYN_MqttClient * client) Transmit an explicit MQTT PINGREQ packet. |
| SYN_Status | syn_mqtt_publish (SYN_MqttClient * client, const char * topic, const void * payload, size_t len, uint8_t qos, bool retain) Publish a message to a topic. |
| SYN_Status | syn_mqtt_subscribe (SYN_MqttClient * client, const char * topic, uint8_t qos) Subscribe to a topic. |
| SYN_PT_Status | syn_mqtt_task (SYN_PT * pt, SYN_Task * task) Cooperative task for driving the MQTT client. |
Public Types Documentation¶
enum SYN_MqttRxPhase¶
Non-blocking packet reception states.
enum SYN_MqttRxPhase {
SYN_MQTT_RX_IDLE,
SYN_MQTT_RX_REMAINING_LEN,
SYN_MQTT_RX_PAYLOAD,
SYN_MQTT_RX_DISCARD
};
enum SYN_MqttState¶
MQTT client connection states.
Public Functions Documentation¶
function syn_mqtt_init¶
Initialize the MQTT client.
SYN_Status syn_mqtt_init (
SYN_MqttClient * client,
const char * host,
uint16_t port,
const char * client_id,
const char * username,
const char * password,
uint16_t keep_alive_s,
uint8_t * rx_buf,
size_t rx_buf_size,
uint8_t * tx_buf,
size_t tx_buf_size
)
Configures broker destination, client ID, authentication credentials, keep-alive timing parameters, and network packet buffers.
Parameters:
clientPointer to client context.hostBroker network address string.portBroker port number.client_idMQTT client identity string.usernameAuthentication username (or NULL).passwordAuthentication password (or NULL).keep_alive_sKeep-alive timeout parameter in seconds.rx_bufReceive buffer storage.rx_buf_sizeReceive buffer capacity.tx_bufTransmit buffer storage.tx_buf_sizeTransmit buffer capacity.
Returns:
SYN_OK on successful configuration, or error parameter code.
function syn_mqtt_ping¶
Transmit an explicit MQTT PINGREQ packet.
Note: PINGREQ packets are sent automatically by syn_mqtt_task based on the configured keep_alive_s interval. This function allows manual pinging on demand.
Parameters:
clientPointer to client context.
Returns:
SYN_OK on success, SYN_ERROR if not connected or transmit failed.
function syn_mqtt_publish¶
Publish a message to a topic.
SYN_Status syn_mqtt_publish (
SYN_MqttClient * client,
const char * topic,
const void * payload,
size_t len,
uint8_t qos,
bool retain
)
Non-blocking publish command. For QoS 0, queued directly. For QoS 1, tracks acknowledgement state.
Parameters:
clientPointer to client context.topicTopic name to target.payloadData payload to send.lenPayload size in bytes.qosQuality of service level (0 or 1).retainRetain flag on broker.
Returns:
SYN_OK on queued, or error status if payload bounds exceeded.
function syn_mqtt_subscribe¶
Subscribe to a topic.
Formats and queues a subscription request for transmission.
Parameters:
clientPointer to client context.topicTopic filter string.qosRequested quality of service.
Returns:
SYN_OK on success.
function syn_mqtt_task¶
Cooperative task for driving the MQTT client.
Yields during connection, socket polling, keep-alive pinging, and packet parsing loops. Runs within the cooperative scheduler context.
Parameters:
ptCooperative protothread handle.taskCorresponding task control block.
Returns:
PT_WAITING or PT_EXITED status.
The documentation for this class was generated from the following file src/syntropic/net/syn_mqtt.h