SELKIELogger  1.0.0
MQTTConnection.h File Reference
#include <stdbool.h>
#include "MQTTTypes.h"
#include "SELKIELoggerBase.h"
Include dependency graph for MQTTConnection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

mqtt_connmqtt_openConnection (const char *host, const int port, mqtt_queue_map *qm)
 Open and configure a connection to an MQTT server. More...
 
void mqtt_closeConnection (mqtt_conn *conn)
 Close MQTT server connection. More...
 
bool mqtt_subscribe_batch (mqtt_conn *conn, mqtt_queue_map *qm)
 Subscribe to all topics configured in a mqtt_queue_map. More...
 
void mqtt_enqueue_messages (mqtt_conn *conn, void *userdat_qm, const struct mosquitto_message *inmsg)
 MQTT callback: Accept incoming messages and process. More...
 
bool mqtt_victron_keepalive (mqtt_conn *conn, mqtt_queue_map *qm, char *sysid)
 Send MQTT keepalive commands required by Victron systems. More...
 

Detailed Description

MQTT connection handling

Definition in file MQTTConnection.h.

Function Documentation

◆ mqtt_closeConnection()

void mqtt_closeConnection ( mqtt_conn conn)

Close MQTT server connection.

Disconnects from server (if still connected), stops the mosquitto event loop and frees resources associated with the connection.

Parameters
[in,out]connConnection to close out

Definition at line 76 of file MQTTConnection.c.

◆ mqtt_enqueue_messages()

void mqtt_enqueue_messages ( mqtt_conn conn,
void *  userdat_qm,
const struct mosquitto_message *  inmsg 
)

MQTT callback: Accept incoming messages and process.

Registered with mosquitto as a message callback by mqtt_openConnection and called by the mosquitto event loop for every message matching our subscriptions.

If mqtt_queue_map.dumpall is true, messages not matching a configured topic will be queued under SLCHAN_RAW as strings with the format "topic: payload". Otherwise they will be ignored.

Zero length messages are never queued.

Parameters
[in]connPointer to MQTT Connection structure
[in]userdat_qmmqtt_queue_map - passed as void pointer by mosquitto library
[in]inmsgIncoming message

Definition at line 136 of file MQTTConnection.c.

◆ mqtt_openConnection()

mqtt_conn* mqtt_openConnection ( const char *  host,
const int  port,
mqtt_queue_map qm 
)

Open and configure a connection to an MQTT server.

Connects to the specified host and port, then configures it based on the configuration in an mqtt_queue_map instance. Sets mqtt_enqueue_messages as the callback for new messages and starts the mosquitto event loop.

Parameters
[in]hostHostname or IP address (as string)
[in]portPort number
[in]qmmqtt_queue_map instance to use for configuration
Returns
Pointer to mqtt_conn structure on success, NULL on error

Definition at line 38 of file MQTTConnection.c.

◆ mqtt_subscribe_batch()

bool mqtt_subscribe_batch ( mqtt_conn conn,
mqtt_queue_map qm 
)

Subscribe to all topics configured in a mqtt_queue_map.

Subscribes to all configured topics in an mqtt_queue_map using mosquitto_subscribe_multiple (if available) or by falling back to placing multiple individual subscription requests if not.

Parameters
[in]connPointer to MQTT Connection structure
[in]qmPointer to mqtt_queue_map
Returns
True on success, false on error

Definition at line 90 of file MQTTConnection.c.

◆ mqtt_victron_keepalive()

bool mqtt_victron_keepalive ( mqtt_conn conn,
mqtt_queue_map qm,
char *  sysid 
)

Send MQTT keepalive commands required by Victron systems.

Sends a keepalive request for all configured topics in the format required for Victron MQTT systems.

Parameters
[in]connPointer to MQTT Connection structure
[in]qmPointer to mqtt_queue_map
[in]sysidSystem serial number
Returns
True on success, false on error

Definition at line 191 of file MQTTConnection.c.