SOIL C++
C++ Unified Device Interface
MQTT::Configuration Class Reference

MQTT publishing configuration. More...

#include <Configuration.h>

Public Member Functions

 Configuration ()
 Default constructor. More...
 
 Configuration (std::string filename)
 JSON Constructor. More...
 
 ~Configuration ()
 Destructor. More...
 
std::string uri ()
 URI Builder. More...
 

Public Attributes

std::string host
 Hostname of the MQTT broker. More...
 
int port
 Port of the MQTT broker. More...
 
std::string username
 Username for connecting to the MQTT broker. More...
 
std::string password
 Password for connecting to the MQTT broker. More...
 
bool clean_session
 Clean session flag. More...
 
std::string root
 MQTT root topic. More...
 
int keep_alive
 Keep alive interval in seconds. More...
 
int min_delay_ms
 Minimum delay between to messages in milliseconds. More...
 
int connection_timeout_s
 Connection timeout in seconds. More...
 
bool ssl
 Use secured connection. More...
 
bool verify
 Skip SSL verification. More...
 
bool websocket
 Use websocket protocol. More...
 
std::string path
 Websocket path. More...
 
std::string certificate_authority
 Path to CA PEM-file. More...
 

Detailed Description

Class acting as enhanced struct to accomodate all configuration options. Therefore all members are public to be directly accessible.

Definition at line 13 of file Configuration.h.

Constructor & Destructor Documentation

◆ Configuration() [1/2]

MQTT::Configuration::Configuration ( )

Default constructor applying the defaults documented.

Definition at line 8 of file Configuration.cpp.

◆ Configuration() [2/2]

MQTT::Configuration::Configuration ( std::string  filename)

Reads the configuration from a JSON-file. See the project assets for an example file.

Parameters
[in]filenamePath to JSON-file (absolute or relative).

Definition at line 27 of file Configuration.cpp.

◆ ~Configuration()

MQTT::Configuration::~Configuration ( )

Standard Destructor

Definition at line 49 of file Configuration.cpp.

Member Function Documentation

◆ uri()

std::string MQTT::Configuration::uri ( )

Builds an URI for the underlying Paho-MQTT library.

Returns
Full URI string, e.g. tcp://127.0.0.1:1883 .

Definition at line 53 of file Configuration.cpp.

Member Data Documentation

◆ certificate_authority

std::string MQTT::Configuration::certificate_authority

Path to a file containing the trusted certificate authorities in PEM-format for OpenSSL. This is mandatory when properly implementing secure MQTT.

Precondition
Make sure that the hostname used for connecting is matching its name in the certificate chain.

Definition at line 133 of file Configuration.h.

◆ clean_session

bool MQTT::Configuration::clean_session

Flag whether to start a clean MQTT session. Defaults to true .

Definition at line 55 of file Configuration.h.

◆ connection_timeout_s

int MQTT::Configuration::connection_timeout_s

Number of seconds to wait until the connection succeeds. This influence the length of the blocking call during connection. Defaults to 30 .

Definition at line 90 of file Configuration.h.

◆ host

std::string MQTT::Configuration::host

Adress or hostname of the MQTT broker. Can be an FQDN or IP address. Defaults to 127.0.0.1 .

Definition at line 22 of file Configuration.h.

◆ keep_alive

int MQTT::Configuration::keep_alive

Keep alive interval in seconds for the MQTT client. Defaults to 30 .

Definition at line 72 of file Configuration.h.

◆ min_delay_ms

int MQTT::Configuration::min_delay_ms

A minimum delay which should be kept between sending two messages, provided in milliseconds. Defaults to 0 .

Postcondition
This is not enforced in the client, but should be called as property of the publishing by the using code.

Definition at line 81 of file Configuration.h.

◆ password

std::string MQTT::Configuration::password

Password when connecting to the MQTT broker. Be mindful with passwords when committing to version control! Defaults to guest .

Definition at line 47 of file Configuration.h.

◆ path

std::string MQTT::Configuration::path

Websocket path that forms the last part of the URI, e.g. /mqtt-ws/. Defaults to "" .

Definition at line 124 of file Configuration.h.

◆ port

int MQTT::Configuration::port

Port to use for the MQTT broker. Defaults to 1883 in the constructor. Typical ports are 1883 (MQTT), 8883 (MQTT over TLS) and 443 (MQTT over secure websockets).

Definition at line 30 of file Configuration.h.

◆ root

std::string MQTT::Configuration::root

Root topic that is prepended to any published topic. This is intended for cases where permisions enfore that you publish under a defined root topic. The default is no root topic prefix.

Definition at line 64 of file Configuration.h.

◆ ssl

bool MQTT::Configuration::ssl

Boolean flag whether to use a secured connection (MQTT over TLS or secure websocket). Defaults to false .

Precondition
If not ignoring verification, trusted root certificated must be provided in a PEM-file.

Definition at line 99 of file Configuration.h.

◆ username

std::string MQTT::Configuration::username

Username when connecting to the MQTT broker. When using RabbitMQ, make sure to consider the VHOST prefix. Defaults to guest .

Definition at line 39 of file Configuration.h.

◆ verify

bool MQTT::Configuration::verify

Boolean flag whether to ignore SSL certificate validation, i.e. for hostname matching and trusted authority. This should only be used for basic development purposes.

Definition at line 107 of file Configuration.h.

◆ websocket

bool MQTT::Configuration::websocket

Boolean flag whether to use the websocket extension of MQTT. Make sure to specify the correct path. Defaults to false .

Definition at line 116 of file Configuration.h.


The documentation for this class was generated from the following files: